/*\ 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 }; /* Global regular expression for parsing the location of a popup. This is also used by the Reveal widget. */ exports.popupLocationRegExp = /^(@?)\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/ /* Objekt containing the available prefixes for coordinates build with the `buildCoordinates` function: - csOffsetParent: Uses a coordinate system based on the offset parent (no prefix). - csAbsolute: Use an absolute coordinate system (prefix "@"). */ exports.coordinatePrefix = { csOffsetParent: "", csAbsolute: "@" } /* 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); } }; /* Cancel all popups at or above a specified level or DOM node level: popup level to cancel (0 cancels all popups) */ Popup.prototype.cancel = function(level) { var numPopups = this.popups.length; level = Math.max(0,Math.min(level,numPopups)); for(var t=level; t