]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
refactor: add defaults to `_enableScroll`/`_disableScroll` properties in Reveal
authorNicolas Coden <nicolas@ncoden.fr>
Sat, 20 Jan 2018 14:42:43 +0000 (15:42 +0100)
committerNicolas Coden <nicolas@ncoden.fr>
Sat, 20 Jan 2018 14:42:43 +0000 (15:42 +0100)
Try to keep a more or less enclosed behavior by using defaults properties. The functions behaviors can be changed when needed.

js/foundation.reveal.js

index 369b2ebc78ba358393276a98dc909ff0c9107a94..3c1bad7532a149d65c3c6f9ab644d0ab79edac93 100644 (file)
@@ -186,7 +186,8 @@ class Reveal extends Plugin {
   * Disables the scroll when Reveal is shown to prevent the background from shifting
   * @param {number} scrollTop
   */
-  _disableScroll(scrollTop){
+  _disableScroll(scrollTop) {
+    scrollTop = scrollTop || $(window).scrollTop();
     if ($(document).height() > $(window).height()) {
       $("html")
         .css("top", -scrollTop);
@@ -197,7 +198,8 @@ class Reveal extends Plugin {
   * Reenables the scroll when Reveal closes
   * @param {number} scrollTop
   */
-  _enableScroll(scrollTop){
+  _enableScroll(scrollTop) {
+    scrollTop = scrollTop || parseInt($("html").css("top"));
     if ($(document).height() > $(window).height()) {
       $("html")
         .css("top", "");
@@ -264,9 +266,7 @@ class Reveal extends Plugin {
       this.$element.trigger('closeme.zf.reveal', this.id);
     }
 
-    var scrollTop = $(window).scrollTop();
-
-    this._disableScroll(scrollTop);
+    this._disableScroll();
 
     var _this = this;