vendor/assets/javascripts/foundation/foundation.reveal.js in foundation-rails-5.5.1.2 vs vendor/assets/javascripts/foundation/foundation.reveal.js in foundation-rails-5.5.2.0

- old
+ new

@@ -2,11 +2,11 @@ 'use strict'; Foundation.libs.reveal = { name : 'reveal', - version : '5.5.1', + version : '5.5.2', locked : false, settings : { animation : 'fadeAndPop', @@ -19,10 +19,11 @@ root_element : 'body', open : function(){}, opened : function(){}, close : function(){}, closed : function(){}, + on_ajax_error: $.noop, bg : $('.reveal-modal-bg'), css : { open : { 'opacity' : 0, 'visibility' : 'visible', @@ -50,20 +51,20 @@ .on('click.fndtn.reveal', '[' + this.add_namespace('data-reveal-id') + ']:not([disabled])', function (e) { e.preventDefault(); if (!self.locked) { var element = S(this), - ajax = element.data(self.data_attr('reveal-ajax')); + ajax = element.data(self.data_attr('reveal-ajax')), + replaceContentSel = element.data(self.data_attr('reveal-replace-content')); self.locked = true; if (typeof ajax === 'undefined') { self.open.call(self, element); } else { var url = ajax === true ? element.attr('href') : ajax; - - self.open.call(self, element, {url : url}); + self.open.call(self, element, {url : url}, { replaceContentSel : replaceContentSel }); } } }); S(document) @@ -80,11 +81,11 @@ return; } } self.locked = true; - self.close.call(self, bg_clicked ? S('[' + self.attr_name() + '].open') : S(this).closest('[' + self.attr_name() + ']')); + self.close.call(self, bg_clicked ? S('[' + self.attr_name() + '].open:not(.toback)') : S(this).closest('[' + self.attr_name() + ']')); } }); if (S('[' + self.attr_name() + ']', this.scope).length > 0) { S(this.scope) @@ -151,10 +152,11 @@ } var settings = modal.data(self.attr_name(true) + '-init'); settings = settings || this.settings; + if (modal.hasClass('open') && target.attr('data-reveal-id') == modal.attr('id')) { return self.close(modal); } if (!modal.hasClass('open')) { @@ -163,12 +165,19 @@ if (typeof modal.data('css-top') === 'undefined') { modal.data('css-top', parseInt(modal.css('top'), 10)) .data('offset', this.cache_offset(modal)); } + modal.attr('tabindex','0').attr('aria-hidden','false'); + this.key_up_on(modal); // PATCH #3: turning on key up capture only when a reveal window is open + // Prevent namespace event from triggering twice + modal.on('open.fndtn.reveal', function(e) { + if (e.namespace !== 'fndtn.reveal') return; + }); + modal.on('open.fndtn.reveal').trigger('open.fndtn.reveal'); if (open_modal.length < 1) { this.toggle_bg(modal, true); } @@ -180,70 +189,86 @@ } if (typeof ajax_settings === 'undefined' || !ajax_settings.url) { if (open_modal.length > 0) { if (settings.multiple_opened) { - this.to_back(open_modal); + self.to_back(open_modal); } else { - this.hide(open_modal, settings.css.close); + self.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; - $.extend(ajax_settings, { success : function (data, textStatus, jqXHR) { if ( $.isFunction(old_success) ) { var result = old_success(data, textStatus, jqXHR); if (typeof result == 'string') { data = result; } } - modal.html(data); + if (typeof options !== 'undefined' && typeof options.replaceContentSel !== 'undefined') { + modal.find(options.replaceContentSel).html(data); + } else { + modal.html(data); + } + self.S(modal).foundation('section', 'reflow'); self.S(modal).children().foundation(); if (open_modal.length > 0) { if (settings.multiple_opened) { - this.to_back(open_modal); + self.to_back(open_modal); } else { - this.hide(open_modal, settings.css.close); + self.hide(open_modal, settings.css.close); } } self.show(modal, settings.css.open); } }); + // check for if user initalized with error callback + if (settings.on_ajax_error !== $.noop) { + $.extend(ajax_settings, { + error : settings.on_ajax_error + }); + } + $.ajax(ajax_settings); } } self.S(window).trigger('resize'); }, close : function (modal) { var modal = modal && modal.length ? modal : this.S(this.scope), open_modals = this.S('[' + this.attr_name() + '].open'), - settings = modal.data(this.attr_name(true) + '-init') || this.settings; + settings = modal.data(this.attr_name(true) + '-init') || this.settings, + self = this; if (open_modals.length > 0) { + + modal.removeAttr('tabindex','0').attr('aria-hidden','true'); + this.locked = true; this.key_up_off(modal); // PATCH #3: turning on key up capture only when a reveal window is open - modal.trigger('close').trigger('close.fndtn.reveal'); - + + modal.trigger('close.fndtn.reveal'); + if ((settings.multiple_opened && open_modals.length === 1) || !settings.multiple_opened || modal.length > 1) { - this.toggle_bg(modal, false); - this.to_front(modal); + self.toggle_bg(modal, false); + self.to_front(modal); } - + if (settings.multiple_opened) { - this.hide(modal, settings.css.close, settings); - this.to_front($($.makeArray(open_modals).reverse()[1])); + self.hide(modal, settings.css.close, settings); + self.to_front($($.makeArray(open_modals).reverse()[1])); } else { - this.hide(open_modals, settings.css.close, settings); + self.hide(open_modals, settings.css.close, settings); } } }, close_targets : function () { @@ -274,11 +299,12 @@ show : function (el, css) { // is modal if (css) { var settings = el.data(this.attr_name(true) + '-init') || this.settings, - root_element = settings.root_element; + root_element = settings.root_element, + context = this; if (el.parent(root_element).length === 0) { var placeholder = el.wrap('<div style="display: none;" />').parent(); el.on('closed.fndtn.reveal.wrapped', function () { @@ -302,33 +328,33 @@ return setTimeout(function () { return el .css(css) .animate(end_css, settings.animation_speed, 'linear', function () { - this.locked = false; - el.trigger('opened').trigger('opened.fndtn.reveal'); - }.bind(this)) + context.locked = false; + el.trigger('opened.fndtn.reveal'); + }) .addClass('open'); - }.bind(this), settings.animation_speed / 2); + }, settings.animation_speed / 2); } if (animData.fade) { css.top = $(window).scrollTop() + el.data('css-top') + 'px'; var end_css = {opacity: 1}; return setTimeout(function () { return el .css(css) .animate(end_css, settings.animation_speed, 'linear', function () { - this.locked = false; - el.trigger('opened').trigger('opened.fndtn.reveal'); - }.bind(this)) + context.locked = false; + el.trigger('opened.fndtn.reveal'); + }) .addClass('open'); - }.bind(this), settings.animation_speed / 2); + }, settings.animation_speed / 2); } - return el.css(css).show().css({opacity : 1}).addClass('open').trigger('opened').trigger('opened.fndtn.reveal'); + return el.css(css).show().css({opacity : 1}).addClass('open').trigger('opened.fndtn.reveal'); } var settings = this.settings; // should we animate the background? @@ -338,23 +364,24 @@ this.locked = false; return el.show(); }, - + to_back : function(el) { el.addClass('toback'); }, - + to_front : function(el) { el.removeClass('toback'); }, hide : function (el, css) { // is modal if (css) { - var settings = el.data(this.attr_name(true) + '-init'); + var settings = el.data(this.attr_name(true) + '-init'), + context = this; settings = settings || this.settings; var animData = getAnimationData(settings.animation); if (!animData.animate) { this.locked = false; @@ -366,31 +393,31 @@ }; return setTimeout(function () { return el .animate(end_css, settings.animation_speed, 'linear', function () { - this.locked = false; - el.css(css).trigger('closed').trigger('closed.fndtn.reveal'); - }.bind(this)) + context.locked = false; + el.css(css).trigger('closed.fndtn.reveal'); + }) .removeClass('open'); - }.bind(this), settings.animation_speed / 2); + }, settings.animation_speed / 2); } if (animData.fade) { var end_css = {opacity : 0}; return setTimeout(function () { return el .animate(end_css, settings.animation_speed, 'linear', function () { - this.locked = false; - el.css(css).trigger('closed').trigger('closed.fndtn.reveal'); - }.bind(this)) + context.locked = false; + el.css(css).trigger('closed.fndtn.reveal'); + }) .removeClass('open'); - }.bind(this), settings.animation_speed / 2); + }, settings.animation_speed / 2); } - return el.hide().css(css).removeClass('open').trigger('closed').trigger('closed.fndtn.reveal'); + return el.hide().css(css).removeClass('open').trigger('closed.fndtn.reveal'); } var settings = this.settings; // should we animate the background? @@ -436,10 +463,10 @@ return str; }, cache_offset : function (modal) { - var offset = modal.show().height() + parseInt(modal.css('top'), 10); + var offset = modal.show().height() + parseInt(modal.css('top'), 10) + modal.scrollY; modal.hide(); return offset; },