From f8340bc4dcc60c66083f0093fcc020e9da3df65c Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 1 Jan 2013 16:14:42 +0000 Subject: [PATCH] Improvements to reveal widget popup handling --- core/modules/utils/dom/popup.js | 8 ++++---- core/modules/widgets/reveal.js | 32 ++++++++++++++++++++++++-------- core/templates/TagTemplate.tid | 4 +++- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/core/modules/utils/dom/popup.js b/core/modules/utils/dom/popup.js index 5bfec3562..b464f26c1 100644 --- a/core/modules/utils/dom/popup.js +++ b/core/modules/utils/dom/popup.js @@ -25,17 +25,18 @@ Popup.prototype.show = function(options) { this.cancel(); this.title = options.title; this.wiki = options.wiki; - // this.rootElement.addEventListener("click",this,true); + this.anchorDomNode = options.domNode; + this.rootElement.addEventListener("click",this,true); }; Popup.prototype.handleEvent = function(event) { - if(event.type === "click") { + if(event.type === "click" && !$tw.utils.domContains(this.anchorDomNode,event.target)) { this.cancel(); } }; Popup.prototype.cancel = function() { - // this.rootElement.removeEventListener("click",this,true); + this.rootElement.removeEventListener("click",this,true); if(this.title) { this.wiki.deleteTiddler(this.title); this.title = null; @@ -51,7 +52,6 @@ Trigger a popup open or closed. Parameters are in a hashmap: Popup.prototype.triggerPopup = function(options) { // Get the current popup state tiddler var value = options.wiki.getTextReference(options.title,""); -console.log("Value is",value) // Check if the popup is open by checking whether it matches "(,)" var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/; if(popupLocationRegExp.test(value)) { diff --git a/core/modules/widgets/reveal.js b/core/modules/widgets/reveal.js index b54e5c716..63ff339b9 100644 --- a/core/modules/widgets/reveal.js +++ b/core/modules/widgets/reveal.js @@ -40,7 +40,7 @@ exports.generateChildNodes = function() { var node = { type: "element", tag: "div", - children: this.renderer.parseTreeNode.children, + children: this.isOpen ? this.renderer.parseTreeNode.children : [], events: [{name: "click", handlerObject: this, handlerMethod: "handleClickEvent"}] }; $tw.utils.addClassToParseTreeNode(node,"tw-reveal"); @@ -122,7 +122,7 @@ exports.handleClickEvent = function(event) { exports.refreshInDom = function(changedAttributes,changedTiddlers) { // Check if any of our attributes have changed, or if a tiddler we're interested in has changed - if(changedAttributes.state || changedAttributes.type || changedAttributes.text || changedAttributes.position || changedAttributes["default"] || changedAttributes.qualifyTiddlerTitles || changedAttributes["class"] || (this.stateTitle && changedTiddlers[this.stateTitle])) { + if(changedAttributes.state || changedAttributes.type || changedAttributes.text || changedAttributes.position || changedAttributes["default"] || changedAttributes.qualifyTiddlerTitles || changedAttributes["class"]) { // Remove old child nodes $tw.utils.removeChildren(this.parentElement); // Regenerate and render children @@ -134,12 +134,28 @@ exports.refreshInDom = function(changedAttributes,changedTiddlers) { } }); } else { - // We don't need to refresh ourselves, so just refresh any child nodes - $tw.utils.each(this.children,function(node) { - if(node.refreshInDom) { - node.refreshInDom(changedTiddlers); - } - }); + var needChildrenRefresh = true; // Avoid refreshing the children nodes if we don't need to + // Get the open state + this.readState(); + // Construct the child nodes if required + if(this.isOpen && this.children[0].children.length === 0) { + this.children[0].children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,this.renderer.parseTreeNode.children); + var parentNode = this.children[0].domNode; + $tw.utils.each(this.children[0].children,function(child) { + parentNode.appendChild(child.renderInDom()); + }); + needChildrenRefresh = false; + } + // Refresh any child nodes + if(needChildrenRefresh) { + $tw.utils.each(this.children,function(node) { + if(node.refreshInDom) { + node.refreshInDom(changedTiddlers); + } + }); + } + // Set the visibility of the children + this.children[0].domNode.style.display = this.isOpen ? (this.isBlock ? "block" : "inline") : "none"; } // Position the content if required this.postRenderInDom(); diff --git a/core/templates/TagTemplate.tid b/core/templates/TagTemplate.tid index ef453d98e..47d757be3 100644 --- a/core/templates/TagTemplate.tid +++ b/core/templates/TagTemplate.tid @@ -7,7 +7,9 @@ title: $:/templates/TagTemplate * <$view field="title" format="link" /> *.divider -* <$list filter="[is[current]tagging[]]" >
  • <$view field="title" format="link" />
  • +*
    +<$list filter="[is[current]tagging[]sort[title]]"/> +
    @@