diff --git a/2bld.sh b/2bld.sh index b432c3a9d..d95a7d5a9 100755 --- a/2bld.sh +++ b/2bld.sh @@ -11,7 +11,7 @@ mkdir -p tmp/tw2 node ./tiddlywiki.js \ editions/tw5.com \ --verbose \ - --rendertiddler TiddlyWiki2ReadMe editions/tw2/readme.md text/html \ + --new_rendertiddler TiddlyWiki2ReadMe editions/tw2/readme.md text/html \ || exit 1 # cook the TiddlyWiki 2.x.x index file @@ -20,7 +20,7 @@ node ./tiddlywiki.js \ editions/tw2 \ --verbose \ --load editions/tw2/source/tiddlywiki.com/index.html.recipe \ - --rendertiddler $:/core/templates/tiddlywiki2.template.html ./tmp/tw2/index.html text/plain \ + --new_rendertiddler $:/core/templates/tiddlywiki2.template.html ./tmp/tw2/index.html text/plain \ || exit 1 -opendiff tmp/tw2/index.html editions/tw2/target/index.2.6.5.html +diff -q tmp/tw2/index.html editions/tw2/target/prebuilt.html diff --git a/bld.sh b/bld.sh index 94b9092d0..40436ffe4 100755 --- a/bld.sh +++ b/bld.sh @@ -35,12 +35,12 @@ rm $TW5_BUILD_OUTPUT/static/* node ./tiddlywiki.js \ ./editions/tw5.com \ --verbose \ - --rendertiddler ReadMe ./readme.md text/html \ - --rendertiddler ContributingTemplate ./contributing.md text/html \ - --rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/index.html text/plain \ - --rendertiddler $:/core/templates/static.template.html $TW5_BUILD_OUTPUT/static.html text/plain \ - --rendertiddler $:/core/templates/static.template.css $TW5_BUILD_OUTPUT/static/static.css text/plain \ - --rendertiddlers [!is[system]] $:/core/templates/static.tiddler.html $TW5_BUILD_OUTPUT/static text/plain \ + --new_rendertiddler ReadMe ./readme.md text/html \ + --new_rendertiddler ContributingTemplate ./contributing.md text/html \ + --new_rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/index.html text/plain \ + --new_rendertiddler $:/core/templates/static.template.html $TW5_BUILD_OUTPUT/static.html text/plain \ + --new_rendertiddler $:/core/templates/static.template.css $TW5_BUILD_OUTPUT/static/static.css text/plain \ + --new_rendertiddlers [!is[system]] $:/core/templates/static.tiddler.html $TW5_BUILD_OUTPUT/static text/plain \ || exit 1 # Second, encrypted.html: a version of the main file encrypted with the password "password" @@ -49,7 +49,7 @@ node ./tiddlywiki.js \ ./editions/tw5.com \ --verbose \ --password password \ - --rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/encrypted.html text/plain \ + --new_rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/encrypted.html text/plain \ || exit 1 # Third, empty.html: empty wiki for reuse @@ -57,7 +57,7 @@ node ./tiddlywiki.js \ node ./tiddlywiki.js \ ./editions/empty \ --verbose \ - --rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/empty.html text/plain \ + --new_rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/empty.html text/plain \ || exit 1 # Fourth, tahoelafs.html: empty wiki with plugin for Tahoe-LAFS @@ -65,7 +65,7 @@ node ./tiddlywiki.js \ node ./tiddlywiki.js \ ./editions/tahoelafs \ --verbose \ - --rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/tahoelafs.html text/plain \ + --new_rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/tahoelafs.html text/plain \ || exit 1 # Fifth, d3demo.html: wiki to demo d3 plugin @@ -73,7 +73,7 @@ node ./tiddlywiki.js \ node ./tiddlywiki.js \ ./editions/d3demo \ --verbose \ - --rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/d3demo.html text/plain \ + --new_rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/d3demo.html text/plain \ || exit 1 # Sixth, run the test edition to run the node.js tests and to generate test.html for tests in the browser diff --git a/core/modules/commands/rendertiddler.js b/core/modules/commands/rendertiddler.js deleted file mode 100644 index b63d9855d..000000000 --- a/core/modules/commands/rendertiddler.js +++ /dev/null @@ -1,44 +0,0 @@ -/*\ -title: $:/core/modules/commands/rendertiddler.js -type: application/javascript -module-type: command - -Command to render a tiddler and save it to a file - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -exports.info = { - name: "rendertiddler", - synchronous: false -}; - -var Command = function(params,commander,callback) { - this.params = params; - this.commander = commander; - this.callback = callback; -}; - -Command.prototype.execute = function() { - if(this.params.length < 2) { - return "Missing filename"; - } - var self = this, - fs = require("fs"), - path = require("path"), - title = this.params[0], - filename = this.params[1], - type = this.params[2] || "text/html"; - fs.writeFile(filename,this.commander.wiki.renderTiddler(type,title),"utf8",function(err) { - self.callback(err); - }); - return null; -}; - -exports.Command = Command; - -})(); diff --git a/core/modules/commands/rendertiddlers.js b/core/modules/commands/rendertiddlers.js deleted file mode 100644 index 1bb1fa448..000000000 --- a/core/modules/commands/rendertiddlers.js +++ /dev/null @@ -1,54 +0,0 @@ -/*\ -title: $:/core/modules/commands/rendertiddlers.js -type: application/javascript -module-type: command - -Command to render several tiddlers to a folder of files - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -exports.info = { - name: "rendertiddlers", - synchronous: true -}; - -var Command = function(params,commander,callback) { - this.params = params; - this.commander = commander; - this.callback = callback; -}; - -Command.prototype.execute = function() { - if(this.params.length < 2) { - return "Missing filename"; - } - var self = this, - fs = require("fs"), - path = require("path"), - wiki = this.commander.wiki, - filter = this.params[0], - template = this.params[1], - pathname = this.params[2], - type = this.params[3] || "text/html", - extension = this.params[4] || ".html", - parser = wiki.parseTiddler(template), - tiddlers = wiki.filterTiddlers(filter); - $tw.utils.each(tiddlers,function(title) { - var renderTree = new $tw.WikiRenderTree(parser,{wiki: wiki, context: {tiddlerTitle: title}, document: $tw.document}); - renderTree.execute(); - var container = $tw.document.createElement("div"); - renderTree.renderInDom(container); - var text = type === "text/html" ? container.innerHTML : container.textContent; - fs.writeFileSync(path.resolve(pathname,encodeURIComponent(title) + extension),text,"utf8"); - }); - return null; -}; - -exports.Command = Command; - -})(); diff --git a/core/modules/rendertree/renderers/element.js b/core/modules/rendertree/renderers/element.js deleted file mode 100644 index 722e24db8..000000000 --- a/core/modules/rendertree/renderers/element.js +++ /dev/null @@ -1,212 +0,0 @@ -/*\ -title: $:/core/modules/rendertree/renderers/element.js -type: application/javascript -module-type: wikirenderer - -Element renderer - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -/* -Element widget. A degenerate widget that renders ordinary HTML elements -*/ -var ElementWidget = function(renderer) { - this.renderer = renderer; - this.tag = this.renderer.parseTreeNode.tag; - this.attributes = this.renderer.attributes; - this.children = this.renderer.renderTree.createRenderers(this.renderer,this.renderer.parseTreeNode.children); - this.events = this.renderer.parseTreeNode.events; -}; - -ElementWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) { - // Check if any of our attribute dependencies have changed - if($tw.utils.count(changedAttributes) > 0) { - // Update our attributes - this.renderer.assignAttributes(); - } - // Refresh any child nodes - $tw.utils.each(this.children,function(node) { - if(node.refreshInDom) { - node.refreshInDom(changedTiddlers); - } - }); -}; - -/* -Element renderer -*/ -var ElementRenderer = function(renderTree,parentRenderer,parseTreeNode) { - // Store state information - this.renderTree = renderTree; - this.parentRenderer = parentRenderer; - this.parseTreeNode = parseTreeNode; - // Initialise widget classes - if(!this.widgetClasses) { - ElementRenderer.prototype.widgetClasses = $tw.modules.applyMethods("widget"); - } - // Select the namespace for the tag - var tagNameSpaces = { - svg: "http://www.w3.org/2000/svg", - math: "http://www.w3.org/1998/Math/MathML" - }; - this.namespace = tagNameSpaces[this.parseTreeNode.tag]; - if(this.namespace) { - this.context = this.context || {}; - this.context.namespace = this.namespace; - } else { - this.namespace = this.renderTree.getContextVariable(this.parentRenderer,"namespace","http://www.w3.org/1999/xhtml"); - } - // Get the context tiddler title - this.tiddlerTitle = this.renderTree.getContextVariable(this.parentRenderer,"tiddlerTitle"); - // Compute our dependencies - this.dependencies = {}; - var self = this; - $tw.utils.each(this.parseTreeNode.attributes,function(attribute,name) { - if(attribute.type === "indirect") { - var tr = $tw.utils.parseTextReference(attribute.textReference); - self.dependencies[tr.title ? tr.title : self.tiddlerTitle] = true; - } - }); - // Compute our attributes - this.attributes = {}; - this.computeAttributes(); - // Create the parasite widget object if required - if(this.parseTreeNode.tag.charAt(0) === "$") { - // Choose the class - var WidgetClass = this.widgetClasses[this.parseTreeNode.tag.substr(1)]; - // Instantiate the widget - if(WidgetClass) { - this.widget = new WidgetClass(this); - } else { - WidgetClass = this.widgetClasses.error; - if(WidgetClass) { - this.widget = new WidgetClass(this,"Unknown widget '<" + this.parseTreeNode.tag + ">'"); - } - } - } - // If we haven't got a widget, use the generic HTML element widget - if(!this.widget) { - this.widget = new ElementWidget(this); - } -}; - -ElementRenderer.prototype.computeAttributes = function() { - var changedAttributes = {}, - self = this, - value; - $tw.utils.each(this.parseTreeNode.attributes,function(attribute,name) { - if(attribute.type === "indirect") { - value = self.renderTree.wiki.getTextReference(attribute.textReference,"",self.tiddlerTitle); - } else if(attribute.type === "macro") { - // Get the macro definition - var macro = self.renderTree.findMacroDefinition(self.parentRenderer,attribute.value.name); - if(!macro) { - value = ""; - } else { - // Substitute the macro parameters - value = self.renderTree.substituteParameters(macro,attribute.value); - // Parse the text and render it as text - value = self.renderTree.wiki.renderText("text/plain","text/vnd.tiddlywiki",value,self.context); - } - } else { // String attribute - value = attribute.value; - } - // Check whether the attribute has changed - if(self.attributes[name] !== value) { - self.attributes[name] = value; - changedAttributes[name] = true; - } - }); - return changedAttributes; -}; - -ElementRenderer.prototype.hasAttribute = function(name) { - return $tw.utils.hop(this.attributes,name); -}; - -ElementRenderer.prototype.getAttribute = function(name,defaultValue) { - if($tw.utils.hop(this.attributes,name)) { - return this.attributes[name]; - } else { - return defaultValue; - } -}; - -ElementRenderer.prototype.renderInDom = function() { - // Check if our widget is providing an element - if(this.widget.tag) { - // Create the element - this.domNode = this.renderTree.document.createElementNS(this.namespace,this.widget.tag); - // Assign any specified event handlers - $tw.utils.addEventListeners(this.domNode,this.widget.events); - // Assign the attributes - this.assignAttributes(); - // Render any child nodes - var self = this; - $tw.utils.each(this.widget.children,function(node) { - if(node.renderInDom) { - self.domNode.appendChild(node.renderInDom()); - } - }); - // Call postRenderInDom if the widget provides it and we're in the browser - if($tw.browser && this.widget.postRenderInDom) { - this.widget.postRenderInDom(); - } - // Return the dom node - return this.domNode; - } else { - // If we're not generating an element, just render our first child - return this.widget.children[0].renderInDom(); - } -}; - -ElementRenderer.prototype.assignAttributes = function() { - var self = this; - $tw.utils.each(this.widget.attributes,function(v,a) { - if(v !== undefined) { - if($tw.utils.isArray(v)) { // Ahem, could there be arrays other than className? - self.domNode.className = v.join(" "); - } else if (typeof v === "object") { // ...or objects other than style? - for(var p in v) { - self.domNode.style[$tw.utils.unHyphenateCss(p)] = v[p]; - } - } else { - // Setting certain attributes can cause a DOM error (eg xmlns on the svg element) - try { - self.domNode.setAttributeNS(null,a,v); - } catch(e) { - } - } - } - }); -}; - -ElementRenderer.prototype.refreshInDom = function(changedTiddlers) { - // Update our attributes if required - var changedAttributes = {}; - if($tw.utils.checkDependencies(this.dependencies,changedTiddlers)) { - changedAttributes = this.computeAttributes(); - } - // Check if the widget has a refreshInDom method - if(this.widget.refreshInDom) { - // Let the widget refresh itself - this.widget.refreshInDom(changedAttributes,changedTiddlers); - } else { - // If not, assign the attributes and refresh any child nodes - this.assignAttributes(); - $tw.utils.each(this.widget.children,function(node) { - if(node.refreshInDom) { - node.refreshInDom(changedTiddlers); - } - }); - } -}; - -exports.element = ElementRenderer - -})(); diff --git a/core/modules/rendertree/renderers/entity.js b/core/modules/rendertree/renderers/entity.js deleted file mode 100644 index 7556513f7..000000000 --- a/core/modules/rendertree/renderers/entity.js +++ /dev/null @@ -1,31 +0,0 @@ -/*\ -title: $:/core/modules/rendertree/renderers/entity.js -type: application/javascript -module-type: wikirenderer - -Entity renderer - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -/* -Entity renderer -*/ -var EntityRenderer = function(renderTree,parentRenderer,parseTreeNode) { - // Store state information - this.renderTree = renderTree; - this.parentRenderer = parentRenderer; - this.parseTreeNode = parseTreeNode; -}; - -EntityRenderer.prototype.renderInDom = function() { - return this.renderTree.document.createTextNode($tw.utils.entityDecode(this.parseTreeNode.entity)); -}; - -exports.entity = EntityRenderer - -})(); diff --git a/core/modules/rendertree/renderers/macrocall.js b/core/modules/rendertree/renderers/macrocall.js deleted file mode 100644 index 1b9cfb3ca..000000000 --- a/core/modules/rendertree/renderers/macrocall.js +++ /dev/null @@ -1,65 +0,0 @@ -/*\ -title: $:/core/modules/rendertree/renderers/macrocall.js -type: application/javascript -module-type: wikirenderer - -Macro call renderer - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -/* -Macro call renderer -*/ -var MacroCallRenderer = function(renderTree,parentRenderer,parseTreeNode) { - // Store state information - this.renderTree = renderTree; - this.parentRenderer = parentRenderer; - this.parseTreeNode = parseTreeNode; - // Find the macro definition - var macro = this.renderTree.findMacroDefinition(this.parentRenderer,this.parseTreeNode.name); - // Insert an error message if we couldn't find the macro - var childTree; - if(!macro) { - childTree = [{type: "text", text: "<>"}]; - } else { - // Substitute the macro parameters - var text = this.renderTree.substituteParameters(macro,this.parseTreeNode); - // Parse the text - childTree = this.renderTree.wiki.parseText("text/vnd.tiddlywiki",text,{parseAsInline: !this.parseTreeNode.isBlock}).tree; - } - // Create the renderers for the child nodes - this.children = this.renderTree.createRenderers(this,childTree); -}; - -MacroCallRenderer.prototype.renderInDom = function() { - // Create the element - this.domNode = this.renderTree.document.createElement(this.parseTreeNode.isBlock ? "div" : "span"); - this.domNode.setAttribute("data-macro-name",this.parseTreeNode.name); - // Render any child nodes - var self = this; - $tw.utils.each(this.children,function(node,index) { - if(node.renderInDom) { - self.domNode.appendChild(node.renderInDom()); - } - }); - // Return the dom node - return this.domNode; -}; - -MacroCallRenderer.prototype.refreshInDom = function(changedTiddlers) { - // Refresh any child nodes - $tw.utils.each(this.children,function(node) { - if(node.refreshInDom) { - node.refreshInDom(changedTiddlers); - } - }); -}; - -exports.macrocall = MacroCallRenderer - -})(); diff --git a/core/modules/rendertree/renderers/macrodef.js b/core/modules/rendertree/renderers/macrodef.js deleted file mode 100644 index f7336a215..000000000 --- a/core/modules/rendertree/renderers/macrodef.js +++ /dev/null @@ -1,30 +0,0 @@ -/*\ -title: $:/core/modules/rendertree/renderers/macrodef.js -type: application/javascript -module-type: wikirenderer - -Macro definition renderer - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -/* -Macro definition renderer -*/ -var MacroDefRenderer = function(renderTree,parentRenderer,parseTreeNode) { - // Store state information - this.renderTree = renderTree; - this.parentRenderer = parentRenderer; - this.parseTreeNode = parseTreeNode; - // Save the macro definition into the context of the rendertree - this.renderTree.context.macroDefinitions = this.renderTree.context.macroDefinitions || {}; - this.renderTree.context.macroDefinitions[this.parseTreeNode.name] = this.parseTreeNode; -}; - -exports.macrodef = MacroDefRenderer - -})(); diff --git a/core/modules/rendertree/renderers/raw.js b/core/modules/rendertree/renderers/raw.js deleted file mode 100644 index 98c77e788..000000000 --- a/core/modules/rendertree/renderers/raw.js +++ /dev/null @@ -1,33 +0,0 @@ -/*\ -title: $:/core/modules/rendertree/renderers/raw.js -type: application/javascript -module-type: wikirenderer - -Raw HTML renderer - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -/* -Raw HTML renderer -*/ -var RawRenderer = function(renderTree,parentRenderer,parseTreeNode) { - // Store state information - this.renderTree = renderTree; - this.parentRenderer = parentRenderer; - this.parseTreeNode = parseTreeNode; -}; - -RawRenderer.prototype.renderInDom = function() { - var domNode = this.renderTree.document.createElement("div"); - domNode.innerHTML = this.parseTreeNode.html; - return domNode; -}; - -exports.raw = RawRenderer - -})(); diff --git a/core/modules/rendertree/renderers/text.js b/core/modules/rendertree/renderers/text.js deleted file mode 100644 index b915d938c..000000000 --- a/core/modules/rendertree/renderers/text.js +++ /dev/null @@ -1,31 +0,0 @@ -/*\ -title: $:/core/modules/rendertree/renderers/text.js -type: application/javascript -module-type: wikirenderer - -Text renderer - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -/* -Text renderer -*/ -var TextRenderer = function(renderTree,parentRenderer,parseTreeNode) { - // Store state information - this.renderTree = renderTree; - this.parentRenderer = parentRenderer; - this.parseTreeNode = parseTreeNode; -}; - -TextRenderer.prototype.renderInDom = function() { - return this.renderTree.document.createTextNode(this.parseTreeNode.text); -}; - -exports.text = TextRenderer - -})(); diff --git a/core/modules/rendertree/wikirendertree.js b/core/modules/rendertree/wikirendertree.js deleted file mode 100644 index dd7fc6b4c..000000000 --- a/core/modules/rendertree/wikirendertree.js +++ /dev/null @@ -1,198 +0,0 @@ -/*\ -title: $:/core/modules/rendertree/wikirendertree.js -type: application/javascript -module-type: global - -Wiki text render tree - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -/* -Create a render tree object for a parse tree - parser: reference to the parse tree to be rendered - options: see below -Options include: - wiki: mandatory reference to wiki associated with this render tree - context: optional hashmap of context variables (see below) - parentRenderer: optional reference to a parent renderer node for the context chain - document: optional document object to use instead of global document -Context variables include: - tiddlerTitle: title of the tiddler providing the context - templateTitle: title of the tiddler providing the current template - macroDefinitions: hashmap of macro definitions -*/ -var WikiRenderTree = function(parser,options) { - this.parser = parser; - this.wiki = options.wiki; - this.context = options.context || {}; - this.parentRenderer = options.parentRenderer; - this.document = options.document; - // Hashmap of the renderer classes - if(!this.rendererClasses) { - WikiRenderTree.prototype.rendererClasses = $tw.modules.applyMethods("wikirenderer"); - } -}; - -/* -Generate the full render tree for this parse tree -*/ -WikiRenderTree.prototype.execute = function() { - this.rendererTree = this.createRenderers(this,this.parser.tree); -}; - -/* -Create an array of renderers for an array of parse tree nodes -*/ -WikiRenderTree.prototype.createRenderers = function(parentRenderer,parseTreeNodes) { - var rendererNodes = []; - if(parseTreeNodes) { - for(var t=0; t - -<$checkbox tiddler="HelloThere" tag="red"/> - -<$checkbox tag="done"> -<$view field="title" format="link"/> - -``` - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var CheckboxWidget = function(renderer) { - // Save state - this.renderer = renderer; - // Generate child nodes - this.generate(); -}; - -CheckboxWidget.prototype.generate = function() { - // Get the parameters from the attributes - this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.tiddlerTitle); - this.tagName = this.renderer.getAttribute("tag"); - this["class"] = this.renderer.getAttribute("class"); - // Compute classes - var classes = ["tw-checkbox"]; - if(this["class"]) { - $tw.utils.pushTop(classes,this["class"]); - } - // Create the checkbox and span elements - var nodeCheckbox = { - type: "element", - tag: "input", - attributes: { - type: {type: "string", value: "checkbox"} - } - }, - nodeSpan = { - type: "element", - tag: "span", - children: this.renderer.parseTreeNode.children - }; - // Set the state of the checkbox - if(this.getValue()) { - $tw.utils.addAttributeToParseTreeNode(nodeCheckbox,"checked","true"); - } - // Set the return element - this.tag = "label"; - this.attributes ={"class": classes.join(" ")}; - this.children = this.renderer.renderTree.createRenderers(this.renderer,[nodeCheckbox,nodeSpan]); - this.events = [{name: "change", handlerObject: this, handlerMethod: "handleChangeEvent"}]; -}; - -CheckboxWidget.prototype.getValue = function() { - var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle); - return tiddler ? tiddler.hasTag(this.tagName) : false; -}; - -CheckboxWidget.prototype.handleChangeEvent = function(event) { - var checked = this.children[0].domNode.checked, - tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle); - if(tiddler && tiddler.hasTag(this.tagName) !== checked) { - var newTags = tiddler.fields.tags.slice(0), - pos = newTags.indexOf(this.tagName); - if(pos !== -1) { - newTags.splice(pos,1); - } - if(checked) { - newTags.push(this.tagName); - } - this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,{tags: newTags})); - } -}; - -CheckboxWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) { - // Check if any of our attributes have changed, or if a tiddler we're interested in has changed - if(changedAttributes.tiddler || changedAttributes.tag || changedAttributes["class"]) { - // Regenerate and rerender the widget and replace the existing DOM node - this.generate(); - var oldDomNode = this.renderer.domNode, - newDomNode = this.renderer.renderInDom(); - oldDomNode.parentNode.replaceChild(newDomNode,oldDomNode); - } else { - // Update the checkbox if necessary - if(changedTiddlers[this.tiddlerTitle]) { - this.children[0].domNode.checked = this.getValue(); - } - // Refresh children - $tw.utils.each(this.children,function(node) { - if(node.refreshInDom) { - node.refreshInDom(changedTiddlers); - } - }); - } -}; - -exports.checkbox = CheckboxWidget; - -})(); diff --git a/core/modules/widgets/count.js b/core/modules/widgets/count.js deleted file mode 100644 index 2c3770e70..000000000 --- a/core/modules/widgets/count.js +++ /dev/null @@ -1,59 +0,0 @@ -/*\ -title: $:/core/modules/widgets/count.js -type: application/javascript -module-type: widget - -Implements the count widget that displays the number of tiddlers that match a filter - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var CountWidget = function(renderer) { - // Save state - this.renderer = renderer; - // Execute the filter to get the initial count - this.executeFilter(); - // Generate child nodes - this.generate(); -}; - -CountWidget.prototype.executeFilter = function() { - // Get attributes - this.filter = this.renderer.getAttribute("filter"); - // Execute the filter - if(this.filter) { - this.currentCount = this.renderer.renderTree.wiki.filterTiddlers(this.filter,this.renderer.tiddlerTitle).length; - } else { - this.currentCount = undefined; - } -}; - -CountWidget.prototype.generate = function() { - // Set the element - this.tag = "span"; - this.attributes = {}; - this.children = this.renderer.renderTree.createRenderers(this.renderer,[ - {type: "text", text: this.currentCount !== undefined ? this.currentCount.toString() : ""} - ]); -}; - -CountWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) { - // Re-execute the filter to get the count - var oldCount = this.currentCount; - this.executeFilter(); - if(this.currentCount !== oldCount) { - // Regenerate and rerender the widget and replace the existing DOM node - this.generate(); - var oldDomNode = this.renderer.domNode, - newDomNode = this.renderer.renderInDom(); - oldDomNode.parentNode.replaceChild(newDomNode,oldDomNode); - } -}; - -exports.count = CountWidget; - -})(); diff --git a/core/modules/widgets/datauri.js b/core/modules/widgets/datauri.js deleted file mode 100644 index a7920cf54..000000000 --- a/core/modules/widgets/datauri.js +++ /dev/null @@ -1,53 +0,0 @@ -/*\ -title: $:/core/modules/widgets/datauri.js -type: application/javascript -module-type: widget - -The datauri widget displays the contents of a tiddler as a data URI. - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var DataUriWidget = function(renderer) { - // Save state - this.renderer = renderer; - // Generate child nodes - this.generate(); -}; - -DataUriWidget.prototype.generate = function() { - // Get parameters from our attributes - this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.tiddlerTitle); - // Compose the data URI - var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle), - uri = ""; - if(tiddler) { - var type = tiddler.fields.type || "text/vnd.tiddlywiki", - typeInfo = $tw.config.contentTypeInfo[type], - isBase64 = typeInfo && typeInfo.encoding === "base64", - parts = ["data:"]; - parts.push(type); - parts.push(isBase64 ? ";base64" : ""); - parts.push(","); - parts.push(isBase64 ? tiddler.fields.text : encodeURIComponent(tiddler.fields.text)); - uri = parts.join(""); - } - // Set the element - this.tag = "pre"; - this.attributes = { - "class": "tw-data-uri" - }; - // Create the renderers for the wrapper and the children - this.children = this.renderer.renderTree.createRenderers(this.renderer,[{ - type: "text", - text: uri - }]); -}; - -exports.datauri = DataUriWidget; - -})(); \ No newline at end of file diff --git a/core/modules/widgets/edit/edit.js b/core/modules/widgets/edit/edit.js deleted file mode 100644 index 74d64d0b9..000000000 --- a/core/modules/widgets/edit/edit.js +++ /dev/null @@ -1,87 +0,0 @@ -/*\ -title: $:/core/modules/widgets/edit/edit.js -type: application/javascript -module-type: widget - -The edit widget uses editor plugins to edit tiddlers of different types. - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var EditWidget = function(renderer) { - // Save state - this.renderer = renderer; - // Initialise the editors if they've not been done already - if(!this.editors) { - EditWidget.prototype.editors = {}; - $tw.modules.applyMethods("editor",this.editors); - } - // Generate child nodes - this.generate(); -}; - -EditWidget.prototype.generate = function() { - // Get parameters from our attributes - this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.tiddlerTitle); - this.fieldName = this.renderer.getAttribute("field"); - this.indexName = this.renderer.getAttribute("index"); - if(!this.fieldName && !this.indexName) { - this.fieldName = "text"; - } - // Choose the editor to use - // TODO: Tiddler field modules should be able to specify a field type from which the editor is derived - this.editorName = this.chooseEditor(); - var Editor = this.editors[this.editorName]; - // Instantiate the editor - this.editor = new Editor(this,this.tiddlerTitle,this.fieldName,this.indexName); - // Ask the editor to create the widget element - this.editor.render(); -}; - -/* -Return the name of the editor that should handle this tiddler field -*/ -EditWidget.prototype.chooseEditor = function() { - var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle); - if(this.fieldName === "text" && tiddler && tiddler.fields.type && this.editors[tiddler.fields.type]) { - return tiddler.fields.type; - } - return "text/vnd.tiddlywiki"; -}; - -EditWidget.prototype.postRenderInDom = function() { - if(this.editor && this.editor.postRenderInDom) { - this.editor.postRenderInDom(); - } -}; - -EditWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) { - // We'll completely regenerate ourselves if any of our attributes have changed - if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.format || this.chooseEditor() !== this.editorName) { - // Regenerate and rerender the widget and replace the existing DOM node - this.generate(); - var oldDomNode = this.renderer.domNode, - newDomNode = this.renderer.renderInDom(); - oldDomNode.parentNode.replaceChild(newDomNode,oldDomNode); - } else if(this.tiddlerTitle && changedTiddlers[this.tiddlerTitle]) { - // Refresh the editor if our tiddler has changed - if(this.editor && this.editor.refreshInDom) { - this.editor.refreshInDom(changedTiddlers); - } - } else { - // Otherwise, just refresh any child nodes - $tw.utils.each(this.children,function(node) { - if(node.refreshInDom) { - node.refreshInDom(changedTiddlers); - } - }); - } -}; - -exports.edit = EditWidget; - -})(); diff --git a/core/modules/widgets/edit/editors/bitmapeditor.js b/core/modules/widgets/edit/editors/bitmapeditor.js deleted file mode 100644 index c2882dbb0..000000000 --- a/core/modules/widgets/edit/editors/bitmapeditor.js +++ /dev/null @@ -1,318 +0,0 @@ -/*\ -title: $:/core/modules/widgets/edit/editors/bitmapeditor.js -type: application/javascript -module-type: editor - -A bitmap editor - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -// Default images sizes -var DEFAULT_IMAGE_WIDTH = 300, - DEFAULT_IMAGE_HEIGHT = 185; - -// The elements of the editor UI -var DOM_CANVAS = 0, - DOM_WIDTH = 1, - DOM_HEIGHT = 2; - -var BitmapEditor = function(editWidget,tiddlerTitle,fieldName,indexName) { - this.editWidget = editWidget; - this.tiddlerTitle = tiddlerTitle; - this.fieldName = fieldName; -}; - -BitmapEditor.prototype.render = function() { - // Set the element details - this.editWidget.tag = "div"; - this.editWidget.attributes = { - "class": "tw-edit-bitmapeditor-wrapper" - }; - var children = [{ - type: "element", - tag: "canvas", - attributes: { - "class": {type: "string", value: "tw-edit-bitmapeditor"} - }, - events: [{ - name: "touchstart", - handlerObject: this, - handlerMethod: "handleTouchStartEvent" - },{ - name: "touchmove", - handlerObject: this, - handlerMethod: "handleTouchMoveEvent" - },{ - name: "touchend", - handlerObject: this, - handlerMethod: "handleTouchEndEvent" - },{ - name: "mousedown", - handlerObject: this, - handlerMethod: "handleMouseDownEvent" - },{ - name: "mousemove", - handlerObject: this, - handlerMethod: "handleMouseMoveEvent" - },{ - name: "mouseup", - handlerObject: this, - handlerMethod: "handleMouseUpEvent" - }] - },{ - type: "element", - tag: "input", - attributes: { - "class": {type: "string", value: "tw-edit-bitmapeditor-width"}, - "type": {type: "string", value: "number"}, - "value": {type: "string", value: ""} - }, - events: [{ - name: "change", - handlerObject: this, - handlerMethod: "handleWidthChangeEvent" - }] - },{ - type: "element", - tag: "input", - attributes: { - "class": {type: "string", value: "tw-edit-bitmapeditor-height"}, - "type": {type: "string", value: "number"}, - "value": {type: "string", value: ""} - }, - events: [{ - name: "change", - handlerObject: this, - handlerMethod: "handleHeightChangeEvent" - }] - }]; - this.editWidget.children = this.editWidget.renderer.renderTree.createRenderers(this.editWidget.renderer,children); -}; - -BitmapEditor.prototype.postRenderInDom = function() { - var tiddler = this.editWidget.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle), - canvas = this.getDomNode(DOM_CANVAS), - currImage = new Image(); - // Set up event handlers for loading the image - var self = this; - currImage.onload = function() { - // Copy the image to the on-screen canvas - self.initCanvas(canvas,currImage.width,currImage.height,currImage); - // And also copy the current bitmap to the off-screen canvas - self.currCanvas = self.editWidget.renderer.renderTree.document.createElement("canvas"); - self.initCanvas(self.currCanvas,currImage.width,currImage.height,currImage); - // Set the width and height input boxes - self.updateSize(); - }; - currImage.onerror = function() { - // Set the on-screen canvas size and clear it - self.initCanvas(canvas,DEFAULT_IMAGE_WIDTH,DEFAULT_IMAGE_HEIGHT); - // Set the off-screen canvas size and clear it - self.currCanvas = self.editWidget.renderer.renderTree.document.createElement("canvas"); - self.initCanvas(self.currCanvas,DEFAULT_IMAGE_WIDTH,DEFAULT_IMAGE_HEIGHT); - // Set the width and height input boxes - self.updateSize(); - } - // Get the current bitmap into an image object - currImage.src = "data:" + tiddler.fields.type + ";base64," + tiddler.fields.text; -}; - -BitmapEditor.prototype.initCanvas = function(canvas,width,height,image) { - canvas.width = width; - canvas.height = height; - var ctx = canvas.getContext("2d"); - if(image) { - ctx.drawImage(image,0,0); - } else { - ctx.fillStyle = "#fff"; - ctx.fillRect(0,0,canvas.width,canvas.height); - } -} - -BitmapEditor.prototype.getDomNode = function(index) { - return this.editWidget.renderer.domNode.childNodes[index]; -}; - -/* -** Update the input boxes with the actual size of the canvas -*/ -BitmapEditor.prototype.updateSize = function() { - this.getDomNode(DOM_WIDTH).value = this.currCanvas.width; - this.getDomNode(DOM_HEIGHT).value = this.currCanvas.height; -}; - -/* -** Change the size of the canvas, preserving the current image -*/ -BitmapEditor.prototype.changeCanvasSize = function(newWidth,newHeight) { - // Create and size a new canvas - var newCanvas = this.editWidget.renderer.renderTree.document.createElement("canvas"); - this.initCanvas(newCanvas,newWidth,newHeight); - // Copy the old image - var ctx = newCanvas.getContext("2d"); - ctx.drawImage(this.currCanvas,0,0); - // Set the new canvas as the current one - this.currCanvas = newCanvas; - // Set the size of the onscreen canvas - var canvas = this.getDomNode(DOM_CANVAS); - canvas.width = newWidth; - canvas.height = newHeight; - // Paint the onscreen canvas with the offscreen canvas - ctx = canvas.getContext("2d"); - ctx.drawImage(this.currCanvas,0,0); -}; - -BitmapEditor.prototype.handleWidthChangeEvent = function(event) { - // Get the new width - var newWidth = parseInt(this.getDomNode(DOM_WIDTH).value,10); - // Update if necessary - if(newWidth > 0 && newWidth !== this.currCanvas.width) { - this.changeCanvasSize(newWidth,this.currCanvas.height); - } - // Update the input controls - this.updateSize(); -}; - -BitmapEditor.prototype.handleHeightChangeEvent = function(event) { - // Get the new width - var newHeight = parseInt(this.getDomNode(DOM_HEIGHT).value,10); - // Update if necessary - if(newHeight > 0 && newHeight !== this.currCanvas.height) { - this.changeCanvasSize(this.currCanvas.width,newHeight); - } - // Update the input controls - this.updateSize(); -}; - -BitmapEditor.prototype.handleTouchStartEvent = function(event) { - this.brushDown = true; - this.strokeStart(event.touches[0].clientX,event.touches[0].clientY); - event.preventDefault(); - event.stopPropagation(); - return false; -}; - -BitmapEditor.prototype.handleTouchMoveEvent = function(event) { - if(this.brushDown) { - this.strokeMove(event.touches[0].clientX,event.touches[0].clientY); - } - event.preventDefault(); - event.stopPropagation(); - return false; -}; - -BitmapEditor.prototype.handleTouchEndEvent = function(event) { - if(this.brushDown) { - this.brushDown = false; - this.strokeEnd(); - } - event.preventDefault(); - event.stopPropagation(); - return false; -}; - -BitmapEditor.prototype.handleMouseDownEvent = function(event) { - this.strokeStart(event.clientX,event.clientY); - this.brushDown = true; - event.preventDefault(); - event.stopPropagation(); - return false; -}; - -BitmapEditor.prototype.handleMouseMoveEvent = function(event) { - if(this.brushDown) { - this.strokeMove(event.clientX,event.clientY); - event.preventDefault(); - event.stopPropagation(); - return false; - } - return true; -}; - -BitmapEditor.prototype.handleMouseUpEvent = function(event) { - if(this.brushDown) { - this.brushDown = false; - this.strokeEnd(); - event.preventDefault(); - event.stopPropagation(); - return false; - } - return true; -}; - -BitmapEditor.prototype.adjustCoordinates = function(x,y) { - var canvas = this.getDomNode(DOM_CANVAS), - canvasRect = canvas.getBoundingClientRect(), - scale = canvas.width/canvasRect.width; - return {x: (x - canvasRect.left) * scale, y: (y - canvasRect.top) * scale}; -}; - -BitmapEditor.prototype.strokeStart = function(x,y) { - // Start off a new stroke - this.stroke = [this.adjustCoordinates(x,y)]; -}; - -BitmapEditor.prototype.strokeMove = function(x,y) { - var canvas = this.getDomNode(DOM_CANVAS), - ctx = canvas.getContext("2d"), - t; - // Add the new position to the end of the stroke - this.stroke.push(this.adjustCoordinates(x,y)); - // Redraw the previous image - ctx.drawImage(this.currCanvas,0,0); - // Render the stroke - ctx.strokeStyle = "#ff0"; - ctx.lineWidth = 3; - ctx.lineCap = "round"; - ctx.lineJoin = "round"; - ctx.beginPath(); - ctx.moveTo(this.stroke[0].x,this.stroke[0].y); - for(t=1; t;base64," - var dataURL = this.getDomNode(DOM_CANVAS).toDataURL(tiddler.fields.type,1.0), - posColon = dataURL.indexOf(":"), - posSemiColon = dataURL.indexOf(";"), - posComma = dataURL.indexOf(","), - type = dataURL.substring(posColon+1,posSemiColon), - text = dataURL.substring(posComma+1); - var update = {type: type, text: text}; - this.editWidget.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,update)); - } -}; - -/* -Note that the bitmap editor intentionally doesn't have a refreshInDom method to avoid the situation where a bitmap being editted is modified externally -*/ - -exports["image/jpg"] = BitmapEditor; -exports["image/jpeg"] = BitmapEditor; -exports["image/png"] = BitmapEditor; -exports["image/gif"] = BitmapEditor; - -})(); diff --git a/core/modules/widgets/edit/editors/texteditor.js b/core/modules/widgets/edit/editors/texteditor.js deleted file mode 100644 index 52c1db49d..000000000 --- a/core/modules/widgets/edit/editors/texteditor.js +++ /dev/null @@ -1,219 +0,0 @@ -/*\ -title: $:/core/modules/widgets/edit/editors/texteditor.js -type: application/javascript -module-type: editor - -A plain text editor - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var MIN_TEXT_AREA_HEIGHT = 100; - -var TextEditor = function(editWidget,tiddlerTitle,fieldName,indexName) { - this.editWidget = editWidget; - this.tiddlerTitle = tiddlerTitle; - this.fieldName = fieldName; - this.indexName = indexName; -}; - -/* -Get the tiddler being edited and current value -*/ -TextEditor.prototype.getEditInfo = function() { - var tiddler = this.editWidget.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle), - value; - if(this.fieldName) { - // Get the current tiddler and the field name - if(tiddler) { - // If we've got a tiddler, the value to display is the field string value - value = tiddler.getFieldString(this.fieldName); - } else { - // Otherwise, we need to construct a default value for the editor - switch(this.fieldName) { - case "text": - value = "Type the text for the tiddler '" + this.tiddlerTitle + "'"; - break; - case "title": - value = this.tiddlerTitle; - break; - default: - value = ""; - break; - } - value = this.editWidget.renderer.getAttribute("default",value); - } - } else { - value = this.editWidget.renderer.renderTree.wiki.extractTiddlerDataItem(this.tiddlerTitle,this.indexName,this.editWidget.renderer.getAttribute("default")); - } - return {tiddler: tiddler, value: value}; -}; - -TextEditor.prototype.render = function() { - // Get the initial value of the editor - var editInfo = this.getEditInfo(); - // Create the editor nodes - var node = { - type: "element", - attributes: {} - }; - // Get the edit type associated with this field - var type = "input"; - if(this.fieldName === "text") { - type = "textarea"; - } else { - var fieldModule = $tw.Tiddler.fieldModules[this.fieldName]; - if(fieldModule && fieldModule.editType) { - type = fieldModule.editType; - } - } - var type = this.editWidget.renderer.getAttribute("type",type); - switch(type) { - case "textarea": - node.tag = "textarea"; - node.children = [{ - type: "text", - text: editInfo.value - }]; - break; - case "color": - node.tag = "input"; - node.attributes.type = {type: "string", value: "color"}; - node.attributes.value = {type: "string", value: editInfo.value}; - break; - case "search": - node.tag = "input"; - node.attributes.type = {type: "string", value: "search"}; - node.attributes.value = {type: "string", value: editInfo.value}; - break; - default: // "input" - node.tag = "input"; - node.attributes.type = {type: "string", value: "text"}; - node.attributes.value = {type: "string", value: editInfo.value}; - break; - } - node.events = [ - {name: "focus", handlerObject: this, handlerMethod: "handleFocusEvent"}, - {name: "blur", handlerObject: this, handlerMethod: "handleBlurEvent"}, - {name: "input", handlerObject: this, handlerMethod: "handleInputEvent"} - ]; - // Add a placeholder if specified - if(this.editWidget.renderer.hasAttribute("placeholder")) { - node.attributes.placeholder = {type: "string", value: this.editWidget.renderer.getAttribute("placeholder")}; - } - // Set the element details - this.editWidget.tag = this.editWidget.renderer.parseTreeNode.isBlock ? "div" : "span"; - this.editWidget.attributes = { - "class": "tw-edit-texteditor" - }; - if(this.editWidget.renderer.hasAttribute("class")) { - this.editWidget.attributes["class"] += " " + this.editWidget.renderer.getAttribute("class"); - } - if(this.editWidget.renderer.hasAttribute("style")) { - this.editWidget.attributes.style = this.editWidget.attributes.style || ""; - this.editWidget.attributes.style += this.editWidget.renderer.getAttribute("style"); - } - this.editWidget.children = this.editWidget.renderer.renderTree.createRenderers(this.editWidget.renderer,[node]); -}; - -TextEditor.prototype.setFocus = function() { - if(this.editWidget.renderer.hasAttribute("focusSet")) { - var title = this.editWidget.renderer.getAttribute("focusSet"); - if(this.editWidget.renderer.getAttribute("qualifyTiddlerTitles") === "yes") { - title = title + "-" + this.editWidget.renderer.renderTree.getContextScopeId(this.editWidget.renderer.parentRenderer); - } - $tw.popup.triggerPopup({ - domNode: this.editWidget.renderer.domNode, - title: title, - wiki: this.editWidget.renderer.renderTree.wiki, - force: true - }); - } -}; - -TextEditor.prototype.handleFocusEvent = function(event) { -// this.saveChanges(); -// this.fixHeight(); - this.setFocus(); - return true; -}; - -TextEditor.prototype.handleBlurEvent = function(event) { -// this.saveChanges(); - return true; -}; - -TextEditor.prototype.handleInputEvent = function(event) { - this.saveChanges(); - this.fixHeight(); - return true; -}; - -TextEditor.prototype.saveChanges = function() { - var text = this.editWidget.children[0].domNode.value - if(this.fieldName) { - var tiddler = this.editWidget.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle); - if(!tiddler) { - tiddler = new $tw.Tiddler({title: this.tiddlerTitle}); - } - var oldValue = tiddler.getFieldString(this.fieldName); - if(text !== oldValue) { - var update = {}; - update[this.fieldName] = text; - this.editWidget.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,update)); - } - } else { - var data = this.editWidget.renderer.renderTree.wiki.getTiddlerData(this.tiddlerTitle,{}); - if(data[this.indexName] !== text) { - data[this.indexName] = text; - this.editWidget.renderer.renderTree.wiki.setTiddlerData(this.tiddlerTitle,data); - } - } -}; - -TextEditor.prototype.fixHeight = function() { - var self = this; - if(this.editWidget.children[0].domNode && this.editWidget.children[0].domNode.type === "textarea") { - $tw.utils.nextTick(function() { - // Resize the textarea to fit its content - var textarea = self.editWidget.children[0].domNode, - scrollPosition = $tw.utils.getScrollPosition(), - scrollTop = scrollPosition.y; - // Set its height to auto so that it snaps to the correct height - textarea.style.height = "auto"; - // Calculate the revised height - var newHeight = Math.max(textarea.scrollHeight + textarea.offsetHeight - textarea.clientHeight,MIN_TEXT_AREA_HEIGHT); - // Only try to change the height if it has changed - if(newHeight !== textarea.offsetHeight) { - textarea.style.height = newHeight + "px"; - // Make sure that the dimensions of the textarea are recalculated - $tw.utils.forceLayout(textarea); - // Check that the scroll position is still visible before trying to scroll back to it - scrollTop = Math.min(scrollTop,self.editWidget.renderer.renderTree.document.body.scrollHeight - window.innerHeight); - window.scrollTo(scrollPosition.x,scrollTop); - } - }); - } -}; - -TextEditor.prototype.postRenderInDom = function() { - this.fixHeight(); -}; - -TextEditor.prototype.refreshInDom = function() { - if(this.editWidget.renderer.renderTree.document.activeElement !== this.editWidget.children[0].domNode) { - var editInfo = this.getEditInfo(); - this.editWidget.children[0].domNode.value = editInfo.value; - } - // Fix the height if needed - this.fixHeight(); -}; - -exports["text/vnd.tiddlywiki"] = TextEditor; -exports["text/plain"] = TextEditor; - -})(); diff --git a/core/modules/widgets/encrypt.js b/core/modules/widgets/encrypt.js deleted file mode 100644 index 342a95027..000000000 --- a/core/modules/widgets/encrypt.js +++ /dev/null @@ -1,51 +0,0 @@ -/*\ -title: $:/core/modules/widgets/encrypt.js -type: application/javascript -module-type: widget - -Implements the encrypt widget. - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var EncryptWidget = function(renderer) { - // Save state - this.renderer = renderer; - // Generate child nodes - this.generate(); -}; - -EncryptWidget.prototype.generate = function() { - // Get the parameters from the attributes - this.filter = this.renderer.getAttribute("filter"); - // Check whether we've got an encryption password - var isEncrypted = $tw.crypto.hasPassword(); - // Encrypt the filtered tiddlers - var tiddlers = this.renderer.renderTree.wiki.filterTiddlers(this.filter), - json = {}, - self = this; - $tw.utils.each(tiddlers,function(title) { - var tiddler = self.renderer.renderTree.wiki.getTiddler(title), - jsonTiddler = {}; - for(var f in tiddler.fields) { - jsonTiddler[f] = tiddler.getFieldString(f); - } - json[title] = jsonTiddler; - }); - var encryptedText = $tw.utils.htmlEncode($tw.crypto.encrypt(JSON.stringify(json))); - // Set the return element - this.tag = "pre"; - this.attributes ={"class": "tw-encrypt"}; - this.children = this.renderer.renderTree.createRenderers(this.renderer,[{ - type: "text", - text: encryptedText - }]); -}; - -exports.encrypt = EncryptWidget; - -})(); diff --git a/core/modules/widgets/error.js b/core/modules/widgets/error.js deleted file mode 100644 index cd722bc45..000000000 --- a/core/modules/widgets/error.js +++ /dev/null @@ -1,37 +0,0 @@ -/*\ -title: $:/core/modules/widgets/error.js -type: application/javascript -module-type: widget - -The error widget displays an error message. - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var ErrorWidget = function(renderer,errorMessage) { - // Save state - this.renderer = renderer; - this.errorMessage = errorMessage; - // Generate child nodes - this.generate(); -}; - -ErrorWidget.prototype.generate = function() { - // Set the element details - this.tag = "span"; - this.attributes = { - "class": "tw-error-widget" - }; - this.children = this.renderer.renderTree.createRenderers(this.renderer,[{ - type: "text", - text: this.errorMessage - }]); -}; - -exports.error = ErrorWidget; - -})(); diff --git a/core/modules/widgets/fieldmangler.js b/core/modules/widgets/fieldmangler.js deleted file mode 100644 index 3d5f3de09..000000000 --- a/core/modules/widgets/fieldmangler.js +++ /dev/null @@ -1,87 +0,0 @@ -/*\ -title: $:/core/modules/widgets/fieldmangler.js -type: application/javascript -module-type: widget - -The fieldmangler widget modifies the fields of the current tiddler in response to messages. - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var FieldManglerWidget = function(renderer) { - // Save state - this.renderer = renderer; - // Generate child nodes - this.generate(); -}; - -FieldManglerWidget.prototype.generate = function() { - var self = this; - // Get parameters from our attributes - this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.tiddlerTitle); - // Set the element - this.tag = "div"; - this.attributes = { - "class": "tw-fieldmangler" - }; - // Set event handlers - this.events = [ - {name: "tw-remove-field", handlerObject: this, handlerMethod: "handleRemoveFieldEvent"}, - {name: "tw-add-field", handlerObject: this, handlerMethod: "handleAddFieldEvent"}, - {name: "tw-remove-tag", handlerObject: this, handlerMethod: "handleRemoveTagEvent"}, - {name: "tw-add-tag", handlerObject: this, handlerMethod: "handleAddTagEvent"} - ]; - // Render the children - this.children = this.renderer.renderTree.createRenderers(this.renderer,this.renderer.parseTreeNode.children); -}; - -FieldManglerWidget.prototype.handleRemoveFieldEvent = function(event) { - var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle), - deletion = {}; - deletion[event.param] = undefined; - this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,deletion)); - return true; -}; - -FieldManglerWidget.prototype.handleAddFieldEvent = function(event) { - var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle); - if(tiddler && typeof event.param === "string" && event.param !== "" && !$tw.utils.hop(tiddler.fields,event.param)) { - var addition = {}; - addition[event.param] = ""; - this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,addition)); - } - return true; -}; - -FieldManglerWidget.prototype.handleRemoveTagEvent = function(event) { - var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle); - if(tiddler && tiddler.fields.tags) { - var p = tiddler.fields.tags.indexOf(event.param); - if(p !== -1) { - var modification = {}; - modification.tags = (tiddler.fields.tags || []).slice(0); - modification.tags.splice(p,1); - this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,modification)); - } - } - return true; -}; - -FieldManglerWidget.prototype.handleAddTagEvent = function(event) { - var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle); - if(tiddler && typeof event.param === "string" && event.param !== "") { - var modification = {}; - modification.tags = (tiddler.fields.tags || []).slice(0); - $tw.utils.pushTop(modification.tags,event.param); - this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddler,modification)); - } - return true; -}; - -exports.fieldmangler = FieldManglerWidget; - -})(); diff --git a/core/modules/widgets/fields.js b/core/modules/widgets/fields.js deleted file mode 100644 index 59a3bad2d..000000000 --- a/core/modules/widgets/fields.js +++ /dev/null @@ -1,94 +0,0 @@ -/*\ -title: $:/core/modules/widgets/fields.js -type: application/javascript -module-type: widget - -The fields widget displays the fields of a tiddler through a text substitution template. - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var FieldsWidget = function(renderer) { - // Save state - this.renderer = renderer; - // Generate child nodes - this.generate(); -}; - -FieldsWidget.prototype.generate = function() { - // Get parameters from our attributes - this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.tiddlerTitle); - this.template = this.renderer.getAttribute("template"); - this.exclude = this.renderer.getAttribute("exclude"); - this.stripTitlePrefix = this.renderer.getAttribute("stripTitlePrefix","no") === "yes"; - // Get the tiddler we're displaying - var tiddler = this.renderer.renderTree.wiki.getTiddler(this.tiddlerTitle); - // Get the exclusion list - var exclude; - if(this.exclude) { - exclude = this.exclude.split(" "); - } else { - exclude = ["text"]; - } - // Compose the template - var text = []; - if(this.template && tiddler) { - var fields = []; - for(var fieldName in tiddler.fields) { - if(exclude.indexOf(fieldName) === -1) { - fields.push(fieldName); - } - } - fields.sort(); - for(var f=0; f 0) { - this.attributes["class"] = classes.join(" "); - } - if(this.renderer.hasAttribute("style")) { - this.attributes.style = this.renderer.getAttribute("style"); - } - if(this.renderer.hasAttribute("tooltip")) { - this.attributes.title = this.renderer.getAttribute("tooltip"); - } - // Create the renderers for the wrapper and the children - this.children = this.renderer.renderTree.createRenderers(this.renderer,[{ - type: "text", - text: text.join("") - }]); -}; - -exports.fields = FieldsWidget; - -})(); diff --git a/core/modules/widgets/grid.js b/core/modules/widgets/grid.js deleted file mode 100644 index 8f393fe7f..000000000 --- a/core/modules/widgets/grid.js +++ /dev/null @@ -1,109 +0,0 @@ -/*\ -title: $:/core/modules/widgets/grid.js -type: application/javascript -module-type: widget - -The grid widget. - -This example renders a table made up of tiddlers titled `MySheet_A_1`, `MySheet_A_2`, `MySheet_A_3`, ... , `MySheet_B_1`, `MySheet_B_2`, `MySheet_B_3` etc. - -``` -<$grid prefix="MySheet" rows=20 cols=20/> -``` - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var GridWidget = function(renderer) { - // Save state - this.renderer = renderer; - // Generate widget elements - this.generate(); -}; - -GridWidget.prototype.generate = function() { - // Get our attributes - this.prefix = this.renderer.getAttribute("prefix","Grid"); - this.rows = parseInt(this.renderer.getAttribute("rows","10"),10); - this.cols = parseInt(this.renderer.getAttribute("cols","10"),10); - this["class"] = this.renderer.getAttribute("class"); - // Set up the classes - var classes = ["tw-grid-frame"]; - if(this["class"]) { - $tw.utils.pushTop(classes,this["class"]); - } - // Create the grid table element - this.tag = "div"; - this.attributes = { - "class": classes.join(" ") - }; - this.children = this.renderer.renderTree.createRenderers(this.renderer,this.generateTable()); -}; - -GridWidget.prototype.generateTable = function() { - var rows = []; - for(var row=0; row0) { - c = String.fromCharCode(col % 26 + "A".charCodeAt(0) - 1) + c; - col = Math.floor(col/26); - } - return this.prefix + "_" + c + "_" + (row + 1); -}; - -GridWidget.prototype.postRenderInDom = function() { -}; - -GridWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) { - // Reexecute the widget if any of our attributes have changed - if(true) { - // Regenerate and rerender the widget and replace the existing DOM node - this.generate(); - var oldDomNode = this.renderer.domNode, - newDomNode = this.renderer.renderInDom(); - oldDomNode.parentNode.replaceChild(newDomNode,oldDomNode); - } else { - } -}; - -exports.grid = GridWidget; - -})(); diff --git a/core/modules/widgets/import.js b/core/modules/widgets/import.js deleted file mode 100644 index 8051a7a76..000000000 --- a/core/modules/widgets/import.js +++ /dev/null @@ -1,256 +0,0 @@ -/*\ -title: $:/core/modules/widgets/import.js -type: application/javascript -module-type: widget - -Implements the import widget. - -``` -<$import> -Import using the "browse..." button or drag files onto this text - -``` - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var ImportWidget = function(renderer) { - // Save state - this.renderer = renderer; - // Generate child nodes - this.generate(); -}; - -ImportWidget.prototype.generate = function() { - // Get the parameters from the attributes - this.browse = this.renderer.getAttribute("browse","yes"); - this["class"] = this.renderer.getAttribute("class"); - // Compute classes - var classes = ["tw-import"]; - if(this["class"]) { - $tw.utils.pushTop(classes,this["class"]); - } - // Create the file input and container elements - var fileInput = { - type: "element", - tag: "input", - attributes: { - type: {type: "string", value: "file"}, - style: {type: "string", value: this.browse === "no" ? "display: none;" : "display: block;"} - }, - events: [{name: "change", handlerObject: this, handlerMethod: "handleChangeEvent"}] - }, - container = { - type: "element", - tag: "div", - children: this.renderer.parseTreeNode.children, - events: [ - {name: "dragenter", handlerObject: this, handlerMethod: "handleDragEnterEvent"}, - {name: "dragover", handlerObject: this, handlerMethod: "handleDragOverEvent"}, - {name: "dragleave", handlerObject: this, handlerMethod: "handleDragLeaveEvent"}, - {name: "drop", handlerObject: this, handlerMethod: "handleDropEvent"}, - {name: "paste", handlerObject: this, handlerMethod: "handlePasteEvent"}] - }; - // Set the return element - this.tag = "div"; - this.attributes = { - "class": classes.join(" ") - }; - this.children = this.renderer.renderTree.createRenderers(this.renderer,[fileInput,container]); -}; - -ImportWidget.prototype.handleChangeEvent = function(event) { - event.stopPropagation(); - this.importFiles(event.target.files); -}; - -ImportWidget.prototype.handleDragEnterEvent = function(event) { - // We count enter/leave events - this.dragEnterCount = (this.dragEnterCount || 0) + 1; - // If we're entering for the first time we need to apply highlighting - if(this.dragEnterCount === 1) { - $tw.utils.addClass(this.renderer.domNode,"tw-dragover"); - } - // Tell the browser that we're ready to handle the drop - event.preventDefault(); - // Tell the browser not to ripple the drag up to any parent drop handlers - event.stopPropagation(); -}; - -ImportWidget.prototype.handleDragOverEvent = function(event) { - // Tell the browser that we're still interested in the drop - event.preventDefault(); - event.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy -}; - -ImportWidget.prototype.handleDragLeaveEvent = function(event) { - // Reduce the enter count - this.dragEnterCount = (this.dragEnterCount || 0) - 1; - // Remove highlighting if we're leaving externally - if(this.dragEnterCount <= 0) { - $tw.utils.removeClass(this.renderer.domNode,"tw-dragover"); - } -}; - -ImportWidget.prototype.handleDropEvent = function(event) { - var dataTransfer = event.dataTransfer; - // Reset the enter count - this.dragEnterCount = 0; - // Remove highlighting - $tw.utils.removeClass(this.renderer.domNode,"tw-dragover"); - // Try to import the various data types we understand - this.importData(dataTransfer); - // Import any files in the drop - this.importFiles(dataTransfer.files); - // Tell the browser that we handled the drop - event.preventDefault(); - // Stop the drop ripple up to any parent handlers - event.stopPropagation(); -}; - -ImportWidget.prototype.handlePasteEvent = function(event) { - // Let the browser handle it if we're in a textarea or input box - if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) == -1) { - var self = this, - items = event.clipboardData.items; - // Enumerate the clipboard items - for(var t = 0; t 0) { - // Use our content as the template - templateTree = this.renderer.parseTreeNode.children; - } else { - // Use default content - templateTree = [{ - type: "element", - tag: "$view", - attributes: { - field: {type: "string", value: "title"}, - format: {type: "string", value: "link"} - } - }]; - } - } - // Create the element widgets - if(this.renderer.hasAttribute("hackTemplate")) { - return { - type: "element", - tag: "$transclude", - isBlock: this.renderer.parseTreeNode.isBlock, - attributes: { - title: {type: "string", value: title} - } - }; - } else { - if(!templateTree) { - templateTree = [{ - type: "element", - tag: "$transclude", - attributes: { - title: {type: "string", value: template} - }, - children: templateTree - }]; - } - return { - type: "element", - tag: "$tiddler", - isBlock: this.renderer.parseTreeNode.isBlock, - attributes: { - title: {type: "string", value: title} - }, - children: templateTree - }; - } -}; - -/* -Remove a list element from the list, along with the attendant DOM nodes -*/ -ListWidget.prototype.removeListElement = function(index) { - // Get the list element - var listElement = this.children[index]; - // Invoke the listview to animate the removal - if(this.listview && this.listview.remove) { - if(!this.listview.remove(index)) { - // Only delete the DOM element if the listview.remove() returned false - listElement.domNode.parentNode.removeChild(listElement.domNode); - } - } else { - // Always remove the DOM node if we didn't invoke the listview - listElement.domNode.parentNode.removeChild(listElement.domNode); - } - // Then delete the actual renderer node - this.children.splice(index,1); -}; - -/* -Return the index of the list element that corresponds to a particular title -startIndex: index to start search (use zero to search from the top) -title: tiddler title to seach for -*/ -ListWidget.prototype.findListElementByTitle = function(startIndex,title) { - var testNode = this.macro ? function(node) { - // We're looking for a macro list element - return node.widget.children[0].parseTreeNode.params[0].value === title; - } : (this.renderer.hasAttribute("hackTemplate") ? function(node) { - // We're looking for a transclusion list element - return node.widget.children[0].attributes.title === title; - } : function(node) { - // We're looking for a transclusion list element - return node.widget.children[0].attributes.title === title; - }); - // Search for the list element - while(startIndex < this.children.length) { - if(testNode(this.children[startIndex])) { - return startIndex; - } - startIndex++; - } - return undefined; -}; - -ListWidget.prototype.postRenderInDom = function() { - this.listview = this.chooseListView(); - this.history = []; -}; - -/* -Select the appropriate list viewer -*/ -ListWidget.prototype.chooseListView = function() { - // Instantiate the list view - var listviewName = this.renderer.getAttribute("listview"); - var ListView = this.listViews[listviewName]; - return ListView ? new ListView(this) : null; -}; - -ListWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) { - // Reexecute the widget if any of our attributes have changed - if(changedAttributes.itemClass || changedAttributes.template || changedAttributes.editTemplate || changedAttributes.emptyMessage || changedAttributes.type || changedAttributes.filter || changedAttributes.template || changedAttributes.history || changedAttributes.listview) { - // Regenerate and rerender the widget and replace the existing DOM node - this.generate(); - var oldDomNode = this.renderer.domNode, - newDomNode = this.renderer.renderInDom(); - oldDomNode.parentNode.replaceChild(newDomNode,oldDomNode); - } else { - // Handle any changes to the list, and refresh any nodes we're reusing - this.handleListChanges(changedTiddlers); - // Update the history list - var history = this.renderer.getAttribute("history"); - if(history && changedTiddlers[history]) { - this.handleHistoryChanges(); - } - } -}; - -ListWidget.prototype.handleListChanges = function(changedTiddlers) { - var t, - prevListLength = this.list.length, - self = this; - // Get the list of tiddlers, having saved the previous length - this.getTiddlerList(); - // Check if the list is empty - if(this.list.length === 0) { - // Check if it was empty before - if(prevListLength === 0) { - // If so, just refresh the empty message - $tw.utils.each(this.children,function(node) { - if(node.refreshInDom) { - node.refreshInDom(changedTiddlers); - } - }); - return; - } else { - // If the list wasn't empty before, empty it - for(t=prevListLength-1; t>=0; t--) { - this.removeListElement(t); - } - // Insert the empty message - this.children = this.renderer.renderTree.createRenderers(this.renderer,[this.getEmptyMessage()]); - $tw.utils.each(this.children,function(node) { - if(node.renderInDom) { - self.renderer.domNode.appendChild(node.renderInDom()); - } - }); - return; - } - } else { - // If it is not empty now, but was empty previously, then remove the empty message - if(prevListLength === 0) { - this.removeListElement(0); - } - } - // Step through the list and adjust our child list elements appropriately - for(t=0; t=t; n--) { - this.removeListElement(n); - } - // Refresh the node we're reusing - this.children[t].refreshInDom(changedTiddlers); - } - } - // Remove any left over elements - for(t=this.children.length-1; t>=this.list.length; t--) { - this.removeListElement(t); - } -}; - -/* -Handle any changes to the history list -*/ -ListWidget.prototype.handleHistoryChanges = function() { - // Get the history data - var historyAtt = this.renderer.getAttribute("history"), - newHistory = this.renderer.renderTree.wiki.getTiddlerData(historyAtt,[]); - // Ignore any entries of the history that match the previous history - var entry = 0; - while(entry < newHistory.length && entry < this.history.length && newHistory[entry].title === this.history[entry].title) { - entry++; - } - // Navigate forwards to each of the new tiddlers - while(entry < newHistory.length) { - if(this.listview && this.listview.navigateTo) { - this.listview.navigateTo(newHistory[entry]); - } - entry++; - } - // Update the history - this.history = newHistory; -}; - -exports.list = ListWidget; - -})(); diff --git a/core/modules/widgets/list/listviews/classic.js b/core/modules/widgets/list/listviews/classic.js deleted file mode 100644 index 4634a54bb..000000000 --- a/core/modules/widgets/list/listviews/classic.js +++ /dev/null @@ -1,100 +0,0 @@ -/*\ -title: $:/core/modules/widgets/list/listviews/classic.js -type: application/javascript -module-type: listview - -Views the list as a linear sequence - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var ClassicListView = function(listWidget) { - this.listWidget = listWidget; -} - -ClassicListView.prototype.navigateTo = function(historyInfo) { - var listElementIndex = this.listWidget.findListElementByTitle(0,historyInfo.title); - if(listElementIndex === undefined) { - return; - } - var listElementNode = this.listWidget.children[listElementIndex], - targetElement = listElementNode.domNode; - // Scroll the node into view - var scrollEvent = this.listWidget.renderer.renderTree.document.createEvent("Event"); - scrollEvent.initEvent("tw-scroll",true,true); - targetElement.dispatchEvent(scrollEvent); -}; - -ClassicListView.prototype.insert = function(index) { - var listElementNode = this.listWidget.children[index], - targetElement = listElementNode.domNode, - duration = $tw.utils.getAnimationDuration(); - // Get the current height of the tiddler - var currMarginBottom = parseInt(window.getComputedStyle(targetElement).marginBottom,10), - currMarginTop = parseInt(window.getComputedStyle(targetElement).marginTop,10), - currHeight = targetElement.offsetHeight + currMarginTop; - // Reset the margin once the transition is over - setTimeout(function() { - $tw.utils.setStyle(targetElement,[ - {transition: "none"}, - {marginBottom: ""} - ]); - },duration); - // Set up the initial position of the element - $tw.utils.setStyle(targetElement,[ - {transition: "none"}, - {marginBottom: (-currHeight) + "px"}, - {opacity: "0.0"} - ]); - $tw.utils.forceLayout(targetElement); - // Transition to the final position - $tw.utils.setStyle(targetElement,[ - {transition: "opacity " + duration + "ms ease-in-out, " + - "margin-bottom " + duration + "ms ease-in-out"}, - {marginBottom: currMarginBottom + "px"}, - {opacity: "1.0"} - ]); -}; - -ClassicListView.prototype.remove = function(index) { - var listElementNode = this.listWidget.children[index], - targetElement = listElementNode.domNode, - duration = $tw.utils.getAnimationDuration(); - // Get the current height of the tiddler - var currWidth = targetElement.offsetWidth, - currMarginBottom = parseInt(window.getComputedStyle(targetElement).marginBottom,10), - currMarginTop = parseInt(window.getComputedStyle(targetElement).marginTop,10), - currHeight = targetElement.offsetHeight + currMarginTop; - // Remove the element at the end of the transition - setTimeout(function() { - if(targetElement.parentNode) { - targetElement.parentNode.removeChild(targetElement); - } - },duration); - // Animate the closure - $tw.utils.setStyle(targetElement,[ - {transition: "none"}, - {transform: "translateX(0px)"}, - {marginBottom: currMarginBottom + "px"}, - {opacity: "1.0"} - ]); - $tw.utils.forceLayout(targetElement); - $tw.utils.setStyle(targetElement,[ - {transition: $tw.utils.roundTripPropertyName("transform") + " " + duration + "ms ease-in-out, " + - "opacity " + duration + "ms ease-in-out, " + - "margin-bottom " + duration + "ms ease-in-out"}, - {transform: "translateX(-" + currWidth + "px)"}, - {marginBottom: (-currHeight) + "px"}, - {opacity: "0.0"} - ]); - // Returning true causes the DOM node not to be deleted - return true; -}; - -exports.classic = ClassicListView; - -})(); diff --git a/core/modules/widgets/list/listviews/pop.js b/core/modules/widgets/list/listviews/pop.js deleted file mode 100644 index 4a8071175..000000000 --- a/core/modules/widgets/list/listviews/pop.js +++ /dev/null @@ -1,75 +0,0 @@ -/*\ -title: $:/core/modules/widgets/list/listviews/pop.js -type: application/javascript -module-type: listview - -Animates list insertions and removals - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var PopListView = function(listWidget) { - this.listWidget = listWidget; -} - -PopListView.prototype.insert = function(index) { - var listElementNode = this.listWidget.children[index], - targetElement = listElementNode.domNode, - duration = $tw.utils.getAnimationDuration(); - // Reset once the transition is over - setTimeout(function() { - $tw.utils.setStyle(targetElement,[ - {transition: "none"}, - {transform: "none"} - ]); - },duration); - // Set up the initial position of the element - $tw.utils.setStyle(targetElement,[ - {transition: "none"}, - {transform: "scale(2)"}, - {opacity: "0.0"} - ]); - $tw.utils.forceLayout(targetElement); - // Transition to the final position - $tw.utils.setStyle(targetElement,[ - {transition: $tw.utils.roundTripPropertyName("transform") + " " + duration + "ms ease-in-out, " + - "opacity " + duration + "ms ease-in-out"}, - {transform: "scale(1)"}, - {opacity: "1.0"} - ]); -}; - -PopListView.prototype.remove = function(index) { - var listElementNode = this.listWidget.children[index], - targetElement = listElementNode.domNode, - duration = $tw.utils.getAnimationDuration(); - // Remove the element at the end of the transition - setTimeout(function() { - if(targetElement.parentNode) { - targetElement.parentNode.removeChild(targetElement); - } - },duration); - // Animate the closure - $tw.utils.setStyle(targetElement,[ - {transition: "none"}, - {transform: "scale(1)"}, - {opacity: "1.0"} - ]); - $tw.utils.forceLayout(targetElement); - $tw.utils.setStyle(targetElement,[ - {transition: $tw.utils.roundTripPropertyName("transform") + " " + duration + "ms ease-in-out, " + - "opacity " + duration + "ms ease-in-out"}, - {transform: "scale(0.1)"}, - {opacity: "0.0"} - ]); - // Returning true causes the DOM node not to be deleted - return true; -}; - -exports.pop = PopListView; - -})(); diff --git a/core/modules/widgets/list/listviews/scroller.js b/core/modules/widgets/list/listviews/scroller.js deleted file mode 100644 index 26d116e6d..000000000 --- a/core/modules/widgets/list/listviews/scroller.js +++ /dev/null @@ -1,31 +0,0 @@ -/*\ -title: $:/core/modules/widgets/list/listviews/scroller.js -type: application/javascript -module-type: listview - -A list view that scrolls to newly inserted elements - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var ScrollerListView = function(listWidget) { - this.listWidget = listWidget; -} - -ScrollerListView.prototype.navigateTo = function(historyInfo) { - var listElementIndex = this.listWidget.findListElementByTitle(0,historyInfo.title), - listElementNode = this.listWidget.children[listElementIndex], - targetElement = listElementNode.domNode; - // Scroll the node into view - var scrollEvent = this.listWidget.renderer.renderTree.document.createEvent("Event"); - scrollEvent.initEvent("tw-scroll",true,true); - targetElement.dispatchEvent(scrollEvent); -}; - -exports.scroller = ScrollerListView; - -})(); diff --git a/core/modules/widgets/list/listviews/zoomin.js b/core/modules/widgets/list/listviews/zoomin.js deleted file mode 100644 index cfed003dc..000000000 --- a/core/modules/widgets/list/listviews/zoomin.js +++ /dev/null @@ -1,207 +0,0 @@ -/*\ -title: $:/core/modules/widgets/list/listviews/zoomin.js -type: application/javascript -module-type: listview - -Zooms between individual tiddlers - -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false */ -"use strict"; - -var ZoominListView = function(listWidget) { - this.listWidget = listWidget; - this.storyNode = this.listWidget.renderer.domNode; - // Set the current tiddler - this.currentTiddler = this.listWidget.children[0].domNode; - // Make all the tiddlers position absolute, and hide all but the first one - this.storyNode.style.position = "relative"; - for(var t=0; t widget -*/ -function findTitleNode(node) { - var t,r; - // Return true if this node is a view widget with the field attribute set to "title" - if(node instanceof $tw.WikiRenderTree.prototype.rendererClasses.element) { - if(node.widget instanceof $tw.WikiRenderTree.prototype.rendererClasses.element.prototype.widgetClasses.view && node.attributes.field === "title") { - return node; - } - if(node.widget.children) { - for(t=0; t