From 06a66cf24e34725af5178d36cb36b2587bfbbfea Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 12 Nov 2013 22:02:26 +0000 Subject: [PATCH] Improve popup dismissal Now we ignore clicks if they come from an element that has an ancestor with the class `tw-popup` --- core/modules/utils/dom/popup.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/modules/utils/dom/popup.js b/core/modules/utils/dom/popup.js index f79e76120..e7d93dbf8 100644 --- a/core/modules/utils/dom/popup.js +++ b/core/modules/utils/dom/popup.js @@ -26,16 +26,28 @@ Popup.prototype.show = function(options) { this.title = options.title; this.wiki = options.wiki; this.anchorDomNode = options.domNode; + $tw.utils.addClass(this.anchorDomNode,"tw-popup"); this.rootElement.addEventListener("click",this,false); }; Popup.prototype.handleEvent = function(event) { - if(event.type === "click" && this.anchorDomNode !== event.target && !$tw.utils.domContains(this.anchorDomNode,event.target)) { - this.cancel(); + // Dismiss the popup if we get a click on an element that doesn't have .tw-popup class + 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() { + if(this.anchorDomNode) { + $tw.utils.removeClass(this.anchorDomNode,"tw-popup"); + this.anchorDomNode = null; + } this.rootElement.removeEventListener("click",this,false); if(this.title) { this.wiki.deleteTiddler(this.title);