From: Kevin Ball Date: Wed, 18 May 2016 19:40:46 +0000 (-0700) Subject: Fix background scrolling for Android and improve on iOS X-Git-Tag: v6.2.2-rc2~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8807%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Fix background scrolling for Android and improve on iOS --- diff --git a/js/foundation.reveal.js b/js/foundation.reveal.js index 50b010e30..c0449763f 100644 --- a/js/foundation.reveal.js +++ b/js/foundation.reveal.js @@ -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);