Skip to content

Instantly share code, notes, and snippets.

@corysimmons
Created May 5, 2015 22:04
Show Gist options
  • Save corysimmons/41d5dba532b37a3c2a84 to your computer and use it in GitHub Desktop.
Save corysimmons/41d5dba532b37a3c2a84 to your computer and use it in GitHub Desktop.
!function(e,t,n,s){"use strict";function i(e){var t=/fade/i.test(e),n=/pop/i.test(e);return{animate:t||n,pop:n,fade:t}}Foundation.libs.reveal={name:"reveal",version:"5.4.7",locked:!1,settings:{animation:"fadeAndPop",animation_speed:250,close_on_background_click:!0,close_on_esc:!0,dismiss_modal_class:"close-reveal-modal",bg_class:"reveal-modal-bg",root_element:"body",open:function(){},opened:function(){},close:function(){},closed:function(){},bg:e(".reveal-modal-bg"),css:{open:{opacity:0,visibility:"visible",display:"block"},close:{opacity:1,visibility:"hidden",display:"none"}}},init:function(t,n,s){e.extend(!0,this.settings,n,s),this.bindings(n,s)},events:function(){var e=this,t=e.S;return t(this.scope).off(".reveal").on("click.fndtn.reveal","["+this.add_namespace("data-reveal-id")+"]:not([disabled])",function(n){if(n.preventDefault(),!e.locked){var s=t(this),i=s.data(e.data_attr("reveal-ajax"));if(e.locked=!0,"undefined"==typeof i)e.open.call(e,s);else{var a=i===!0?s.attr("href"):i;e.open.call(e,s,{url:a})}}}),t(n).on("click.fndtn.reveal",this.close_targets(),function(n){if(n.preventDefault(),!e.locked){var s=t("["+e.attr_name()+"].open").data(e.attr_name(!0)+"-init")||e.settings,i=t(n.target)[0]===t("."+s.bg_class)[0];if(i){if(!s.close_on_background_click)return;n.stopPropagation()}e.locked=!0,e.close.call(e,i?t("["+e.attr_name()+"].open"):t(this).closest("["+e.attr_name()+"]"))}}),t("["+e.attr_name()+"]",this.scope).length>0?t(this.scope).on("open.fndtn.reveal",this.settings.open).on("opened.fndtn.reveal",this.settings.opened).on("opened.fndtn.reveal",this.open_video).on("close.fndtn.reveal",this.settings.close).on("closed.fndtn.reveal",this.settings.closed).on("closed.fndtn.reveal",this.close_video):t(this.scope).on("open.fndtn.reveal","["+e.attr_name()+"]",this.settings.open).on("opened.fndtn.reveal","["+e.attr_name()+"]",this.settings.opened).on("opened.fndtn.reveal","["+e.attr_name()+"]",this.open_video).on("close.fndtn.reveal","["+e.attr_name()+"]",this.settings.close).on("closed.fndtn.reveal","["+e.attr_name()+"]",this.settings.closed).on("closed.fndtn.reveal","["+e.attr_name()+"]",this.close_video),!0},key_up_on:function(){var e=this;return e.S("body").off("keyup.fndtn.reveal").on("keyup.fndtn.reveal",function(t){var n=e.S("["+e.attr_name()+"].open"),s=n.data(e.attr_name(!0)+"-init")||e.settings;s&&27===t.which&&s.close_on_esc&&!e.locked&&e.close.call(e,n)}),!0},key_up_off:function(){return this.S("body").off("keyup.fndtn.reveal"),!0},open:function(n,s){var i,a=this;n?"undefined"!=typeof n.selector?i=a.S("#"+n.data(a.data_attr("reveal-id"))).first():(i=a.S(this.scope),s=n):i=a.S(this.scope);var o=i.data(a.attr_name(!0)+"-init");if(o=o||this.settings,i.hasClass("open")&&n.attr("data-reveal-id")==i.attr("id"))return a.close(i);if(!i.hasClass("open")){var r=a.S("["+a.attr_name()+"].open");if("undefined"==typeof i.data("css-top")&&i.data("css-top",parseInt(i.css("top"),10)).data("offset",this.cache_offset(i)),this.key_up_on(i),i.trigger("open").trigger("open.fndtn.reveal"),r.length<1&&this.toggle_bg(i,!0),"string"==typeof s&&(s={url:s}),"undefined"!=typeof s&&s.url){var d="undefined"!=typeof s.success?s.success:null;e.extend(s,{success:function(t,n,s){e.isFunction(d)&&d(t,n,s),i.html(t),a.S(i).foundation("section","reflow"),a.S(i).children().foundation(),r.length>0&&a.hide(r,o.css.close),a.show(i,o.css.open)}}),e.ajax(s)}else r.length>0&&this.hide(r,o.css.close),this.show(i,o.css.open)}a.S(t).trigger("resize")},close:function(e){var e=e&&e.length?e:this.S(this.scope),t=this.S("["+this.attr_name()+"].open"),n=e.data(this.attr_name(!0)+"-init")||this.settings;t.length>0&&(this.locked=!0,this.key_up_off(e),e.trigger("close").trigger("close.fndtn.reveal"),this.toggle_bg(e,!1),this.hide(t,n.css.close,n))},close_targets:function(){var e="."+this.settings.dismiss_modal_class;return this.settings.close_on_background_click?e+", ."+this.settings.bg_class:e},toggle_bg:function(t,n){0===this.S("."+this.settings.bg_class).length&&(this.settings.bg=e("<div />",{"class":this.settings.bg_class}).appendTo("body").hide());var i=this.settings.bg.filter(":visible").length>0;n!=i&&((n==s?i:!n)?this.hide(this.settings.bg):this.show(this.settings.bg))},show:function(n,s){if(s){var a=n.data(this.attr_name(!0)+"-init")||this.settings,o=a.root_element;if(0===n.parent(o).length){var r=n.wrap('<div style="display: none;" />').parent();n.on("closed.fndtn.reveal.wrapped",function(){n.detach().appendTo(r),n.unwrap().unbind("closed.fndtn.reveal.wrapped")}),n.detach().appendTo(o)}var d=i(a.animation);if(d.animate||(this.locked=!1),d.pop){s.top=e(t).scrollTop()-n.data("offset")+"px";var c={top:e(t).scrollTop()+n.data("css-top")+"px",opacity:1};return setTimeout(function(){return n.css(s).animate(c,a.animation_speed,"linear",function(){this.locked=!1,n.trigger("opened").trigger("opened.fndtn.reveal")}.bind(this)).addClass("open")}.bind(this),a.animation_speed/2)}if(d.fade){s.top=e(t).scrollTop()+n.data("css-top")+"px";var c={opacity:1};return setTimeout(function(){return n.css(s).animate(c,a.animation_speed,"linear",function(){this.locked=!1,n.trigger("opened").trigger("opened.fndtn.reveal")}.bind(this)).addClass("open")}.bind(this),a.animation_speed/2)}return n.css(s).show().css({opacity:1}).addClass("open").trigger("opened").trigger("opened.fndtn.reveal")}var a=this.settings;return i(a.animation).fade?n.fadeIn(a.animation_speed/2):(this.locked=!1,n.show())},hide:function(n,s){if(s){var a=n.data(this.attr_name(!0)+"-init");a=a||this.settings;var o=i(a.animation);if(o.animate||(this.locked=!1),o.pop){var r={top:-e(t).scrollTop()-n.data("offset")+"px",opacity:0};return setTimeout(function(){return n.animate(r,a.animation_speed,"linear",function(){this.locked=!1,n.css(s).trigger("closed").trigger("closed.fndtn.reveal")}.bind(this)).removeClass("open")}.bind(this),a.animation_speed/2)}if(o.fade){var r={opacity:0};return setTimeout(function(){return n.animate(r,a.animation_speed,"linear",function(){this.locked=!1,n.css(s).trigger("closed").trigger("closed.fndtn.reveal")}.bind(this)).removeClass("open")}.bind(this),a.animation_speed/2)}return n.hide().css(s).removeClass("open").trigger("closed").trigger("closed.fndtn.reveal")}var a=this.settings;return i(a.animation).fade?n.fadeOut(a.animation_speed/2):n.hide()},close_video:function(t){var n=e(".flex-video",t.target),s=e("iframe",n);s.length>0&&(s.attr("data-src",s[0].src),s.attr("src",s.attr("src")),n.hide())},open_video:function(t){var n=e(".flex-video",t.target),i=n.find("iframe");if(i.length>0){var a=i.attr("data-src");if("string"==typeof a)i[0].src=i.attr("data-src");else{var o=i[0].src;i[0].src=s,i[0].src=o}n.show()}},data_attr:function(e){return this.namespace.length>0?this.namespace+"-"+e:e},cache_offset:function(e){var t=e.show().height()+parseInt(e.css("top"),10);return e.hide(),t},off:function(){e(this.scope).off(".fndtn.reveal")},reflow:function(){}}}(jQuery,window,window.document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment