(function(){var a=function(a,b){return function(){return a.apply(b,arguments)}},b=function(a,b){function d(){this.constructor=a}for(var e in b)c.call(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a},c={}.hasOwnProperty,d=[].indexOf||function(a){for(var b=0,c=this.length;b").addClass(this.prefix+"-modal"),this.template&&this.modalEl.html(this.buildTemplate(this.template,d)),this.$el.html(this.modalEl),this.viewContainer?(this.viewContainerEl=this.modalEl.find(this.viewContainer),this.viewContainerEl.addClass(this.prefix+"-modal__views")):this.viewContainerEl=this.modalEl,b=e.$(document.activeElement),this.previousFocus||(this.previousFocus=b),b.blur(),(null!=(f=this.views)?f.length:void 0)>0&&this.showViewOnRender&&this.openAt(a),"function"==typeof this.onRender&&this.onRender(),!!this.active||(this.delegateModalEvents(),this.$el.fadeIn&&this.animate?(this.modalEl.css({opacity:0}),this.$el.fadeIn({duration:100,complete:this.rendererCompleted})):this.rendererCompleted(),this)},h.prototype.rendererCompleted=function(){var a;return this.keyControl&&(e.$("body").on("keyup.bbm",this.checkKey),this.$el.on("mouseup.bbm",this.clickOutsideElement),this.$el.on("click.bbm",this.clickOutside)),this.modalEl.css({opacity:1}).addClass(this.prefix+"-modal--open"),this.setInitialFocus(),"function"==typeof this.onShow&&this.onShow(),null!=(a=this.currentView)&&"function"==typeof a.onShow?a.onShow():void 0},h.prototype.setInitialFocus=function(){return this.autofocus?this.$(this.autofocus).focus():this.$("*").filter(g).filter(":visible").first().focus()},h.prototype.setUIElements=function(){var a;if(this.template=this.getOption("template"),this.views=this.getOption("views"),null!=(a=this.views)&&(a.length=c.size(this.views)),this.viewContainer=this.getOption("viewContainer"),this.animate=this.getOption("animate"),c.isUndefined(this.template)&&c.isUndefined(this.views))throw new Error("No template or views defined for Backbone.Modal");if(this.template&&this.views&&c.isUndefined(this.viewContainer))throw new Error("No viewContainer defined for Backbone.Modal")},h.prototype.getOption=function(a){if(a)return this.options&&d.call(this.options,a)>=0&&null!=this.options[a]?this.options[a]:this[a]},h.prototype.serializeData=function(){var a;return a={},this.model&&(a=c.extend(a,this.model.toJSON())),this.collection&&(a=c.extend(a,{items:this.collection.toJSON()})),a},h.prototype.delegateModalEvents=function(){var a,b,d,e,f,g,h;this.active=!0,a=this.getOption("cancelEl"),g=this.getOption("submitEl"),g&&this.$el.on("click",g,this.triggerSubmit),a&&this.$el.on("click",a,this.triggerCancel),e=[];for(b in this.views)c.isString(b)&&"length"!==b?(d=b.match(/^(\S+)\s*(.*)$/),h=d[1],f=d[2],e.push(this.$el.on(h,f,this.views[b],this.triggerView))):e.push(void 0);return e},h.prototype.undelegateModalEvents=function(){var a,b,d,e,f,g,h;this.active=!1,a=this.getOption("cancelEl"),g=this.getOption("submitEl"),g&&this.$el.off("click",g,this.triggerSubmit),a&&this.$el.off("click",a,this.triggerCancel),e=[];for(b in this.views)c.isString(b)&&"length"!==b?(d=b.match(/^(\S+)\s*(.*)$/),h=d[1],f=d[2],e.push(this.$el.off(h,f,this.views[b],this.triggerView))):e.push(void 0);return e},h.prototype.checkKey=function(a){if(this.active)switch(a.keyCode){case 27:return this.triggerCancel(a);case 13:return this.triggerSubmit(a)}},h.prototype.clickOutside=function(a){var b;if((null!=(b=this.outsideElement)?b.hasClass(this.prefix+"-wrapper"):void 0)&&this.active)return this.triggerCancel()},h.prototype.clickOutsideElement=function(a){return this.outsideElement=e.$(a.target)},h.prototype.buildTemplate=function(a,b){return("function"==typeof a?a:c.template(e.$(a).html()))(b)},h.prototype.buildView=function(a,b){var d;if(a)return b&&c.isFunction(b)&&(b=b()),c.isFunction(a)?(d=new a(b||this.args[0]),d instanceof e.View?{el:d.render().$el,view:d}:{el:a(b||this.args[0])}):{view:a,el:a.$el}},h.prototype.triggerView=function(a){var b,d,e,f,g,h,i;if(null!=a&&"function"==typeof a.preventDefault&&a.preventDefault(),h=a.data,f=this.buildView(h.view,h.viewOptions),this.currentView&&(this.previousView=this.currentView,!(null!=(i=h.openOptions)?i.skipSubmit:void 0))){if(!1===("function"==typeof(b=this.previousView).beforeSubmit?b.beforeSubmit(a):void 0))return;"function"==typeof(d=this.previousView).submit&&d.submit()}this.currentView=f.view||f.el,e=0;for(g in this.views)h.view===this.views[g].view&&(this.currentIndex=e),e++;return h.onActive&&(c.isFunction(h.onActive)?h.onActive(this):c.isString(h.onActive)&&this[h.onActive].call(this,h)),this.shouldAnimate?this.animateToView(f.el):(this.shouldAnimate=!0,this.$(this.viewContainerEl).html(f.el))},h.prototype.animateToView=function(a){var b,c,d,f,g,h,i;return h={position:"relative",top:-9999,left:-9999},i=e.$("").css(h),i.html(this.$el.clone().css(h)),0!==e.$("tester").length?e.$("tester").replaceWith(i):e.$("body").append(i),c=this.viewContainer?i.find(this.viewContainer):i.find("."+this.prefix+"-modal"),c.removeAttr("style"),f=c.outerHeight(),c.html(a),d=c.outerHeight(),f===d?(this.$(this.viewContainerEl).html(a),"function"==typeof(b=this.currentView).onShow&&b.onShow(),null!=(g=this.previousView)&&"function"==typeof g.destroy?g.destroy():void 0):this.animate?(this.$(this.viewContainerEl).css({opacity:0}),this.$(this.viewContainerEl).animate({height:d},100,function(b){return function(){var c,d;return b.$(b.viewContainerEl).css({opacity:1}).removeAttr("style"),b.$(b.viewContainerEl).html(a),"function"==typeof(c=b.currentView).onShow&&c.onShow(),null!=(d=b.previousView)&&"function"==typeof d.destroy?d.destroy():void 0}}(this))):this.$(this.viewContainerEl).css({height:d}).html(a)},h.prototype.triggerSubmit=function(a){var b,c;if(null!=a&&a.preventDefault(),!e.$(null!=a?a.target:void 0).is("textarea")&&!(this.beforeSubmit&&!1===this.beforeSubmit(a)||this.currentView&&this.currentView.beforeSubmit&&!1===this.currentView.beforeSubmit(a)))return this.submit||(null!=(b=this.currentView)?b.submit:void 0)||this.getOption("submitEl")?(null!=(c=this.currentView)&&"function"==typeof c.submit&&c.submit(),"function"==typeof this.submit&&this.submit(),this.regionEnabled?this.trigger("modal:destroy"):this.destroy()):this.triggerCancel()},h.prototype.triggerCancel=function(a){if(null!=a&&a.preventDefault(),!this.beforeCancel||!1!==this.beforeCancel())return"function"==typeof this.cancel&&this.cancel(),this.regionEnabled?this.trigger("modal:destroy"):this.destroy()},h.prototype.destroy=function(){var a;return e.$("body").off("keyup.bbm",this.checkKey),this.$el.off("mouseup.bbm",this.clickOutsideElement),this.$el.off("click.bbm",this.clickOutside),e.$("tester").remove(),"function"==typeof this.onDestroy&&this.onDestroy(),this.shouldAnimate=!1,this.modalEl.addClass(this.prefix+"-modal--destroy"),a=function(a){return function(){var b,c;return null!=(b=a.currentView)&&"function"==typeof b.remove&&b.remove(),a.remove(),null!=(c=a.previousFocus)&&"function"==typeof c.focus?c.focus():void 0}}(this),this.$el.fadeOut&&this.animate?(this.$el.fadeOut({duration:200}),c.delay(function(){return a()},200)):a()},h.prototype.openAt=function(a){var b,d,e,f,g;c.isNumber(a)?b=a:c.isNumber(a._index)&&(b=a._index),e=0;for(f in this.views)if("length"!==f)if(c.isNumber(b))e===b&&(g=this.views[f]),e++;else if(c.isObject(a))for(d in this.views[f])a[d]===this.views[f][d]&&(g=this.views[f]);return g&&(this.currentIndex=c.indexOf(this.views,g),this.triggerView({data:c.extend(g,{openOptions:a})})),this},h.prototype.next=function(a){if(null==a&&(a={}),this.currentIndex+1