From f2b235cb147afd693cf9c6a8f3c14be20761282e Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Fri, 23 Aug 2013 09:40:41 +1200 Subject: [PATCH] MDL-41214 notification: now looks at menubar zIndex as well --- ...moodle-core-notification-dialogue-debug.js | 67 +++++++++---------- .../moodle-core-notification-dialogue-min.js | 2 +- .../moodle-core-notification-dialogue.js | 67 +++++++++---------- lib/yui/src/notification/js/dialogue.js | 67 +++++++++---------- 4 files changed, 100 insertions(+), 103 deletions(-) diff --git a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js index 9581c3efbc55f..f91750a9f7246 100644 --- a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js +++ b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js @@ -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. @@ -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). * diff --git a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-min.js b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-min.js index 17126d6b6875a..71d6e0239433f 100644 --- a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-min.js +++ b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-min.js @@ -1 +1 @@ -YUI.add("moodle-core-notification-dialogue",function(e,t){var n,r,i,s,o,u,a,f;n="moodle-dialogue",r="notificationBase",i=0,s="yesLabel",o="noLabel",u="title",a="question",f={BASE:"moodle-dialogue-base",WRAP:"moodle-dialogue-wrap",HEADER:"moodle-dialogue-hd",BODY:"moodle-dialogue-bd",CONTENT:"moodle-dialogue-content",FOOTER:"moodle-dialogue-ft",HIDDEN:"hidden",LIGHTBOX:"moodle-dialogue-lightbox"},M.core=M.core||{};var l="Moodle dialogue",c,h,p,d,v;DIALOGUE_MODAL_CLASS="yui3-widget-modal",h=n+"-fullscreen",p=n+"-hidden",d="[role=dialog]",v="no-scrolling",c=function(t){i++;var n="moodle-dialogue-"+i;t.notificationBase=e.Node.create('
').append(e.Node.create('').append(e.Node.create('
')).append(e.Node.create('
')).append(e.Node.create('
'))),e.one(document.body).append(t.notificationBase),t.additionalBaseClass&&t.notificationBase.addClass(t.additionalBaseClass),t.srcNode="#"+n,t.width=t.width||"400px",t.visible=t.visible||!1,t.center=t.centered&&!0,t.centered=!1,t.COUNT=i,t.width==="auto"&&delete t.width,t.lightbox!==!1&&(t.modal=!0),delete t.lightbox,t.closeButton===!1?t.buttons=null:t.buttons=[{section:e.WidgetStdMod.HEADER,classNames:"closebutton",action:function(){this.hide()}}],c.superclass.constructor.apply(this,[t]),t.closeButton!==!1&&this.get("buttons").header[0].setAttribute("title",this.get("closeButtonTitle"))},e.extend(c,e.Panel,{_resizeevent:null,_orientationevent:null,initializer:function(t){var n;this.render(),this.show(),this.after("visibleChange",this.visibilityChanged,this),t.center&&this.centerDialogue(),t.visible||this.hide(),this.set("COUNT",i),n=this.get("boundingBox"),t.extraClasses&&e.Array.each(t.extraClasses,n.addClass,n),t.visible&&this.applyZIndex()},applyZIndex:function(){var t=0,n,r;r=this.get("boundingBox"),this.get("zIndex")?r.setStyle("zIndex",this.get("zIndex")):(e.all(d).each(function(e){n=e.getStyle("zIndex"),n||(n=e.get("parentNode").getStyle("zIndex")),n&&(n=parseInt(n,10),n>t&&(t=n))}),t>0&&r.setStyle("zIndex",t+1))},toggleDocumentScrolling:function(){var t=e.one(e.config.doc.body),n=!0,r;r="."+h+", ."+DIALOGUE_MODAL_CLASS,e.all(r).each(function(e){e.hasClass(p)||(n=!1)}),e.UA.ie>0&&(t=e.one("html")),n?t.hasClass(v)&&t.removeClass(v):t.addClass(v)},visibilityChanged:function(t){var n;t.attrName==="visible"&&(this.get("maskNode").addClass(f.LIGHTBOX),t.prevVal&&!t.newVal&&(this._resizeevent&&(this._resizeevent.detach(),this._resizeevent=null),this._orientationevent&&(this._orientationevent.detach(),this._orientationevent=null)),!t.prevVal&&t.newVal&&(this.applyZIndex(),this.makeResponsive(),this.shouldResizeFullscreen()||this.get("draggable")&&(n="#"+this.get("id")+" ."+f.HEADER,this.plug(e.Plugin.Drag,{handles:[n]}),e.one(n).setStyle("cursor","move"))),this.get("center")&&!t.prevVal&&t.newVal&&this.centerDialogue(),this.toggleDocumentScrolling())},makeResponsive:function(){var t=this.get("boundingBox"),r;this.shouldResizeFullscreen()?(t.addClass(n+"-fullscreen"),t.setStyles({left:null,top:null,width:null,height:null}),r=e.one("#"+this.get("id")+" ."+f.BODY),r.setStyle("overflow","auto")):this.get("responsive")&&(t.removeClass(n+"-fullscreen").setStyles({overflow:"inherit",width:this.get("width"),height:this.get("height")}),r=e.one("#"+this.get("id")+" ."+f.BODY),r.setStyle("overflow","inherit"))},centerDialogue:function(){var t=this.get("boundingBox"),n=t.hasClass(p),r,i;if(this.shouldResizeFullscreen())return;n&&t.setStyle("top","-1000px").removeClass(p),r=Math.max(Math.round((t.get("winWidth")-t.get("offsetWidth"))/2),15),i=Math.max(Math.round((t.get("winHeight")-t.get("offsetHeight"))/2),15)+e.one(window).get("scrollTop"),t.setStyles({left:r,top:i}),n&&t.addClass(p)},shouldResizeFullscreen:function(){return window===window.parent&&this.get("responsive")&&Math.floor(e.one(document.body).get("winWidth"))').append(e.Node.create('').append(e.Node.create('
')).append(e.Node.create('
')).append(e.Node.create('
'))),e.one(document.body).append(t.notificationBase),t.additionalBaseClass&&t.notificationBase.addClass(t.additionalBaseClass),t.srcNode="#"+n,t.width=t.width||"400px",t.visible=t.visible||!1,t.center=t.centered&&!0,t.centered=!1,t.COUNT=i,t.width==="auto"&&delete t.width,t.lightbox!==!1&&(t.modal=!0),delete t.lightbox,t.closeButton===!1?t.buttons=null:t.buttons=[{section:e.WidgetStdMod.HEADER,classNames:"closebutton",action:function(){this.hide()}}],c.superclass.constructor.apply(this,[t]),t.closeButton!==!1&&this.get("buttons").header[0].setAttribute("title",this.get("closeButtonTitle"))},e.extend(c,e.Panel,{_resizeevent:null,_orientationevent:null,initializer:function(t){var n;this.render(),this.show(),this.after("visibleChange",this.visibilityChanged,this),t.center&&this.centerDialogue(),t.visible||this.hide(),this.set("COUNT",i),n=this.get("boundingBox"),t.extraClasses&&e.Array.each(t.extraClasses,n.addClass,n),t.visible&&this.applyZIndex()},applyZIndex:function(){var t=0,n=this.get("boundingBox"),r=this.get("zIndex");r?n.setStyle("zIndex",r):(e.all(v+", "+m).each(function(e){var n=this.findZIndex(e);n>t&&(t=n)},this),t>0&&n.setStyle("zIndex",(t+1).toString()))},findZIndex:function(e){var t=e.getStyle("zIndex")||e.ancestor().getStyle("zIndex");return t?parseInt(t,10):0},toggleDocumentScrolling:function(){var t=e.one(e.config.doc.body),n=!0,r;r="."+h+", ."+d,e.all(r).each(function(e){e.hasClass(p)||(n=!1)}),e.UA.ie>0&&(t=e.one("html")),n?t.hasClass(g)&&t.removeClass(g):t.addClass(g)},visibilityChanged:function(t){var n;t.attrName==="visible"&&(this.get("maskNode").addClass(f.LIGHTBOX),t.prevVal&&!t.newVal&&(this._resizeevent&&(this._resizeevent.detach(),this._resizeevent=null),this._orientationevent&&(this._orientationevent.detach(),this._orientationevent=null)),!t.prevVal&&t.newVal&&(this.applyZIndex(),this.makeResponsive(),this.shouldResizeFullscreen()||this.get("draggable")&&(n="#"+this.get("id")+" ."+f.HEADER,this.plug(e.Plugin.Drag,{handles:[n]}),e.one(n).setStyle("cursor","move"))),this.get("center")&&!t.prevVal&&t.newVal&&this.centerDialogue(),this.toggleDocumentScrolling())},makeResponsive:function(){var t=this.get("boundingBox"),r;this.shouldResizeFullscreen()?(t.addClass(n+"-fullscreen"),t.setStyles({left:null,top:null,width:null,height:null}),r=e.one("#"+this.get("id")+" ."+f.BODY),r.setStyle("overflow","auto")):this.get("responsive")&&(t.removeClass(n+"-fullscreen").setStyles({overflow:"inherit",width:this.get("width"),height:this.get("height")}),r=e.one("#"+this.get("id")+" ."+f.BODY),r.setStyle("overflow","inherit"))},centerDialogue:function(){var t=this.get("boundingBox"),n=t.hasClass(p),r,i;if(this.shouldResizeFullscreen())return;n&&t.setStyle("top","-1000px").removeClass(p),r=Math.max(Math.round((t.get("winWidth")-t.get("offsetWidth"))/2),15),i=Math.max(Math.round((t.get("winHeight")-t.get("offsetHeight"))/2),15)+e.one(window).get("scrollTop"),t.setStyles({left:r,top:i}),n&&t.addClass(p)},shouldResizeFullscreen:function(){return window===window.parent&&this.get("responsive")&&Math.floor(e.one(document.body).get("winWidth")) 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). * diff --git a/lib/yui/src/notification/js/dialogue.js b/lib/yui/src/notification/js/dialogue.js index bc2a5e75dcf15..1f19cc80d3cc6 100644 --- a/lib/yui/src/notification/js/dialogue.js +++ b/lib/yui/src/notification/js/dialogue.js @@ -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. @@ -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). *