From 6538be4f08f2dce9df842c2cf97f19881882a49e Mon Sep 17 00:00:00 2001 From: Kevin Ball Date: Wed, 18 May 2016 12:40:46 -0700 Subject: [PATCH] Fix background scrolling for Android and improve on iOS --- js/foundation.reveal.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) 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); -- 2.47.2