From 41ccb7fd0eb72cca378b89bdf479774fb53d19f1 Mon Sep 17 00:00:00 2001 From: Marius Olbertz Date: Sun, 15 Jan 2017 19:03:34 +0100 Subject: [PATCH] Make `.is-reveal-open` class on body persists if another Reveal is still visible. Added visual and automatic test. --- js/foundation.reveal.js | 13 ++++++++---- test/javascript/components/reveal.js | 31 +++++++++++++++++++++++++--- test/visual/reveal/basic.html | 15 ++++++++++++++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/js/foundation.reveal.js b/js/foundation.reveal.js index a3b1bfca4..b18538add 100644 --- a/js/foundation.reveal.js +++ b/js/foundation.reveal.js @@ -379,14 +379,15 @@ class Reveal { } // jQuery method of hiding else { + + this.$element.hide(this.options.hideDelay); + if (this.options.overlay) { this.$overlay.hide(0, finishUp); } else { finishUp(); } - - this.$element.hide(this.options.hideDelay); } // Conditionals to remove extra event listeners added on open @@ -402,14 +403,18 @@ class Reveal { function finishUp() { if (_this.isMobile) { - $('html, body').removeClass('is-reveal-open'); + if ($('.reveal:visible').length === 0) { + $('html, body').removeClass('is-reveal-open'); + } if(_this.originalScrollPos) { $('body').scrollTop(_this.originalScrollPos); _this.originalScrollPos = null; } } else { - $('body').removeClass('is-reveal-open'); + if ($('.reveal:visible').length === 0) { + $('body').removeClass('is-reveal-open'); + } } diff --git a/test/javascript/components/reveal.js b/test/javascript/components/reveal.js index bca91dc47..433a9256b 100644 --- a/test/javascript/components/reveal.js +++ b/test/javascript/components/reveal.js @@ -175,16 +175,42 @@ describe('Reveal', function() { $html.should.have.attr('aria-hidden', 'true'); }); - it('removes class from body', function() { + it('removes class from body', function(done) { $html = $(template).appendTo('body'); plugin = new Foundation.Reveal($html, {}); // Open it first plugin.open(); + + $html.on('closed.zf.reveal', function() { + $('body').should.not.have.class('is-reveal-open'); + done(); + }); + plugin.close(); + }); + it('does not remove class from body if another reveal is open', function(done) { + $html = $(template).appendTo('body'); + plugin = new Foundation.Reveal($html, {multipleOpened: true}); + + let $html2 = $(template).attr('id', 'exampleModal2').appendTo('body'); + let plugin2 = new Foundation.Reveal($html2, {multipleOpened: true, vOffset: 10}); + + // Open both first + plugin.open(); + plugin2.open(); + + + $html.on('closed.zf.reveal', function() { - $('body').should.not.have.class('is-reveal-open'); + $('body').should.have.class('is-reveal-open'); + plugin2.destroy(); + $html2.remove(); + done(); + }); + + plugin.close(); }); it('fires closed.zf.reveal event', function(done) { $html = $(template).appendTo('body'); @@ -247,7 +273,6 @@ describe('Reveal', function() { $anchor.trigger('click'); plugin.$overlay.should.be.visible; - $anchor.remove(); }); it('closes a modal on overlay click if closeOnClick option is true', function() { diff --git a/test/visual/reveal/basic.html b/test/visual/reveal/basic.html index 317a30edb..2922d555a 100644 --- a/test/visual/reveal/basic.html +++ b/test/visual/reveal/basic.html @@ -72,6 +72,21 @@

Close modal

+ +
+

Multiple opened

+

Each link should open a separate modal.

+

Open modal 1

+

Open modal 2

+
+

Modal 1 - Now click the other one.

+

Close modal

+
+
+

Modal 2 - Now click the other one.

+

Close modal

+
+
-- 2.47.2