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;
}
},
/**
- * 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;
},
* @method disableScrollLock
* @chainable
*/
- disableScrollLock: function() {
+ disableScrollLock: function(force) {
if (this.isActive()) {
Y.log('Disabling LockScroll.', 'debug', 'moodle-core-lockscroll');
this._enabled = false;
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);
}