!function(e){"use strict";const t="data-modal-close",i=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',".select2-hidden-accessible","select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]"];e.fn.eacmodal=function(t){if("object"==typeof(t=t||{})||!t)return this.each((function(){const i=new e.eacmodal(e(this),t);e(this).data("eacmodal",i)}));let i=this;const o=Array.prototype.slice.call(arguments,1);return this.each((function(){const s=e(this).data("eacmodal");s&&"function"==typeof s?.view[t]&&(i=s.view[t].apply(s.view,o))})),i},e.eacmodal=function(t,i){return this.$el=t,this.options=e.extend({},e.eacmodal.defaults,i||{}),this.options.template&&(this.view=new e.eacmodal.View(this.options).render(),this.$el.data("eacmodal",this)),this},e.eacmodal.View=wp.Backbone.View.extend({tagName:"div",className:"eac-modal",attributes:{"aria-hidden":"true",role:"dialog"},preinitialize(e){this.options=e;const{template:t,data:i}=this.options;t&&"string"==typeof t&&(this.template=wp.template(t)),i&&"object"==typeof i&&(this.model=new Backbone.Model(i)),this.activeElement=null,wp.Backbone.View.prototype.preinitialize.apply(this,arguments)},prepare(){const e=this.model||{};return _.pick(e,_.filter(_.keys(e),(t=>_.isString(e[t])||_.isNumber(e[t])||_.isBoolean(e[t]))))},render(){return _.bindAll(this,"render"),wp.Backbone.View.prototype.render.apply(this,arguments),this.$el.attr("id",_.uniqueId("eac-modal-")),this.$el.wrapInner('<div class="eac-modal__main" role="main"></div>'),this.$el.wrapInner('<div class="eac-modal__content" tabindex="0"></div>'),this.$el.append('<div class="eac-modal__overlay" tabindex="-1" data-modal-close></div>'),this.options.autoOpen&&this.open(),this},open(){const t=this.options.events||{};this.activeElement=document.activeElement,e("body").css("overflow","hidden"),this.$el.attr("aria-hidden","false"),this.$el.addClass("is-open"),e(document.body).append(this.$el),e(document.body).trigger("eac_update_ui"),this.delegateEvents({keydown:"onKeydown",touchstart:"onClick",click:"onClick"});for(const e in t){let i=t[e];"function"!=typeof i&&(i=this.options[i]);const o=e.match(/^(\S+)\s*(.*)$/);this.$el.on(o[1],o[2],i.bind(this))}this.setFocus(),"function"==typeof this.options.onOpen&&this.options.onOpen.call(this)},close(t=null){t&&t.preventDefault&&t.preventDefault(),this.$el.removeClass("is-open"),e("body").css("overflow",""),this.$el.remove(),this.$el.data("eacmodal",null),this.undelegateEvents(),this.activeElement.focus(),this.options.onClose&&this.options.onClose.call(this)},onClick(e){(e.target.hasAttribute(t)||e.target.parentNode.hasAttribute(t))&&(e.preventDefault(),e.stopPropagation(),this.close(e))},onKeydown(e){27===e.keyCode&&this.close(e),9===e.keyCode&&this.retainFocus(e)},getFocusableNodes(){return this.$el.find(i.join(",")).toArray()},setFocus(){const i=this.getFocusableNodes();if(0===i.length)return;const o=i.filter((e=>!e.hasAttribute(t)));o.length>0?e(o[0]).hasClass("select2-hidden-accessible")?e(o[0]).select2("focus"):e(o[0]).focus():e(i[0]).focus()},retainFocus(t){let i=this.getFocusableNodes();if(0!==i.length)if(i=i.filter((e=>null!==e.offsetParent)),this.el.contains(document.activeElement)){const o=i.indexOf(document.activeElement);t.shiftKey&&0===o&&(e(i[i.length-1]).focus(),t.preventDefault()),t.shiftKey||o!==i.length-1||(e(i[0]).focus(),t.preventDefault())}else e(i[0]).focus()},getValues(){const t={};return this.$("input, select, textarea").each(((i,o)=>{const s=e(o),n=s.attr("name"),a=s.attr("type");"method"!==n&&("radio"===a?t[n]=s.is(":checked")?s.val()||0:t[n]:"checkbox"===a?(t[n]=t[n]||[],s.is(":checked")&&t[n].push(s.val())):t[n]=s.val()||"")})),t}}),e.eacmodal.defaults={template:"",data:{},events:{},autoOpen:!0,onOpen(){},onClose(){}}}(jQuery,Backbone,_);