mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-02 20:29:10 +00:00
Improve popup dismissal
Now we ignore clicks if they come from an element that has an ancestor with the class `tw-popup`
This commit is contained in:
parent
145e3ece78
commit
06a66cf24e
@ -26,16 +26,28 @@ Popup.prototype.show = function(options) {
|
|||||||
this.title = options.title;
|
this.title = options.title;
|
||||||
this.wiki = options.wiki;
|
this.wiki = options.wiki;
|
||||||
this.anchorDomNode = options.domNode;
|
this.anchorDomNode = options.domNode;
|
||||||
|
$tw.utils.addClass(this.anchorDomNode,"tw-popup");
|
||||||
this.rootElement.addEventListener("click",this,false);
|
this.rootElement.addEventListener("click",this,false);
|
||||||
};
|
};
|
||||||
|
|
||||||
Popup.prototype.handleEvent = function(event) {
|
Popup.prototype.handleEvent = function(event) {
|
||||||
if(event.type === "click" && this.anchorDomNode !== event.target && !$tw.utils.domContains(this.anchorDomNode,event.target)) {
|
// Dismiss the popup if we get a click on an element that doesn't have .tw-popup class
|
||||||
this.cancel();
|
if(event.type === "click") {
|
||||||
|
var node = event.target;
|
||||||
|
while(node && !$tw.utils.hasClass(node,"tw-popup")) {
|
||||||
|
node = node.parentNode;
|
||||||
|
}
|
||||||
|
if(!node) {
|
||||||
|
this.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Popup.prototype.cancel = function() {
|
Popup.prototype.cancel = function() {
|
||||||
|
if(this.anchorDomNode) {
|
||||||
|
$tw.utils.removeClass(this.anchorDomNode,"tw-popup");
|
||||||
|
this.anchorDomNode = null;
|
||||||
|
}
|
||||||
this.rootElement.removeEventListener("click",this,false);
|
this.rootElement.removeEventListener("click",this,false);
|
||||||
if(this.title) {
|
if(this.title) {
|
||||||
this.wiki.deleteTiddler(this.title);
|
this.wiki.deleteTiddler(this.title);
|
||||||
|
Loading…
Reference in New Issue
Block a user