var DIALOGUE_NAME = 'Moodle dialogue',
DIALOGUE,
- DIALOGUE_FULLSCREEN_CLASS,
- DIALOGUE_HIDDEN_CLASS,
- EXISTING_WINDOW_SELECTOR,
- NOSCROLLING_CLASS;
-
-DIALOGUE_MODAL_CLASS = 'yui3-widget-modal';
-DIALOGUE_FULLSCREEN_CLASS = DIALOGUE_PREFIX+'-fullscreen';
-DIALOGUE_HIDDEN_CLASS = DIALOGUE_PREFIX+'-hidden';
-EXISTING_WINDOW_SELECTOR = '[role=dialog]';
-NOSCROLLING_CLASS = 'no-scrolling';
+ DIALOGUE_FULLSCREEN_CLASS = DIALOGUE_PREFIX + '-fullscreen',
+ DIALOGUE_HIDDEN_CLASS = DIALOGUE_PREFIX + '-hidden',
+ DIALOGUE_MODAL_CLASS = 'yui3-widget-modal',
+ DIALOGUE_SELECTOR =' [role=dialog]',
+ MENUBAR_SELECTOR = '[role=menubar]',
+ NOSCROLLING_CLASS = 'no-scrolling';
/**
* A re-usable dialogue box with Moodle classes applied.
*/
applyZIndex : function() {
var highestzindex = 0,
- zindex,
- bb;
-
- bb = this.get('boundingBox');
- if (this.get('zIndex')) {
+ bb = this.get('boundingBox'),
+ zindex = this.get('zIndex');
+ if (zindex) {
// The zindex was specified so we should use that.
- bb.setStyle('zIndex', this.get('zIndex'));
+ bb.setStyle('zIndex', zindex);
} else {
- // Determine the correct zindex by looking at all existing dialogs in the page.
- // Get the zindex of the parent of each wrapper node.
- Y.all(EXISTING_WINDOW_SELECTOR).each(function (node) {
- zindex = node.getStyle('zIndex');
-
- // In most cases the zindex is set on the parent of the dialog.
- if (!zindex) {
- zindex = node.get('parentNode').getStyle('zIndex');
- }
-
- if (zindex) {
- zindex = parseInt(zindex, 10);
-
- if (zindex > highestzindex) {
- highestzindex = zindex;
- }
+ // Determine the correct zindex by looking at all existing dialogs and menubars in the page.
+ Y.all(DIALOGUE_SELECTOR+', '+MENUBAR_SELECTOR).each(function (node) {
+ var zindex = this.findZIndex(node);
+ if (zindex > highestzindex) {
+ highestzindex = zindex;
}
- });
+ }, this);
// Only set the zindex if we found a wrapper.
if (highestzindex > 0) {
- bb.setStyle('zIndex', highestzindex + 1);
+ bb.setStyle('zIndex', (highestzindex + 1).toString());
}
}
},
+ /**
+ * Finds the zIndex of the given node or its parent.
+ *
+ * @method findZIndex
+ * @param Node node
+ * @returns int Return either the zIndex of 0 if one was not found.
+ */
+ findZIndex : function(node) {
+ // In most cases the zindex is set on the parent of the dialog.
+ var zindex = node.getStyle('zIndex') || node.ancestor().getStyle('zIndex');
+ if (zindex) {
+ return parseInt(zindex, 10);
+ }
+ return 0;
+ },
+
/**
* Enable or disable document scrolling (see if there are any modal or fullscreen popups).
*