From b959e5085ac0d16d99ac3354e0d098a32a7f39b7 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 25 Feb 2014 10:42:45 +0800 Subject: [PATCH] MDL-44334 Javascript: Prevent scroll locking for small screen heights --- .../moodle-core-chooserdialogue-debug.js | 2 +- .../moodle-core-chooserdialogue-min.js | 2 +- .../moodle-core-chooserdialogue.js | 2 +- .../moodle-core-lockscroll-debug.js | 13 ++++++++++++- .../moodle-core-lockscroll-min.js | 2 +- .../moodle-core-lockscroll.js | 12 +++++++++++- .../moodle-core-notification-dialogue-debug.js | 7 +++++-- .../moodle-core-notification-dialogue-min.js | 4 ++-- .../moodle-core-notification-dialogue.js | 7 +++++-- lib/yui/src/chooserdialogue/js/chooserdialogue.js | 2 +- lib/yui/src/lockscroll/js/lockscroll.js | 13 ++++++++++++- lib/yui/src/notification/js/dialogue.js | 7 +++++-- 12 files changed, 57 insertions(+), 16 deletions(-) diff --git a/lib/yui/build/moodle-core-chooserdialogue/moodle-core-chooserdialogue-debug.js b/lib/yui/build/moodle-core-chooserdialogue/moodle-core-chooserdialogue-debug.js index e3e3b8f8b98..9413f1e2698 100644 --- a/lib/yui/build/moodle-core-chooserdialogue/moodle-core-chooserdialogue-debug.js +++ b/lib/yui/build/moodle-core-chooserdialogue/moodle-core-chooserdialogue-debug.js @@ -221,7 +221,7 @@ Y.extend(CHOOSERDIALOGUE, Y.Base, { if (newheight > this.get('minheight')) { // Disable the page scrollbars. if (this.panel.lockScroll && !this.panel.lockScroll.isActive()) { - this.panel.lockScroll.enableScrollLock(); + this.panel.lockScroll.enableScrollLock(true); } } else { // Re-enable the page scrollbars. diff --git a/lib/yui/build/moodle-core-chooserdialogue/moodle-core-chooserdialogue-min.js b/lib/yui/build/moodle-core-chooserdialogue/moodle-core-chooserdialogue-min.js index ccf12497753..b1de0344079 100644 --- a/lib/yui/build/moodle-core-chooserdialogue/moodle-core-chooserdialogue-min.js +++ b/lib/yui/build/moodle-core-chooserdialogue/moodle-core-chooserdialogue-min.js @@ -1 +1 @@ -YUI.add("moodle-core-chooserdialogue",function(e,t){var n=function(){n.superclass.constructor.apply(this,arguments)};e.extend(n,e.Base,{panel:null,submitbutton:null,container:null,listenevents:[],bodycontent:null,headercontent:null,instanceconfig:null,hiddenRadioValue:null,setup_chooser_dialogue:function(e,t,n){this.bodycontent=e,this.headercontent=t,this.instanceconfig=n},prepare_chooser:function(){if(this.panel)return;var t,n={bodyContent:this.bodycontent.get("innerHTML"),headerContent:this.headercontent.get("innerHTML"),width:"540px",draggable:!0,visible:!1,zindex:100,modal:!0,shim:!0,closeButtonTitle:this.get("closeButtonTitle"),focusOnPreviousTargetAfterHide:!0,render:!1};for(t in this.instanceconfig)n[t]=this.instanceconfig[t];this.panel=new M.core.dialogue(n),this.bodycontent.remove(),this.headercontent.remove(),this.panel.hide(),this.panel.render(),this.container=this.panel.get("boundingBox").one(".choosercontainer"),this.options=this.container.all(".option input[type=radio]"),this.hiddenRadioValue=e.Node.create(''),this.container.one("form").appendChild(this.hiddenRadioValue),this.panel.get("boundingBox").addClass("chooserdialogue")},display_chooser:function(t){var n,r,i;this.prepare_chooser(),t.preventDefault(),n=this.panel.get("boundingBox"),r=this.container.one(".alloptions"),i=e.one("document").on("orientationchange",function(){this.center_dialogue(r)},this),this.listenevents.push(i),i=e.one("window").on("resize",function(){this.center_dialogue(r)},this),this.listenevents.push(i),i=this.container.on("click",this.check_options,this),this.listenevents.push(i),i=this.container.on("key_up",this.check_options,this),this.listenevents.push(i),i=this.container.on("dblclick",function(e){e.target.ancestor("div.option")&&(this.check_options(),this.submitbutton.setAttribute("disabled","disabled"),this.options.setAttribute("disabled","disabled"),this.cancel_listenevents(),this.container.one("form").submit())},this),this.listenevents.push(i),this.container.one("form").on("submit",function(){this.submitbutton.setAttribute("disabled","disabled"),this.options.setAttribute("disabled","disabled"),this.cancel_listenevents()},this),i=this.container.one(".addcancel").on("click",this.cancel_popup,this),this.listenevents.push(i),i=n.one("button.closebutton").on("click",this.cancel_popup,this),this.listenevents.push(i),i=e.one("document").on("keydown",this.handle_key_press,this),this.listenevents.push(i),this.submitbutton=this.container.one(".submitbutton"),this.submitbutton.set("disabled","true"),this.options.removeAttribute("disabled"),this.panel.show(t),this.center_dialogue(r),this.container.one(".option input[type=radio]").focus(),this.check_options()},cancel_listenevents:function(){var e;while(this.listenevents.length)e=this.listenevents.shift(),e.detach()},center_dialogue:function(e){var t=this.panel.get("boundingBox"),n=t.get("winHeight"),r,i;if(this.panel.shouldResizeFullscreen())return;r=this.get("maxheight"),n<=r&&(n<=this.get("minheight")?r=this.get("minheight"):r=n),r>this.get("minheight")?this.panel.lockScroll&&!this.panel.lockScroll.isActive()&&this.panel.lockScroll.enableScrollLock():this.panel.lockScroll&&this.panel.lockScroll.isActive()&&this.panel.lockScroll.disableScrollLock(),i=r,r-=110,e.setStyle("maxHeight",r+"px"),dialogueheight=t.getStyle("height"),dialogueheight.match(/.*px$/)?dialogueheight=dialogueheight.replace(/px$/,""):dialogueheight=i,dialogueheight'),this.container.one("form").appendChild(this.hiddenRadioValue),this.panel.get("boundingBox").addClass("chooserdialogue")},display_chooser:function(t){var n,r,i;this.prepare_chooser(),t.preventDefault(),n=this.panel.get("boundingBox"),r=this.container.one(".alloptions"),i=e.one("document").on("orientationchange",function(){this.center_dialogue(r)},this),this.listenevents.push(i),i=e.one("window").on("resize",function(){this.center_dialogue(r)},this),this.listenevents.push(i),i=this.container.on("click",this.check_options,this),this.listenevents.push(i),i=this.container.on("key_up",this.check_options,this),this.listenevents.push(i),i=this.container.on("dblclick",function(e){e.target.ancestor("div.option")&&(this.check_options(),this.submitbutton.setAttribute("disabled","disabled"),this.options.setAttribute("disabled","disabled"),this.cancel_listenevents(),this.container.one("form").submit())},this),this.listenevents.push(i),this.container.one("form").on("submit",function(){this.submitbutton.setAttribute("disabled","disabled"),this.options.setAttribute("disabled","disabled"),this.cancel_listenevents()},this),i=this.container.one(".addcancel").on("click",this.cancel_popup,this),this.listenevents.push(i),i=n.one("button.closebutton").on("click",this.cancel_popup,this),this.listenevents.push(i),i=e.one("document").on("keydown",this.handle_key_press,this),this.listenevents.push(i),this.submitbutton=this.container.one(".submitbutton"),this.submitbutton.set("disabled","true"),this.options.removeAttribute("disabled"),this.panel.show(t),this.center_dialogue(r),this.container.one(".option input[type=radio]").focus(),this.check_options()},cancel_listenevents:function(){var e;while(this.listenevents.length)e=this.listenevents.shift(),e.detach()},center_dialogue:function(e){var t=this.panel.get("boundingBox"),n=t.get("winHeight"),r,i;if(this.panel.shouldResizeFullscreen())return;r=this.get("maxheight"),n<=r&&(n<=this.get("minheight")?r=this.get("minheight"):r=n),r>this.get("minheight")?this.panel.lockScroll&&!this.panel.lockScroll.isActive()&&this.panel.lockScroll.enableScrollLock(!0):this.panel.lockScroll&&this.panel.lockScroll.isActive()&&this.panel.lockScroll.disableScrollLock(),i=r,r-=110,e.setStyle("maxHeight",r+"px"),dialogueheight=t.getStyle("height"),dialogueheight.match(/.*px$/)?dialogueheight=dialogueheight.replace(/px$/,""):dialogueheight=i,dialogueheight this.get('minheight')) { // Disable the page scrollbars. if (this.panel.lockScroll && !this.panel.lockScroll.isActive()) { - this.panel.lockScroll.enableScrollLock(); + this.panel.lockScroll.enableScrollLock(true); } } else { // Re-enable the page scrollbars. diff --git a/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-debug.js b/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-debug.js index bd96b87de2d..c9e045c2edd 100644 --- a/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-debug.js +++ b/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-debug.js @@ -48,14 +48,25 @@ Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, [] * the body to ensure that premature disabling does not occur. * * @method enableScrollLock + * @param {Boolean} forceOnSmallWindow Whether to enable the scroll lock, even for small window sizes. * @chainable */ - enableScrollLock: function() { + enableScrollLock: function(forceOnSmallWindow) { if (this.isActive()) { Y.log('LockScroll already active. Ignoring enable request', 'warn', 'moodle-core-lockscroll'); return; } + var dialogueHeight = this.get('host').get('boundingBox').get('region').height, + // Most modern browsers use win.innerHeight, but some older versions of IE use documentElement.clientHeight. + // We fall back to 0 if neither can be found which has the effect of disabling scroll locking. + windowHeight = Y.config.win.innerHeight || Y.config.doc.documentElement.clientHeight || 0; + + if (!forceOnSmallWindow && dialogueHeight > (windowHeight - 10)) { + Y.log('Dialogue height smaller than window height. Ignoring enable request.', 'warn', 'moodle-core-lockscroll'); + return; + } + Y.log('Enabling LockScroll.', 'debug', 'moodle-core-lockscroll'); this._enabled = true; var body = Y.one(Y.config.doc.body); diff --git a/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-min.js b/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-min.js index 14c414624c3..9760a7812a5 100644 --- a/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-min.js +++ b/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-min.js @@ -1 +1 @@ -YUI.add("moodle-core-lockscroll",function(e,t){e.namespace("M.core").LockScroll=e.Base.create("lockScroll",e.Plugin.Base,[],{_enabled:!1,destructor:function(){this.disableScrollLock()},enableScrollLock:function(){if(this.isActive())return;this._enabled=!0;var t=e.one(e.config.doc.body);t.addClass("lockscroll");var n=parseInt(t.getAttribute("data-activeScrollLocks"),10)||0,r=n+1;return t.setAttribute("data-activeScrollLocks",r),this},disableScrollLock:function(){if(this.isActive()){this._enabled=!1;var t=e.one(e.config.doc.body),n=parseInt(t.getAttribute("data-activeScrollLocks"),10)||1,r=n-1;n===1&&t.removeClass("lockscroll"),t.setAttribute("data-activeScrollLocks",n-1)}return this},isActive:function(){return this._enabled}},{NS:"lockScroll",ATTRS:{}})},"@VERSION@",{requires:["plugin","base-build"]}); +YUI.add("moodle-core-lockscroll",function(e,t){e.namespace("M.core").LockScroll=e.Base.create("lockScroll",e.Plugin.Base,[],{_enabled:!1,destructor:function(){this.disableScrollLock()},enableScrollLock:function(t){if(this.isActive())return;var n=this.get("host").get("boundingBox").get("region").height,r=e.config.win.innerHeight||e.config.doc.documentElement.clientHeight||0;if(!t&&n>r-10)return;this._enabled=!0;var i=e.one(e.config.doc.body);i.addClass("lockscroll");var s=parseInt(i.getAttribute("data-activeScrollLocks"),10)||0,o=s+1;return i.setAttribute("data-activeScrollLocks",o),this},disableScrollLock:function(){if(this.isActive()){this._enabled=!1;var t=e.one(e.config.doc.body),n=parseInt(t.getAttribute("data-activeScrollLocks"),10)||1,r=n-1;n===1&&t.removeClass("lockscroll"),t.setAttribute("data-activeScrollLocks",n-1)}return this},isActive:function(){return this._enabled}},{NS:"lockScroll",ATTRS:{}})},"@VERSION@",{requires:["plugin","base-build"]}); diff --git a/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll.js b/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll.js index 598745297c1..9d59fe9ffd8 100644 --- a/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll.js +++ b/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll.js @@ -48,13 +48,23 @@ Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, [] * the body to ensure that premature disabling does not occur. * * @method enableScrollLock + * @param {Boolean} forceOnSmallWindow Whether to enable the scroll lock, even for small window sizes. * @chainable */ - enableScrollLock: function() { + enableScrollLock: function(forceOnSmallWindow) { if (this.isActive()) { return; } + var dialogueHeight = this.get('host').get('boundingBox').get('region').height, + // Most modern browsers use win.innerHeight, but some older versions of IE use documentElement.clientHeight. + // We fall back to 0 if neither can be found which has the effect of disabling scroll locking. + windowHeight = Y.config.win.innerHeight || Y.config.doc.documentElement.clientHeight || 0; + + if (!forceOnSmallWindow && dialogueHeight > (windowHeight - 10)) { + return; + } + this._enabled = true; var body = Y.one(Y.config.doc.body); 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 69d33688bb6..2805d55a704 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 @@ -326,12 +326,15 @@ Y.extend(DIALOGUE, Y.Panel, { header = this.headerNode, content = this.bodyNode; + result = DIALOGUE.superclass.show.call(this); + // Lock scroll if the plugin is present. if (this.lockScroll) { - this.lockScroll.enableScrollLock(); + // We need to force the scroll locking for full screen dialogues, even if they have a small vertical size to + // prevent the background scrolling while the dialogue is open. + this.lockScroll.enableScrollLock(this.shouldResizeFullscreen()); } - result = DIALOGUE.superclass.show.call(this); if (header && header !== '') { header.focus(); } else if (content && content !== '') { 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 01dc98c6696..72068de1c8a 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,2 +1,2 @@ -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=n+"-fullscreen",p=n+"-hidden",d=" [role=dialog]",v="[role=menubar]",m=".moodle-has-zindex",g='input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]';c=function(t){var n=e.clone(t);i++;var r="moodle-dialogue-"+i;n.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(n.notificationBase),n.additionalBaseClass&&n.notificationBase.addClass(n.additionalBaseClass),n.srcNode="#"+r,n.COUNT=i,n.closeButton===!1?n.buttons=null:n.buttons=[{section:e.WidgetStdMod.HEADER,classNames:"closebutton",action:function(){this.hide()}}],c.superclass.constructor.apply(this,[n]),n.closeButton!==!1&&this.get("buttons").header[0].setAttribute("title",this.get("closeButtonTitle"))},e.extend(c,e.Panel,{_resizeevent:null,_orientationevent:null,_calculatedzindex:!1,initializer:function(){var t;this.get("render")&&this.render(),this.makeResponsive(),this.after("visibleChange",this.visibilityChanged,this),this.get("center")&&this.centerDialogue(),this.set("COUNT",i),this.get("modal")&&this.plug(e.M.core.LockScroll),t=this.get("boundingBox"),e.Array.each(this.get("extraClasses"),t.addClass,t),this.get("visible")&&this.applyZIndex(),this.on("maskShow",this.applyZIndex),this.get("visible")&&(this.show(),this.keyDelegation()),this.after("destroyedChange",function(){this.get(r).remove(!0)},this)},applyZIndex:function(){var t=1,n=1,r=this.get("boundingBox"),i=this.get("maskNode"),s=this.get("zIndex");s!==0&&!this._calculatedzindex?r.setStyle("zIndex",s):(e.all(d+", "+v+", "+m).each(function(e){var n=this.findZIndex(e);n>t&&(t=n)},this),n=(t+1).toString(),r.setStyle("zIndex",n),i.setStyle("zIndex",n),this.set("zIndex",n),this._calculatedzindex=!0)},findZIndex:function(e){var t=e.getStyle("zIndex")||e.ancestor().getStyle("zIndex");return t?parseInt(t,10):0},visibilityChanged:function(t){var n,r;t.attrName==="visible"&&(this.get("maskNode").addClass(f.LIGHTBOX),t.prevVal&&!t.newVal&&(r=this.get("boundingBox"),this._resizeevent&&(this._resizeevent.detach(),this._resizeevent=null),this._orientationevent&&(this._orientationevent.detach(),this._orientationevent=null),r.detach("key",this.keyDelegation)),!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.keyDelegation()),this.get("center")&&!t.prevVal&&t.newVal&&this.centerDialogue())},makeResponsive:function(){var t=this.get("boundingBox"),n;this.shouldResizeFullscreen()?(t.addClass(h),t.setStyles({left:null,top:null,width:null,height:null,right:null,bottom:null}),n=e.one("#"+this.get("id")+" ."+f.BODY)):this.get("responsive")&&(t.removeClass(h).setStyles({width:this.get("width"),height:this.get("height")}),n=e.one("#"+this.get("id")+" ."+f.BODY))},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(n.notificationBase),n.additionalBaseClass&&n.notificationBase.addClass(n.additionalBaseClass),n.srcNode="#"+r,n.COUNT=i,n.closeButton===!1?n.buttons=null:n.buttons=[{section:e.WidgetStdMod.HEADER,classNames:"closebutton",action:function(){this.hide()}}],c.superclass.constructor.apply(this,[n]),n.closeButton!==!1&&this.get("buttons").header[0].setAttribute("title",this.get("closeButtonTitle"))},e.extend(c,e.Panel,{_resizeevent:null,_orientationevent:null,_calculatedzindex:!1,initializer:function(){var t;this.get("render")&&this.render(),this.makeResponsive(),this.after("visibleChange",this.visibilityChanged,this),this.get("center")&&this.centerDialogue(),this.set("COUNT",i),this.get("modal")&&this.plug(e.M.core.LockScroll),t=this.get("boundingBox"),e.Array.each(this.get("extraClasses"),t.addClass,t),this.get("visible")&&this.applyZIndex(),this.on("maskShow",this.applyZIndex),this.get("visible")&&(this.show(),this.keyDelegation()),this.after("destroyedChange",function(){this.get(r).remove(!0)},this)},applyZIndex:function(){var t=1,n=1,r=this.get("boundingBox"),i=this.get("maskNode"),s=this.get("zIndex");s!==0&&!this._calculatedzindex?r.setStyle("zIndex",s):(e.all(d+", "+v+", "+m).each(function(e){var n=this.findZIndex(e);n>t&&(t=n)},this),n=(t+1).toString(),r.setStyle("zIndex",n),i.setStyle("zIndex",n),this.set("zIndex",n),this._calculatedzindex=!0)},findZIndex:function(e){var t=e.getStyle("zIndex")||e.ancestor().getStyle("zIndex");return t?parseInt(t,10):0},visibilityChanged:function(t){var n,r;t.attrName==="visible"&&(this.get("maskNode").addClass(f.LIGHTBOX),t.prevVal&&!t.newVal&&(r=this.get("boundingBox"),this._resizeevent&&(this._resizeevent.detach(),this._resizeevent=null),this._orientationevent&&(this._orientationevent.detach(),this._orientationevent=null),r.detach("key",this.keyDelegation)),!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.keyDelegation()),this.get("center")&&!t.prevVal&&t.newVal&&this.centerDialogue())},makeResponsive:function(){var t=this.get("boundingBox"),n;this.shouldResizeFullscreen()?(t.addClass(h),t.setStyles({left:null,top:null,width:null,height:null,right:null,bottom:null}),n=e.one("#"+this.get("id")+" ."+f.BODY)):this.get("responsive")&&(t.removeClass(h).setStyles({width:this.get("width"),height:this.get("height")}),n=e.one("#"+this.get("id")+" ."+f.BODY))},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")) this.get('minheight')) { // Disable the page scrollbars. if (this.panel.lockScroll && !this.panel.lockScroll.isActive()) { - this.panel.lockScroll.enableScrollLock(); + this.panel.lockScroll.enableScrollLock(true); } } else { // Re-enable the page scrollbars. diff --git a/lib/yui/src/lockscroll/js/lockscroll.js b/lib/yui/src/lockscroll/js/lockscroll.js index 10f5ad40e11..489b1efb4c7 100644 --- a/lib/yui/src/lockscroll/js/lockscroll.js +++ b/lib/yui/src/lockscroll/js/lockscroll.js @@ -46,14 +46,25 @@ Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, [] * the body to ensure that premature disabling does not occur. * * @method enableScrollLock + * @param {Boolean} forceOnSmallWindow Whether to enable the scroll lock, even for small window sizes. * @chainable */ - enableScrollLock: function() { + enableScrollLock: function(forceOnSmallWindow) { if (this.isActive()) { Y.log('LockScroll already active. Ignoring enable request', 'warn', 'moodle-core-lockscroll'); return; } + var dialogueHeight = this.get('host').get('boundingBox').get('region').height, + // Most modern browsers use win.innerHeight, but some older versions of IE use documentElement.clientHeight. + // We fall back to 0 if neither can be found which has the effect of disabling scroll locking. + windowHeight = Y.config.win.innerHeight || Y.config.doc.documentElement.clientHeight || 0; + + if (!forceOnSmallWindow && dialogueHeight > (windowHeight - 10)) { + Y.log('Dialogue height smaller than window height. Ignoring enable request.', 'warn', 'moodle-core-lockscroll'); + return; + } + Y.log('Enabling LockScroll.', 'debug', 'moodle-core-lockscroll'); this._enabled = true; var body = Y.one(Y.config.doc.body); diff --git a/lib/yui/src/notification/js/dialogue.js b/lib/yui/src/notification/js/dialogue.js index 34c82102ab8..c9c0a733477 100644 --- a/lib/yui/src/notification/js/dialogue.js +++ b/lib/yui/src/notification/js/dialogue.js @@ -295,12 +295,15 @@ Y.extend(DIALOGUE, Y.Panel, { header = this.headerNode, content = this.bodyNode; + result = DIALOGUE.superclass.show.call(this); + // Lock scroll if the plugin is present. if (this.lockScroll) { - this.lockScroll.enableScrollLock(); + // We need to force the scroll locking for full screen dialogues, even if they have a small vertical size to + // prevent the background scrolling while the dialogue is open. + this.lockScroll.enableScrollLock(this.shouldResizeFullscreen()); } - result = DIALOGUE.superclass.show.call(this); if (header && header !== '') { header.focus(); } else if (content && content !== '') {