From c81672b56ddae1fbf605d384b69387c2e56d0afa Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Sat, 16 Nov 2013 09:01:16 +0800 Subject: [PATCH] MDL-42928 JavaScript: Disable lockScroll for small chooserdialogues --- .../moodle-core-chooserdialogue-debug.js | 14 ++++++++++++++ .../moodle-core-chooserdialogue-min.js | 2 +- .../moodle-core-chooserdialogue.js | 14 ++++++++++++++ lib/yui/src/chooserdialogue/js/chooserdialogue.js | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) 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 2ec1c665277..de909c337b9 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 @@ -208,6 +208,20 @@ Y.extend(CHOOSERDIALOGUE, Y.Base, { } } + // If the dialogue is larger than a reasonable minimum height, we + // disable the page scrollbars. + if (newheight > this.get('minheight')) { + // Disable the page scrollbars. + if (this.panel.lockScroll && !this.panel.lockScroll.isActive()) { + this.panel.lockScroll.enableScrollLock(); + } + } else { + // Re-enable the page scrollbars. + if (this.panel.lockScroll && this.panel.lockScroll.isActive()) { + this.panel.lockScroll.disableScrollLock(); + } + } + // Take off 15px top and bottom for borders, plus 40px each for the title and button area before setting the // new max-height totalheight = newheight; 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 60c02e4df9e..68c6d892944 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,setup_chooser_dialogue:function(e,t,n){this.bodycontent=e,this.headercontent=t,this.instanceconfig=n},prepare_chooser:function(){if(this.panel)return;var e,t={bodyContent:this.bodycontent.get("innerHTML"),headerContent:this.headercontent.get("innerHTML"),width:"540px",draggable:!0,visible:!1,zindex:100,lightbox:!0,shim:!0,render:!1,closeButtonTitle:this.get("closeButtonTitle")};for(e in this.instanceconfig)t[e]=this.instanceconfig[e];this.panel=new M.core.dialogue(t),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.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.jumplink=this.container.one(".jump"),this.submitbutton=this.container.one(".submitbutton"),this.submitbutton.set("disabled","true"),this.options.removeAttribute("disabled"),this.panel.show(),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),i=r,r-=110,e.setStyle("maxHeight",r+"px"),dialogueheight=t.getStyle("height"),dialogueheight.match(/.*px$/)?dialogueheight=dialogueheight.replace(/px$/,""):dialogueheight=i,dialogueheightthis.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.get('minheight')) { + // Disable the page scrollbars. + if (this.panel.lockScroll && !this.panel.lockScroll.isActive()) { + this.panel.lockScroll.enableScrollLock(); + } + } else { + // Re-enable the page scrollbars. + if (this.panel.lockScroll && this.panel.lockScroll.isActive()) { + this.panel.lockScroll.disableScrollLock(); + } + } + // Take off 15px top and bottom for borders, plus 40px each for the title and button area before setting the // new max-height totalheight = newheight; diff --git a/lib/yui/src/chooserdialogue/js/chooserdialogue.js b/lib/yui/src/chooserdialogue/js/chooserdialogue.js index 81c4f7d011d..a2a812f290c 100644 --- a/lib/yui/src/chooserdialogue/js/chooserdialogue.js +++ b/lib/yui/src/chooserdialogue/js/chooserdialogue.js @@ -206,6 +206,20 @@ Y.extend(CHOOSERDIALOGUE, Y.Base, { } } + // If the dialogue is larger than a reasonable minimum height, we + // disable the page scrollbars. + if (newheight > this.get('minheight')) { + // Disable the page scrollbars. + if (this.panel.lockScroll && !this.panel.lockScroll.isActive()) { + this.panel.lockScroll.enableScrollLock(); + } + } else { + // Re-enable the page scrollbars. + if (this.panel.lockScroll && this.panel.lockScroll.isActive()) { + this.panel.lockScroll.disableScrollLock(); + } + } + // Take off 15px top and bottom for borders, plus 40px each for the title and button area before setting the // new max-height totalheight = newheight;