dojo.provide("dijit._base.popup"); dojo.require("dijit._base.focus"); dojo.require("dijit._base.place"); dojo.require("dijit._base.window"); dijit.popup = new function(){ // summary: // This class is used to show/hide widgets as popups. var stack = [], beginZIndex=1000, idGen = 1; this.prepare = function(/*DomNode*/ node){ // summary: // Prepares a node to be used as a popup // // description: // Attaches node to dojo.doc.body, and // positions it off screen, but not display:none, so that // the widget doesn't appear in the page flow and/or cause a blank // area at the bottom of the viewport (making scrollbar longer), but // initialization of contained widgets works correctly var s = node.style; s.visibility = "hidden"; // so TAB key doesn't navigate to hidden popup s.position = "absolute"; s.top = "-9999px"; if(s.display == "none"){ s.display=""; } dojo.body().appendChild(node); }; /*===== dijit.popup.__OpenArgs = function(){ // popup: Widget // widget to display // parent: Widget // the button etc. that is displaying this popup // around: DomNode // DOM node (typically a button); place popup relative to this node. (Specify this *or* "x" and "y" parameters.) // x: Integer // Absolute horizontal position (in pixels) to place node at. (Specify this *or* "around" parameter.) // y: Integer // Absolute vertical position (in pixels) to place node at. (Specity this *or* "around" parameter.) // orient: Object || String // When the around parameter is specified, orient should be an // ordered list of tuples of the form (around-node-corner, popup-node-corner). // dijit.popup.open() tries to position the popup according to each tuple in the list, in order, // until the popup appears fully within the viewport. // // The default value is {BL:'TL', TL:'BL'}, which represents a list of two tuples: // 1. (BL, TL) // 2. (TL, BL) // where BL means "bottom left" and "TL" means "top left". // So by default, it first tries putting the popup below the around node, left-aligning them, // and then tries to put it above the around node, still left-aligning them. Note that the // default is horizontally reversed when in RTL mode. // // When an (x,y) position is specified rather than an around node, orient is either // "R" or "L". R (for right) means that it tries to put the popup to the right of the mouse, // specifically positioning the popup's top-right corner at the mouse position, and if that doesn't // fit in the viewport, then it tries, in order, the bottom-right corner, the top left corner, // and the top-right corner. // onCancel: Function // callback when user has canceled the popup by // 1. hitting ESC or // 2. by using the popup widget's proprietary cancel mechanism (like a cancel button in a dialog); // i.e. whenever popupWidget.onCancel() is called, args.onCancel is called // onClose: Function // callback whenever this popup is closed // onExecute: Function // callback when user "executed" on the popup/sub-popup by selecting a menu choice, etc. (top menu only) // padding: dijit.__Position // adding a buffer around the opening position. This is only useful when around is not set. this.popup = popup; this.parent = parent; this.around = around; this.x = x; this.y = y; this.orient = orient; this.onCancel = onCancel; this.onClose = onClose; this.onExecute = onExecute; this.padding = padding; } =====*/ this.open = function(/*dijit.popup.__OpenArgs*/ args){ // summary: // Popup the widget at the specified position // // example: // opening at the mouse position // | dijit.popup.open({popup: menuWidget, x: evt.pageX, y: evt.pageY}); // // example: // opening the widget as a dropdown // | dijit.popup.open({parent: this, popup: menuWidget, around: this.domNode, onClose: function(){...} }); // // Note that whatever widget called dijit.popup.open() should also listen to its own _onBlur callback // (fired from _base/focus.js) to know that focus has moved somewhere else and thus the popup should be closed. var widget = args.popup, orient = args.orient || {'BL':'TL', 'TL':'BL'}, around = args.around, id = (args.around && args.around.id) ? (args.around.id+"_dropdown") : ("popup_"+idGen++); // make wrapper div to hold widget and possibly hold iframe behind it. // we can't attach the iframe as a child of the widget.domNode because // widget.domNode might be a ,