1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-29 00:33:15 +00:00

Improvements to reveal widget popup handling

This commit is contained in:
Jeremy Ruston 2013-01-01 16:14:42 +00:00
parent 8fdeefd7d1
commit f8340bc4dc
3 changed files with 31 additions and 13 deletions

View File

@ -25,17 +25,18 @@ Popup.prototype.show = function(options) {
this.cancel(); this.cancel();
this.title = options.title; this.title = options.title;
this.wiki = options.wiki; 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) { Popup.prototype.handleEvent = function(event) {
if(event.type === "click") { if(event.type === "click" && !$tw.utils.domContains(this.anchorDomNode,event.target)) {
this.cancel(); this.cancel();
} }
}; };
Popup.prototype.cancel = function() { Popup.prototype.cancel = function() {
// this.rootElement.removeEventListener("click",this,true); this.rootElement.removeEventListener("click",this,true);
if(this.title) { if(this.title) {
this.wiki.deleteTiddler(this.title); this.wiki.deleteTiddler(this.title);
this.title = null; this.title = null;
@ -51,7 +52,6 @@ Trigger a popup open or closed. Parameters are in a hashmap:
Popup.prototype.triggerPopup = function(options) { Popup.prototype.triggerPopup = function(options) {
// Get the current popup state tiddler // Get the current popup state tiddler
var value = options.wiki.getTextReference(options.title,""); var value = options.wiki.getTextReference(options.title,"");
console.log("Value is",value)
// Check if the popup is open by checking whether it matches "(<x>,<y>)" // Check if the popup is open by checking whether it matches "(<x>,<y>)"
var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/; var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/;
if(popupLocationRegExp.test(value)) { if(popupLocationRegExp.test(value)) {

View File

@ -40,7 +40,7 @@ exports.generateChildNodes = function() {
var node = { var node = {
type: "element", type: "element",
tag: "div", tag: "div",
children: this.renderer.parseTreeNode.children, children: this.isOpen ? this.renderer.parseTreeNode.children : [],
events: [{name: "click", handlerObject: this, handlerMethod: "handleClickEvent"}] events: [{name: "click", handlerObject: this, handlerMethod: "handleClickEvent"}]
}; };
$tw.utils.addClassToParseTreeNode(node,"tw-reveal"); $tw.utils.addClassToParseTreeNode(node,"tw-reveal");
@ -122,7 +122,7 @@ exports.handleClickEvent = function(event) {
exports.refreshInDom = function(changedAttributes,changedTiddlers) { exports.refreshInDom = function(changedAttributes,changedTiddlers) {
// Check if any of our attributes have changed, or if a tiddler we're interested in has changed // 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 // Remove old child nodes
$tw.utils.removeChildren(this.parentElement); $tw.utils.removeChildren(this.parentElement);
// Regenerate and render children // Regenerate and render children
@ -134,12 +134,28 @@ exports.refreshInDom = function(changedAttributes,changedTiddlers) {
} }
}); });
} else { } else {
// We don't need to refresh ourselves, so just refresh any child nodes var needChildrenRefresh = true; // Avoid refreshing the children nodes if we don't need to
$tw.utils.each(this.children,function(node) { // Get the open state
if(node.refreshInDom) { this.readState();
node.refreshInDom(changedTiddlers); // 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 // Position the content if required
this.postRenderInDom(); this.postRenderInDom();

View File

@ -7,7 +7,9 @@ title: $:/templates/TagTemplate
* <$view field="title" format="link" /> * <$view field="title" format="link" />
*.divider *.divider
* <$list filter="[is[current]tagging[]]" ><li><$view field="title" format="link" /></li></$list> * <div>
<$list filter="[is[current]tagging[]sort[title]]"/>
</div>
@@ @@