From b95b05085c1ee1e68f275186acef77cb2a9dcd1d Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Mon, 11 Jun 2012 08:18:44 +0100 Subject: [PATCH] MDL-33649 Hide page scrollbars when a chooser is open This has the effect of preventing page scrolling which makes the chooser difficult to use when there are many options or the page is too small. --- lib/yui/chooserdialogue/chooserdialogue.js | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/yui/chooserdialogue/chooserdialogue.js b/lib/yui/chooserdialogue/chooserdialogue.js index 7f720d26026..bd29b818770 100644 --- a/lib/yui/chooserdialogue/chooserdialogue.js +++ b/lib/yui/chooserdialogue/chooserdialogue.js @@ -17,6 +17,9 @@ YUI.add('moodle-core-chooserdialogue', function(Y) { // Any event listeners we may need to cancel later listenevents : [], + // The initial overflow setting + initialoverflow : '', + setup_chooser_dialogue : function(bodycontent, headercontent, config) { // Set Default options var params = { @@ -65,6 +68,14 @@ YUI.add('moodle-core-chooserdialogue', function(Y) { var bb = this.overlay.get('boundingBox'); var dialogue = this.container.one('.alloptions'); + // Get the overflow setting when the chooser was opened - we + // may need this later + if (Y.UA.ie > 0) { + this.initialoverflow = Y.one('html').getStyle('overflow'); + } else { + this.initialoverflow = Y.one('body').getStyle('overflow'); + } + var thisevent; // These will trigger a check_options call to display the correct help @@ -168,9 +179,21 @@ YUI.add('moodle-core-chooserdialogue', function(Y) { // Set a fixed position if the window is large enough if (newheight > this.get('minheight')) { bb.setStyle('position', 'fixed'); + // Disable the page scrollbars + if (Y.UA.ie > 0) { + Y.one('html').setStyle('overflow', 'hidden'); + } else { + Y.one('body').setStyle('overflow', 'hidden'); + } } else { bb.setStyle('position', 'absolute'); offsettop = Y.one('window').get('scrollTop'); + // Ensure that the page scrollbars are enabled + if (Y.UA.ie > 0) { + Y.one('html').setStyle('overflow', this.initialoverflow); + } else { + Y.one('body').setStyle('overflow', this.initialoverflow); + } } // Take off 15px top and bottom for borders, plus 40px each for the title and button area before setting the @@ -203,6 +226,14 @@ YUI.add('moodle-core-chooserdialogue', function(Y) { hide : function() { // Detach the global keypress handler before hiding Y.one('document').detach('keyup', this.handle_key_press, this); + + // Re-enable the page scrollbars + if (Y.UA.ie > 0) { + Y.one('html').setStyle('overflow', this.initialoverflow); + } else { + Y.one('body').setStyle('overflow', this.initialoverflow); + } + this.container.detachAll(); this.overlay.hide(); },