"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var i=0;i").addClass("reveal-overlay").appendTo(this.options.appendTo)}},{key:"_updatePosition",value:function(){var t,i,o=this.$element.outerWidth(),n=e(window).width(),s=this.$element.outerHeight(),a=e(window).height();t="auto"===this.options.hOffset?parseInt((n-o)/2,10):parseInt(this.options.hOffset,10),i="auto"===this.options.vOffset?s>a?parseInt(Math.min(100,a/10),10):parseInt((a-s)/4,10):parseInt(this.options.vOffset,10),this.$element.css({top:i+"px"}),this.$overlay&&"auto"===this.options.hOffset||(this.$element.css({left:t+"px"}),this.$element.css({margin:"0px"}))}},{key:"_events",value:function(){var t=this,i=this;this.$element.on({"open.zf.trigger":this.open.bind(this),"close.zf.trigger":function(o,n){if(o.target===i.$element[0]||e(o.target).parents("[data-closable]")[0]===n)return t.close.apply(t)},"toggle.zf.trigger":this.toggle.bind(this),"resizeme.zf.trigger":function(){i._updatePosition()}}),this.$anchor.length&&this.$anchor.on("keydown.zf.reveal",function(e){13!==e.which&&32!==e.which||(e.stopPropagation(),e.preventDefault(),i.open())}),this.options.closeOnClick&&this.options.overlay&&this.$overlay.off(".zf.reveal").on("click.zf.reveal",function(t){t.target!==i.$element[0]&&!e.contains(i.$element[0],t.target)&&e.contains(document,t.target)&&i.close()}),this.options.deepLink&&e(window).on("popstate.zf.reveal:"+this.id,this._handleState.bind(this))}},{key:"_handleState",value:function(e){window.location.hash!=="#"+this.id||this.isActive?this.close():this.open()}},{key:"open",value:function(){function t(){n.isMobile?(n.originalScrollPos||(n.originalScrollPos=window.pageYOffset),e("html, body").addClass("is-reveal-open")):e("body").addClass("is-reveal-open")}var i=this;if(this.options.deepLink){var o="#"+this.id;window.history.pushState?window.history.pushState(null,null,o):window.location.hash=o}this.isActive=!0,this.$element.css({visibility:"hidden"}).show().scrollTop(0),this.options.overlay&&this.$overlay.css({visibility:"hidden"}).show(),this._updatePosition(),this.$element.hide().css({visibility:""}),this.$overlay&&(this.$overlay.css({visibility:""}).hide(),this.$element.hasClass("fast")?this.$overlay.addClass("fast"):this.$element.hasClass("slow")&&this.$overlay.addClass("slow")),this.options.multipleOpened||this.$element.trigger("closeme.zf.reveal",this.id);var n=this;this.options.animationIn?!function(){var e=function(){n.$element.attr({"aria-hidden":!1,tabindex:-1}).focus(),t(),Foundation.Keyboard.trapFocus(n.$element)};i.options.overlay&&Foundation.Motion.animateIn(i.$overlay,"fade-in"),Foundation.Motion.animateIn(i.$element,i.options.animationIn,function(){i.$element&&(i.focusableElements=Foundation.Keyboard.findFocusable(i.$element),e())})}():(this.options.overlay&&this.$overlay.show(0),this.$element.show(this.options.showDelay)),this.$element.attr({"aria-hidden":!1,tabindex:-1}).focus(),Foundation.Keyboard.trapFocus(this.$element),this.$element.trigger("open.zf.reveal"),t(),setTimeout(function(){i._extraHandlers()},0)}},{key:"_extraHandlers",value:function(){var t=this;this.$element&&(this.focusableElements=Foundation.Keyboard.findFocusable(this.$element),this.options.overlay||!this.options.closeOnClick||this.options.fullScreen||e("body").on("click.zf.reveal",function(i){i.target!==t.$element[0]&&!e.contains(t.$element[0],i.target)&&e.contains(document,i.target)&&t.close()}),this.options.closeOnEsc&&e(window).on("keydown.zf.reveal",function(e){Foundation.Keyboard.handleKey(e,"Reveal",{close:function(){t.options.closeOnEsc&&(t.close(),t.$anchor.focus())}})}),this.$element.on("keydown.zf.reveal",function(i){var o=e(this);Foundation.Keyboard.handleKey(i,"Reveal",{open:function(){t.$element.find(":focus").is(t.$element.find("[data-close]"))?setTimeout(function(){t.$anchor.focus()},1):o.is(t.focusableElements)&&t.open()},close:function(){t.options.closeOnEsc&&(t.close(),t.$anchor.focus())},handled:function(e){e&&i.preventDefault()}})}))}},{key:"close",value:function(){function t(){i.isMobile?(e("html, body").removeClass("is-reveal-open"),i.originalScrollPos&&(e("body").scrollTop(i.originalScrollPos),i.originalScrollPos=null)):e("body").removeClass("is-reveal-open"),Foundation.Keyboard.releaseFocus(i.$element),i.$element.attr("aria-hidden",!0),i.$element.trigger("closed.zf.reveal")}if(!this.isActive||!this.$element.is(":visible"))return!1;var i=this;this.options.animationOut?(this.options.overlay?Foundation.Motion.animateOut(this.$overlay,"fade-out",t):t(),Foundation.Motion.animateOut(this.$element,this.options.animationOut)):(this.options.overlay?this.$overlay.hide(0,t):t(),this.$element.hide(this.options.hideDelay)),this.options.closeOnEsc&&e(window).off("keydown.zf.reveal"),!this.options.overlay&&this.options.closeOnClick&&e("body").off("click.zf.reveal"),this.$element.off("keydown.zf.reveal"),this.options.resetOnClose&&this.$element.html(this.$element.html()),this.isActive=!1,i.options.deepLink&&(window.history.replaceState?window.history.replaceState("",document.title,window.location.href.replace("#"+this.id,"")):window.location.hash="")}},{key:"toggle",value:function(){this.isActive?this.close():this.open()}},{key:"destroy",value:function(){this.options.overlay&&(this.$element.appendTo(e(this.options.appendTo)),this.$overlay.hide().off().remove()),this.$element.hide().off(),this.$anchor.off(".zf"),e(window).off(".zf.reveal:"+this.id),Foundation.unregisterPlugin(this)}}]),t}();n.defaults={animationIn:"",animationOut:"",showDelay:0,hideDelay:0,closeOnClick:!0,closeOnEsc:!0,multipleOpened:!1,vOffset:"auto",hOffset:"auto",fullScreen:!1,btmOffsetPct:10,overlay:!0,resetOnClose:!1,deepLink:!1,appendTo:"body"},Foundation.plugin(n,"Reveal")}(jQuery);