From: Kevin Ball Date: Tue, 25 Oct 2016 17:18:57 +0000 (-0700) Subject: Fix a race condition when reveal is using animations X-Git-Tag: v6.3-rc1~26^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b067936b717d24e87d302faef74699e583d0a51;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Fix a race condition when reveal is using animations --- diff --git a/js/foundation.reveal.js b/js/foundation.reveal.js index 05f949c20..700a02500 100644 --- a/js/foundation.reveal.js +++ b/js/foundation.reveal.js @@ -232,16 +232,30 @@ class Reveal { */ this.$element.trigger('closeme.zf.reveal', this.id); } + + var _this = this; + + function addRevealOpenClasses() { + if (_this.isMobile) { + if(!_this.originalScrollPos) { + _this.originalScrollPos = window.pageYOffset; + } + $('html, body').addClass('is-reveal-open'); + } + else { + $('body').addClass('is-reveal-open'); + } + } // Motion UI method of reveal if (this.options.animationIn) { - var _this = this; - function afterAnimationFocus(){ + function afterAnimation(){ _this.$element .attr({ 'aria-hidden': false, 'tabindex': -1 }) .focus(); + addRevealOpenClasses(); } if (this.options.overlay) { Foundation.Motion.animateIn(this.$overlay, 'fade-in'); @@ -249,7 +263,7 @@ class Reveal { Foundation.Motion.animateIn(this.$element, this.options.animationIn, () => { if(this.$element) { // protect against object having been removed this.focusableElements = Foundation.Keyboard.findFocusable(this.$element); - afterAnimationFocus(); + afterAnimation(); } }); } @@ -275,13 +289,7 @@ class Reveal { */ this.$element.trigger('open.zf.reveal'); - if (this.isMobile) { - this.originalScrollPos = window.pageYOffset; - $('html, body').addClass('is-reveal-open'); - } - else { - $('body').addClass('is-reveal-open'); - } + addRevealOpenClasses(); setTimeout(() => { this._extraHandlers();