Skip to content

Commit

Permalink
Improved the user interface; made the xhtml exported valid
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuowei committed Apr 18, 2011
1 parent a52ddb8 commit 76267ab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 5 additions & 2 deletions brief2html.htm
@@ -1,12 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Brief2HTML</title>
<script src="briefs.js"></script>

<script src="brief2html.js"></script>
</head>
<body>
<textarea id="main-textarea" cols="80" rows="25"></textarea>
<button id="startbutton">Go!</button>
<button id="startbutton">Go!</button><br>
Output:<br>
<textarea id="output-textarea" cols="80" rows="25"></textarea>
<a id="output-link">Save</a>
</body>
</html>
14 changes: 12 additions & 2 deletions brief2html.js
@@ -1,4 +1,6 @@
var textArea;
var outputTextArea;
var outputLink;
var startButton;
var briefDom;
var BRIEF_PREFIX = "brief-"
Expand All @@ -7,17 +9,21 @@ var BRIEF_XHTML_DOCTYPE = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//

function init(){
textArea=document.getElementById("main-textarea");
outputTextArea=document.getElementById("output-textarea");
outputLink=document.getElementById("output-link");
startButton=document.getElementById("startbutton");
startButton.onclick=startParse;
}
function startParse(){
var briefXML = brief2html(textArea.value);
alert(briefXML);
outputTextArea.value = briefXML;
outputLink.href = "data:text/application/xhtml+xml," + encodeURIComponent(briefXML);
}
function brief2html(briefScriptText){
var parser = new BriefParser(briefScriptText);
var world = parser.parse();
alert(world);
//alert(world);
var doc = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null);
var head = document.createElementNS('http://www.w3.org/1999/xhtml', 'head');
doc.documentElement.appendChild(head);
Expand Down Expand Up @@ -58,11 +64,15 @@ function brief2html(briefScriptText){
var actorElem = doc.createElementNS('http://www.w3.org/1999/xhtml', "img");
//actorElem.setAttribute("id", BRIEF_PREFIX + "actor-"+escapeId(actor.name));
actorElem.setAttribute("class", BRIEF_PREFIX + "actor " + BRIEF_PREFIX + escapeId(actor.name));
actorElem.setAttribute("alt", "");
var actorstyle="left:"+actor.x+"px;top:"+actor.y+"px;width:"+actor.width+"px;" +
"height:"+actor.height+"px;";
if(actor.image){
actorElem.setAttribute("src", actor.image);
}
else{
actorElem.setAttribute("src", "");
}
if(!actor.visible){
actorstyle+="display:none;";
}
Expand All @@ -89,7 +99,7 @@ function getScript(action){
options[opt]=options[opt].trim();
jsOptionsStr = jsOptionsStr + "'" + options[opt] + "'" + (opt!=options.length-1? ",": "");
}
console.log(command + options);
//console.log(command + options);
switch(command){
case "move":
case "goto":
Expand Down
4 changes: 4 additions & 0 deletions brieflib.js
Expand Up @@ -9,6 +9,10 @@ var brief={
var actor = this.getActor(actorName);
actor.style.display = "";
},
"hide": function(actorName){
var actor = this.getActor(actorName);
actor.style.display = "none";
},
"toggle": function(actorName){
alert("The toggle function is not yet supported.");
},
Expand Down

0 comments on commit 76267ab

Please sign in to comment.