1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Update popup.js

This commit is contained in:
Simon Huber 2019-07-10 09:55:32 +02:00 committed by GitHub
parent 8aa6427d67
commit 7811614d53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -148,19 +148,43 @@ Popup.prototype.show = function(options) {
} }
}; };
/*
Detect if a Popup contains an input field that has focus
Returns true or false
*/
Popup.prototype.detectInputWithinPopup = function(node) {
var withinPopup = false;
for(var i=0; i<this.popups.length; i++) {
var popup = (this.popups[i] && this.popups[i].domNode) ? this.popups[i].domNode : null;
while(node && popup) {
if(node === popup || (node.classList && node.classList.contains("tc-popup-keep"))) {
withinPopup = true;
}
node = node.parentNode;
}
}
return withinPopup;
};
/* /*
Cancel all popups at or above a specified level or DOM node Cancel all popups at or above a specified level or DOM node
level: popup level to cancel (0 cancels all popups) level: popup level to cancel (0 cancels all popups)
*/ */
Popup.prototype.cancel = function(level) { Popup.prototype.cancel = function(level,focusedInputNode) {
var numPopups = this.popups.length; var numPopups = this.popups.length;
level = Math.max(0,Math.min(level,numPopups)); level = Math.max(0,Math.min(level,numPopups));
for(var t=level; t<numPopups; t++) { for(var t=level; t<numPopups; t++) {
var inputWithinPopup;
if(focusedInputNode) {
inputWithinPopup = this.detectInputWithinPopup(focusedInputNode);
}
if(!inputWithinPopup) {
var popup = this.popups.pop(); var popup = this.popups.pop();
if(popup.title) { if(popup.title) {
popup.wiki.deleteTiddler(popup.title); popup.wiki.deleteTiddler(popup.title);
} }
} }
}
if(this.popups.length === 0) { if(this.popups.length === 0) {
this.rootElement.removeEventListener("click",this,false); this.rootElement.removeEventListener("click",this,false);
} }