vendor/assets/javascripts/foundation/foundation.reveal.js in foundation-rails-5.1.1.0 vs vendor/assets/javascripts/foundation/foundation.reveal.js in foundation-rails-5.2.0.0

- old
+ new

@@ -2,11 +2,11 @@ 'use strict'; Foundation.libs.reveal = { name : 'reveal', - version : '5.1.1', + version : '5.2.0', locked : false, settings : { animation: 'fadeAndPop', @@ -63,20 +63,24 @@ } } }); S(document) - .on('click.fndtn.reveal', this.close_targets(), function (e) { + .on('touchend.fndtn.reveal click.fndtn.reveal', this.close_targets(), function (e) { e.preventDefault(); if (!self.locked) { var settings = S('[' + self.attr_name() + '].open').data(self.attr_name(true) + '-init'), bg_clicked = S(e.target)[0] === S('.' + settings.bg_class)[0]; - if (bg_clicked && !settings.close_on_background_click) { - return; + if (bg_clicked) { + if (settings.close_on_background_click) { + e.stopPropagation(); + } else { + return; + } } self.locked = true; self.close.call(self, bg_clicked ? S('[' + self.attr_name() + '].open') : S(this).closest('[' + self.attr_name() + ']')); } @@ -166,12 +170,11 @@ }; } if (typeof ajax_settings === 'undefined' || !ajax_settings.url) { if (open_modal.length > 0) { - var open_modal_settings = open_modal.data(self.attr_name(true) + '-init'); - this.hide(open_modal, open_modal_settings.css.close); + this.hide(open_modal, settings.css.close); } this.show(modal, settings.css.open); } else { var old_success = typeof ajax_settings.success !== 'undefined' ? ajax_settings.success : null; @@ -184,12 +187,11 @@ modal.html(data); self.S(modal).foundation('section', 'reflow'); if (open_modal.length > 0) { - var open_modal_settings = open_modal.data(self.attr_name(true)); - self.hide(open_modal, open_modal_settings.css.close); + self.hide(open_modal, settings.css.close); } self.show(modal, settings.css.open); } }); @@ -225,11 +227,11 @@ toggle_bg : function (modal) { var settings = modal.data(this.attr_name(true)); if (this.S('.' + this.settings.bg_class).length === 0) { this.settings.bg = $('<div />', {'class': this.settings.bg_class}) - .appendTo('body'); + .appendTo('body').hide(); } if (this.settings.bg.filter(':visible').length > 0) { this.hide(this.settings.bg); } else { @@ -251,11 +253,15 @@ }); el.detach().appendTo(rootElement); } - if (/pop/i.test(settings.animation)) { + var animData = getAnimationData(settings.animation); + if (!animData.animate) { + this.locked = false; + } + if (animData.pop) { css.top = $(window).scrollTop() - el.data('offset') + 'px'; var end_css = { top: $(window).scrollTop() + el.data('css-top') + 'px', opacity: 1 }; @@ -269,11 +275,12 @@ }.bind(this)) .addClass('open'); }.bind(this), settings.animation_speed / 2); } - if (/fade/i.test(settings.animation)) { + if (animData.fade) { + css.top = $(window).scrollTop() + el.data('css-top') + 'px'; var end_css = {opacity: 1}; return setTimeout(function () { return el .css(css) @@ -289,11 +296,11 @@ } var settings = this.settings; // should we animate the background? - if (/fade/i.test(settings.animation)) { + if (getAnimationData(settings.animation).fade) { return el.fadeIn(settings.animation_speed / 2); } this.locked = false; @@ -302,11 +309,15 @@ hide : function (el, css) { // is modal if (css) { var settings = el.data(this.attr_name(true) + '-init'); - if (/pop/i.test(settings.animation)) { + var animData = getAnimationData(settings.animation); + if (!animData.animate) { + this.locked = false; + } + if (animData.pop) { var end_css = { top: - $(window).scrollTop() - el.data('offset') + 'px', opacity: 0 }; @@ -318,11 +329,11 @@ }.bind(this)) .removeClass('open'); }.bind(this), settings.animation_speed / 2); } - if (/fade/i.test(settings.animation)) { + if (animData.fade) { var end_css = {opacity: 0}; return setTimeout(function () { return el .animate(end_css, settings.animation_speed, 'linear', function () { @@ -337,11 +348,11 @@ } var settings = this.settings; // should we animate the background? - if (/fade/i.test(settings.animation)) { + if (getAnimationData(settings.animation).fade) { return el.fadeOut(settings.animation_speed / 2); } return el.hide(); }, @@ -394,6 +405,23 @@ $(this.scope).off('.fndtn.reveal'); }, reflow : function () {} }; + + /* + * getAnimationData('popAndFade') // {animate: true, pop: true, fade: true} + * getAnimationData('fade') // {animate: true, pop: false, fade: true} + * getAnimationData('pop') // {animate: true, pop: true, fade: false} + * getAnimationData('foo') // {animate: false, pop: false, fade: false} + * getAnimationData(null) // {animate: false, pop: false, fade: false} + */ + function getAnimationData(str) { + var fade = /fade/i.test(str); + var pop = /pop/i.test(str); + return { + animate: fade || pop, + pop: pop, + fade: fade + }; + } }(jQuery, this, this.document));