/*\ title: $:/core/modules/utils/dom/popup.js type: application/javascript module-type: utils Module that creates a $tw.utils.Popup object prototype that manages popups in the browser \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; /* Creates a Popup object with these options: rootElement: the DOM element to which the popup zapper should be attached */ var Popup = function(options) { options = options || {}; this.rootElement = options.rootElement || document.documentElement; this.popups = []; // Array of {title:,wiki:,domNode:} objects }; /* Trigger a popup open or closed. Parameters are in a hashmap: title: title of the tiddler where the popup details are stored domNode: dom node to which the popup will be positioned (one of domNode or domNodeRect is required) domNodeRect: rectangle to which the popup will be positioned wiki: wiki force: if specified, forces the popup state to true or false (instead of toggling it) floating: if true, skips registering the popup, meaning that it will need manually clearing */ Popup.prototype.triggerPopup = function(options) { // Check if this popup is already active var index = this.findPopup(options.title); // Compute the new state var state = index === -1; if(options.force !== undefined) { state = options.force; } // Show or cancel the popup according to the new state if(state) { this.show(options); } else { this.cancel(index); } }; Popup.prototype.findPopup = function(title) { var index = -1; for(var t=0; t 0) { this.rootElement.addEventListener("click",this,true); } }; /* Detect if a Popup contains an input field that has focus Returns true or false */ Popup.prototype.detectInputWithinPopup = function(node) { var withinPopup = false, currNode = node; for(var i=0; i