!function(a,b){if("object"==typeof exports){var c=require("underscore"),d=require("backbone"),e=require("backbone.wreqr"),f=require("backbone.babysitter");module.exports=b(c,d,e,f)}else"function"==typeof define&&define.amd&&define(["underscore","backbone","backbone.wreqr","backbone.babysitter"],b)}(this,function(a,b){!function(a,b,c){"use strict";function d(a,b){var c=new Error(a);throw c.name=b||"Error",c}var e={};b.Marionette=e,e.$=b.$;var f=Array.prototype.slice;return e.extend=b.Model.extend,e.getOption=function(a,b){if(a&&b){var c;return c=a.options&&b in a.options&&void 0!==a.options[b]?a.options[b]:a[b]}},e.normalizeMethods=function(a){var b,d={};return c.each(a,function(a,e){b=a,c.isFunction(b)||(b=this[b]),b&&(d[e]=b)},this),d},e.normalizeUIKeys=function(a,b){return"undefined"!=typeof a?(c.each(c.keys(a),function(c){var d=/@ui.[a-zA-Z_$0-9]*/g;c.match(d)&&(a[c.replace(d,function(a){return b[a.slice(4)]})]=a[c],delete a[c])}),a):void 0},e.actAsCollection=function(a,b){var d=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck"];c.each(d,function(d){a[d]=function(){var a=c.values(c.result(this,b)),e=[a].concat(c.toArray(arguments));return c[d].apply(c,e)}})},e.triggerMethod=function(){function a(a,b,c){return c.toUpperCase()}var b=/(^|:)(\w)/gi,d=function(d){var e="on"+d.replace(b,a),f=this[e];return c.isFunction(this.trigger)&&this.trigger.apply(this,arguments),c.isFunction(f)?f.apply(this,c.tail(arguments)):void 0};return d}(),e.MonitorDOMRefresh=function(a){function b(a){a._isShown=!0,e(a)}function d(a){a._isRendered=!0,e(a)}function e(a){a._isShown&&a._isRendered&&f(a)&&c.isFunction(a.triggerMethod)&&a.triggerMethod("dom:refresh")}function f(b){return a.contains(b.el)}return function(a){a.listenTo(a,"show",function(){b(a)}),a.listenTo(a,"render",function(){d(a)})}}(document.documentElement),function(a){function b(a,b,e,f){var g=f.split(/\s+/);c.each(g,function(c){var f=a[c];f||d("Method '"+c+"' was configured as an event handler, but does not exist."),a.listenTo(b,e,f)})}function e(a,b,c,d){a.listenTo(b,c,d)}function f(a,b,d,e){var f=e.split(/\s+/);c.each(f,function(c){var e=a[c];a.stopListening(b,d,e)})}function g(a,b,c,d){a.stopListening(b,c,d)}function h(a,b,d,e,f){b&&d&&(c.isFunction(d)&&(d=d.call(a)),c.each(d,function(d,g){c.isFunction(d)?e(a,b,g,d):f(a,b,g,d)}))}a.bindEntityEvents=function(a,c,d){h(a,c,d,e,b)},a.unbindEntityEvents=function(a,b,c){h(a,b,c,g,f)}}(e),e.Callbacks=function(){this._deferred=e.$.Deferred(),this._callbacks=[]},c.extend(e.Callbacks.prototype,{add:function(a,b){this._callbacks.push({cb:a,ctx:b}),this._deferred.done(function(c,d){b&&(c=b),a.call(c,d)})},run:function(a,b){this._deferred.resolve(b,a)},reset:function(){var a=this._callbacks;this._deferred=e.$.Deferred(),this._callbacks=[],c.each(a,function(a){this.add(a.cb,a.ctx)},this)}}),e.Controller=function(a){this.triggerMethod=e.triggerMethod,this.options=a||{},c.isFunction(this.initialize)&&this.initialize(this.options)},e.Controller.extend=e.extend,c.extend(e.Controller.prototype,b.Events,{close:function(){this.stopListening();var a=Array.prototype.slice.call(arguments);this.triggerMethod.apply(this,["close"].concat(a)),this.off()}}),e.Region=function(a){if(this.options=a||{},this.el=e.getOption(this,"el"),this.el||d("An 'el' must be specified for a region.","NoElError"),this.initialize){var b=Array.prototype.slice.apply(arguments);this.initialize.apply(this,b)}},c.extend(e.Region,{buildRegion:function(a,b){var e=c.isString(a),f=c.isString(a.selector),g=c.isUndefined(a.regionType),h=c.isFunction(a);h||e||f||d("Region must be specified as a Region type, a selector string or an object with selector property");var i,j;e&&(i=a),a.selector&&(i=a.selector,delete a.selector),h&&(j=a),!h&&g&&(j=b),a.regionType&&(j=a.regionType,delete a.regionType),(e||h)&&(a={}),a.el=i;var k=new j(a);return a.parentEl&&(k.getEl=function(b){var d=a.parentEl;return c.isFunction(d)&&(d=d()),d.find(b)}),k}}),c.extend(e.Region.prototype,b.Events,{show:function(a,b){this.ensureEl();var d=b||{},f=a.isClosed||c.isUndefined(a.$el),g=a!==this.currentView,h=!!d.preventClose,i=!h&&g;i&&this.close(),a.render(),e.triggerMethod.call(this,"before:show",a),e.triggerMethod.call(a,"before:show"),(g||f)&&this.open(a),this.currentView=a,e.triggerMethod.call(this,"show",a),e.triggerMethod.call(a,"show")},ensureEl:function(){this.$el&&0!==this.$el.length||(this.$el=this.getEl(this.el))},getEl:function(a){return e.$(a)},open:function(a){this.$el.empty().append(a.el)},close:function(){var a=this.currentView;a&&!a.isClosed&&(a.close?a.close():a.remove&&a.remove(),e.triggerMethod.call(this,"close",a),delete this.currentView)},attachView:function(a){this.currentView=a},reset:function(){this.close(),delete this.$el}}),e.Region.extend=e.extend,e.RegionManager=function(a){var b=a.Controller.extend({constructor:function(b){this._regions={},a.Controller.prototype.constructor.call(this,b)},addRegions:function(a,b){var d={};return c.each(a,function(a,e){c.isString(a)&&(a={selector:a}),a.selector&&(a=c.defaults({},a,b));var f=this.addRegion(e,a);d[e]=f},this),d},addRegion:function(b,d){var e,f=c.isObject(d),g=c.isString(d),h=!!d.selector;return e=g||f&&h?a.Region.buildRegion(d,a.Region):c.isFunction(d)?a.Region.buildRegion(d,a.Region):d,this._store(b,e),this.triggerMethod("region:add",b,e),e},get:function(a){return this._regions[a]},removeRegion:function(a){var b=this._regions[a];this._remove(a,b)},removeRegions:function(){c.each(this._regions,function(a,b){this._remove(b,a)},this)},closeRegions:function(){c.each(this._regions,function(a){a.close()},this)},close:function(){this.removeRegions(),a.Controller.prototype.close.apply(this,arguments)},_store:function(a,b){this._regions[a]=b,this._setLength()},_remove:function(a,b){b.close(),b.stopListening(),delete this._regions[a],this._setLength(),this.triggerMethod("region:remove",a,b)},_setLength:function(){this.length=c.size(this._regions)}});return a.actAsCollection(b.prototype,"_regions"),b}(e),e.TemplateCache=function(a){this.templateId=a},c.extend(e.TemplateCache,{templateCaches:{},get:function(a){var b=this.templateCaches[a];return b||(b=new e.TemplateCache(a),this.templateCaches[a]=b),b.load()},clear:function(){var a,b=f.call(arguments),c=b.length;if(c>0)for(a=0;c>a;a++)delete this.templateCaches[b[a]];else this.templateCaches={}}}),c.extend(e.TemplateCache.prototype,{load:function(){if(this.compiledTemplate)return this.compiledTemplate;var a=this.loadTemplate(this.templateId);return this.compiledTemplate=this.compileTemplate(a),this.compiledTemplate},loadTemplate:function(a){var b=e.$(a).html();return b&&0!==b.length||d("Could not find template: '"+a+"'","NoTemplateError"),b},compileTemplate:function(a){return c.template(a)}}),e.Renderer={render:function(a,b){a||d("Cannot render the template since it's false, null or undefined.","TemplateNotFoundError");var c;return(c="function"==typeof a?a:e.TemplateCache.get(a))(b)}},e.View=b.View.extend({constructor:function(a){c.bindAll(this,"render"),this.options=c.extend({},c.result(this,"options"),c.isFunction(a)?a.call(this):a),this.events=this.normalizeUIKeys(c.result(this,"events")),c.isObject(this.behaviors)&&new e.Behaviors(this),b.View.prototype.constructor.apply(this,arguments),e.MonitorDOMRefresh(this),this.listenTo(this,"show",this.onShowCalled)},triggerMethod:e.triggerMethod,normalizeMethods:e.normalizeMethods,getTemplate:function(){return e.getOption(this,"template")},mixinTemplateHelpers:function(a){a=a||{};var b=e.getOption(this,"templateHelpers");return c.isFunction(b)&&(b=b.call(this)),c.extend(a,b)},normalizeUIKeys:function(a){var b=c.result(this,"ui");return e.normalizeUIKeys(a,b)},configureTriggers:function(){if(this.triggers){var a={},b=this.normalizeUIKeys(c.result(this,"triggers"));return c.each(b,function(b,d){var e=c.isObject(b),f=e?b.event:b;a[d]=function(a){if(a){var c=a.preventDefault,d=a.stopPropagation,g=e?b.preventDefault:c,h=e?b.stopPropagation:d;g&&c&&c.apply(a),h&&d&&d.apply(a)}var i={view:this,model:this.model,collection:this.collection};this.triggerMethod(f,i)}},this),a}},delegateEvents:function(a){this._delegateDOMEvents(a),e.bindEntityEvents(this,this.model,e.getOption(this,"modelEvents")),e.bindEntityEvents(this,this.collection,e.getOption(this,"collectionEvents"))},_delegateDOMEvents:function(a){a=a||this.events,c.isFunction(a)&&(a=a.call(this));var d={},e=c.result(this,"behaviorEvents")||{},f=this.configureTriggers();c.extend(d,e,a,f),b.View.prototype.delegateEvents.call(this,d)},undelegateEvents:function(){var a=Array.prototype.slice.call(arguments);b.View.prototype.undelegateEvents.apply(this,a),e.unbindEntityEvents(this,this.model,e.getOption(this,"modelEvents")),e.unbindEntityEvents(this,this.collection,e.getOption(this,"collectionEvents"))},onShowCalled:function(){},close:function(){if(!this.isClosed){var a=Array.prototype.slice.call(arguments),b=this.triggerMethod.apply(this,["before:close"].concat(a));b!==!1&&(this.isClosed=!0,this.triggerMethod.apply(this,["close"].concat(a)),this.unbindUIElements(),this.remove())}},bindUIElements:function(){if(this.ui){this._uiBindings||(this._uiBindings=this.ui);var a=c.result(this,"_uiBindings");this.ui={},c.each(c.keys(a),function(b){var c=a[b];this.ui[b]=this.$(c)},this)}},unbindUIElements:function(){this.ui&&this._uiBindings&&(c.each(this.ui,function(a,b){delete this.ui[b]},this),this.ui=this._uiBindings,delete this._uiBindings)}}),e.ItemView=e.View.extend({constructor:function(){e.View.prototype.constructor.apply(this,arguments)},serializeData:function(){var a={};return this.model?a=this.model.toJSON():this.collection&&(a={items:this.collection.toJSON()}),a},render:function(){this.isClosed=!1,this.triggerMethod("before:render",this),this.triggerMethod("item:before:render",this);var a=this.serializeData();a=this.mixinTemplateHelpers(a);var b=this.getTemplate(),c=e.Renderer.render(b,a);return this.$el.html(c),this.bindUIElements(),this.triggerMethod("render",this),this.triggerMethod("item:rendered",this),this},close:function(){this.isClosed||(this.triggerMethod("item:before:close"),e.View.prototype.close.apply(this,arguments),this.triggerMethod("item:closed"))}}),e.CollectionView=e.View.extend({itemViewEventPrefix:"itemview",constructor:function(){this._initChildViewStorage(),e.View.prototype.constructor.apply(this,arguments),this._initialEvents(),this.initRenderBuffer()},initRenderBuffer:function(){this.elBuffer=document.createDocumentFragment(),this._bufferedChildren=[]},startBuffering:function(){this.initRenderBuffer(),this.isBuffering=!0},endBuffering:function(){this.isBuffering=!1,this.appendBuffer(this,this.elBuffer),this._triggerShowBufferedChildren(),this.initRenderBuffer()},_triggerShowBufferedChildren:function(){this._isShown&&(c.each(this._bufferedChildren,function(a){e.triggerMethod.call(a,"show")}),this._bufferedChildren=[])},_initialEvents:function(){this.collection&&(this.listenTo(this.collection,"add",this.addChildView),this.listenTo(this.collection,"remove",this.removeItemView),this.listenTo(this.collection,"reset",this.render))},addChildView:function(a){this.closeEmptyView();var b=this.getItemView(a),c=this.collection.indexOf(a);this.addItemView(a,b,c)},onShowCalled:function(){this.children.each(function(a){e.triggerMethod.call(a,"show")})},triggerBeforeRender:function(){this.triggerMethod("before:render",this),this.triggerMethod("collection:before:render",this)},triggerRendered:function(){this.triggerMethod("render",this),this.triggerMethod("collection:rendered",this)},render:function(){return this.isClosed=!1,this.triggerBeforeRender(),this._renderChildren(),this.triggerRendered(),this},_renderChildren:function(){this.startBuffering(),this.closeEmptyView(),this.closeChildren(),this.isEmpty(this.collection)?this.showEmptyView():this.showCollection(),this.endBuffering()},showCollection:function(){var a;this.collection.each(function(b,c){a=this.getItemView(b),this.addItemView(b,a,c)},this)},showEmptyView:function(){var a=this.getEmptyView();if(a&&!this._showingEmptyView){this._showingEmptyView=!0;var c=new b.Model;this.addItemView(c,a,0)}},closeEmptyView:function(){this._showingEmptyView&&(this.closeChildren(),delete this._showingEmptyView)},getEmptyView:function(){return e.getOption(this,"emptyView")},getItemView:function(){var a=e.getOption(this,"itemView");return a||d("An `itemView` must be specified","NoItemViewError"),a},addItemView:function(a,b,d){var f=e.getOption(this,"itemViewOptions");c.isFunction(f)&&(f=f.call(this,a,d));var g=this.buildItemView(a,b,f);return this.addChildViewEventForwarding(g),this.triggerMethod("before:item:added",g),this.children.add(g),this.renderItemView(g,d),this._isShown&&!this.isBuffering&&e.triggerMethod.call(g,"show"),this.triggerMethod("after:item:added",g),g},addChildViewEventForwarding:function(a){var b=e.getOption(this,"itemViewEventPrefix");this.listenTo(a,"all",function(){var d=f.call(arguments),g=d[0],h=this.normalizeMethods(this.getItemEvents());d[0]=b+":"+g,d.splice(1,0,a),"undefined"!=typeof h&&c.isFunction(h[g])&&h[g].apply(this,d),e.triggerMethod.apply(this,d)},this)},getItemEvents:function(){return c.isFunction(this.itemEvents)?this.itemEvents.call(this):this.itemEvents},renderItemView:function(a,b){a.render(),this.appendHtml(this,a,b)},buildItemView:function(a,b,d){var e=c.extend({model:a},d);return new b(e)},removeItemView:function(a){var b=this.children.findByModel(a);this.removeChildView(b),this.checkEmpty()},removeChildView:function(a){a&&(a.close?a.close():a.remove&&a.remove(),this.stopListening(a),this.children.remove(a)),this.triggerMethod("item:removed",a)},isEmpty:function(){return!this.collection||0===this.collection.length},checkEmpty:function(){this.isEmpty(this.collection)&&this.showEmptyView()},appendBuffer:function(a,b){a.$el.append(b)},appendHtml:function(a,b){a.isBuffering?(a.elBuffer.appendChild(b.el),a._bufferedChildren.push(b)):a.$el.append(b.el)},_initChildViewStorage:function(){this.children=new b.ChildViewContainer},close:function(){this.isClosed||(this.triggerMethod("collection:before:close"),this.closeChildren(),this.triggerMethod("collection:closed"),e.View.prototype.close.apply(this,arguments))},closeChildren:function(){this.children.each(function(a){this.removeChildView(a)},this),this.checkEmpty()}}),e.CompositeView=e.CollectionView.extend({constructor:function(){e.CollectionView.prototype.constructor.apply(this,arguments)},_initialEvents:function(){this.once("render",function(){this.collection&&(this.listenTo(this.collection,"add",this.addChildView),this.listenTo(this.collection,"remove",this.removeItemView),this.listenTo(this.collection,"reset",this._renderChildren))})},getItemView:function(){var a=e.getOption(this,"itemView")||this.constructor;return a||d("An `itemView` must be specified","NoItemViewError"),a},serializeData:function(){var a={};return this.model&&(a=this.model.toJSON()),a},render:function(){this.isRendered=!0,this.isClosed=!1,this.resetItemViewContainer(),this.triggerBeforeRender();var a=this.renderModel();return this.$el.html(a),this.bindUIElements(),this.triggerMethod("composite:model:rendered"),this._renderChildren(),this.triggerMethod("composite:rendered"),this.triggerRendered(),this},_renderChildren:function(){this.isRendered&&(this.triggerMethod("composite:collection:before:render"),e.CollectionView.prototype._renderChildren.call(this),this.triggerMethod("composite:collection:rendered"))},renderModel:function(){var a={};a=this.serializeData(),a=this.mixinTemplateHelpers(a);var b=this.getTemplate();return e.Renderer.render(b,a)},appendBuffer:function(a,b){var c=this.getItemViewContainer(a);c.append(b)},appendHtml:function(a,b){if(a.isBuffering)a.elBuffer.appendChild(b.el),a._bufferedChildren.push(b);else{var c=this.getItemViewContainer(a);c.append(b.el)}},getItemViewContainer:function(a){if("$itemViewContainer"in a)return a.$itemViewContainer;var b,f=e.getOption(a,"itemViewContainer");if(f){var g=c.isFunction(f)?f.call(a):f;b="@"===g.charAt(0)&&a.ui?a.ui[g.substr(4)]:a.$(g),b.length<=0&&d("The specified `itemViewContainer` was not found: "+a.itemViewContainer,"ItemViewContainerMissingError")}else b=a.$el;return a.$itemViewContainer=b,b},resetItemViewContainer:function(){this.$itemViewContainer&&delete this.$itemViewContainer}}),e.Layout=e.ItemView.extend({regionType:e.Region,constructor:function(a){a=a||{},this._firstRender=!0,this._initializeRegions(a),e.ItemView.prototype.constructor.call(this,a)},render:function(){return this.isClosed&&this._initializeRegions(),this._firstRender?this._firstRender=!1:this.isClosed||this._reInitializeRegions(),e.ItemView.prototype.render.apply(this,arguments)},close:function(){this.isClosed||(this.regionManager.close(),e.ItemView.prototype.close.apply(this,arguments))},addRegion:function(a,b){var c={};return c[a]=b,this._buildRegions(c)[a]},addRegions:function(a){return this.regions=c.extend({},this.regions,a),this._buildRegions(a)},removeRegion:function(a){return delete this.regions[a],this.regionManager.removeRegion(a)},getRegion:function(a){return this.regionManager.get(a)},_buildRegions:function(a){var b=this,c={regionType:e.getOption(this,"regionType"),parentEl:function(){return b.$el}};return this.regionManager.addRegions(a,c)},_initializeRegions:function(a){var b;this._initRegionManager(),b=c.isFunction(this.regions)?this.regions(a):this.regions||{},this.addRegions(b)},_reInitializeRegions:function(){this.regionManager.closeRegions(),this.regionManager.each(function(a){a.reset()})},_initRegionManager:function(){this.regionManager=new e.RegionManager,this.listenTo(this.regionManager,"region:add",function(a,b){this[a]=b,this.trigger("region:add",a,b)}),this.listenTo(this.regionManager,"region:remove",function(a,b){delete this[a],this.trigger("region:remove",a,b)})}}),e.Behavior=function(a,b){function c(b,c){this.view=c,this.defaults=a.result(this,"defaults")||{},this.options=a.extend({},this.defaults,b),this.$=function(){return this.view.$.apply(this.view,arguments)},this.initialize.apply(this,arguments)}return a.extend(c.prototype,b.Events,{initialize:function(){},close:function(){this.stopListening()},triggerMethod:e.triggerMethod}),c.extend=e.extend,c}(c,b),e.Behaviors=function(a,b){function c(a){this.behaviors=c.parseBehaviors(a,b.result(a,"behaviors")),c.wrap(a,this.behaviors,["bindUIElements","unbindUIElements","delegateEvents","undelegateEvents","onShow","onClose","behaviorEvents","triggerMethod","setElement","close"])}var d={setElement:function(a,c){a.apply(this,b.tail(arguments,2)),b.each(c,function(a){a.$el=this.$el},this)},close:function(a,c){var d=b.tail(arguments,2);a.apply(this,d),b.invoke(c,"close",d)},onShow:function(c,d){var e=b.tail(arguments,2);b.each(d,function(b){a.triggerMethod.apply(b,["show"].concat(e))}),b.isFunction(c)&&c.apply(this,e)},onClose:function(c,d){var e=b.tail(arguments,2);b.each(d,function(b){a.triggerMethod.apply(b,["close"].concat(e))}),b.isFunction(c)&&c.apply(this,e)},bindUIElements:function(a,c){a.apply(this),b.invoke(c,a)},unbindUIElements:function(a,c){a.apply(this),b.invoke(c,a)},triggerMethod:function(a,c){var d=b.tail(arguments,2);a.apply(this,d),b.each(c,function(b){a.apply(b,d)})},delegateEvents:function(c,d){var e=b.tail(arguments,2);c.apply(this,e),b.each(d,function(b){a.bindEntityEvents(b,this.model,a.getOption(b,"modelEvents")),a.bindEntityEvents(b,this.collection,a.getOption(b,"collectionEvents"))},this)},undelegateEvents:function(c,d){var e=b.tail(arguments,2);c.apply(this,e),b.each(d,function(b){a.unbindEntityEvents(b,this.model,a.getOption(b,"modelEvents")),a.unbindEntityEvents(b,this.collection,a.getOption(b,"collectionEvents"))},this)},behaviorEvents:function(c,d){var e={},f=b.result(this,"ui");return b.each(d,function(c,d){var g={},h=b.result(c,"events")||{},i=b.result(c,"ui"),j=b.extend({},f,i);h=a.normalizeUIKeys(h,j),b.each(b.keys(h),function(a){var e=new Array(d+2).join(" "),f=a+e,i=b.isFunction(h[a])?h[a]:c[h[a]];g[f]=b.bind(i,c)}),e=b.extend(e,g)}),e}};return b.extend(c,{behaviorsLookup:function(){throw new Error("You must define where your behaviors are stored. See https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.behaviors.md#behaviorslookup")},getBehaviorClass:function(a,d){return a.behaviorClass?a.behaviorClass:b.isFunction(c.behaviorsLookup)?c.behaviorsLookup.apply(this,arguments)[d]:c.behaviorsLookup[d]},parseBehaviors:function(a,d){return b.map(d,function(b,d){var e=c.getBehaviorClass(b,d);return new e(b,a)})},wrap:function(a,c,e){b.each(e,function(e){a[e]=b.partial(d[e],a[e],c)})}}),c}(e,c),e.AppRouter=b.Router.extend({constructor:function(a){b.Router.prototype.constructor.apply(this,arguments),this.options=a||{};var c=e.getOption(this,"appRoutes"),d=this._getController();this.processAppRoutes(d,c),this.on("route",this._processOnRoute,this)},appRoute:function(a,b){var c=this._getController();this._addAppRoute(c,a,b)},_processOnRoute:function(a,b){var d=c.invert(this.appRoutes)[a];c.isFunction(this.onRoute)&&this.onRoute(a,d,b)},processAppRoutes:function(a,b){if(b){var d=c.keys(b).reverse();c.each(d,function(c){this._addAppRoute(a,c,b[c])},this)}},_getController:function(){return e.getOption(this,"controller")},_addAppRoute:function(a,b,e){var f=a[e];f||d("Method '"+e+"' was not found on the controller"),this.route(b,e,c.bind(f,a))}}),e.Application=function(a){this._initRegionManager(),this._initCallbacks=new e.Callbacks,this.vent=new b.Wreqr.EventAggregator,this.commands=new b.Wreqr.Commands,this.reqres=new b.Wreqr.RequestResponse,this.submodules={},c.extend(this,a),this.triggerMethod=e.triggerMethod},c.extend(e.Application.prototype,b.Events,{execute:function(){this.commands.execute.apply(this.commands,arguments)},request:function(){return this.reqres.request.apply(this.reqres,arguments)},addInitializer:function(a){this._initCallbacks.add(a)},start:function(a){this.triggerMethod("initialize:before",a),this._initCallbacks.run(a,this),this.triggerMethod("initialize:after",a),this.triggerMethod("start",a)},addRegions:function(a){return this._regionManager.addRegions(a)},closeRegions:function(){this._regionManager.closeRegions()},removeRegion:function(a){this._regionManager.removeRegion(a)},getRegion:function(a){return this._regionManager.get(a)},module:function(a,b){var c=e.Module.getClass(b),d=f.call(arguments);return d.unshift(this),c.create.apply(c,d)},_initRegionManager:function(){this._regionManager=new e.RegionManager,this.listenTo(this._regionManager,"region:add",function(a,b){this[a]=b}),this.listenTo(this._regionManager,"region:remove",function(a){delete this[a]})}}),e.Application.extend=e.extend,e.Module=function(a,b,d){this.moduleName=a,this.options=c.extend({},this.options,d),this.initialize=d.initialize||this.initialize,this.submodules={},this._setupInitializersAndFinalizers(),this.app=b,this.startWithParent=!0,this.triggerMethod=e.triggerMethod,c.isFunction(this.initialize)&&this.initialize(this.options,a,b)},e.Module.extend=e.extend,c.extend(e.Module.prototype,b.Events,{initialize:function(){},addInitializer:function(a){this._initializerCallbacks.add(a)},addFinalizer:function(a){this._finalizerCallbacks.add(a)},start:function(a){this._isInitialized||(c.each(this.submodules,function(b){b.startWithParent&&b.start(a)}),this.triggerMethod("before:start",a),this._initializerCallbacks.run(a,this),this._isInitialized=!0,this.triggerMethod("start",a))},stop:function(){this._isInitialized&&(this._isInitialized=!1,e.triggerMethod.call(this,"before:stop"),c.each(this.submodules,function(a){a.stop()}),this._finalizerCallbacks.run(void 0,this),this._initializerCallbacks.reset(),this._finalizerCallbacks.reset(),e.triggerMethod.call(this,"stop"))},addDefinition:function(a,b){this._runModuleDefinition(a,b)},_runModuleDefinition:function(a,d){if(a){var f=c.flatten([this,this.app,b,e,e.$,c,d]);a.apply(this,f)}},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new e.Callbacks,this._finalizerCallbacks=new e.Callbacks}}),c.extend(e.Module,{create:function(a,b,d){var e=a,g=f.call(arguments);g.splice(0,3),b=b.split(".");var h=b.length,i=[];return i[h-1]=d,c.each(b,function(b,c){var f=e;e=this._getModule(f,b,a,d),this._addModuleDefinition(f,e,i[c],g)},this),e},_getModule:function(a,b,d,e){var f=c.extend({},e),g=this.getClass(e),h=a[b];return h||(h=new g(b,d,f),a[b]=h,a.submodules[b]=h),h},getClass:function(a){var b=e.Module;return a?a.prototype instanceof b?a:a.moduleClass||b:b},_addModuleDefinition:function(a,b,c,d){var e=this._getDefine(c),f=this._getStartWithParent(c,b);e&&b.addDefinition(e,d),this._addStartWithParent(a,b,f)},_getStartWithParent:function(a,b){var d;return c.isFunction(a)&&a.prototype instanceof e.Module?(d=b.constructor.prototype.startWithParent,c.isUndefined(d)?!0:d):c.isObject(a)?(d=a.startWithParent,c.isUndefined(d)?!0:d):!0},_getDefine:function(a){return!c.isFunction(a)||a.prototype instanceof e.Module?c.isObject(a)?a.define:null:a},_addStartWithParent:function(a,b,c){b.startWithParent=b.startWithParent&&c,b.startWithParent&&!b.startWithParentIsConfigured&&(b.startWithParentIsConfigured=!0,a.addInitializer(function(a){b.startWithParent&&b.start(a)}))}}),e}(this,b,a);return b.Marionette});
Пример #2
0
(function(e,t){if(typeof define=="function"&&define.amd)define(["backbone","underscore","backbone.wreqr","backbone.babysitter"],function(n,r){return e.Marionette=t(e,n,r)});else if(typeof exports!="undefined"){var n=require("backbone"),r=require("underscore"),i=require("backbone.wreqr"),s=require("backbone.babysitter");module.exports=t(e,n,r)}else e.Marionette=t(e,e.Backbone,e._)})(this,function(e,t,n){function o(e,t){var n=new Error(e);throw n.name=t||"Error",n}var r=e.Marionette,i=t.Marionette={};i.VERSION="2.0.1",i.noConflict=function(){return e.Marionette=r,this},i.Deferred=t.$.Deferred;var s=Array.prototype.slice;return i.extend=t.Model.extend,i.getOption=function(e,t){if(!e||!t)return;var n;return e.options&&e.options[t]!==undefined?n=e.options[t]:n=e[t],n},i.proxyGetOption=function(e){return i.getOption(this,e)},i.normalizeMethods=function(e){var t={},r;return n.each(e,function(e,i){r=e,n.isFunction(r)||(r=this[r]);if(!r)return;t[i]=r},this),t},i.normalizeUIKeys=function(e,t){if(typeof e=="undefined")return;return n.each(n.keys(e),function(n){var r=/@ui.[a-zA-Z_$0-9]*/g;n.match(r)&&(e[n.replace(r,function(e){return t[e.slice(4)]})]=e[n],delete e[n])}),e},i.actAsCollection=function(e,t){var r=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck"];n.each(r,function(r){e[r]=function(){var e=n.values(n.result(this,t)),i=[e].concat(n.toArray(arguments));return n[r].apply(n,i)}})},i.triggerMethod=function(){function t(e,t,n){return n.toUpperCase()}var e=/(^|:)(\w)/gi,r=function(r){var i="on"+r.replace(e,t),s=this[i],o;return n.isFunction(s)&&(o=s.apply(this,n.tail(arguments))),n.isFunction(this.trigger)&&this.trigger.apply(this,arguments),o};return r}(),i.MonitorDOMRefresh=function(e){function t(e){e._isShown=!0,i(e)}function r(e){e._isRendered=!0,i(e)}function i(e){e._isShown&&e._isRendered&&s(e)&&n.isFunction(e.triggerMethod)&&e.triggerMethod("dom:refresh")}function s(t){return e.contains(t.el)}return function(e){e.listenTo(e,"show",function(){t(e)}),e.listenTo(e,"render",function(){r(e)})}}(document.documentElement),function(e){function t(e,t,r,i){var s=i.split(/\s+/);n.each(s,function(n){var i=e[n];i||o('Method "'+n+'" was configured as an event handler, but does not exist.'),e.listenTo(t,r,i)})}function r(e,t,n,r){e.listenTo(t,n,r)}function i(e,t,r,i){var s=i.split(/\s+/);n.each(s,function(n){var i=e[n];e.stopListening(t,r,i)})}function s(e,t,n,r){e.stopListening(t,n,r)}function u(e,t,r,i,s){if(!t||!r)return;n.isFunction(r)&&(r=r.call(e)),n.each(r,function(r,o){n.isFunction(r)?i(e,t,o,r):s(e,t,o,r)})}e.bindEntityEvents=function(e,n,i){u(e,n,i,r,t)},e.unbindEntityEvents=function(e,t,n){u(e,t,n,s,i)},e.proxyBindEntityEvents=function(t,n){return e.bindEntityEvents(this,t,n)},e.proxyUnbindEntityEvents=function(t,n){return e.unbindEntityEvents(this,t,n)}}(i),i.Callbacks=function(){this._deferred=i.Deferred(),this._callbacks=[]},n.extend(i.Callbacks.prototype,{add:function(e,t){var r=n.result(this._deferred,"promise");this._callbacks.push({cb:e,ctx:t}),r.then(function(n){t&&(n.context=t),e.call(n.context,n.options)})},run:function(e,t){this._deferred.resolve({options:e,context:t})},reset:function(){var e=this._callbacks;this._deferred=i.Deferred(),this._callbacks=[],n.each(e,function(e){this.add(e.cb,e.ctx)},this)}}),i.Controller=function(e){this.triggerMethod=i.triggerMethod,this.options=e||{},n.isFunction(this.initialize)&&this.initialize(this.options)},i.Controller.extend=i.extend,n.extend(i.Controller.prototype,t.Events,{destroy:function(){var e=Array.prototype.slice.call(arguments);this.triggerMethod.apply(this,["before:destroy"].concat(e)),this.triggerMethod.apply(this,["destroy"].concat(e)),this.stopListening(),this.off()},triggerMethod:i.triggerMethod,getOption:i.proxyGetOption}),i.Region=function(e){this.options=e||{},this.el=this.getOption("el"),this.el=this.el instanceof t.$?this.el[0]:this.el,this.el||o('An "el" must be specified for a region.',"NoElError"),this.$el=this.getEl(this.el);if(this.initialize){var n=Array.prototype.slice.apply(arguments);this.initialize.apply(this,n)}},n.extend(i.Region,{buildRegion:function(e,r){var i=n.isString(e),s=n.isString(e.selector),u=n.isUndefined(e.regionClass),a=n.isFunction(e);!a&&!i&&!s&&o("Region must be specified as a Region class,a selector string or an object with selector property");var f,l;i&&(f=e),e.selector&&(f=e.selector,delete e.selector),a&&(l=e),!a&&u&&(l=r),e.regionClass&&(l=e.regionClass,delete e.regionClass);if(i||a)e={};e.el=f;var c=new l(e);return e.parentEl&&(c.getEl=function(r){if(n.isObject(r))return t.$(r);var i=e.parentEl;return n.isFunction(i)&&(i=i()),i.find(r)}),c}}),n.extend(i.Region.prototype,t.Events,{show:function(e,t){this._ensureElement();var r=t||{},i=e!==this.currentView,s=!!r.preventDestroy,o=!!r.forceShow,u=!!this.currentView,a=!s&&i;a&&this.empty();var f=i||o;return f?(e.render(),u&&this.triggerMethod("before:swap",e),this.triggerMethod("before:show",e),this.triggerMethod.call(e,"before:show"),this.attachHtml(e),this.currentView=e,u&&this.triggerMethod("swap",e),this.triggerMethod("show",e),n.isFunction(e.triggerMethod)?e.triggerMethod("show"):this.triggerMethod.call(e,"show"),this):this},_ensureElement:function(){n.isObject(this.el)||(this.$el=this.getEl(this.el),this.el=this.$el[0]),(!this.$el||this.$el.length===0)&&o('An "el" '+this.$el.selector+" must exist in DOM")},getEl:function(e){return t.$(e)},attachHtml:function(e){this.el.innerHTML="",this.el.appendChild(e.el)},empty:function(){var e=this.currentView;if(!e||e.isDestroyed)return;this.triggerMethod("before:empty",e),e.destroy?e.destroy():e.remove&&e.remove(),this.triggerMethod("empty",e),delete this.currentView},attachView:function(e){this.currentView=e},reset:function(){this.empty(),this.$el&&(this.el=this.$el.selector),delete this.$el},getOption:i.proxyGetOption,triggerMethod:i.triggerMethod}),i.Region.extend=i.extend,i.RegionManager=function(e){var t=e.Controller.extend({constructor:function(t){this._regions={},e.Controller.call(this,t)},addRegions:function(e,t){var r={};return n.each(e,function(e,i){n.isString(e)&&(e={selector:e}),e.selector&&(e=n.defaults({},e,t));var s=this.addRegion(i,e);r[i]=s},this),r},addRegion:function(t,r){var i,s=n.isObject(r),o=n.isString(r),u=!!r.selector;return o||s&&u?i=e.Region.buildRegion(r,e.Region):n.isFunction(r)?i=e.Region.buildRegion(r,e.Region):i=r,this.triggerMethod("before:add:region",t,i),this._store(t,i),this.triggerMethod("add:region",t,i),i},get:function(e){return this._regions[e]},getRegions:function(){return n.clone(this._regions)},removeRegion:function(e){var t=this._regions[e];this._remove(e,t)},removeRegions:function(){n.each(this._regions,function(e,t){this._remove(t,e)},this)},emptyRegions:function(){n.each(this._regions,function(e){e.empty()},this)},destroy:function(){this.removeRegions(),e.Controller.prototype.destroy.apply(this,arguments)},_store:function(e,t){this._regions[e]=t,this._setLength()},_remove:function(e,t){this.triggerMethod("before:remove:region",e,t),t.empty(),t.stopListening(),delete this._regions[e],this._setLength(),this.triggerMethod("remove:region",e,t)},_setLength:function(){this.length=n.size(this._regions)}});return e.actAsCollection(t.prototype,"_regions"),t}(i),i.TemplateCache=function(e){this.templateId=e},n.extend(i.TemplateCache,{templateCaches:{},get:function(e){var t=this.templateCaches[e];return t||(t=new i.TemplateCache(e),this.templateCaches[e]=t),t.load()},clear:function(){var e,t=s.call(arguments),n=t.length;if(n>0)for(e=0;e<n;e++)delete this.templateCaches[t[e]];else this.templateCaches={}}}),n.extend(i.TemplateCache.prototype,{load:function(){if(this.compiledTemplate)return this.compiledTemplate;var e=this.loadTemplate(this.templateId);return this.compiledTemplate=this.compileTemplate(e),this.compiledTemplate},loadTemplate:function(e){var n=t.$(e).html();return(!n||n.length===0)&&o('Could not find template: "'+e+'"',"NoTemplateError"),n},compileTemplate:function(e){return n.template(e)}}),i.Renderer={render:function(e,t){e||o("Cannot render the template since its false, null or undefined.","TemplateNotFoundError");var n;return typeof e=="function"?n=e:n=i.TemplateCache.get(e),n(t)}},i.View=t.View.extend({constructor:function(e){n.bindAll(this,"render"),this.options=n.extend({},n.result(this,"options"),n.isFunction(e)?e.call(this):e),this.events=this.normalizeUIKeys(n.result(this,"events")),n.isObject(this.behaviors)&&new i.Behaviors(this),t.View.apply(this,arguments),i.MonitorDOMRefresh(this),this.listenTo(this,"show",this.onShowCalled)},getTemplate:function(){return this.getOption("template")},mixinTemplateHelpers:function(e){e=e||{};var t=this.getOption("templateHelpers");return n.isFunction(t)&&(t=t.call(this)),n.extend(e,t)},normalizeUIKeys:function(e){var t=n.result(this,"ui"),r=n.result(this,"_uiBindings");return i.normalizeUIKeys(e,r||t)},configureTriggers:function(){if(!this.triggers)return;var e={},t=this.normalizeUIKeys(n.result(this,"triggers"));return n.each(t,function(t,r){var i=n.isObject(t),s=i?t.event:t;e[r]=function(e){if(e){var n=e.preventDefault,r=e.stopPropagation,o=i?t.preventDefault:n,u=i?t.stopPropagation:r;o&&n&&n.apply(e),u&&r&&r.apply(e)}var a={view:this,model:this.model,collection:this.collection};this.triggerMethod(s,a)}},this),e},delegateEvents:function(e){this._delegateDOMEvents(e),this.bindEntityEvents(this.model,this.getOption("modelEvents")),this.bindEntityEvents(this.collection,this.getOption("collectionEvents"))},_delegateDOMEvents:function(e){e=e||this.events,n.isFunction(e)&&(e=e.call(this)),e=this.normalizeUIKeys(e);var r={},i=n.result(this,"behaviorEvents")||{},s=this.configureTriggers();n.extend(r,i,e,s),t.View.prototype.delegateEvents.call(this,r)},undelegateEvents:function(){var e=Array.prototype.slice.call(arguments);t.View.prototype.undelegateEvents.apply(this,e),this.unbindEntityEvents(this.model,this.getOption("modelEvents")),this.unbindEntityEvents(this.collection,this.getOption("collectionEvents"))},onShowCalled:function(){},_ensureViewIsIntact:function(){if(this.isDestroyed){var e=new Error("Cannot use a view thats already been destroyed.");throw e.name="ViewDestroyedError",e}},destroy:function(){if(this.isDestroyed)return;var e=Array.prototype.slice.call(arguments);this.triggerMethod.apply(this,["before:destroy"].concat(e)),this.isDestroyed=!0,this.triggerMethod.apply(this,["destroy"].concat(e)),this.unbindUIElements(),this.remove()},bindUIElements:function(){if(!this.ui)return;this._uiBindings||(this._uiBindings=this.ui);var e=n.result(this,"_uiBindings");this.ui={},n.each(n.keys(e),function(t){var n=e[t];this.ui[t]=this.$(n)},this)},unbindUIElements:function(){if(!this.ui||!this._uiBindings)return;n.each(this.ui,function(e,t){delete this.ui[t]},this),this.ui=this._uiBindings,delete this._uiBindings},triggerMethod:i.triggerMethod,normalizeMethods:i.normalizeMethods,getOption:i.proxyGetOption,bindEntityEvents:i.proxyBindEntityEvents,unbindEntityEvents:i.proxyUnbindEntityEvents}),i.ItemView=i.View.extend({constructor:function(){i.View.apply(this,arguments)},serializeData:function(){var e={};return this.model?e=this.model.toJSON():this.collection&&(e={items:this.collection.toJSON()}),e},render:function(){this._ensureViewIsIntact(),this.triggerMethod("before:render",this);var e=this.serializeData();e=this.mixinTemplateHelpers(e);var t=this.getTemplate(),n=i.Renderer.render(t,e);return this.attachElContent(n),this.bindUIElements(),this.triggerMethod("render",this),this},attachElContent:function(e){return this.$el.html(e),this},destroy:function(){if(this.isDestroyed)return;i.View.prototype.destroy.apply(this,arguments)}}),i.CollectionView=i.View.extend({childViewEventPrefix:"childview",constructor:function(e){var t=e||{};this.sort=n.isUndefined(t.sort)?!0:t.sort,this._initChildViewStorage(),i.View.apply(this,arguments),this._initialEvents(),this.initRenderBuffer()},initRenderBuffer:function(){this.elBuffer=document.createDocumentFragment(),this._bufferedChildren=[]},startBuffering:function(){this.initRenderBuffer(),this.isBuffering=!0},endBuffering:function(){this.isBuffering=!1,this._triggerBeforeShowBufferedChildren(),this.attachBuffer(this,this.elBuffer),this._triggerShowBufferedChildren(),this.initRenderBuffer()},_triggerBeforeShowBufferedChildren:function(){this._isShown&&n.invoke(this._bufferedChildren,"triggerMethod","before:show")},_triggerShowBufferedChildren:function(){this._isShown&&(n.each(this._bufferedChildren,function(e){n.isFunction(e.triggerMethod)?e.triggerMethod("show"):i.triggerMethod.call(e,"show")}),this._bufferedChildren=[])},_initialEvents:function(){this.collection&&(this.listenTo(this.collection,"add",this._onCollectionAdd),this.listenTo(this.collection,"remove",this._onCollectionRemove),this.listenTo(this.collection,"reset",this.render),this.sort&&this.listenTo(this.collection,"sort",this._sortViews))},_onCollectionAdd:function(e,t,n){this.destroyEmptyView();var r=this.getChildView(e),i=this.collection.indexOf(e);this.addChild(e,r,i)},_onCollectionRemove:function(e){var t=this.children.findByModel(e);this.removeChildView(t),this.checkEmpty()},onShowCalled:function(){this.children.each(function(e){n.isFunction(e.triggerMethod)?e.triggerMethod("show"):i.triggerMethod.call(e,"show")})},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderChildren(),this.triggerMethod("render",this),this},_sortViews:function(){var e=this.collection.find(function(e,t){var n=this.children.findByModel(e);return n&&n._index!==t},this);e&&this.render()},_renderChildren:function(){this.startBuffering(),this.destroyEmptyView(),this.destroyChildren(),this.isEmpty(this.collection)?this.showEmptyView():(this.triggerMethod("before:render:collection",this),this.showCollection(),this.triggerMethod("render:collection",this)),this.endBuffering()},showCollection:function(){var e;this.collection.each(function(t,n){e=this.getChildView(t),this.addChild(t,e,n)},this)},showEmptyView:function(){var e=this.getEmptyView();if(e&&!this._showingEmptyView){this.triggerMethod("before:render:empty"),this._showingEmptyView=!0;var n=new t.Model;this.addEmptyView(n,e),this.triggerMethod("render:empty")}},destroyEmptyView:function(){this._showingEmptyView&&(this.destroyChildren(),delete this._showingEmptyView)},getEmptyView:function(){return this.getOption("emptyView")},addEmptyView:function(e,t){var r=this.getOption("emptyViewOptions")||this.getOption("childViewOptions");n.isFunction(r)&&(r=r.call(this));var i=this.buildChildView(e,t,r);this._isShown&&this.triggerMethod.call(i,"before:show"),this.children.add(i),this.renderChildView(i,-1),this._isShown&&this.triggerMethod.call(i,"show")},getChildView:function(e){var t=this.getOption("childView");return t||o('A "childView" must be specified',"NoChildViewError"),t},addChild:function(e,t,r){var i=this.getOption("childViewOptions");n.isFunction(i)&&(i=i.call(this,e,r));var s=this.buildChildView(e,t,i);return this._updateIndices(s,!0,r),this._addChildView(s,r),s},_updateIndices:function(e,t,n){if(!this.sort)return;t?(e._index=n,this.children.each(function(t){t._index>=e._index&&t._index++})):this.children.each(function(t){t._index>=e._index&&t._index--})},_addChildView:function(e,t){this.proxyChildEvents(e),this.triggerMethod("before:add:child",e),this.children.add(e),this.renderChildView(e,t),this._isShown&&!this.isBuffering&&(n.isFunction(e.triggerMethod)?e.triggerMethod("show"):i.triggerMethod.call(e,"show")),this.triggerMethod("add:child",e)},renderChildView:function(e,t){e.render(),this.attachHtml(this,e,t)},buildChildView:function(e,t,r){var i=n.extend({model:e},r);return new t(i)},removeChildView:function(e){e&&(this.triggerMethod("before:remove:child",e),e.destroy?e.destroy():e.remove&&e.remove(),this.stopListening(e),this.children.remove(e),this.triggerMethod("remove:child",e),this._updateIndices(e,!1))},isEmpty:function(e){return!this.collection||this.collection.length===0},checkEmpty:function(){this.isEmpty(this.collection)&&this.showEmptyView()},attachBuffer:function(e,t){e.$el.append(t)},attachHtml:function(e,t,n){e.isBuffering?(e.elBuffer.appendChild(t.el),e._bufferedChildren.push(t)):e._insertBefore(t,n)||e._insertAfter(t)},_insertBefore:function(e,t){var n,r=this.sort&&t<this.children.length-1;return r&&(n=this.children.find(function(e){return e._index===t+1})),n?(n.$el.before(e.el),!0):!1},_insertAfter:function(e){this.$el.append(e.el)},_initChildViewStorage:function(){this.children=new t.ChildViewContainer},destroy:function(){if(this.isDestroyed)return;this.triggerMethod("before:destroy:collection"),this.destroyChildren(),this.triggerMethod("destroy:collection"),i.View.prototype.destroy.apply(this,arguments)},destroyChildren:function(){this.children.each(this.removeChildView,this),this.checkEmpty()},proxyChildEvents:function(e){var t=this.getOption("childViewEventPrefix");this.listenTo(e,"all",function(){var r=Array.prototype.slice.call(arguments),i=r[0],s=this.normalizeMethods(n.result(this,"childEvents"));r[0]=t+":"+i,r.splice(1,0,e),typeof s!="undefined"&&n.isFunction(s[i])&&s[i].apply(this,r.slice(1)),this.triggerMethod.apply(this,r)},this)}}),i.CompositeView=i.CollectionView.extend({constructor:function(){i.CollectionView.apply(this,arguments)},_initialEvents:function(){this.once("render",function(){this.collection&&(this.listenTo(this.collection,"add",this._onCollectionAdd),this.listenTo(this.collection,"remove",this._onCollectionRemove),this.listenTo(this.collection,"reset",this._renderChildren),this.sort&&this.listenTo(this.collection,"sort",this._sortViews))})},getChildView:function(e){var t=this.getOption("childView")||this.constructor;return t||o('A "childView" must be specified',"NoChildViewError"),t},serializeData:function(){var e={};return this.model&&(e=this.model.toJSON()),e},render:function(){return this._ensureViewIsIntact(),this.isRendered=!0,this.resetChildViewContainer(),this.triggerMethod("before:render",this),this._renderRoot(),this._renderChildren(),this.triggerMethod("render",this),this},_renderChildren:function(){this.isRendered&&i.CollectionView.prototype._renderChildren.call(this)},_renderRoot:function(){var e={};e=this.serializeData(),e=this.mixinTemplateHelpers(e),this.triggerMethod("before:render:template");var t=this.getTemplate(),n=i.Renderer.render(t,e);this.attachElContent(n),this.bindUIElements(),this.triggerMethod("render:template")},attachElContent:function(e){return this.$el.html(e),this},attachBuffer:function(e,t){var n=this.getChildViewContainer(e);n.append(t)},_insertAfter:function(e){var t=this.getChildViewContainer(this);t.append(e.el)},getChildViewContainer:function(e){if("$childViewContainer"in e)return e.$childViewContainer;var t,r=i.getOption(e,"childViewContainer");if(r){var s=n.isFunction(r)?r.call(e):r;s.charAt(0)==="@"&&e.ui?t=e.ui[s.substr(4)]:t=e.$(s),t.length<=0&&o('The specified "childViewContainer" was not found: '+e.childViewContainer,"ChildViewContainerMissingError")}else t=e.$el;return e.$childViewContainer=t,t},resetChildViewContainer:function(){this.$childViewContainer&&delete this.$childViewContainer}}),i.LayoutView=i.ItemView.extend({regionClass:i.Region,constructor:function(e){e=e||{},this._firstRender=!0,this._initializeRegions(e),i.ItemView.call(this,e)},render:function(){return this._ensureViewIsIntact(),this._firstRender?this._firstRender=!1:this._reInitializeRegions(),i.ItemView.prototype.render.apply(this,arguments)},destroy:function(){if(this.isDestroyed)return;this.regionManager.destroy(),i.ItemView.prototype.destroy.apply(this,arguments)},addRegion:function(e,t){this.triggerMethod("before:region:add",e);var n={};return n[e]=t,this._buildRegions(n)[e]},addRegions:function(e){return this.regions=n.extend({},this.regions,e),this._buildRegions(e)},removeRegion:function(e){return this.triggerMethod("before:region:remove",e),delete this.regions[e],this.regionManager.removeRegion(e)},getRegion:function(e){return this.regionManager.get(e)},getRegions:function(){return this.regionManager.getRegions()},_buildRegions:function(e){var t=this,n={regionClass:this.getOption("regionClass"),parentEl:function(){return t.$el}};return this.regionManager.addRegions(e,n)},_initializeRegions:function(e){var t;this._initRegionManager(),n.isFunction(this.regions)?t=this.regions(e):t=this.regions||{};var r=this.getOption.call(e,"regions");n.isFunction(r)&&(r=r.call(this,e)),n.extend(t,r),this.addRegions(t)},_reInitializeRegions:function(){this.regionManager.emptyRegions(),this.regionManager.each(function(e){e.reset()})},getRegionManager:function(){return new i.RegionManager},_initRegionManager:function(){this.regionManager=this.getRegionManager(),this.listenTo(this.regionManager,"before:add:region",function(e){this.triggerMethod("before:add:region",e)}),this.listenTo(this.regionManager,"add:region",function(e,t){this[e]=t,this.triggerMethod("add:region",e,t)}),this.listenTo(this.regionManager,"before:remove:region",function(e){this.triggerMethod("before:remove:region",e)}),this.listenTo(this.regionManager,"remove:region",function(e,t){delete this[e],this.triggerMethod("remove:region",e,t)})}}),i.Behavior=function(e,t){function n(t,n){this.view=n,this.defaults=e.result(this,"defaults")||{},this.options=e.extend({},this.defaults,t),this.$=function(){return this.view.$.apply(this.view,arguments)},this.initialize.apply(this,arguments)}return e.extend(n.prototype,t.Events,{initialize:function(){},destroy:function(){this.stopListening()},triggerMethod:i.triggerMethod,getOption:i.proxyGetOption,bindEntityEvents:i.proxyBindEntityEvents,unbindEntityEvents:i.proxyUnbindEntityEvents}),n.extend=i.extend,n}(n,t),i.Behaviors=function(e,t){function n(e,r){r=n.parseBehaviors(e,r||t.result(e,"behaviors")),n.wrap(e,r,["bindUIElements","unbindUIElements","delegateEvents","undelegateEvents","behaviorEvents","triggerMethod","setElement","destroy"])}var r={setElement:function(e,n){e.apply(this,t.tail(arguments,2)),t.each(n,function(e){e.$el=this.$el},this)},destroy:function(e,n){var r=t.tail(arguments,2);e.apply(this,r),t.invoke(n,"destroy",r)},bindUIElements:function(e,n){e.apply(this),t.invoke(n,e)},unbindUIElements:function(e,n){e.apply(this),t.invoke(n,e)},triggerMethod:function(e,n){var r=t.tail(arguments,2);e.apply(this,r),t.each(n,function(t){e.apply(t,r)})},delegateEvents:function(n,r){var i=t.tail(arguments,2);n.apply(this,i),t.each(r,function(t){e.bindEntityEvents(t,this.model,e.getOption(t,"modelEvents")),e.bindEntityEvents(t,this.collection,e.getOption(t,"collectionEvents"))},this)},undelegateEvents:function(n,r){var i=t.tail(arguments,2);n.apply(this,i),t.each(r,function(t){e.unbindEntityEvents(t,this.model,e.getOption(t,"modelEvents")),e.unbindEntityEvents(t,this.collection,e.getOption(t,"collectionEvents"))},this)},behaviorEvents:function(n,r){var i={},s=t.result(this,"ui");return t.each(r,function(n,r){var o={},u=t.clone(t.result(n,"events"))||{},a=t.result(n,"ui"),f=t.extend({},s,a);u=e.normalizeUIKeys(u,f),t.each(t.keys(u),function(e){var i=(new Array(r+2)).join(" "),s=e+i,a=t.isFunction(u[e])?u[e]:n[u[e]];o[s]=t.bind(a,n)}),i=t.extend(i,o)}),i}};return t.extend(n,{behaviorsLookup:function(){throw new Error("You must define where your behaviors are stored.See https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.behaviors.md#behaviorslookup")},getBehaviorClass:function(e,r){return e.behaviorClass?e.behaviorClass:t.isFunction(n.behaviorsLookup)?n.behaviorsLookup.apply(this,arguments)[r]:n.behaviorsLookup[r]},parseBehaviors:function(e,r){return t.chain(r).map(function(r,i){var s=n.getBehaviorClass(r,i),o=new s(r,e),u=n.parseBehaviors(e,t.result(o,"behaviors"));return[o].concat(u)}).flatten().value()},wrap:function(e,n,i){t.each(i,function(i){e[i]=t.partial(r[i],e[i],n)})}}),n}(i,n),i.AppRouter=t.Router.extend({constructor:function(e){t.Router.apply(this,arguments),this.options=e||{};var n=this.getOption("appRoutes"),r=this._getController();this.processAppRoutes(r,n),this.on("route",this._processOnRoute,this)},appRoute:function(e,t){var n=this._getController();this._addAppRoute(n,e,t)},_processOnRoute:function(e,t){var r=n.invert(this.appRoutes)[e];n.isFunction(this.onRoute)&&this.onRoute(e,r,t)},processAppRoutes:function(e,t){if(!t)return;var r=n.keys(t).reverse();n.each(r,function(n){this._addAppRoute(e,n,t[n])},this)},_getController:function(){return this.getOption("controller")},_addAppRoute:function(e,t,r){var i=e[r];i||o('Method "'+r+'" was not found on the controller'),this.route(t,r,n.bind(i,e))},getOption:i.proxyGetOption}),i.Application=function(e){this._initRegionManager(),this._initCallbacks=new i.Callbacks;var r=t.Wreqr.radio.channel("global");this.vent=r.vent,this.commands=r.commands,this.reqres=r.reqres,this.submodules={},n.extend(this,e)},n.extend(i.Application.prototype,t.Events,{execute:function(){this.commands.execute.apply(this.commands,arguments)},request:function(){return this.reqres.request.apply(this.reqres,arguments)},addInitializer:function(e){this._initCallbacks.add(e)},start:function(e){this.triggerMethod("before:start",e),this._initCallbacks.run(e,this),this.triggerMethod("start",e)},addRegions:function(e){return this._regionManager.addRegions(e)},emptyRegions:function(){this._regionManager.emptyRegions()},removeRegion:function(e){this._regionManager.removeRegion(e)},getRegion:function(e){return this._regionManager.get(e)},getRegions:function(){return this._regionManager.getRegions()},module:function(e,t){var n=i.Module.getClass(t),r=s.call(arguments);return r.unshift(this),n.create.apply(n,r)},_initRegionManager:function(){this._regionManager=new i.RegionManager,this.listenTo(this._regionManager,"before:add:region",function(e){this.triggerMethod("before:add:region",e)}),this.listenTo(this._regionManager,"add:region",function(e,t){this[e]=t,this.triggerMethod("add:region",e,t)}),this.listenTo(this._regionManager,"before:remove:region",function(e){this.triggerMethod("before:remove:region",e)}),this.listenTo(this._regionManager,"remove:region",function(e,t){delete this[e],this.triggerMethod("remove:region",e,t)})},triggerMethod:i.triggerMethod}),i.Application.extend=i.extend,i.Module=function(e,t,r){this.moduleName=e,this.options=n.extend({},this.options,r),this.initialize=r.initialize||this.initialize,this.submodules={},this._setupInitializersAndFinalizers(),this.app=t,this.startWithParent=!0,n.isFunction(this.initialize)&&this.initialize(e,t,this.options)},i.Module.extend=i.extend,n.extend(i.Module.prototype,t.Events,{initialize:function(){},addInitializer:function(e){this._initializerCallbacks.add(e)},addFinalizer:function(e){this._finalizerCallbacks.add(e)},start:function(e){if(this._isInitialized)return;n.each(this.submodules,function(t){t.startWithParent&&t.start(e)}),this.triggerMethod("before:start",e),this._initializerCallbacks.run(e,this),this._isInitialized=!0,this.triggerMethod("start",e)},stop:function(){if(!this._isInitialized)return;this._isInitialized=!1,this.triggerMethod("before:stop"),n.each(this.submodules,function(e){e.stop()}),this._finalizerCallbacks.run(undefined,this),this._initializerCallbacks.reset(),this._finalizerCallbacks.reset(),this.triggerMethod("stop")},addDefinition:function(e,t){this._runModuleDefinition(e,t)},_runModuleDefinition:function(e,r){if(!e)return;var s=n.flatten([this,this.app,t,i,t.$,n,r]);e.apply(this,s)},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new i.Callbacks,this._finalizerCallbacks=new i.Callbacks},triggerMethod:i.triggerMethod}),n.extend(i.Module,{create:function(e,t,r){var i=e,o=s.call(arguments);o.splice(0,3),t=t.split(".");var u=t.length,a=[];return a[u-1]=r,n.each(t,function(t,n){var s=i;i=this._getModule(s,t,e,r),this._addModuleDefinition(s,i,a[n],o)},this),i},_getModule:function(e,t,r,i,s){var o=n.extend({},i),u=this.getClass(i),a=e[t];return a||(a=new u(t,r,o),e[t]=a,e.submodules[t]=a),a},getClass:function(e){var t=i.Module;return e?e.prototype instanceof t?e:e.moduleClass||t:t},_addModuleDefinition:function(e,t,n,r){var i=this._getDefine(n),s=this._getStartWithParent(n,t);i&&t.addDefinition(i,r),this._addStartWithParent(e,t,s)},_getStartWithParent:function(e,t){var r;return n.isFunction(e)&&e.prototype instanceof i.Module?(r=t.constructor.prototype.startWithParent,n.isUndefined(r)?!0:r):n.isObject(e)?(r=e.startWithParent,n.isUndefined(r)?!0:r):!0},_getDefine:function(e){return!n.isFunction(e)||e.prototype instanceof i.Module?n.isObject(e)?e.define:null:e},_addStartWithParent:function(e,t,n){t.startWithParent=t.startWithParent&&n;if(!t.startWithParent||!!t.startWithParentIsConfigured)return;t.startWithParentIsConfigured=!0,e.addInitializer(function(e){t.startWithParent&&t.start(e)})}}),i});