Skip to content

Commit

Permalink
Use pull request foundation#10786 from SassNinja/fix-reveal-enable-sc…
Browse files Browse the repository at this point in the history
…roll for v6.5.0

7e67525 Fix reveal enableScroll calculation of scrollTop
4f27733 refactor: add defaults to `_enableScroll`/`_disableScroll` properties in Reveal
808fc3b style: document the foundation#10786 bug in Reveal

Co-Authored-By: Nicolas Coden <nicolas@ncoden.fr>
Signed-off-by: Nicolas Coden <nicolas@ncoden.fr>
  • Loading branch information
SassNinja and ncoden committed Jun 16, 2018
1 parent a16a521 commit cfd9458
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions js/foundation.reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,23 @@ class Reveal extends Plugin {

/**
* Disables the scroll when Reveal is shown to prevent the background from shifting
* @param {number} scrollTop - Scroll to visually apply, window current scroll by default
*/
_disableScroll(){
_disableScroll(scrollTop) {
scrollTop = scrollTop || $(window).scrollTop();
if ($(document).height() > $(window).height()) {
var scrollTop = $(window).scrollTop();
$("html")
.css("top", -scrollTop);
}
}

/**
* Reenables the scroll when Reveal closes
* @param {number} scrollTop - Scroll to restore, html "top" property by default (as set by `_disableScroll`)
*/
_enableScroll(){
_enableScroll(scrollTop) {
scrollTop = scrollTop || parseInt($("html").css("top"));
if ($(document).height() > $(window).height()) {
var scrollTop = parseInt($("html").css("top"));
$("html")
.css("top", "");
$(window).scrollTop(-scrollTop);
Expand Down Expand Up @@ -401,6 +403,11 @@ class Reveal extends Plugin {

function finishUp() {

// Get the current top before the modal is closed and restore the scroll after.
// TODO: use component properties instead of HTML properties
// See https://github.com/zurb/foundation-sites/pull/10786
var scrollTop = parseInt($("html").css("top"));

if ($('.reveal:visible').length === 0) {
$('html').removeClass('is-reveal-open');
}
Expand All @@ -409,7 +416,7 @@ class Reveal extends Plugin {

_this.$element.attr('aria-hidden', true);

_this._enableScroll();
_this._enableScroll(scrollTop);

/**
* Fires when the modal is done closing.
Expand Down

0 comments on commit cfd9458

Please sign in to comment.