1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-26 07:13: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.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 "(<x>,<y>)"
var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/;
if(popupLocationRegExp.test(value)) {

View File

@ -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();

View File

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