Skip to content

Commit

Permalink
Merge branch 'MDL-54121-master' of git://github.com/damyon/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed May 17, 2016
2 parents 96fd377 + 6885517 commit f0a2dbf
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,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;
}
Expand Down Expand Up @@ -96,6 +91,44 @@ Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, []
return this;
},

/**
* Recalculate whether lock scrolling should be on or off.
*
* @method shouldLockScroll
* @param {Boolean} forceOnSmallWindow Whether to enable the scroll lock, even for small window sizes.
* @return boolean
*/
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)) {
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 (this.shouldLockScroll(forceOnSmallWindow)) {
this.enableScrollLock(forceOnSmallWindow);
} else {
this.disableScrollLock(true);
}

return this;
},

/**
* Stop locking the page scroll.
*
Expand All @@ -105,7 +138,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;
Expand All @@ -117,7 +150,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);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 41 additions & 8 deletions lib/yui/build/moodle-core-lockscroll/moodle-core-lockscroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,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)) {
return;
}

Expand Down Expand Up @@ -91,6 +86,44 @@ Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, []
return this;
},

/**
* Recalculate whether lock scrolling should be on or off.
*
* @method shouldLockScroll
* @param {Boolean} forceOnSmallWindow Whether to enable the scroll lock, even for small window sizes.
* @return boolean
*/
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)) {
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 (this.shouldLockScroll(forceOnSmallWindow)) {
this.enableScrollLock(forceOnSmallWindow);
} else {
this.disableScrollLock(true);
}

return this;
},

/**
* Stop locking the page scroll.
*
Expand All @@ -100,7 +133,7 @@ Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, []
* @method disableScrollLock
* @chainable
*/
disableScrollLock: function() {
disableScrollLock: function(force) {
if (this.isActive()) {
this._enabled = false;

Expand All @@ -111,7 +144,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ Y.extend(DIALOGUE, Y.Panel, {
'height' : this.get('height')});
}
}

// Update Lock scroll if the plugin is present.
if (this.lockScroll) {
this.lockScroll.updateScrollLock(this.shouldResizeFullscreen());
}
},
/**
* Center the dialog on the screen.
Expand Down Expand Up @@ -387,13 +392,6 @@ Y.extend(DIALOGUE, Y.Panel, {
this.get('boundingBox').setXY(this._originalPosition);
}

// Lock scroll if the plugin is present.
if (this.lockScroll) {
// 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());
}

// Try and find a node to focus on using the focusOnShowSelector attribute.
if (focusSelector !== null) {
focusNode = this.get('boundingBox').one(focusSelector);
Expand Down
Loading

0 comments on commit f0a2dbf

Please sign in to comment.