From 04e91245cbb831fc45cec0d2186cdb9137073fa6 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sat, 9 Jun 2012 18:36:32 +0100 Subject: [PATCH] Refactored macro mechanism Now there is now longer a dummy DOM element corresponding to the macro itself. Instead, macros must create a single element child. This allows us to more easily fit Bootstrap's requirements for HTML layout (eg, that problem with links in navbars not being recognised). The refactoring isn't complete, there are still a few bugs to chase down --- core/modules/macros/button.js | 5 +- core/modules/macros/chooser.js | 2 +- core/modules/macros/comment.js | 2 +- core/modules/macros/download.js | 5 +- core/modules/macros/echo.js | 2 +- core/modules/macros/edit/edit.js | 27 +++---- .../macros/edit/editors/bitmapeditor.js | 32 ++++----- .../modules/macros/edit/editors/texteditor.js | 18 ++--- core/modules/macros/image.js | 13 ++-- core/modules/macros/include.js | 6 +- core/modules/macros/link.js | 15 ++-- core/modules/macros/list.js | 10 ++- core/modules/macros/slider.js | 27 +++---- core/modules/macros/story/story.js | 11 +-- core/modules/macros/tiddler.js | 19 ++--- core/modules/macros/version.js | 2 +- core/modules/macros/video.js | 14 ++-- core/modules/macros/view.js | 16 ++--- core/modules/macros/zoomer.js | 2 +- core/modules/treenodes/element.js | 11 --- core/modules/treenodes/macro.js | 71 +++++-------------- core/modules/treenodes/node.js | 7 -- 22 files changed, 134 insertions(+), 183 deletions(-) diff --git a/core/modules/macros/button.js b/core/modules/macros/button.js index 6f12abcc2..e31036f1b 100644 --- a/core/modules/macros/button.js +++ b/core/modules/macros/button.js @@ -40,7 +40,10 @@ exports.executeMacro = function() { if(this.hasParameter("class")) { attributes["class"] = this.params["class"].split(" "); } - return [$tw.Tree.Element("button",attributes,[$tw.Tree.Text(this.params.label)])]; + if(this.classes) { + $tw.utils.pushTop(attributes["class"],this.classes); + } + return $tw.Tree.Element("button",attributes,[$tw.Tree.Text(this.params.label)]); }; })(); diff --git a/core/modules/macros/chooser.js b/core/modules/macros/chooser.js index 8a217d788..ef1ee78c4 100644 --- a/core/modules/macros/chooser.js +++ b/core/modules/macros/chooser.js @@ -149,7 +149,7 @@ exports.handleEvent = function(event) { exports.executeMacro = function() { this.chooserDisplayed = false; - return []; + return $tw.Tree.Element("div",{},[]); }; })(); diff --git a/core/modules/macros/comment.js b/core/modules/macros/comment.js index ed3c77fa5..bf4194db4 100644 --- a/core/modules/macros/comment.js +++ b/core/modules/macros/comment.js @@ -18,7 +18,7 @@ exports.info = { }; exports.executeMacro = function() { - return []; + return null; }; diff --git a/core/modules/macros/download.js b/core/modules/macros/download.js index 0f9416974..8d0586fe0 100644 --- a/core/modules/macros/download.js +++ b/core/modules/macros/download.js @@ -47,7 +47,10 @@ exports.executeMacro = function() { } else { content.push($tw.Tree.Text("Download \"" + this.downloadFilename + "\"")); } - return [$tw.Tree.Element("button",attributes,content)]; + if(this.classes) { + attributes["class"] = this.classes.slice(0); + } + return $tw.Tree.Element("button",attributes,content); }; })(); diff --git a/core/modules/macros/echo.js b/core/modules/macros/echo.js index 0eafd79f2..713d4ed32 100644 --- a/core/modules/macros/echo.js +++ b/core/modules/macros/echo.js @@ -20,7 +20,7 @@ exports.info = { }; exports.executeMacro = function() { - return [$tw.Tree.Text(this.params.text)]; + return $tw.Tree.Text(this.params.text); }; diff --git a/core/modules/macros/edit/edit.js b/core/modules/macros/edit/edit.js index 3c3debd90..a71e80d76 100644 --- a/core/modules/macros/edit/edit.js +++ b/core/modules/macros/edit/edit.js @@ -35,11 +35,9 @@ exports.executeMacro = function() { } this.editor = new Editor(this); // Call the editor to generate the child nodes - var children = this.editor.getChildren(); - for(var t=0; t;base64," - var dataURL = this.macroNode.children[0].domNode.toDataURL(tiddler.fields.type,1.0), + var dataURL = this.macroNode.child.domNode.toDataURL(tiddler.fields.type,1.0), posColon = dataURL.indexOf(":"), posSemiColon = dataURL.indexOf(";"), posComma = dataURL.indexOf(","), diff --git a/core/modules/macros/edit/editors/texteditor.js b/core/modules/macros/edit/editors/texteditor.js index 2c10c56a5..bdfd160a9 100644 --- a/core/modules/macros/edit/editors/texteditor.js +++ b/core/modules/macros/edit/editors/texteditor.js @@ -16,7 +16,7 @@ function TextEditor(macroNode) { this.macroNode = macroNode; } -TextEditor.prototype.getChildren = function() { +TextEditor.prototype.getChild = function() { var tiddler = this.macroNode.wiki.getTiddler(this.macroNode.tiddlerTitle), field = this.macroNode.hasParameter("field") ? this.macroNode.params.field : "title", value; @@ -48,12 +48,12 @@ TextEditor.prototype.getChildren = function() { attributes.type = "text"; attributes.value = value; } - return [$tw.Tree.Element(tagName,attributes,content)]; + return $tw.Tree.Element("div",{},[$tw.Tree.Element(tagName,attributes,content)]); }; TextEditor.prototype.addEventHandlers = function() { - this.macroNode.domNode.addEventListener("focus",this,false); - this.macroNode.domNode.addEventListener("keyup",this,false); + this.macroNode.child.domNode.addEventListener("focus",this,false); + this.macroNode.child.domNode.addEventListener("keyup",this,false); }; TextEditor.prototype.handleEvent = function(event) { @@ -70,7 +70,7 @@ TextEditor.prototype.handleEvent = function(event) { }; TextEditor.prototype.saveChanges = function() { - var text = this.macroNode.children[0].domNode.value, + var text = this.macroNode.child.children[0].domNode.value, tiddler = this.macroNode.wiki.getTiddler(this.macroNode.tiddlerTitle); if(tiddler && text !== tiddler.fields[this.macroNode.params.field]) { var update = {}; @@ -80,9 +80,9 @@ TextEditor.prototype.saveChanges = function() { }; TextEditor.prototype.fixHeight = function() { - if(this.macroNode.children[0] && this.macroNode.children[0].domNode) { - var wrapper = this.macroNode.domNode, - textarea = this.macroNode.children[0].domNode; + if(this.macroNode.child && this.macroNode.child.domNode) { + var wrapper = this.macroNode.child.domNode, + textarea = this.macroNode.child.children[0].domNode; // Set the text area height to 1px temporarily, which allows us to read the true scrollHeight var prevWrapperHeight = wrapper.style.height; wrapper.style.height = textarea.style.height + "px"; @@ -99,7 +99,7 @@ TextEditor.prototype.postRenderInDom = function() { TextEditor.prototype.isRefreshable = function() { // Don't refresh the editor if it contains the caret or selection - return document.activeElement !== this.macroNode.children[0].domNode; + return document.activeElement !== this.macroNode.child.children[0].domNode; }; exports["text/x-tiddlywiki"] = TextEditor; diff --git a/core/modules/macros/image.js b/core/modules/macros/image.js index 1c7e00d38..056741f5d 100644 --- a/core/modules/macros/image.js +++ b/core/modules/macros/image.js @@ -24,24 +24,21 @@ exports.info = { exports.executeMacro = function() { if(this.wiki.tiddlerExists(this.params.src)) { var imageTree = this.wiki.parseTiddler(this.params.src).tree, - cloneImage = []; - for(var t=0; t