Skip to content

Commit

Permalink
MDL-41214 notification: now looks at menubar zIndex as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Sep 1, 2013
1 parent ee78814 commit f2b235c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 103 deletions.
Expand Up @@ -38,16 +38,12 @@ M.core = M.core || {};

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.
Expand Down Expand Up @@ -157,39 +153,42 @@ Y.extend(DIALOGUE, Y.Panel, {
*/
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).
*
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -38,16 +38,12 @@ M.core = M.core || {};

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.
Expand Down Expand Up @@ -157,39 +153,42 @@ Y.extend(DIALOGUE, Y.Panel, {
*/
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).
*
Expand Down
67 changes: 33 additions & 34 deletions lib/yui/src/notification/js/dialogue.js
Expand Up @@ -7,16 +7,12 @@

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.
Expand Down Expand Up @@ -126,39 +122,42 @@ Y.extend(DIALOGUE, Y.Panel, {
*/
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).
*
Expand Down

0 comments on commit f2b235c

Please sign in to comment.