MDL-54121 core-notification: Fix lockscroll recalc for nest dialogues
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 13 May 2016 02:18:29 +0000 (10:18 +0800)
committerDamyon Wiese <damyon@moodle.com>
Fri, 13 May 2016 04:12:05 +0000 (12:12 +0800)
lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-debug.js
lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-min.js
lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll.js
lib/yui/src/lockscroll/js/lockscroll.js

index f048876..d79fed4 100644 (file)
Binary files a/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-debug.js and b/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-debug.js differ
index 6f5faee..e7d7c8a 100644 (file)
Binary files a/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-min.js and b/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll-min.js differ
index a024bd7..e447cd1 100644 (file)
Binary files a/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll.js and b/lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll.js differ
index 1f1212b..226b30f 100644 (file)
@@ -55,12 +55,7 @@ Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, []
             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)) {
+        if (!this.shouldLockScroll(forceOnSmallWindow)) {
             Y.log('Dialogue height greater than window height. Ignoring enable request.', 'warn', 'moodle-core-lockscroll');
             return;
         }
@@ -95,29 +90,40 @@ Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, []
     },
 
     /**
-     * Recalculate whether lock scrolling should be on or off because the size of the dialogue changed.
+     * Recalculate whether lock scrolling should be on or off.
      *
-     * @method updateScrollLock
+     * @method shouldLockScroll
      * @param {Boolean} forceOnSmallWindow Whether to enable the scroll lock, even for small window sizes.
-     * @chainable
+     * @return boolean
      */
-    updateScrollLock: function(forceOnSmallWindow) {
-        var shouldBeEnabled = true,
-            dialogueHeight = this.get('host').get('boundingBox').get('region').height,
+    shouldLockScroll: function(forceOnSmallWindow) {
+        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)) {
-            shouldBeEnabled = false;
+            return false;
+        } else {
+            return true;
         }
+    },
 
+    /**
+     * Recalculate whether lock scrolling should be on or off because the size of the dialogue changed.
+     *
+     * @method updateScrollLock
+     * @param {Boolean} forceOnSmallWindow Whether to enable the scroll lock, even for small window sizes.
+     * @chainable
+     */
+    updateScrollLock: function(forceOnSmallWindow) {
         // Both these functions already check if scroll lock is active and do the right thing.
-        if (shouldBeEnabled) {
+        if (this.shouldLockScroll(forceOnSmallWindow)) {
             this.enableScrollLock(forceOnSmallWindow);
         } else {
-            this.disableScrollLock();
+            this.disableScrollLock(true);
         }
+
         return this;
     },
 
@@ -130,7 +136,7 @@ Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, []
      * @method disableScrollLock
      * @chainable
      */
-    disableScrollLock: function() {
+    disableScrollLock: function(force) {
         if (this.isActive()) {
             Y.log('Disabling LockScroll.', 'debug', 'moodle-core-lockscroll');
             this._enabled = false;
@@ -142,7 +148,7 @@ Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, []
             var currentCount = parseInt(body.getAttribute('data-activeScrollLocks'), 10) || 1,
                 newCount = currentCount - 1;
 
-            if (currentCount === 1) {
+            if (force || currentCount === 1) {
                 body.removeClass('lockscroll');
                 body.setStyle('maxWidth', null);
             }