!function(t,e,n){"use strict";t.fn.WCBackboneModal=function(e){return this.each(function(){new t.WCBackboneModal(t(this),e)})},t.WCBackboneModal=function(e,n){var o=t.extend({},t.WCBackboneModal.defaultOptions,n);o.template&&new t.WCBackboneModal.View({target:o.template,string:o.variable})},t.WCBackboneModal.defaultOptions={template:"",variable:{}},t.WCBackboneModal.View=e.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:undefined,_string:undefined,events:{"click .modal-close":"closeButton","click #btn-ok":"addButton","click #btn-next":"nextButton","touchstart #btn-ok":"addButton",keydown:"keyboardActions",input:"handleInputValidation"},resizeContent:function(){var e=t(".wc-backbone-modal-content").find("article"),n=.75*t(window).height();e.css({"max-height":n+"px"})},initialize:function(e){var o=this;this._target=e.target,this._string=e.string,n.bindAll(this,"render"),this.render(),t(window).on("resize",function(){o.resizeContent()})},render:function(){var e=wp.template(this._target);this.$el.append(e(this._string)),t(document.body).css({overflow:"hidden"}).append(this.$el),this.resizeContent(),this.$(".wc-backbone-modal-content").attr("tabindex","0").trigger("focus"),t(document.body).trigger("init_tooltips"),t(document.body).trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(e,n){e.preventDefault(),t(document.body).trigger("wc_backbone_modal_before_remove",[this._target,this.getFormData(),!!n]),this.undelegateEvents(),t(document).off("focusin"),t(document.body).css({overflow:"auto"}),this.remove(),t(document.body).trigger("wc_backbone_modal_removed",this._target)},addButton:function(e){t(document.body).trigger("wc_backbone_modal_response",[this._target,this.getFormData()]),this.closeButton(e,!0)},nextButton:function(e){var n=this;t(document.body).trigger("wc_backbone_modal_next_response",[this._target,this.getFormData(),function(){n.closeButton(e)}])},getFormData:function(e=!0){var n={};return e&&t(document.body).trigger("wc_backbone_modal_before_update",this._target),t.each(t("form",this.$el).serializeArray(),function(e,o){-1!==o.name.indexOf("[]")?(o.name=o.name.replace("[]",""),n[o.name]=t.makeArray(n[o.name]),n[o.name].push(o.value)):n[o.name]=o.value}),n},handleInputValidation:function(){t(document.body).trigger("wc_backbone_modal_validation",[this._target,this.getFormData(!1)])},keyboardActions:function(e){var n=e.keyCode||e.which;13!==n||e.target.tagName&&("input"===e.target.tagName.toLowerCase()||"textarea"===e.target.tagName.toLowerCase())||(t("#btn-ok").length?this.addButton(e):t("#btn-next").length&&this.nextButton(e)),27===n&&this.closeButton(e)}})}(jQuery,Backbone,_);