]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Fix background scrolling for Android and improve on iOS 8807/head
authorKevin Ball <kmball11@gmail.com>
Wed, 18 May 2016 19:40:46 +0000 (12:40 -0700)
committerKevin Ball <kmball11@gmail.com>
Wed, 18 May 2016 19:40:46 +0000 (12:40 -0700)
js/foundation.reveal.js

index 50b010e30e05329d956cfbadb61af2611e2856d3..c0449763f6611314a4bee0a2373be36dbaf54642 100644 (file)
@@ -42,9 +42,7 @@ class Reveal {
     this.id = this.$element.attr('id');
     this.isActive = false;
     this.cached = {mq: Foundation.MediaQuery.current};
-    this.isiOS = iPhoneSniff();
-
-    if(this.isiOS){ this.$element.addClass('is-ios'); }
+    this.isMobile = mobileSniff();
 
     this.$anchor = $(`[data-open="${this.id}"]`).length ? $(`[data-open="${this.id}"]`) : $(`[data-toggle="${this.id}"]`);
     this.$anchor.attr({
@@ -271,17 +269,14 @@ class Reveal {
      */
     this.$element.trigger('open.zf.reveal');
 
-    if (this.isiOS) {
-      var scrollPos = window.pageYOffset;
-      $('html, body').addClass('is-reveal-open').scrollTop(scrollPos);
+    if (this.isMobile) {
+      this.originalScrollPos = window.pageYOffset;
+      $('html, body').addClass('is-reveal-open');
     }
     else {
       $('body').addClass('is-reveal-open');
     }
 
-    $('body')
-      .addClass('is-reveal-open');
-
     setTimeout(() => {
       this._extraHandlers();
     }, 0);
@@ -408,8 +403,12 @@ class Reveal {
     this.$element.off('keydown.zf.reveal');
 
     function finishUp() {
-      if (_this.isiOS) {
+      if (_this.isMobile) {
         $('html, body').removeClass('is-reveal-open');
+        if(_this.originalScrollPos) {
+          $('body').scrollTop(_this.originalScrollPos);
+          _this.originalScrollPos = null;
+        }
       }
       else {
         $('body').removeClass('is-reveal-open');
@@ -565,4 +564,12 @@ function iPhoneSniff() {
   return /iP(ad|hone|od).*OS/.test(window.navigator.userAgent);
 }
 
+function androidSniff() {
+  return /Android/.test(window.navigator.userAgent);
+}
+
+function mobileSniff() {
+  return iPhoneSniff() || androidSniff();
+}
+
 }(jQuery);