!function(a,b){if("function"==typeof define&&define.amd)define(["backbone","underscore","backbone.wreqr","backbone.babysitter"],function(c,d){return a.Marionette=b(a,c,d)});else if("undefined"!=typeof exports){{var c=require("backbone"),d=require("underscore");require("backbone.wreqr"),require("backbone.babysitter")}module.exports=b(a,c,d)}else a.Marionette=b(a,a.Backbone,a._)}(this,function(a,b,c){"use strict";var d=a.Marionette,e=b.Marionette={};e.VERSION="2.2.2",e.noConflict=function(){return a.Marionette=d,this},e.Deferred=b.$.Deferred;var f=Array.prototype.slice;e.extend=b.Model.extend,e.getOption=function(a,b){if(a&&b){var c;return c=a.options&&void 0!==a.options[b]?a.options[b]:a[b]}},e.proxyGetOption=function(a){return e.getOption(this,a)},e.normalizeMethods=function(a){var b={};return c.each(a,function(a,d){c.isFunction(a)||(a=this[a]),a&&(b[d]=a)},this),b},e.normalizeUIString=function(a,b){return a.replace(/@ui\.[a-zA-Z_$0-9]*/g,function(a){return b[a.slice(4)]})},e.normalizeUIKeys=function(a,b){return"undefined"!=typeof a?(a=c.clone(a),c.each(c.keys(a),function(c){var d=e.normalizeUIString(c,b);d!==c&&(a[d]=a[c],delete a[c])}),a):void 0},e.normalizeUIValues=function(a,b){return"undefined"!=typeof a?(c.each(a,function(d,f){c.isString(d)&&(a[f]=e.normalizeUIString(d,b))}),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(a){function b(a,b,c){return c.toUpperCase()}var d,e=/(^|:)(\w)/gi,f="on"+a.replace(e,b),g=this[f];return c.isFunction(g)&&(d=g.apply(this,c.tail(arguments))),c.isFunction(this.trigger)&&this.trigger.apply(this,arguments),d},e.triggerMethodOn=function(a,b){var d,f=c.tail(arguments,2);return d=c.isFunction(a.triggerMethod)?a.triggerMethod:e.triggerMethod,d.apply(a,[b].concat(f))},e.MonitorDOMRefresh=function(a){function d(a){a._isShown=!0,f(a)}function e(a){a._isRendered=!0,f(a)}function f(a){a._isShown&&a._isRendered&&g(a)&&c.isFunction(a.triggerMethod)&&a.triggerMethod("dom:refresh")}function g(c){return b.$.contains(a,c.el)}return function(a){a.listenTo(a,"show",function(){d(a)}),a.listenTo(a,"render",function(){e(a)})}}(document.documentElement),function(a){function b(b,d,e,f){var g=f.split(/\s+/);c.each(g,function(c){var f=b[c];if(!f)throw new a.Error('Method "'+c+'" was configured as an event handler, but does not exist.');b.listenTo(d,e,f)})}function d(a,b,c,d){a.listenTo(b,c,d)}function e(a,b,d,e){var f=e.split(/\s+/);c.each(f,function(c){var e=a[c];a.stopListening(b,d,e)})}function f(a,b,c,d){a.stopListening(b,c,d)}function g(b,d,e,f,g){if(d&&e){if(!c.isFunction(e)&&!c.isObject(e))throw new a.Error({message:"Bindings must be an object or function.",url:"marionette.functions.html#marionettebindentityevents"});c.isFunction(e)&&(e=e.call(b)),c.each(e,function(a,e){c.isFunction(a)?f(b,d,e,a):g(b,d,e,a)})}}a.bindEntityEvents=function(a,c,e){g(a,c,e,d,b)},a.unbindEntityEvents=function(a,b,c){g(a,b,c,f,e)},a.proxyBindEntityEvents=function(b,c){return a.bindEntityEvents(this,b,c)},a.proxyUnbindEntityEvents=function(b,c){return a.unbindEntityEvents(this,b,c)}}(e);var g=["description","fileName","lineNumber","name","message","number"];return e.Error=e.extend.call(Error,{urlRoot:"http://marionettejs.com/docs/v"+e.VERSION+"/",constructor:function(a,b){c.isObject(a)?(b=a,a=b.message):b||(b={});var d=Error.call(this,a);c.extend(this,c.pick(d,g),c.pick(b,g)),this.captureStackTrace(),b.url&&(this.url=this.urlRoot+b.url)},captureStackTrace:function(){Error.captureStackTrace&&Error.captureStackTrace(this,e.Error)},toString:function(){return this.name+": "+this.message+(this.url?" See: "+this.url:"")}}),e.Error.extend=e.extend,e.Callbacks=function(){this._deferred=e.Deferred(),this._callbacks=[]},c.extend(e.Callbacks.prototype,{add:function(a,b){var d=c.result(this._deferred,"promise");this._callbacks.push({cb:a,ctx:b}),d.then(function(c){b&&(c.context=b),a.call(c.context,c.options)})},run:function(a,b){this._deferred.resolve({options:a,context:b})},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.options=a||{},c.isFunction(this.initialize)&&this.initialize(this.options)},e.Controller.extend=e.extend,c.extend(e.Controller.prototype,b.Events,{destroy:function(){var a=f.call(arguments);return this.triggerMethod.apply(this,["before:destroy"].concat(a)),this.triggerMethod.apply(this,["destroy"].concat(a)),this.stopListening(),this.off(),this},triggerMethod:e.triggerMethod,getOption:e.proxyGetOption}),e.Object=function(a){this.options=c.extend({},c.result(this,"options"),a),this.initialize.apply(this,arguments)},e.Object.extend=e.extend,c.extend(e.Object.prototype,b.Events,{initialize:function(){},destroy:function(){this.triggerMethod("before:destroy"),this.triggerMethod("destroy"),this.stopListening()},triggerMethod:e.triggerMethod,getOption:e.proxyGetOption,bindEntityEvents:e.proxyBindEntityEvents,unbindEntityEvents:e.proxyUnbindEntityEvents}),e.Region=function(a){if(this.options=a||{},this.el=this.getOption("el"),this.el=this.el instanceof b.$?this.el[0]:this.el,!this.el)throw new e.Error({name:"NoElError",message:'An "el" must be specified for a region.'});if(this.$el=this.getEl(this.el),this.initialize){var c=f.apply(arguments);this.initialize.apply(this,c)}},c.extend(e.Region,{buildRegion:function(a,b){if(c.isString(a))return this._buildRegionFromSelector(a,b);if(a.selector||a.el||a.regionClass)return this._buildRegionFromObject(a,b);if(c.isFunction(a))return this._buildRegionFromRegionClass(a);throw new e.Error({message:"Improper region configuration type.",url:"marionette.region.html#region-configuration-types"})},_buildRegionFromSelector:function(a,b){return new b({el:a})},_buildRegionFromObject:function(a,d){var e=a.regionClass||d,f=c.omit(a,"selector","regionClass");a.selector&&!f.el&&(f.el=a.selector);var g=new e(f);return a.parentEl&&(g.getEl=function(d){if(c.isObject(d))return b.$(d);var e=a.parentEl;return c.isFunction(e)&&(e=e()),e.find(d)}),g},_buildRegionFromRegionClass:function(a){return new a}}),c.extend(e.Region.prototype,b.Events,{show:function(a,b){this._ensureElement();var c=b||{},d=a!==this.currentView,f=!!c.preventDestroy,g=!!c.forceShow,h=!!this.currentView,i=d&&!f,j=d||g;return h&&this.triggerMethod("before:swapOut",this.currentView),i?this.empty():h&&j&&this.currentView.off("destroy",this.empty,this),j?(a.once("destroy",this.empty,this),a.render(),h&&this.triggerMethod("before:swap",a),this.triggerMethod("before:show",a),e.triggerMethodOn(a,"before:show"),this.attachHtml(a),h&&this.triggerMethod("swapOut",this.currentView),this.currentView=a,h&&this.triggerMethod("swap",a),this.triggerMethod("show",a),e.triggerMethodOn(a,"show"),this):this},_ensureElement:function(){if(c.isObject(this.el)||(this.$el=this.getEl(this.el),this.el=this.$el[0]),!this.$el||0===this.$el.length)throw new e.Error('An "el" '+this.$el.selector+" must exist in DOM")},getEl:function(a){return b.$(a)},attachHtml:function(a){this.$el.html(""),this.el.appendChild(a.el)},empty:function(){var a=this.currentView;if(a)return a.off("destroy",this.empty,this),this.triggerMethod("before:empty",a),this._destroyView(),this.triggerMethod("empty",a),delete this.currentView,this},_destroyView:function(){var a=this.currentView;a.destroy&&!a.isDestroyed?a.destroy():a.remove&&a.remove()},attachView:function(a){return this.currentView=a,this},hasView:function(){return!!this.currentView},reset:function(){return this.empty(),this.$el&&(this.el=this.$el.selector),delete this.$el,this},getOption:e.proxyGetOption,triggerMethod:e.triggerMethod}),e.Region.extend=e.extend,e.RegionManager=function(a){var b=a.Controller.extend({constructor:function(b){this._regions={},a.Controller.call(this,b)},addRegions:function(a,b){c.isFunction(a)&&(a=a.apply(this,arguments));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,c){var d;return d=c instanceof a.Region?c:a.Region.buildRegion(c,a.Region),this.triggerMethod("before:add:region",b,d),this._store(b,d),this.triggerMethod("add:region",b,d),d},get:function(a){return this._regions[a]},getRegions:function(){return c.clone(this._regions)},removeRegion:function(a){var b=this._regions[a];return this._remove(a,b),b},removeRegions:function(){var a=this.getRegions();return c.each(a,function(a,b){this._remove(b,a)},this),a},emptyRegions:function(){var a=this.getRegions();return c.each(a,function(a){a.empty()},this),a},destroy:function(){return this.removeRegions(),a.Controller.prototype.destroy.apply(this,arguments)},_store:function(a,b){this._regions[a]=b,this._setLength()},_remove:function(a,b){this.triggerMethod("before:remove:region",a,b),b.empty(),b.stopListening(),delete this._regions[a],this._setLength(),this.triggerMethod("remove:region",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 c=b.$(a).html();if(!c||0===c.length)throw new e.Error({name:"NoTemplateError",message:'Could not find template: "'+a+'"'});return c},compileTemplate:function(a){return c.template(a)}}),e.Renderer={render:function(a,b){if(!a)throw new e.Error({name:"TemplateNotFoundError",message:"Cannot render the template since its false, null or undefined."});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._behaviors=e.Behaviors(this),b.View.apply(this,arguments),e.MonitorDOMRefresh(this),this.listenTo(this,"show",this.onShowCalled)},getTemplate:function(){return this.getOption("template")},serializeModel:function(a){return a.toJSON.apply(a,f.call(arguments,1))},mixinTemplateHelpers:function(a){a=a||{};var b=this.getOption("templateHelpers");return c.isFunction(b)&&(b=b.call(this)),c.extend(a,b)},normalizeUIKeys:function(a){var b=c.result(this,"ui"),d=c.result(this,"_uiBindings");return e.normalizeUIKeys(a,d||b)},normalizeUIValues:function(a){var b=c.result(this,"ui"),d=c.result(this,"_uiBindings");return e.normalizeUIValues(a,d||b)},configureTriggers:function(){if(this.triggers){var a={},b=this.normalizeUIKeys(c.result(this,"triggers"));return c.each(b,function(b,c){a[c]=this._buildViewTrigger(b)},this),a}},delegateEvents:function(a){return this._delegateDOMEvents(a),this.bindEntityEvents(this.model,this.getOption("modelEvents")),this.bindEntityEvents(this.collection,this.getOption("collectionEvents")),c.each(this._behaviors,function(a){a.bindEntityEvents(this.model,a.getOption("modelEvents")),a.bindEntityEvents(this.collection,a.getOption("collectionEvents"))},this),this},_delegateDOMEvents:function(a){var d=a||this.events;c.isFunction(d)&&(d=d.call(this)),d=this.normalizeUIKeys(d),c.isUndefined(a)&&(this.events=d);var e={},f=c.result(this,"behaviorEvents")||{},g=this.configureTriggers(),h=c.result(this,"behaviorTriggers")||{};c.extend(e,f,d,g,h),b.View.prototype.delegateEvents.call(this,e)},undelegateEvents:function(){var a=f.call(arguments);return b.View.prototype.undelegateEvents.apply(this,a),this.unbindEntityEvents(this.model,this.getOption("modelEvents")),this.unbindEntityEvents(this.collection,this.getOption("collectionEvents")),c.each(this._behaviors,function(a){a.unbindEntityEvents(this.model,a.getOption("modelEvents")),a.unbindEntityEvents(this.collection,a.getOption("collectionEvents"))},this),this},onShowCalled:function(){},_ensureViewIsIntact:function(){if(this.isDestroyed)throw new e.Error({name:"ViewDestroyedError",message:'View (cid: "'+this.cid+'") has already been destroyed and cannot be used.'})},destroy:function(){if(!this.isDestroyed){var a=f.call(arguments);return this.triggerMethod.apply(this,["before:destroy"].concat(a)),this.isDestroyed=!0,this.triggerMethod.apply(this,["destroy"].concat(a)),this.unbindUIElements(),this.remove(),c.invoke(this._behaviors,"destroy",a),this}},bindUIElements:function(){this._bindUIElements(),c.invoke(this._behaviors,this._bindUIElements)},_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._unbindUIElements(),c.invoke(this._behaviors,this._unbindUIElements)},_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)},_buildViewTrigger:function(a){var b=c.isObject(a),d=c.defaults({},b?a:{},{preventDefault:!0,stopPropagation:!0}),e=b?d.event:a;return function(a){a&&(a.preventDefault&&d.preventDefault&&a.preventDefault(),a.stopPropagation&&d.stopPropagation&&a.stopPropagation());var b={view:this,model:this.model,collection:this.collection};this.triggerMethod(e,b)}},setElement:function(){var a=b.View.prototype.setElement.apply(this,arguments);return c.invoke(this._behaviors,"proxyViewProperties",this),a},triggerMethod:function(){var a=arguments,b=e.triggerMethod,d=b.apply(this,a);return c.each(this._behaviors,function(c){b.apply(c,a)}),d},normalizeMethods:e.normalizeMethods,getOption:e.proxyGetOption,bindEntityEvents:e.proxyBindEntityEvents,unbindEntityEvents:e.proxyUnbindEntityEvents}),e.ItemView=e.View.extend({constructor:function(){e.View.apply(this,arguments)},serializeData:function(){var a={};return this.model?a=c.partial(this.serializeModel,this.model).apply(this,arguments):this.collection&&(a={items:c.partial(this.serializeCollection,this.collection).apply(this,arguments)}),a},serializeCollection:function(a){return a.toJSON.apply(a,f.call(arguments,1))},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderTemplate(),this.bindUIElements(),this.triggerMethod("render",this),this},_renderTemplate:function(){var a=this.getTemplate();if(a!==!1){if(!a)throw new e.Error({name:"UndefinedTemplateError",message:"Cannot render the template since it is null or undefined."});var b=this.serializeData();b=this.mixinTemplateHelpers(b);var c=e.Renderer.render(a,b,this);return this.attachElContent(c),this}},attachElContent:function(a){return this.$el.html(a),this},destroy:function(){return this.isDestroyed?void 0:e.View.prototype.destroy.apply(this,arguments)}}),e.CollectionView=e.View.extend({childViewEventPrefix:"childview",constructor:function(a){var b=a||{};c.isUndefined(this.sort)&&(this.sort=c.isUndefined(b.sort)?!0:b.sort),this.once("render",this._initialEvents),this._initChildViewStorage(),e.View.apply(this,arguments),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&&c.each(this._bufferedChildren,c.partial(this._triggerMethodOnChild,"before:show"))},_triggerShowBufferedChildren:function(){this._isShown&&(c.each(this._bufferedChildren,c.partial(this._triggerMethodOnChild,"show")),this._bufferedChildren=[])},_triggerMethodOnChild:function(a,b){e.triggerMethodOn(b,a)},_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(a){this.destroyEmptyView();var b=this.getChildView(a),c=this.collection.indexOf(a);this.addChild(a,b,c)},_onCollectionRemove:function(a){var b=this.children.findByModel(a);this.removeChildView(b),this.checkEmpty()},onShowCalled:function(){this.children.each(c.partial(this._triggerMethodOnChild,"show"))},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderChildren(),this.triggerMethod("render",this),this},resortView:function(){this.render()},_sortViews:function(){var a=this.collection.find(function(a,b){var c=this.children.findByModel(a);return!c||c._index!==b},this);a&&this.resortView()},_emptyViewIndex:-1,_renderChildren:function(){this.destroyEmptyView(),this.destroyChildren(),this.isEmpty(this.collection)?this.showEmptyView():(this.triggerMethod("before:render:collection",this),this.startBuffering(),this.showCollection(),this.endBuffering(),this.triggerMethod("render:collection",this))},showCollection:function(){var a;this.collection.each(function(b,c){a=this.getChildView(b),this.addChild(b,a,c)},this)},showEmptyView:function(){var a=this.getEmptyView();if(a&&!this._showingEmptyView){this.triggerMethod("before:render:empty"),this._showingEmptyView=!0;var c=new b.Model;this.addEmptyView(c,a),this.triggerMethod("render:empty")}},destroyEmptyView:function(){this._showingEmptyView&&(this.triggerMethod("before:remove:empty"),this.destroyChildren(),delete this._showingEmptyView,this.triggerMethod("remove:empty"))},getEmptyView:function(){return this.getOption("emptyView")},addEmptyView:function(a,b){var d=this.getOption("emptyViewOptions")||this.getOption("childViewOptions");c.isFunction(d)&&(d=d.call(this,a,this._emptyViewIndex));var f=this.buildChildView(a,b,d);this.proxyChildEvents(f),this._isShown&&e.triggerMethodOn(f,"before:show"),this.children.add(f),this.renderChildView(f,this._emptyViewIndex),this._isShown&&e.triggerMethodOn(f,"show")},getChildView:function(){var a=this.getOption("childView");if(!a)throw new e.Error({name:"NoChildViewError",message:'A "childView" must be specified'});return a},addChild:function(a,b,d){var e=this.getOption("childViewOptions");c.isFunction(e)&&(e=e.call(this,a,d));var f=this.buildChildView(a,b,e);return this._updateIndices(f,!0,d),this._addChildView(f,d),f},_updateIndices:function(a,b,c){this.sort&&(b?(a._index=c,this.children.each(function(b){b._index>=a._index&&b._index++})):this.children.each(function(b){b._index>=a._index&&b._index--}))},_addChildView:function(a,b){this.proxyChildEvents(a),this.triggerMethod("before:add:child",a),this.children.add(a),this.renderChildView(a,b),this._isShown&&!this.isBuffering&&e.triggerMethodOn(a,"show"),this.triggerMethod("add:child",a)},renderChildView:function(a,b){return a.render(),this.attachHtml(this,a,b),a},buildChildView:function(a,b,d){var e=c.extend({model:a},d);return new b(e)},removeChildView:function(a){return a&&(this.triggerMethod("before:remove:child",a),a.destroy?a.destroy():a.remove&&a.remove(),this.stopListening(a),this.children.remove(a),this.triggerMethod("remove:child",a),this._updateIndices(a,!1)),a},isEmpty:function(){return!this.collection||0===this.collection.length},checkEmpty:function(){this.isEmpty(this.collection)&&this.showEmptyView()},attachBuffer:function(a,b){a.$el.append(b)},attachHtml:function(a,b,c){a.isBuffering?(a.elBuffer.appendChild(b.el),a._bufferedChildren.push(b)):a._insertBefore(b,c)||a._insertAfter(b)},_insertBefore:function(a,b){var c,d=this.sort&&b<this.children.length-1;return d&&(c=this.children.find(function(a){return a._index===b+1})),c?(c.$el.before(a.el),!0):!1},_insertAfter:function(a){this.$el.append(a.el)},_initChildViewStorage:function(){this.children=new b.ChildViewContainer},destroy:function(){return this.isDestroyed?void 0:(this.triggerMethod("before:destroy:collection"),this.destroyChildren(),this.triggerMethod("destroy:collection"),e.View.prototype.destroy.apply(this,arguments))},destroyChildren:function(){var a=this.children.map(c.identity);return this.children.each(this.removeChildView,this),this.checkEmpty(),a},proxyChildEvents:function(a){var b=this.getOption("childViewEventPrefix");this.listenTo(a,"all",function(){var d=f.call(arguments),e=d[0],g=this.normalizeMethods(c.result(this,"childEvents"));d[0]=b+":"+e,d.splice(1,0,a),"undefined"!=typeof g&&c.isFunction(g[e])&&g[e].apply(this,d.slice(1)),this.triggerMethod.apply(this,d)},this)}}),e.CompositeView=e.CollectionView.extend({constructor:function(){e.CollectionView.apply(this,arguments)},_initialEvents: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(){var a=this.getOption("childView")||this.constructor;if(!a)throw new e.Error({name:"NoChildViewError",message:'A "childView" must be specified'});return a},serializeData:function(){var a={};return this.model&&(a=c.partial(this.serializeModel,this.model).apply(this,arguments)),a},render:function(){return this._ensureViewIsIntact(),this.isRendered=!0,this.resetChildViewContainer(),this.triggerMethod("before:render",this),this._renderTemplate(),this._renderChildren(),this.triggerMethod("render",this),this},_renderChildren:function(){this.isRendered&&e.CollectionView.prototype._renderChildren.call(this)},_renderTemplate:function(){var a={};a=this.serializeData(),a=this.mixinTemplateHelpers(a),this.triggerMethod("before:render:template");var b=this.getTemplate(),c=e.Renderer.render(b,a,this);this.attachElContent(c),this.bindUIElements(),this.triggerMethod("render:template")},attachElContent:function(a){return this.$el.html(a),this},attachBuffer:function(a,b){var c=this.getChildViewContainer(a);c.append(b)},_insertAfter:function(a){var b=this.getChildViewContainer(this);b.append(a.el)},getChildViewContainer:function(a){if("$childViewContainer"in a)return a.$childViewContainer;var b,d=e.getOption(a,"childViewContainer");if(d){var f=c.isFunction(d)?d.call(a):d;if(b="@"===f.charAt(0)&&a.ui?a.ui[f.substr(4)]:a.$(f),b.length<=0)throw new e.Error({name:"ChildViewContainerMissingError",message:'The specified "childViewContainer" was not found: '+a.childViewContainer})}else b=a.$el;return a.$childViewContainer=b,b},resetChildViewContainer:function(){this.$childViewContainer&&delete this.$childViewContainer}}),e.LayoutView=e.ItemView.extend({regionClass:e.Region,constructor:function(a){a=a||{},this._firstRender=!0,this._initializeRegions(a),e.ItemView.call(this,a)},render:function(){return this._ensureViewIsIntact(),this._firstRender?this._firstRender=!1:this._reInitializeRegions(),e.ItemView.prototype.render.apply(this,arguments)},destroy:function(){return this.isDestroyed?this:(this.regionManager.destroy(),e.ItemView.prototype.destroy.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)},getRegions:function(){return this.regionManager.getRegions()},_buildRegions:function(a){var b=this,c={regionClass:this.getOption("regionClass"),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||{};var d=this.getOption.call(a,"regions");c.isFunction(d)&&(d=d.call(this,a)),c.extend(b,d),b=this.normalizeUIValues(b),this.addRegions(b)},_reInitializeRegions:function(){this.regionManager.emptyRegions(),this.regionManager.each(function(a){a.reset()})},getRegionManager:function(){return new e.RegionManager},_initRegionManager:function(){this.regionManager=this.getRegionManager(),this.listenTo(this.regionManager,"before:add:region",function(a){this.triggerMethod("before:add:region",a)}),this.listenTo(this.regionManager,"add:region",function(a,b){this[a]=b,this.triggerMethod("add:region",a,b)}),this.listenTo(this.regionManager,"before:remove:region",function(a){this.triggerMethod("before:remove:region",a)}),this.listenTo(this.regionManager,"remove:region",function(a,b){delete this[a],this.triggerMethod("remove:region",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(){},destroy:function(){this.stopListening()},proxyViewProperties:function(a){this.$el=a.$el,this.el=a.el},triggerMethod:e.triggerMethod,getOption:e.proxyGetOption,bindEntityEvents:e.proxyBindEntityEvents,unbindEntityEvents:e.proxyUnbindEntityEvents}),c.extend=e.extend,c}(c,b),e.Behaviors=function(a,b){function c(a,d){return b.isObject(a.behaviors)?(d=c.parseBehaviors(a,d||b.result(a,"behaviors")),c.wrap(a,d,b.keys(e)),d):{}}function d(a,c){this._view=a,this._viewUI=b.result(a,"ui"),this._behaviors=c,this._triggers={}}var e={behaviorTriggers:function(a,b){var c=new d(this,b);return c.buildBehaviorTriggers()},behaviorEvents:function(c,d){var e={},f=b.result(this,"ui");return b.each(d,function(c,d){var g={},h=b.clone(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 a.Error({message:"You must define where your behaviors are stored.",url:"marionette.behaviors.html#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.chain(d).map(function(d,e){var f=c.getBehaviorClass(d,e),g=new f(d,a),h=c.parseBehaviors(a,b.result(g,"behaviors"));return[g].concat(h)}).flatten().value()},wrap:function(a,c,d){b.each(d,function(d){a[d]=b.partial(e[d],a[d],c)})}}),b.extend(d.prototype,{buildBehaviorTriggers:function(){return b.each(this._behaviors,this._buildTriggerHandlersForBehavior,this),this._triggers},_buildTriggerHandlersForBehavior:function(c,d){var e=b.extend({},this._viewUI,b.result(c,"ui")),f=b.clone(b.result(c,"triggers"))||{};f=a.normalizeUIKeys(f,e),b.each(f,b.partial(this._setHandlerForBehavior,c,d),this)},_setHandlerForBehavior:function(a,b,c,d){var e=d.replace(/^\S+/,function(a){return a+".behaviortriggers"+b});this._triggers[e]=this._view._buildViewTrigger(c)}}),c}(e,c),e.AppRouter=b.Router.extend({constructor:function(a){this.options=a||{},b.Router.apply(this,arguments);var c=this.getOption("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.getOption("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 this.getOption("controller")},_addAppRoute:function(a,b,d){var f=a[d];if(!f)throw new e.Error('Method "'+d+'" was not found on the controller');this.route(b,d,c.bind(f,a))},getOption:e.proxyGetOption}),e.Application=function(a){this.options=a,this._initializeRegions(a),this._initCallbacks=new e.Callbacks,this.submodules={},c.extend(this,a),this._initChannel(),this.initialize.apply(this,arguments)},c.extend(e.Application.prototype,b.Events,{initialize:function(){},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("before:start",a),this._initCallbacks.run(a,this),this.triggerMethod("start",a)},addRegions:function(a){return this._regionManager.addRegions(a)},emptyRegions:function(){return this._regionManager.emptyRegions()},removeRegion:function(a){return this._regionManager.removeRegion(a)},getRegion:function(a){return this._regionManager.get(a)},getRegions:function(){return this._regionManager.getRegions()},module:function(a,b){var c=e.Module.getClass(b),d=f.call(arguments);return d.unshift(this),c.create.apply(c,d)},getRegionManager:function(){return new e.RegionManager},_initializeRegions:function(a){var b=c.isFunction(this.regions)?this.regions(a):this.regions||{};this._initRegionManager();var d=e.getOption(a,"regions");return c.isFunction(d)&&(d=d.call(this,a)),c.extend(b,d),this.addRegions(b),this},_initRegionManager:function(){this._regionManager=this.getRegionManager(),this.listenTo(this._regionManager,"before:add:region",function(a){this.triggerMethod("before:add:region",a)}),this.listenTo(this._regionManager,"add:region",function(a,b){this[a]=b,this.triggerMethod("add:region",a,b)}),this.listenTo(this._regionManager,"before:remove:region",function(a){this.triggerMethod("before:remove:region",a)}),this.listenTo(this._regionManager,"remove:region",function(a,b){delete this[a],this.triggerMethod("remove:region",a,b)})},_initChannel:function(){this.channelName=c.result(this,"channelName")||"global",this.channel=c.result(this,"channel")||b.Wreqr.radio.channel(this.channelName),this.vent=c.result(this,"vent")||this.channel.vent,this.commands=c.result(this,"commands")||this.channel.commands,this.reqres=c.result(this,"reqres")||this.channel.reqres},triggerMethod:e.triggerMethod,getOption:e.proxyGetOption}),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,c.isFunction(this.initialize)&&this.initialize(a,b,this.options)},e.Module.extend=e.extend,c.extend(e.Module.prototype,b.Events,{startWithParent:!0,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,this.triggerMethod("before:stop"),c.each(this.submodules,function(a){a.stop()}),this._finalizerCallbacks.run(void 0,this),this._initializerCallbacks.reset(),this._finalizerCallbacks.reset(),this.triggerMethod("stop"))},addDefinition:function(a,b){this._runModuleDefinition(a,b)},_runModuleDefinition:function(a,d){if(a){var f=c.flatten([this,this.app,b,e,b.$,c,d]);a.apply(this,f)}},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new e.Callbacks,this._finalizerCallbacks=new e.Callbacks},triggerMethod:e.triggerMethod}),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;
Пример #2
0
!function(a,b){if("function"==typeof define&&define.amd)define(["backbone","underscore","backbone.wreqr","backbone.babysitter"],function(c,d){return a.Marionette=b(a,c,d)});else if("undefined"!=typeof exports){{var c=require("backbone"),d=require("underscore");require("backbone.wreqr"),require("backbone.babysitter")}module.exports=b(a,c,d)}else a.Marionette=b(a,a.Backbone,a._)}(this,function(a,b,c){"use strict";function d(a,b){var c=new Error(a);throw c.name=b||"Error",c}var e=a.Marionette,f=b.Marionette={};f.VERSION="2.1.0-pre",f.noConflict=function(){return a.Marionette=e,this},f.Deferred=b.$.Deferred;var g=Array.prototype.slice;return f.extend=b.Model.extend,f.getOption=function(a,b){if(a&&b){var c;return c=a.options&&void 0!==a.options[b]?a.options[b]:a[b]}},f.proxyGetOption=function(a){return f.getOption(this,a)},f.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},f.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},f.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)}})},f.triggerMethod=function(){function a(a,b,c){return c.toUpperCase()}var b=/(^|:)(\w)/gi,d=function(d){var e,f="on"+d.replace(b,a),g=this[f];return c.isFunction(g)&&(e=g.apply(this,c.tail(arguments))),c.isFunction(this.trigger)&&this.trigger.apply(this,arguments),e};return d}(),f.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)},a.proxyBindEntityEvents=function(b,c){return a.bindEntityEvents(this,b,c)},a.proxyUnbindEntityEvents=function(b,c){return a.unbindEntityEvents(this,b,c)}}(f),f.Callbacks=function(){this._deferred=f.Deferred(),this._callbacks=[]},c.extend(f.Callbacks.prototype,{add:function(a,b){var d=c.result(this._deferred,"promise");this._callbacks.push({cb:a,ctx:b}),d.then(function(c){b&&(c.context=b),a.call(c.context,c.options)})},run:function(a,b){this._deferred.resolve({options:a,context:b})},reset:function(){var a=this._callbacks;this._deferred=f.Deferred(),this._callbacks=[],c.each(a,function(a){this.add(a.cb,a.ctx)},this)}}),f.Controller=function(a){this.options=a||{},c.isFunction(this.initialize)&&this.initialize(this.options)},f.Controller.extend=f.extend,c.extend(f.Controller.prototype,b.Events,{destroy:function(){var a=g.call(arguments);return this.triggerMethod.apply(this,["before:destroy"].concat(a)),this.triggerMethod.apply(this,["destroy"].concat(a)),this.stopListening(),this.off(),this},triggerMethod:f.triggerMethod,getOption:f.proxyGetOption}),f.Object=function(a){this.options=c.extend({},c.result(this,"options"),a),this.initialize(this.options)},f.Object.extend=f.extend,c.extend(f.Object.prototype,{initialize:function(){},destroy:function(){this.triggerMethod("before:destroy"),this.triggerMethod("destroy"),this.stopListening()},triggerMethod:f.triggerMethod,getOption:f.proxyGetOption,bindEntityEvents:f.proxyBindEntityEvents,unbindEntityEvents:f.proxyUnbindEntityEvents}),c.extend(f.Object.prototype,b.Events),f.Region=function(a){if(this.options=a||{},this.el=this.getOption("el"),this.el=this.el instanceof b.$?this.el[0]:this.el,this.el||d('An "el" must be specified for a region.',"NoElError"),this.$el=this.getEl(this.el),this.initialize){var c=g.apply(arguments);this.initialize.apply(this,c)}},c.extend(f.Region,{buildRegion:function(a,b){return c.isString(a)?this._buildRegionFromSelector(a,b):a.selector||a.el||a.regionClass?this._buildRegionFromObject(a,b):c.isFunction(a)?this._buildRegionFromRegionClass(a):void d("Improper region configuration type. Please refer to http://marionettejs.com/docs/marionette.region.html#region-configuration-types")},_buildRegionFromSelector:function(a,b){return new b({el:a})},_buildRegionFromObject:function(a,d){var e=a.regionClass||d,f=c.omit(a,"selector","regionClass");a.selector&&!f.el&&(f.el=a.selector);var g=new e(f);return a.parentEl&&(g.getEl=function(d){if(c.isObject(d))return b.$(d);var e=a.parentEl;return c.isFunction(e)&&(e=e()),e.find(d)}),g},_buildRegionFromRegionClass:function(a){return new a}}),c.extend(f.Region.prototype,b.Events,{show:function(a,b){this._ensureElement();var d=b||{},e=a!==this.currentView,f=!!d.preventDestroy,g=!!d.forceShow,h=!!this.currentView,i=!f&&e;i&&this.empty();var j=e||g;return j?(a.once("destroy",c.bind(this.empty,this)),a.render(),h&&this.triggerMethod("before:swap",a),this.triggerMethod("before:show",a),c.isFunction(a.triggerMethod)?a.triggerMethod("before:show"):this.triggerMethod.call(a,"before:show"),this.attachHtml(a),this.currentView=a,h&&this.triggerMethod("swap",a),this.triggerMethod("show",a),c.isFunction(a.triggerMethod)?a.triggerMethod("show"):this.triggerMethod.call(a,"show"),this):this},_ensureElement:function(){c.isObject(this.el)||(this.$el=this.getEl(this.el),this.el=this.$el[0]),this.$el&&0!==this.$el.length||d('An "el" '+this.$el.selector+" must exist in DOM")},getEl:function(a){return b.$(a)},attachHtml:function(a){this.el.innerHTML="",this.el.appendChild(a.el)},empty:function(){var a=this.currentView;if(a)return this.triggerMethod("before:empty",a),this._destroyView(),this.triggerMethod("empty",a),delete this.currentView,this},_destroyView:function(){var a=this.currentView;a.destroy&&!a.isDestroyed?a.destroy():a.remove&&a.remove()},attachView:function(a){return this.currentView=a,this},hasView:function(){return!!this.currentView},reset:function(){return this.empty(),this.$el&&(this.el=this.$el.selector),delete this.$el,this},getOption:f.proxyGetOption,triggerMethod:f.triggerMethod}),f.Region.extend=f.extend,f.RegionManager=function(a){var b=a.Controller.extend({constructor:function(b){this._regions={},a.Controller.call(this,b)},addRegions:function(a,b){c.isFunction(a)&&(a=a.apply(this,arguments));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.triggerMethod("before:add:region",b,e),this._store(b,e),this.triggerMethod("add:region",b,e),e},get:function(a){return this._regions[a]},getRegions:function(){return c.clone(this._regions)},removeRegion:function(a){var b=this._regions[a];return this._remove(a,b),b},removeRegions:function(){var a=this.getRegions();return c.each(this._regions,function(a,b){this._remove(b,a)},this),a},emptyRegions:function(){var a=this.getRegions();return c.each(a,function(a){a.empty()},this),a},destroy:function(){return this.removeRegions(),a.Controller.prototype.destroy.apply(this,arguments)},_store:function(a,b){this._regions[a]=b,this._setLength()},_remove:function(a,b){this.triggerMethod("before:remove:region",a,b),b.empty(),b.stopListening(),delete this._regions[a],this._setLength(),this.triggerMethod("remove:region",a,b)},_setLength:function(){this.length=c.size(this._regions)}});return a.actAsCollection(b.prototype,"_regions"),b}(f),f.TemplateCache=function(a){this.templateId=a},c.extend(f.TemplateCache,{templateCaches:{},get:function(a){var b=this.templateCaches[a];return b||(b=new f.TemplateCache(a),this.templateCaches[a]=b),b.load()},clear:function(){var a,b=g.call(arguments),c=b.length;if(c>0)for(a=0;c>a;a++)delete this.templateCaches[b[a]];else this.templateCaches={}}}),c.extend(f.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 c=b.$(a).html();return c&&0!==c.length||d('Could not find template: "'+a+'"',"NoTemplateError"),c},compileTemplate:function(a){return c.template(a)}}),f.Renderer={render:function(a,b){a||d("Cannot render the template since its false, null or undefined.","TemplateNotFoundError");var c;return(c="function"==typeof a?a:f.TemplateCache.get(a))(b)}},f.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 f.Behaviors(this),b.View.apply(this,arguments),f.MonitorDOMRefresh(this),this.listenTo(this,"show",this.onShowCalled)},getTemplate:function(){return this.getOption("template")},serializeModel:function(a){return a.toJSON.apply(a,g.call(arguments,1))},mixinTemplateHelpers:function(a){a=a||{};var b=this.getOption("templateHelpers");return c.isFunction(b)&&(b=b.call(this)),c.extend(a,b)},normalizeUIKeys:function(a){var b=c.result(this,"ui"),d=c.result(this,"_uiBindings");return f.normalizeUIKeys(a,d||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){return this._delegateDOMEvents(a),this.bindEntityEvents(this.model,this.getOption("modelEvents")),this.bindEntityEvents(this.collection,this.getOption("collectionEvents")),this},_delegateDOMEvents:function(a){a=a||this.events,c.isFunction(a)&&(a=a.call(this)),a=this.normalizeUIKeys(a);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=g.call(arguments);return b.View.prototype.undelegateEvents.apply(this,a),this.unbindEntityEvents(this.model,this.getOption("modelEvents")),this.unbindEntityEvents(this.collection,this.getOption("collectionEvents")),this},onShowCalled:function(){},_ensureViewIsIntact:function(){if(this.isDestroyed){var a=new Error("Cannot use a view thats already been destroyed.");throw a.name="ViewDestroyedError",a}},destroy:function(){if(!this.isDestroyed){var a=g.call(arguments);return this.triggerMethod.apply(this,["before:destroy"].concat(a)),this.isDestroyed=!0,this.triggerMethod.apply(this,["destroy"].concat(a)),this.unbindUIElements(),this.remove(),this}},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)},triggerMethod:f.triggerMethod,normalizeMethods:f.normalizeMethods,getOption:f.proxyGetOption,bindEntityEvents:f.proxyBindEntityEvents,unbindEntityEvents:f.proxyUnbindEntityEvents}),f.ItemView=f.View.extend({constructor:function(){f.View.apply(this,arguments)},serializeData:function(){var a={};return this.model?a=c.partial(this.serializeModel,this.model).apply(this,arguments):this.collection&&(a={items:c.partial(this.serializeCollection,this.collection).apply(this,arguments)}),a},serializeCollection:function(a){return a.toJSON.apply(a,g.call(arguments,1))},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderTemplate(),this.bindUIElements(),this.triggerMethod("render",this),this},_renderTemplate:function(){var a=this.getTemplate();if(a!==!1){a||d("Cannot render the template since it is null or undefined.","UndefinedTemplateError");var b=this.serializeData();b=this.mixinTemplateHelpers(b);var c=f.Renderer.render(a,b,this);return this.attachElContent(c),this}},attachElContent:function(a){return this.$el.html(a),this},destroy:function(){return this.isDestroyed?void 0:f.View.prototype.destroy.apply(this,arguments)}}),f.CollectionView=f.View.extend({childViewEventPrefix:"childview",constructor:function(a){var b=a||{};this.sort=c.isUndefined(b.sort)?!0:b.sort,this._initChildViewStorage(),f.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&&c.invoke(this._bufferedChildren,"triggerMethod","before:show")},_triggerShowBufferedChildren:function(){this._isShown&&(c.each(this._bufferedChildren,function(a){c.isFunction(a.triggerMethod)?a.triggerMethod("show"):f.triggerMethod.call(a,"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(a){this.destroyEmptyView();var b=this.getChildView(a),c=this.collection.indexOf(a);this.addChild(a,b,c)},_onCollectionRemove:function(a){var b=this.children.findByModel(a);this.removeChildView(b),this.checkEmpty()},onShowCalled:function(){this.children.each(function(a){c.isFunction(a.triggerMethod)?a.triggerMethod("show"):f.triggerMethod.call(a,"show")})},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderChildren(),this.triggerMethod("render",this),this},resortView:function(){this.render()},_sortViews:function(){var a=this.collection.find(function(a,b){var c=this.children.findByModel(a);return!c||c._index!==b},this);a&&this.resortView()},_renderChildren:function(){this.destroyEmptyView(),this.destroyChildren(),this.isEmpty(this.collection)?this.showEmptyView():(this.triggerMethod("before:render:collection",this),this.startBuffering(),this.showCollection(),this.endBuffering(),this.triggerMethod("render:collection",this))},showCollection:function(){var a;this.collection.each(function(b,c){a=this.getChildView(b),this.addChild(b,a,c)},this)},showEmptyView:function(){var a=this.getEmptyView();if(a&&!this._showingEmptyView){this.triggerMethod("before:render:empty"),this._showingEmptyView=!0;var c=new b.Model;this.addEmptyView(c,a),this.triggerMethod("render:empty")}},destroyEmptyView:function(){this._showingEmptyView&&(this.destroyChildren(),delete this._showingEmptyView)},getEmptyView:function(){return this.getOption("emptyView")},addEmptyView:function(a,b){var d=this.getOption("emptyViewOptions")||this.getOption("childViewOptions");c.isFunction(d)&&(d=d.call(this));var e=this.buildChildView(a,b,d);this._isShown&&this.triggerMethod.call(e,"before:show"),this.children.add(e),this.renderChildView(e,-1),this._isShown&&this.triggerMethod.call(e,"show")},getChildView:function(){var a=this.getOption("childView");return a||d('A "childView" must be specified',"NoChildViewError"),a},addChild:function(a,b,d){var e=this.getOption("childViewOptions");c.isFunction(e)&&(e=e.call(this,a,d));var f=this.buildChildView(a,b,e);return this._updateIndices(f,!0,d),this._addChildView(f,d),f},_updateIndices:function(a,b,c){this.sort&&(b?(a._index=c,this.children.each(function(b){b._index>=a._index&&b._index++})):this.children.each(function(b){b._index>=a._index&&b._index--}))},_addChildView:function(a,b){this.proxyChildEvents(a),this.triggerMethod("before:add:child",a),this.children.add(a),this.renderChildView(a,b),this._isShown&&!this.isBuffering&&(c.isFunction(a.triggerMethod)?a.triggerMethod("show"):f.triggerMethod.call(a,"show")),this.triggerMethod("add:child",a)},renderChildView:function(a,b){return a.render(),this.attachHtml(this,a,b),a},buildChildView:function(a,b,d){var e=c.extend({model:a},d);return new b(e)},removeChildView:function(a){return a&&(this.triggerMethod("before:remove:child",a),a.destroy?a.destroy():a.remove&&a.remove(),this.stopListening(a),this.children.remove(a),this.triggerMethod("remove:child",a),this._updateIndices(a,!1)),a},isEmpty:function(){return!this.collection||0===this.collection.length},checkEmpty:function(){this.isEmpty(this.collection)&&this.showEmptyView()},attachBuffer:function(a,b){a.$el.append(b)},attachHtml:function(a,b,c){a.isBuffering?(a.elBuffer.appendChild(b.el),a._bufferedChildren.push(b)):a._insertBefore(b,c)||a._insertAfter(b)},_insertBefore:function(a,b){var c,d=this.sort&&b<this.children.length-1;return d&&(c=this.children.find(function(a){return a._index===b+1})),c?(c.$el.before(a.el),!0):!1},_insertAfter:function(a){this.$el.append(a.el)},_initChildViewStorage:function(){this.children=new b.ChildViewContainer},destroy:function(){return this.isDestroyed?void 0:(this.triggerMethod("before:destroy:collection"),this.destroyChildren(),this.triggerMethod("destroy:collection"),f.View.prototype.destroy.apply(this,arguments))},destroyChildren:function(){var a=this.children.map(c.identity);return this.children.each(this.removeChildView,this),this.checkEmpty(),a},proxyChildEvents:function(a){var b=this.getOption("childViewEventPrefix");this.listenTo(a,"all",function(){var d=g.call(arguments),e=d[0],f=this.normalizeMethods(c.result(this,"childEvents"));d[0]=b+":"+e,d.splice(1,0,a),"undefined"!=typeof f&&c.isFunction(f[e])&&f[e].apply(this,d.slice(1)),this.triggerMethod.apply(this,d)},this)}}),f.CompositeView=f.CollectionView.extend({constructor:function(){f.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(){var a=this.getOption("childView")||this.constructor;return a||d('A "childView" must be specified',"NoChildViewError"),a},serializeData:function(){var a={};return this.model&&(a=c.partial(this.serializeModel,this.model).apply(this,arguments)),a},render:function(){return this._ensureViewIsIntact(),this.isRendered=!0,this.resetChildViewContainer(),this.triggerMethod("before:render",this),this._renderTemplate(),this._renderChildren(),this.triggerMethod("render",this),this},_renderChildren:function(){this.isRendered&&f.CollectionView.prototype._renderChildren.call(this)},_renderTemplate:function(){var a={};a=this.serializeData(),a=this.mixinTemplateHelpers(a),this.triggerMethod("before:render:template");var b=this.getTemplate(),c=f.Renderer.render(b,a,this);this.attachElContent(c),this.bindUIElements(),this.triggerMethod("render:template")},attachElContent:function(a){return this.$el.html(a),this},attachBuffer:function(a,b){var c=this.getChildViewContainer(a);c.append(b)},_insertAfter:function(a){var b=this.getChildViewContainer(this);b.append(a.el)},getChildViewContainer:function(a){if("$childViewContainer"in a)return a.$childViewContainer;var b,e=f.getOption(a,"childViewContainer");if(e){var g=c.isFunction(e)?e.call(a):e;b="@"===g.charAt(0)&&a.ui?a.ui[g.substr(4)]:a.$(g),b.length<=0&&d('The specified "childViewContainer" was not found: '+a.childViewContainer,"ChildViewContainerMissingError")}else b=a.$el;return a.$childViewContainer=b,b},resetChildViewContainer:function(){this.$childViewContainer&&delete this.$childViewContainer}}),f.LayoutView=f.ItemView.extend({regionClass:f.Region,constructor:function(a){a=a||{},this._firstRender=!0,this._initializeRegions(a),f.ItemView.call(this,a)},render:function(){return this._ensureViewIsIntact(),this._firstRender?this._firstRender=!1:this._reInitializeRegions(),f.ItemView.prototype.render.apply(this,arguments)},destroy:function(){return this.isDestroyed?this:(this.regionManager.destroy(),f.ItemView.prototype.destroy.apply(this,arguments))},addRegion:function(a,b){this.triggerMethod("before:region:add",a);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 this.triggerMethod("before:region:remove",a),delete this.regions[a],this.regionManager.removeRegion(a)},getRegion:function(a){return this.regionManager.get(a)},getRegions:function(){return this.regionManager.getRegions()},_buildRegions:function(a){var b=this,c={regionClass:this.getOption("regionClass"),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||{};var d=this.getOption.call(a,"regions");c.isFunction(d)&&(d=d.call(this,a)),c.extend(b,d),this.addRegions(b)},_reInitializeRegions:function(){this.regionManager.emptyRegions(),this.regionManager.each(function(a){a.reset()})},getRegionManager:function(){return new f.RegionManager},_initRegionManager:function(){this.regionManager=this.getRegionManager(),this.listenTo(this.regionManager,"before:add:region",function(a){this.triggerMethod("before:add:region",a)}),this.listenTo(this.regionManager,"add:region",function(a,b){this[a]=b,this.triggerMethod("add:region",a,b)}),this.listenTo(this.regionManager,"before:remove:region",function(a){this.triggerMethod("before:remove:region",a)}),this.listenTo(this.regionManager,"remove:region",function(a,b){delete this[a],this.triggerMethod("remove:region",a,b)})}}),f.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(){},destroy:function(){this.stopListening()},triggerMethod:f.triggerMethod,getOption:f.proxyGetOption,bindEntityEvents:f.proxyBindEntityEvents,unbindEntityEvents:f.proxyUnbindEntityEvents}),c.extend=f.extend,c}(c,b),f.Behaviors=function(a,b){function c(a,e){e=c.parseBehaviors(a,e||b.result(a,"behaviors")),c.wrap(a,e,b.keys(d))}var d={setElement:function(a,c){return a.apply(this,b.tail(arguments,2)),b.each(c,function(a){a.$el=this.$el,a.el=this.el},this),this},destroy:function(a,c){var d=b.tail(arguments,2);return a.apply(this,d),b.invoke(c,"destroy",d),this},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);return 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),this},undelegateEvents:function(c,d){var e=b.tail(arguments,2);return 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),this},behaviorEvents:function(c,d){var e={},f=b.result(this,"ui");return b.each(d,function(c,d){var g={},h=b.clone(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.chain(d).map(function(d,e){var f=c.getBehaviorClass(d,e),g=new f(d,a),h=c.parseBehaviors(a,b.result(g,"behaviors"));return[g].concat(h)}).flatten().value()},wrap:function(a,c,e){b.each(e,function(e){a[e]=b.partial(d[e],a[e],c)})}}),c}(f,c),f.AppRouter=b.Router.extend({constructor:function(a){b.Router.apply(this,arguments),this.options=a||{};var c=this.getOption("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.getOption("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 this.getOption("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))},getOption:f.proxyGetOption}),f.Application=function(a){this._initializeRegions(a),this._initCallbacks=new f.Callbacks,this.submodules={},c.extend(this,a),this._initChannel()},c.extend(f.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("before:start",a),this._initCallbacks.run(a,this),this.triggerMethod("start",a)},addRegions:function(a){return this._regionManager.addRegions(a)},emptyRegions:function(){return this._regionManager.emptyRegions()},removeRegion:function(a){return this._regionManager.removeRegion(a)},getRegion:function(a){return this._regionManager.get(a)},getRegions:function(){return this._regionManager.getRegions()},module:function(a,b){var c=f.Module.getClass(b),d=g.call(arguments);return d.unshift(this),c.create.apply(c,d)},getRegionManager:function(){return new f.RegionManager},_initializeRegions:function(a){var b=c.isFunction(this.regions)?this.regions(a):this.regions||{};this._initRegionManager();var d=f.getOption(a,"regions");return c.isFunction(d)&&(d=d.call(this,a)),c.extend(b,d),this.addRegions(b),this},_initRegionManager:function(){this._regionManager=this.getRegionManager(),this.listenTo(this._regionManager,"before:add:region",function(a){this.triggerMethod("before:add:region",a)}),this.listenTo(this._regionManager,"add:region",function(a,b){this[a]=b,this.triggerMethod("add:region",a,b)}),this.listenTo(this._regionManager,"before:remove:region",function(a){this.triggerMethod("before:remove:region",a)}),this.listenTo(this._regionManager,"remove:region",function(a,b){delete this[a],this.triggerMethod("remove:region",a,b)})},_initChannel:function(){this.channelName=c.result(this,"channelName")||"global",this.channel=c.result(this,"channel")||b.Wreqr.radio.channel(this.channelName),this.vent=c.result(this,"vent")||this.channel.vent,this.commands=c.result(this,"commands")||this.channel.commands,this.reqres=c.result(this,"reqres")||this.channel.reqres},triggerMethod:f.triggerMethod,getOption:f.proxyGetOption}),f.Application.extend=f.extend,f.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,c.isFunction(this.initialize)&&this.initialize(a,b,this.options)},f.Module.extend=f.extend,c.extend(f.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,this.triggerMethod("before:stop"),c.each(this.submodules,function(a){a.stop()}),this._finalizerCallbacks.run(void 0,this),this._initializerCallbacks.reset(),this._finalizerCallbacks.reset(),this.triggerMethod("stop"))},addDefinition:function(a,b){this._runModuleDefinition(a,b)},_runModuleDefinition:function(a,d){if(a){var e=c.flatten([this,this.app,b,f,b.$,c,d]);a.apply(this,e)}},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new f.Callbacks,this._finalizerCallbacks=new f.Callbacks},triggerMethod:f.triggerMethod}),c.extend(f.Module,{create:function(a,b,d){var e=a,f=g.call(arguments);f.splice(0,3),b=b.split(".");var h=b.length,i=[];return i[h-1]=d,c.each(b,function(b,c){var g=e;e=this._getModule(g,b,a,d),this._addModuleDefinition(g,e,i[c],f)},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=f.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 f.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 f.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)}))}}),f});
Пример #3
0
!function(a,b){if("function"==typeof define&&define.amd)define(["underscore","d3"],function(a,c){return b(a,c)});else if("object"==typeof module&&module.exports){{var c=require("underscore");require("d3")}module.exports=b(c)}else a.tauChart=b(a._,a.d3)}(this,function(a,b){var c,d,e;return function(a){function b(a,b){return u.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n=b&&b.split("/"),o=s.map,p=o&&o["*"]||{};if(a&&"."===a.charAt(0))if(b){for(n=n.slice(0,n.length-1),a=a.split("/"),g=a.length-1,s.nodeIdCompat&&w.test(a[g])&&(a[g]=a[g].replace(w,"")),a=n.concat(a),k=0;k<a.length;k+=1)if(m=a[k],"."===m)a.splice(k,1),k-=1;else if(".."===m){if(1===k&&(".."===a[2]||".."===a[0]))break;k>0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}else 0===a.indexOf("./")&&(a=a.substring(2));if((n||p)&&o){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),n)for(l=n.length;l>0;l-=1)if(e=o[n.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&p&&p[d]&&(i=p[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(b,c){return function(){var d=v.call(arguments,0);return"string"!=typeof d[0]&&1===d.length&&d.push(null),n.apply(a,d.concat([b,c]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){q[a]=b}}function j(c){if(b(r,c)){var d=r[c];delete r[c],t[c]=!0,m.apply(a,d)}if(!b(q,c)&&!b(t,c))throw new Error("No "+c);return q[c]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return function(){return s&&s.config&&s.config[a]||{}}}var m,n,o,p,q={},r={},s={},t={},u=Object.prototype.hasOwnProperty,v=[].slice,w=/\.js$/;o=function(a,b){var c,d=k(a),e=d[0];return a=d[1],e&&(e=f(e,b),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(b)):f(a,b):(a=f(a,b),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},p={require:function(a){return g(a)},exports:function(a){var b=q[a];return"undefined"!=typeof b?b:q[a]={}},module:function(a){return{id:a,uri:"",exports:q[a],config:l(a)}}},m=function(c,d,e,f){var h,k,l,m,n,s,u=[],v=typeof e;if(f=f||c,"undefined"===v||"function"===v){for(d=!d.length&&e.length?["require","exports","module"]:d,n=0;n<d.length;n+=1)if(m=o(d[n],f),k=m.f,"require"===k)u[n]=p.require(c);else if("exports"===k)u[n]=p.exports(c),s=!0;else if("module"===k)h=u[n]=p.module(c);else if(b(q,k)||b(r,k)||b(t,k))u[n]=j(k);else{if(!m.p)throw new Error(c+" missing "+k);m.p.load(m.n,g(f,!0),i(k),{}),u[n]=q[k]}l=e?e.apply(q[c],u):void 0,c&&(h&&h.exports!==a&&h.exports!==q[c]?q[c]=h.exports:l===a&&s||(q[c]=l))}else c&&(q[c]=e)},c=d=n=function(b,c,d,e,f){if("string"==typeof b)return p[b]?p[b](c):j(o(b,c).f);if(!b.splice){if(s=b,s.deps&&n(s.deps,s.callback),!c)return;c.splice?(b=c,c=d,d=null):b=a}return c=c||function(){},"function"==typeof d&&(d=e,e=f),e?m(a,b,c,d):setTimeout(function(){m(a,b,c,d)},4),n},n.config=function(a){return n(a)},c._defined=q,e=function(a,c,d){c.splice||(d=c,c=[]),b(q,a)||b(r,a)||(r[a]=[a,c,d])},e.amd={jQuery:!0}}(),e("../node_modules/almond/almond",function(){}),e("utils/utils-dom",["exports"],function(c){var d={getScrollbarWidth:function(){var a=document.createElement("div");a.style.overflow="scroll",a.style.visibility="hidden",a.style.position="absolute",a.style.width="100px",a.style.height="100px",document.body.appendChild(a);var b=a.offsetWidth-a.clientWidth;return document.body.removeChild(a),b},getStyle:function(a,b){return window.getComputedStyle(a,void 0).getPropertyValue(b)},getContainerSize:function(a){var b=parseInt(this.getStyle(a,"padding-left")||0,10),c=parseInt(this.getStyle(a,"padding-right")||0,10),d=parseInt(this.getStyle(a,"padding-bottom")||0,10),e=parseInt(this.getStyle(a,"padding-top")||0,10),f=parseInt(this.getStyle(a,"border-width")||0,10),g=a.getBoundingClientRect();return{width:g.width-b-c-2*f,height:g.height-d-e-2*f}},getAxisTickLabelSize:function(c){var d=['<svg class="graphical-report__svg">','<g class="graphical-report__cell cell">','<g class="x axis">','<g class="tick"><text><%= xTick %></text></g>',"</g>","</g>","</svg>"].join(""),e=a.template(d),f=document.createElement("div");f.style.position="absolute",f.style.visibility="hidden",f.style.width="100px",f.style.height="100px",f.style.border="1px solid green",document.body.appendChild(f),f.innerHTML=e({xTick:c});var g=b.select(f).selectAll(".x.axis .tick text")[0][0],h={width:g.clientWidth||g.scrollWidth,height:g.clientHeight||g.scrollHeight};return document.body.removeChild(f),h}};c.utilsDom=d}),e("dsl-reader",["exports"],function(b){var c=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},d=function(){var b=function(a,b){this.domain=a,this.UnitsRegistry=b};return c(b,null,{buildGraph:{writable:!0,value:function(a){var b=this,c=function(a){return b.UnitsRegistry.get(a.type).walk(b.domain.mix(a),c)};return c(a.unit)}},calcLayout:{writable:!0,value:function(b,c){b.options={top:0,left:0,width:c.width,height:c.height};var d=function(b){if(!b.$matrix)return b;var c,e=b.options,f=b.guide.padding,g=e.width-(f.l+f.r),h=e.height-(f.t+f.b),i=b.$matrix.sizeR(),j=b.$matrix.sizeC(),k=g/j,l=h/i;return c=b.guide.split?{calcHeight:function(a,b,c,d){return a/d},calcTop:function(a,b,c,d){return(b+1)*(a/d)*c}}:{calcHeight:function(a){return a},calcTop:function(a,b){return b*l}},b.$matrix.iterate(function(b,e,f){var g=f.length;a.each(f,function(a,f){a.options={width:k,left:e*k,height:c.calcHeight(l,b,f,g),top:c.calcTop(l,b,f,g)},d(a)})}),b};return d(b)}},renderGraph:{writable:!0,value:function(a,b){var c=this;a.options.container=b;var d=function(a){return c.UnitsRegistry.get(a.type).draw(c.domain.mix(a),d)};return d(a),a.options.container}}}),b}();b.DSLReader=d}),e("utils/utils",["exports"],function(a){var b={clone:function(a){return JSON.parse(JSON.stringify(a))},isArray:function(a){return Array.isArray(a)},autoScale:function(a){var b=10,c=Math.min.apply(null,a),d=Math.max.apply(null,a);if(c===d){var e=d>=0?-1:1,f=d||1;d-=e*f/b}for(var g=[c,d],h=g[1]-g[0],i=Math.pow(10,Math.floor(Math.log(h/b)/Math.LN10)),j=b/h*i,k=[[.15,10],[.35,5],[.75,2],[1,1]],l=-1;j>k[++l][0];);i*=k[l][1],g[0]=Math.floor(g[0]/i)*i,g[1]=Math.ceil(g[1]/i)*i;var m=c-g[0],n=g[1]-d,o=i/2;if(c>=0)g[0]=0;else{var p=o>=m?i:0;g[0]=g[0]-p}if(0>=d)g[1]=0;else{var q=o>=n?i:0;g[1]=g[1]+q}return[parseFloat(g[0].toFixed(15)),parseFloat(g[1].toFixed(15))]}};a.utils=b}),e("formatter-registry",["exports","d3"],function(b,c){var d=c,e={"x-num-auto":function(a){var b=parseFloat(a.toFixed(2));return Math.abs(b)<1?b.toString():d.format("s")(b)},percent:function(a){var b=parseFloat((100*a).toFixed(2));return b.toString()+"%"},day:d.time.format("%d-%b-%Y"),week:d.time.format("%d-%b-%Y"),"week-range":function(a){var b=new Date(a),c=new Date(a),e=new Date(c.setDate(c.getDate()+7)),f=d.time.format("%d-%b-%Y");return f(b)+" - "+f(e)},month:function(a){var b=new Date(a),c=b.getMonth(),e=0===c?"%B, %Y":"%B";return d.time.format(e)(a)},"month-year":d.time.format("%B, %Y"),quarter:function(a){var b=new Date(a),c=b.getMonth(),d=(c-c%3)/3;return"Q"+(d+1)+" "+b.getFullYear()},year:d.time.format("%Y"),"x-time-auto":null};e["x-time-ms"]=e["x-time-auto"],e["x-time-sec"]=e["x-time-auto"],e["x-time-min"]=e["x-time-auto"],e["x-time-hour"]=e["x-time-auto"],e["x-time-day"]=e["x-time-auto"],e["x-time-week"]=e["x-time-auto"],e["x-time-month"]=e.month,e["x-time-quarter"]=e.quarter,e["x-time-year"]=e.year;var f=function(a){return(a||"").toString()},g={get:function(b){var c=e.hasOwnProperty(b),g=c?e[b]:f;return c&&(g=e[b]),!c&&b&&(g=function(c){var e=a.isDate(c)?d.time.format(b):d.format(b);return e(c)}),c||b||(g=f),g},add:function(a,b){e[a]=b}};b.FormatterRegistry=g}),e("utils/utils-draw",["exports","../utils/utils","../formatter-registry"],function(c,d,e){var f=d.utils,g=e.FormatterRegistry,h=function(a,b){return"translate("+a+","+b+")"},i=function(a){return"rotate("+a+")"},j=function(b){return a.contains(["bottom","top"],b.toLowerCase())?"h":"v"},k=function(a,c){a.each(function(){var a=b.select(this),d=a.text().split(/\s+/).reverse();a.text(null);for(var e,f=[],g=!1;!g&&(e=d.pop());)if(f.push(e),a.text(f.join(" ")),a.node().getComputedTextLength()>c){f.pop();var h=f.join(" ");h+="...",a.text(h),g=!0}})},l=function(a,c,d,e,f){var g=function(a,b,c,d,e,f,g){var h=g*c+f,i=a.append("tspan").attr("x",d).attr("y",e).attr("dy",h+"em").text(b);return i};a.each(function(){var a=b.select(this),h=a.text().split(/\s+/),i=1.1,j=a.attr("x"),k=a.attr("y"),l=parseFloat(a.attr("dy"));a.text(null);var m=g(a,null,i,j,k,l,0),n=!1,o=h.reduce(function(a,b){if(n)return a;var e=a.length===d,f=a[a.length-1],g=m.text(f+b).node().getComputedTextLength()>c;return g&&e&&(a[a.length-1]=f+"...",n=!0),g&&!e&&a.push(b),g||(a[a.length-1]=f+" "+b),a},[""]);k=f?-1*(o.length-1)*Math.floor(.5*e):k,o.forEach(function(b,c){return g(a,b,i,j,k,l,c)}),m.remove()})},m=function(a,b,c){var d=a.selectAll(".tick line"),e=c/d[0].length,f=e/2;if("ordinal"===b.scaleType||"period"===b.scaleType){var g="h"===j(b.guide.scaleOrient),h=g?"x":"y",i=g?f:-f;d.attr(h+"1",i).attr(h+"2",i)}},n=function(a,b){var c="h"===j(b.guide.scaleOrient)?1:-1,d=a.append("text").attr("transform",i(b.guide.label.rotate)).attr("class","label").attr("x",c*b.guide.size*.5).attr("y",c*b.guide.label.padding).style("text-anchor",b.guide.label.textAnchor),e=" > ",f=b.guide.label.text.split(e),g=f.length;f.forEach(function(a,b){d.append("tspan").attr("class","label-token label-token-"+b).text(a),g-1>b&&d.append("tspan").attr("class","label-token-delimiter label-token-delimiter-"+b).text(e)})},o=function(a,b){var c="h"===j(b.guide.scaleOrient),d=b.guide.rotate,e=a.selectAll(".tick text");e.attr("transform",i(d)).style("text-anchor",b.guide.textAnchor),90===d&&e.attr("x",9).attr("y",0),b.guide.tickFormatWordWrap?e.call(l,b.guide.tickFormatWordWrapLimit,b.guide.tickFormatWordWrapLines,b.guide.$maxTickTextH,!c):e.call(k,b.guide.tickFormatWordWrapLimit)},p=function(a,c,d){var e=this;if(a.scaleDim){var f=b.svg.axis().scale(a.scaleObj).orient(a.guide.scaleOrient),i=g.get(a.guide.tickFormat);null!==i&&(f.ticks(Math.round(d/a.guide.density)),f.tickFormat(i));var j=e.append("g").attr("class",a.guide.cssClass).attr("transform",h.apply(null,c)).call(f);m(j,a,d),o(j,a),n(j,a)}},q=function(a,c,d){var e=this,f=e.append("g").attr("class","grid").attr("transform",h(0,0)),i=(a.guide.showGridLines||"").toLowerCase();if(i.length>0){var j=f.append("g").attr("class","grid-lines");if(i.indexOf("x")>-1&&a.x.scaleDim){var k=a.x,l=b.svg.axis().scale(k.scaleObj).orient(k.guide.scaleOrient).tickSize(c),n=g.get(k.guide.tickFormat);null!==n&&(l.ticks(Math.round(d/k.guide.density)),l.tickFormat(n));var o=j.append("g").attr("class","grid-lines-x").call(l);m(o,k,d);var p=o.select("g.tick");if(p.node()&&"translate(0,0)"!==p.attr("transform")){var q=p.node().cloneNode(!0);j.node().appendChild(q),b.select(q).attr("class","border").attr("transform",h(0,0)).select("line").attr("x1",0).attr("x2",0)}}if(i.indexOf("y")>-1&&a.y.scaleDim){var r=a.y,s=b.svg.axis().scale(r.scaleObj).orient(r.guide.scaleOrient).tickSize(-d),n=g.get(r.guide.tickFormat);null!==n&&(s.ticks(Math.round(c/r.guide.density)),s.tickFormat(n));var t=j.append("g").attr("class","grid-lines-y").call(s);m(t,r,c)}j.selectAll("text").remove()}return f},r=function(c){var d,e,g=a.times(10,function(a){return"color10-"+(1+a)}),h=c.guide.color||{},i=c.color,j=i.scaleDim,k=h.brewer||g;return f.isArray(k)?(e=c.domain(j),d=k):(e=Object.keys(k),d=e.map(function(a){return k[a]})),{get:function(a){return b.scale.ordinal().range(d).domain(e)(a)},dimension:j}},s=function(b){return b.options=b.options||{},b.guide=b.guide||{},b.guide.padding=a.defaults(b.guide.padding||{},{l:0,b:0,r:0,t:0}),b.guide.x=a.defaults(b.guide.x||{},{label:"",padding:0,density:30,cssClass:"x axis",scaleOrient:"bottom",rotate:0,textAnchor:"middle",tickPeriod:null,tickFormat:null,autoScale:!0}),b.guide.x.label=a.isObject(b.guide.x.label)?b.guide.x.label:{text:b.guide.x.label},b.guide.x.label=a.defaults(b.guide.x.label,{padding:32,rotate:0,textAnchor:"middle"}),b.guide.x.tickFormat=b.guide.x.tickFormat||b.guide.x.tickPeriod,b.guide.y=a.defaults(b.guide.y||{},{label:"",padding:0,density:30,cssClass:"y axis",scaleOrient:"left",rotate:0,textAnchor:"end",tickPeriod:null,tickFormat:null,autoScale:!0}),b.guide.y.label=a.isObject(b.guide.y.label)?b.guide.y.label:{text:b.guide.y.label},b.guide.y.label=a.defaults(b.guide.y.label,{padding:32,rotate:-90,textAnchor:"middle"}),b.guide.y.tickFormat=b.guide.y.tickFormat||b.guide.y.tickPeriod,b},t={translate:h,rotate:i,getOrientation:j,fnDrawDimAxis:p,fnDrawGrid:q,generateColor:r,applyNodeDefaults:s};c.utilsDraw=t}),e("spec-engine-factory",["exports","./utils/utils","./utils/utils-draw","./formatter-registry"],function(b,c,d,e){var f=c.utils,g=d.utilsDraw,h=e.FormatterRegistry,i=function(b,c){return b.guide=b.guide||{},b.guide.padding=b.guide.padding||{l:0,t:0,r:0,b:0},b=a.defaults(b,c),b.guide=a.defaults(b.guide,f.clone(c.guide)),b.guide.x=a.defaults(b.guide.x,f.clone(c.guide.x)),b.guide.y=a.defaults(b.guide.y,f.clone(c.guide.y)),b},j=function(a){var b=a.unit||[],c=!a.hasOwnProperty("unit"),d=!b.some(function(a){return a.hasOwnProperty("unit")});return{type:a.type,isLeaf:c,isLeafParent:!c&&d}},k=function(b,c,d,e){if(0===b.length)return{width:0,height:0};if(null===c){var f=d("TauChart Library");return f.width=.625*e,f}var g=a.max(b,function(a){return c(a).toString().length});return d(c(g))},l=function(a,b,c){var d=a.dimType,e=a.scaleType,f="*";if("measure"===d&&"time"===e){var g=b.source.filter(function(a){return null!==a}).sort(),h=0;if(g.length>1){for(var i=1,j=g.length,k=[];j>i;)k.push(g[i]-g[i-1]),++i;var l=k.reduce(function(a,b){return a+=b},0);h=l/k.length}var m=[[31536e6,"year"],[7776e6,"quarter"],[2592e6,"month"],[6048e5,"week"],[864e5,"day"],[36e5,"hour"],[6e4,"min"],[1e3,"sec"],[0,"ms"]],n=-1;do++n;while(m[n][0]>h);f=m[n][1]}var o=[d,e,f].join(":"),p=[d,e].join(":");return c[o]||c[p]||c[d]||null},m=function(b,c){var d=g.applyNodeDefaults(b),e=c(j(d),d),f=a.omit(e,"unit");return(e.unit||[]).forEach(function(a){return m(i(a,f),c)}),e},n={NONE:function(a,b,c){return function(a,b){return b.guide.x.tickFontHeight=c.getAxisTickLabelSize("X").height,b.guide.y.tickFontHeight=c.getAxisTickLabelSize("Y").height,b}},AUTO:function(a,b,c){var d=[],e=[],f=null,g=null;return m(a.unit,function(a,b){if(a.isLeaf)return b;!f&&b.x&&(f=b),!g&&b.y&&(g=b),b.x&&(b.guide.x.label.text=b.guide.x.label.text||b.x),b.y&&(b.guide.y.label.text=b.guide.y.label.text||b.y);var c=b.guide.x.label.text;c&&(d.push(c),b.guide.x.label.text="");var h=b.guide.y.label.text;return h&&(e.push(h),b.guide.y.label.text=""),b}),f&&(f.guide.x.label.text=d.join(" > ")),g&&(g.guide.y.label.text=e.join(" > ")),function(a,d){if(a.isLeaf)return d;var e=!a.isLeaf&&!a.isLeafParent;e&&(d.guide.x.cssClass+=" facet-axis",d.guide.y.cssClass+=" facet-axis");var f=b.dimension(d.x),g=b.dimension(d.y),i="measure"===f.dimType,j="measure"===g.dimType,m={map:d.guide.x.tickLabel,min:d.guide.x.tickMin,max:d.guide.x.tickMax,period:d.guide.x.tickPeriod,autoScale:d.guide.x.autoScale},n={map:d.guide.y.tickLabel,min:d.guide.y.tickMin,max:d.guide.y.tickMax,period:d.guide.y.tickPeriod,autoScale:d.guide.y.autoScale},o=b.scaleMeta(d.x,m),p=o.values,q=b.scaleMeta(d.y,n),r=q.values;d.guide.x.tickFormat=d.guide.x.tickFormat||l(f,o,c.defaultFormats),d.guide.y.tickFormat=d.guide.y.tickFormat||l(g,q,c.defaultFormats);var s=0===p.length,t=0===r.length,u=k(p,h.get(d.guide.x.tickFormat),c.getAxisTickLabelSize,c.xAxisTickLabelLimit),v=k(r,h.get(d.guide.y.tickFormat),c.getAxisTickLabelSize,c.yAxisTickLabelLimit),w=a.isLeafParent?c.xAxisPadding:0,x=a.isLeafParent?c.yAxisPadding:0,y=!e&&!!f.dimType&&"measure"!==f.dimType;d.guide.x.padding=s?0:w,d.guide.y.padding=t?0:x,d.guide.x.rotate=y?90:0,d.guide.x.textAnchor=y?"start":d.guide.x.textAnchor;var z=s?0:c.xTickWidth,A=t?0:c.yTickWidth;d.guide.x.tickFormatWordWrapLimit=c.xAxisTickLabelLimit,d.guide.y.tickFormatWordWrapLimit=c.yAxisTickLabelLimit;var B=y?u.width:u.height;!i&&B>c.xAxisTickLabelLimit&&(B=c.xAxisTickLabelLimit),!y&&u.width>c.xAxisTickLabelLimit&&(d.guide.x.tickFormatWordWrap=!0,d.guide.x.tickFormatWordWrapLines=c.xTickWordWrapLinesLimit,B=c.xTickWordWrapLinesLimit*u.height);var C=v.width;!j&&C>c.yAxisTickLabelLimit&&(C=c.yAxisTickLabelLimit,d.guide.y.tickFormatWordWrap=!0,d.guide.y.tickFormatWordWrapLines=c.yTickWordWrapLinesLimit);var D=z+B,E=A+C,F=c.xFontLabelHeight,G=c.yFontLabelHeight,H=c.distToXAxisLabel,I=c.distToYAxisLabel,J=Math.min(c.xAxisTickLabelLimit,y?u.height:u.width);d.guide.x.density=c.xDensityKoeff*J;var K=Math.ceil(v.width/c.yAxisTickLabelLimit),L=Math.min(K,c.yTickWordWrapLinesLimit),M=Math.min(c.yAxisTickLabelLimit,L*v.height);d.guide.y.density=c.yDensityKoeff*M,d.guide.x.label.padding=d.guide.x.label.text?D+H:0,d.guide.y.label.padding=d.guide.y.label.text?E+I:0;var N=d.guide.x.label.text?d.guide.x.label.padding+F:D,O=d.guide.y.label.text?d.guide.y.label.padding+G:E;return d.guide.x.label.text=d.guide.x.label.text.toUpperCase(),d.guide.y.label.text=d.guide.y.label.text.toUpperCase(),d.guide.padding.b=w+N,d.guide.padding.l=x+O,d.guide.x.tickFontHeight=u.height,d.guide.y.tickFontHeight=v.height,d.guide.x.$minimalDomain=p.length,d.guide.y.$minimalDomain=r.length,d.guide.x.$maxTickTextW=u.width,d.guide.x.$maxTickTextH=u.height,d.guide.y.$maxTickTextW=v.width,d.guide.y.$maxTickTextH=v.height,d}}},o={get:function(a,b){var c=n[a]||n.NONE;return function(a,d){var e=f.clone(a);return m(e.unit,c(e,d,b)),e}}};b.SpecEngineFactory=o}),e("matrix",["exports"],function(b){var c=function(){var b=function(b,c){var d,e=a.toArray(arguments);d=a.isArray(e[0])?e[0]:a.times(b,function(){return a.times(c,function(){return null})}),this.cube=d};return b.prototype={iterate:function(b){var c=this.cube;return a.each(c,function(c,d){a.each(c,function(a,c){b(d,c,a)})}),this},getRC:function(a,b){return this.cube[a][b]},setRC:function(a,b,c){return this.cube[a][b]=c,this},sizeR:function(){return this.cube.length},sizeC:function(){var a=this.cube[0]||[];return a.length}},b}();b.TMatrix=c}),e("layout-engine-factory",["exports","./utils/utils","./utils/utils-draw","./matrix"],function(a,b,c,d){var e=b.utils,f=c.utilsDraw,g=d.TMatrix,h=function(a,b){var c=b?b:{depth:-1,paddings:[]},d=(a.guide||{}).padding||{l:0,b:0,r:0,t:0};return c.depth+=1,c.paddings.unshift({l:d.l,b:d.b,r:d.r,t:d.t}),a.unit&&a.unit.length&&h(a.unit[0],c),c},i={NONE:function(a){return a},EXTRACT:function(a){var b=function(a,c,d){var e=a,f=e.sizeR(),h=e.sizeC();e.iterate(function(a,e,i){i.forEach(function(b){return d(b,{firstRow:0===a,firstCol:0===e,lastRow:a===f-1,lastCol:e===h-1,depth:c})}),i.filter(function(a){return a.$matrix}).forEach(function(a){a.$matrix=new g(a.$matrix.cube),b(a.$matrix,c-1,d)})})},c=e.clone(a),d=new g([[[c]]]),i=h(c),j=i.paddings.reduce(function(a,b){return a.l+=b.l,a.b+=b.b,a},{l:0,b:0}),k=e.clone(j),l=i.paddings.reverse().map(function(a){return a.l=k.l-a.l,a.b=k.b-a.b,k={l:a.l,b:a.b},a});i.paddings=l.reverse();var m=10,n=f.applyNodeDefaults({type:"COORDS.RECT",options:e.clone(a.options),$matrix:new g([[[c]]]),guide:{padding:{l:j.l-m,b:j.b-m,r:0,t:0}}});return b(d,i.depth,function(a,b){var c=b.depth;a.guide.x.hide=!b.lastRow,a.guide.y.hide=!b.firstCol;var d=c>1?0:m,e=c>1?m:0;return a.guide.x.padding+=i.paddings[c].b,a.guide.y.padding+=i.paddings[c].l,a.guide.x.padding-=e,a.guide.y.padding-=e,a.guide.padding.l=d,a.guide.padding.b=d,a.guide.padding.r=d,a.guide.padding.t=d,a.guide.showGridLines=c>1?"":"xy",a}),n}},j={get:function(a){return i[a]||i.NONE}};a.LayoutEngineFactory=j}),e("plugins",["exports"],function(a){{var c=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},d=function(){var a=function(a){this._plugins=a};return c(a,null,{_call:{writable:!0,value:function(a,b){for(var c=0;c<this._plugins.length;c++)"function"==typeof this._plugins[c][a]&&this._plugins[c][a].apply(this._plugins[c],b)}},render:{writable:!0,value:function(){this._call("render",arguments)}},click:{writable:!0,value:function(){this._call("click",arguments)}},mouseover:{writable:!0,value:function(){this._call("mouseover",arguments)}},mouseout:{writable:!0,value:function(){this._call("mouseout",arguments)}},mousemove:{writable:!0,value:function(){this._call("mousemove",arguments)}}}),a}(),e=function(a){return function(){this.on("click",function(c){a.click(new g(c),new f(b.select(this)))}).on("mouseover",function(c){a.mouseover(new g(c),new f(b.select(this)))}).on("mouseout",function(c){a.mouseout(new g(c),new f(b.select(this)))}).on("mousemove",function(c){a.mousemove(new g(c),new f(b.select(this)))})}},f=function(a){this.element=a},g=function(a){this.datum=a};!function(){var a=function(a,b){this.svg=a.svg,this.html=a.html,this.mapper=b};return c(a,null,{elements:{writable:!0,value:function(){return this.svg.selectAll(".i-role-datum")}}}),a}()}a.propagateDatumEvents=e,a.Plugins=d}),e("const",["exports"],function(a){a.CSS_PREFIX="graphical-report__"}),e("unit-domain-period-generator",["exports"],function(a){var b={day:{cast:function(a){return new Date(a.setHours(0,0,0,0))},next:function(a){return new Date(a.setDate(a.getDate()+1))}},week:{cast:function(a){return a=new Date(a.setHours(0,0,0,0)),a=new Date(a.setDate(a.getDate()-a.getDay()))},next:function(a){return new Date(a.setDate(a.getDate()+7))}},month:{cast:function(a){return a=new Date(a.setHours(0,0,0,0)),a=new Date(a.setDate(1))},next:function(a){return new Date(a.setMonth(a.getMonth()+1))}},quarter:{cast:function(a){a=new Date(a.setHours(0,0,0,0)),a=new Date(a.setDate(1));var b=a.getMonth(),c=b-b%3;return new Date(a.setMonth(c))},next:function(a){return new Date(a.setMonth(a.getMonth()+3))}},year:{cast:function(a){return a=new Date(a.setHours(0,0,0,0)),a=new Date(a.setDate(1)),a=new Date(a.setMonth(0))},next:function(a){return new Date(a.setFullYear(a.getFullYear()+1))}}},c={add:function(a,c){return b[a.toLowerCase()]=c,this},get:function(a){return b[a.toLowerCase()]},generate:function(a,c,d){var e=[],f=b[d.toLowerCase()];if(f){var g=f.cast(new Date(c)),h=f.cast(new Date(a));for(e.push(h);(h=f.next(new Date(h)))<=g;)e.push(h)}return e}};a.UnitDomainPeriodGenerator=c}),e("unit-domain-mixin",["exports","./unit-domain-period-generator","./utils/utils","underscore","d3"],function(a,b,c,d,e){var f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},g=b.UnitDomainPeriodGenerator,h=c.utils,i=d,j=e,k={ordinal:function(a){return a},linear:function(a,b){var c=b.autoScale?h.autoScale(a):j.extent(a),d=i.isNumber(b.min)?b.min:c[0],e=i.isNumber(b.max)?b.max:c[1];return[Math.min(d,c[0]),Math.max(e,c[1])]},period:function(a,b){var c=j.extent(a),d=i.isNull(b.min)||i.isUndefined(b.min)?c[0]:new Date(b.min).getTime(),e=i.isNull(b.max)||i.isUndefined(b.max)?c[1]:new Date(b.max).getTime(),f=[new Date(Math.min(d,c[0])),new Date(Math.max(e,c[1]))];return g.generate(f[0],f[1],b.period)},time:function(a,b){var c=j.extent(a),d=i.isNull(b.min)||i.isUndefined(b.min)?c[0]:new Date(b.min).getTime(),e=i.isNull(b.max)||i.isUndefined(b.max)?c[1]:new Date(b.max).getTime();return[new Date(Math.min(d,c[0])),new Date(Math.max(e,c[1]))]}},l={ordinal:function(a,b){return j.scale.ordinal().domain(a).rangePoints(b,1)},linear:function(a,b){return j.scale.linear().domain(a).rangeRound(b,1)},period:function(a,b){return j.scale.ordinal().domain(a).rangePoints(b,1)},time:function(a,b){return j.time.scale().domain(a).range(b)}},m=function(){var a=function(a,b){var c=function(a){return function(b){return b[a]}},d=function(b){var d=a[b]||{},e=d.value?c(d.value):function(a){return a},f=i.contains(["period","time"],d.scale);return f?i.compose(function(a){return new Date(a).getTime()},e):e},e=function(b){var c=a[b]||{};return c.order||null},f=function(a){var b={category:function(a,b,c){return c},order:function(a,b,c){var d=e(a);return d?i.union(d,c):i.sortBy(c,b)},measure:function(a,b,c){return i.sortBy(c,b)},"as-is":function(a,b,c){return c}};return b[a]||b["as-is"]},h=function(a){var b={category:f("category"),order:function(a,b,c){var d=e(a);return d?i.union(c,d):c},measure:f("measure"),"as-is":f("as-is")};return b[a]||b["as-is"]};this.fnDimension=function(b,c){var d=(c||{}).dimensions||{},e=a[b]||{},f=d[b]||{};return{scaleDim:b,scaleType:f.scale||e.scale,dimType:f.type||e.type}},this.fnSource=function(a){var c=i.map(a,function(a,b){return function(c){return d(b)(c[b])===a}});return i(b).filter(function(a){return i.every(c,function(b){return b(a)})})};var j=function(c,e){if(!a[c])return[null];var f=d(c),g=i(b).chain().pluck(c).uniq(f).value();return e(c,f,g)};this.fnDomain=function(b){var c=d(b),e=(a[b]||{}).type,g=j(b,f(e));return g.map(c)};var m=function(b,e){var f=e||{},l=i.defaults({},a[b]),m=f.map?c(f.map):d(b),n=f.period?function(a){return g.get(f.period).cast(new Date(a))}:function(a){return a},o=j(b,h(l.type)).map(m),p=l.scale?k[l.scale](o,f):[];return{extract:function(a){return n(m(a))},values:p,source:o}};this.fnScaleMeta=m,this.fnScaleTo=function(b,c,d){var e=d||{},f=i.defaults({},a[b]),g=m(b,d),h=l[f.scale](g.values,c,e),j=function(a){return h(g.extract(a))};return Object.keys(h).forEach(function(a){return j[a]=h[a]}),j}};return f(a,null,{mix:{writable:!0,value:function(a){return a.dimension=this.fnDimension,a.source=this.fnSource,a.domain=this.fnDomain,a.scaleMeta=this.fnScaleMeta,a.scaleTo=this.fnScaleTo,a.partition=function(){return a.source(a.$where)},a}}}),a}();a.UnitDomainMixin=m}),e("units-registry",["exports"],function(a){var b={},c={add:function(a,c){var d={};return d.draw="function"==typeof c?c:c.draw,d.walk=c.walk||function(a){return a},b[a]=d,this},get:function(a){if(!b.hasOwnProperty(a))throw new Error("Unknown unit type: "+a);return b[a]}};a.UnitsRegistry=c}),e("charts/tau.plot",["exports","../dsl-reader","../spec-engine-factory","../layout-engine-factory","../plugins","../utils/utils","../utils/utils-dom","../const","../unit-domain-mixin","../units-registry"],function(c,d,e,f,g,h,i,j,k,l){var m=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},n=d.DSLReader,o=e.SpecEngineFactory,p=f.LayoutEngineFactory,q=g.Plugins,r=g.propagateDatumEvents,s=h.utils,t=i.utilsDom,u=j.CSS_PREFIX,v=k.UnitDomainMixin,w=l.UnitsRegistry,x=function(){var c=function d(b){var c=this.convertConfig(b);this.config=a.defaults(c,{excludeNull:!0,spec:null,data:[],plugins:[]}),c.spec.dimensions=this._normalizeDimensions(c.spec.dimensions,c.data),this.plugins=this.config.plugins,this.spec=this.config.spec,this.data=this.config.excludeNull?this._autoExcludeNullValues(c.spec.dimensions,this.config.data):this.config.data,this._plugins=new q(this.config.plugins);var e=d.globalSettings,f={};Object.keys(e).forEach(function(b){f[b]=a.isFunction(e[b])?e[b]:s.clone(e[b])}),this.settings=f,this.settings.specEngine=this.config.specEngine||this.settings.specEngine,this.settings.layoutEngine=this.config.layoutEngine||this.settings.layoutEngine};return m(c,null,{renderTo:{writable:!0,value:function(c,d){var e=b.select(c),f=e[0][0];if(null===f)throw new Error("Target element not found");var g=a.defaults(d||{},t.getContainerSize(f));if(0!==this.data.length){f.innerHTML="";var h=new v(this.spec.dimensions,this.data),i=o.get(this.settings.specEngine,this.settings),j=i(this.spec,h.mix({})),k=function(a){var b;if(a.unit){var c=k(a.unit[0]),d=a.guide,e=d.x.$minimalDomain||1,f=d.y.$minimalDomain||1,g=Math.max(e*d.x.density,e*c.w),h=Math.max(f*d.y.density,f*c.h);b={w:g+d.padding.l+d.padding.r,h:h+d.padding.t+d.padding.b}}else b={w:0,h:0};return b},l=k(j.unit),m=l.w,q=l.h,s=t.getScrollbarWidth(),x=g.width-m,y=g.height-q,z=x>=0?g.width:m,A=y>=0?0:s,B=y>=0?g.height:q,C=x>=0?0:s;g.height=B-C,g.width=z-A;var D=this.settings,E=function(a,b){var c=a.guide.x.$minimalDomain||1,d=a.guide.y.$minimalDomain||1,e=b.width/c,f=b.height/d,g=D.xMinimumDensityKoeff;if(0!==a.guide.x.rotate&&e>g*a.guide.x.$maxTickTextW){a.guide.x.rotate=0,a.guide.x.textAnchor="middle";var h=Math.min(D.xAxisTickLabelLimit,a.guide.x.$maxTickTextW),i=0-h+a.guide.x.$maxTickTextH;a.guide.x.label.padding=a.guide.x.label.padding+i,a.guide.padding.b=a.guide.padding.b+i}var j={width:e,height:f};a.unit&&E(a.unit[0],j)};E(j.unit,g);var F=new n(h,w),G=F.buildGraph(j),H=p.get(this.settings.layoutEngine)(G),I=F.calcLayout(H,g),J=F.renderGraph(I,e.append("svg").attr("class",u+"svg").attr("width",g.width).attr("height",g.height));J.selectAll(".i-role-datum").call(r(this._plugins)),this._plugins.render(J)}}},_autoDetectDimensions:{writable:!0,value:function(b){var c={type:"category",scale:"ordinal"},d=function(b,c){var d=c;return a.isDate(b)?(d.type="measure",d.scale="time"):a.isObject(b)?(d.type="order",d.scale="ordinal"):a.isNumber(b)&&(d.type="measure",d.scale="linear"),d},e=function(a,b){return Object.keys(b).forEach(function(e){var f=b.hasOwnProperty(e)?b[e]:null;if(a[e]=a[e]||{type:null,hasNull:!1},null===f)a[e].hasNull=!0;else{var g=d(f,s.clone(c)),h=g.type,i=g.scale,j=null!==a[e].type&&a[e].type!==h;a[e].type=j?c.type:h,a[e].scale=j?c.scale:i}}),a};return a.reduce(b,e,{})}},_autoExcludeNullValues:{writable:!0,value:function(a,b){var c=[];Object.keys(a).forEach(function(b){var d=a[b];d.hasOwnProperty("hasNull")&&!d.hasNull||"measure"!==d.type&&"period"!==d.scale||c.push(b)});var d;return d=0===c.length?b:b.filter(function(a){return!c.some(function(b){return!a.hasOwnProperty(b)||null===a[b]})})}},_autoAssignScales:{writable:!0,value:function(a){var b="category",c={category:"ordinal",order:"ordinal",measure:"linear"},d={};return Object.keys(a).forEach(function(e){var f=a[e],g=(f.type||b).toLowerCase();d[e]={},d[e].type=g,d[e].scale=f.scale||c[g],d[e].value=f.value}),d}},_normalizeDimensions:{writable:!0,value:function(a,b){var c=a?a:this._autoDetectDimensions(b);return this._autoAssignScales(c)}},convertConfig:{writable:!0,value:function(a){return a}}}),c}();c.Plot=x}),e("charts/tau.chart",["exports","./tau.plot","../utils/utils"],function(b,c,d){function e(a){return a?a:null}function f(a){return m.isArray(a)?a:[a]}function g(a,b){return{type:a,x:b.x,y:b.y,color:b.color,guide:{color:b.colorGuide},flip:b.flip,size:b.size}}function h(a,b){return b.reduce(function(b,c,d){return"measure"===a[c].type&&(b.countMeasureAxis++,b.indexMeasureAxis.push(d)),"measure"!==a[c].type&&1===b.countMeasureAxis?b.status=n.WARNING:b.countMeasureAxis>1&&(b.status=n.FAIL),b},{status:n.SUCCESS,countMeasureAxis:0,indexMeasureAxis:[]})}function i(b,c){var d=f(c.x),i=f(c.y),j=h(c.dimensions,d),k=h(c.dimensions,i);d=o[j.status](d,j),i=o[k.status](i,k);for(var l=f(c.guide),m=Math.max(d.length,i.length),n={type:"COORDS.RECT",unit:[]},p=l[l.length-1],q=p&&p.color||{},r=m;r>0;r--){var s=d.pop(),t=i.pop(),u=l.pop()||{};r===m?(n.x=s,n.y=t,n.unit.push(g(b,{x:e(s),y:e(t),color:c.color,size:c.size,flip:c.flip,colorGuide:q})),n.guide=a.defaults(u,{padding:{l:45,b:45,r:24,t:24},showGridLines:"xy",x:{label:s},y:{label:t}})):n={type:"COORDS.RECT",x:e(s),y:e(t),unit:[n],guide:a.defaults(u,{padding:{l:45,b:45,r:0,t:0},x:{label:s},y:{label:t}})}}return c.spec={dimensions:c.dimensions,unit:n},c}var j=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},k=function(a,b){a.prototype=Object.create(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),a.__proto__=b},l=c.Plot,m=d.utils,n={SUCCESS:"SUCCESS",WARNING:"WARNING",FAIL:"FAIL"},o=function(b){return b[n.SUCCESS]=function(a){return a},b[n.FAIL]=function(){throw new Error("This configuration is not supported, See http://api.taucharts.com/basic/facet.html#easy-approach-for-creating-facet-chart")},b[n.WARNING]=function(b,c){var d=b[c.indexMeasureAxis[0]],e=a.without(b,d);return e.push(d),e},b}({}),p={scatterplot:function(a){return i("ELEMENT.POINT",a)},line:function(a){return i("ELEMENT.LINE",a)},bar:function(a){return a.flip=!1,i("ELEMENT.INTERVAL",a)},horizontalBar:function(a){return a.flip=!0,i("ELEMENT.INTERVAL",a)}},q=function(a){var b=function(){a.apply(this,arguments)
Пример #4
0
!function(a,b){if("function"==typeof define&&define.amd)define(["underscore","d3"],function(a,c){return b(a,c)});else if("object"==typeof module&&module.exports){{var c=require("underscore");require("d3")}module.exports=b(c)}else a.tauChart=b(a._,a.d3)}(this,function(a,b){var c,d,e;return function(a){function b(a,b){return u.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n=b&&b.split("/"),o=s.map,p=o&&o["*"]||{};if(a&&"."===a.charAt(0))if(b){for(n=n.slice(0,n.length-1),a=a.split("/"),g=a.length-1,s.nodeIdCompat&&w.test(a[g])&&(a[g]=a[g].replace(w,"")),a=n.concat(a),k=0;k<a.length;k+=1)if(m=a[k],"."===m)a.splice(k,1),k-=1;else if(".."===m){if(1===k&&(".."===a[2]||".."===a[0]))break;k>0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}else 0===a.indexOf("./")&&(a=a.substring(2));if((n||p)&&o){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),n)for(l=n.length;l>0;l-=1)if(e=o[n.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&p&&p[d]&&(i=p[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(b,c){return function(){var d=v.call(arguments,0);return"string"!=typeof d[0]&&1===d.length&&d.push(null),n.apply(a,d.concat([b,c]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){q[a]=b}}function j(c){if(b(r,c)){var d=r[c];delete r[c],t[c]=!0,m.apply(a,d)}if(!b(q,c)&&!b(t,c))throw new Error("No "+c);return q[c]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return function(){return s&&s.config&&s.config[a]||{}}}var m,n,o,p,q={},r={},s={},t={},u=Object.prototype.hasOwnProperty,v=[].slice,w=/\.js$/;o=function(a,b){var c,d=k(a),e=d[0];return a=d[1],e&&(e=f(e,b),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(b)):f(a,b):(a=f(a,b),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},p={require:function(a){return g(a)},exports:function(a){var b=q[a];return"undefined"!=typeof b?b:q[a]={}},module:function(a){return{id:a,uri:"",exports:q[a],config:l(a)}}},m=function(c,d,e,f){var h,k,l,m,n,s,u=[],v=typeof e;if(f=f||c,"undefined"===v||"function"===v){for(d=!d.length&&e.length?["require","exports","module"]:d,n=0;n<d.length;n+=1)if(m=o(d[n],f),k=m.f,"require"===k)u[n]=p.require(c);else if("exports"===k)u[n]=p.exports(c),s=!0;else if("module"===k)h=u[n]=p.module(c);else if(b(q,k)||b(r,k)||b(t,k))u[n]=j(k);else{if(!m.p)throw new Error(c+" missing "+k);m.p.load(m.n,g(f,!0),i(k),{}),u[n]=q[k]}l=e?e.apply(q[c],u):void 0,c&&(h&&h.exports!==a&&h.exports!==q[c]?q[c]=h.exports:l===a&&s||(q[c]=l))}else c&&(q[c]=e)},c=d=n=function(b,c,d,e,f){if("string"==typeof b)return p[b]?p[b](c):j(o(b,c).f);if(!b.splice){if(s=b,s.deps&&n(s.deps,s.callback),!c)return;c.splice?(b=c,c=d,d=null):b=a}return c=c||function(){},"function"==typeof d&&(d=e,e=f),e?m(a,b,c,d):setTimeout(function(){m(a,b,c,d)},4),n},n.config=function(a){return n(a)},c._defined=q,e=function(a,c,d){c.splice||(d=c,c=[]),b(q,a)||b(r,a)||(r[a]=[a,c,d])},e.amd={jQuery:!0}}(),e("../node_modules/almond/almond",function(){}),e("utils/utils",["exports"],function(a){var b={clone:function(a){return JSON.parse(JSON.stringify(a))},isArray:function(a){return Array.isArray(a)},autoScale:function(a){var b=10,c=Math.min.apply(null,a),d=Math.max.apply(null,a);if(c===d){var e=d>=0?-1:1,f=d||1;d-=e*f/b}for(var g=[c,d],h=g[1]-g[0],i=Math.pow(10,Math.floor(Math.log(h/b)/Math.LN10)),j=b/h*i,k=[[.15,10],[.35,5],[.75,2],[1,1]],l=-1;j>k[++l][0];);i*=k[l][1],g[0]=Math.floor(g[0]/i)*i,g[1]=Math.ceil(g[1]/i)*i;var m=c-g[0],n=g[1]-d,o=i/2;if(c>=0)g[0]=0;else{var p=o>=m?i:0;g[0]=g[0]-p}if(0>=d)g[1]=0;else{var q=o>=n?i:0;g[1]=g[1]+q}return[parseFloat(g[0].toFixed(15)),parseFloat(g[1].toFixed(15))]}};a.utils=b}),e("unit-domain-period-generator",["exports"],function(a){var b={day:{cast:function(a){return new Date(a.setHours(0,0,0,0))},next:function(a){return new Date(a.setDate(a.getDate()+1))}},week:{cast:function(a){return a=new Date(a.setHours(0,0,0,0)),a=new Date(a.setDate(a.getDate()-a.getDay()))},next:function(a){return new Date(a.setDate(a.getDate()+7))}},month:{cast:function(a){return a=new Date(a.setHours(0,0,0,0)),a=new Date(a.setDate(1))},next:function(a){return new Date(a.setMonth(a.getMonth()+1))}},quarter:{cast:function(a){a=new Date(a.setHours(0,0,0,0)),a=new Date(a.setDate(1));var b=a.getMonth(),c=b-b%3;return new Date(a.setMonth(c))},next:function(a){return new Date(a.setMonth(a.getMonth()+3))}},year:{cast:function(a){return a=new Date(a.setHours(0,0,0,0)),a=new Date(a.setDate(1)),a=new Date(a.setMonth(0))},next:function(a){return new Date(a.setFullYear(a.getFullYear()+1))}}},c={add:function(a,c){return b[a.toLowerCase()]=c,this},get:function(a){return b[a.toLowerCase()]},generate:function(a,c,d){var e=[],f=b[d.toLowerCase()];if(f){var g=f.cast(new Date(c)),h=f.cast(new Date(a));for(e.push(h);(h=f.next(new Date(h)))<=g;)e.push(h)}return e}};a.UnitDomainPeriodGenerator=c}),e("unit-domain-mixin",["exports","./unit-domain-period-generator","./utils/utils","underscore","d3"],function(a,b,c,d,e){var f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},g=b.UnitDomainPeriodGenerator,h=c.utils,i=d,j=e,k={ordinal:function(a,b){return j.scale.ordinal().domain(a).rangePoints(b,1)},linear:function(a,b,c){var d=c.autoScale?h.autoScale(a):j.extent(a),e=i.isNumber(c.min)?c.min:d[0],f=i.isNumber(c.max)?c.max:d[1],g=[Math.min(e,d[0]),Math.max(f,d[1])];return j.scale.linear().domain(g).rangeRound(b,1)},period:function(a,b,c){var d=j.extent(a),e=i.isNull(c.min)||i.isUndefined(c.min)?d[0]:new Date(c.min).getTime(),f=i.isNull(c.max)||i.isUndefined(c.max)?d[1]:new Date(c.max).getTime(),h=[Math.min(e,d[0]),Math.max(f,d[1])],k=g.generate(h[0],h[1],c.period);return j.scale.ordinal().domain(k).rangePoints(b,1)},time:function(a,b,c){var d=j.extent(a),e=i.isNull(c.min)||i.isUndefined(c.min)?d[0]:new Date(c.min).getTime(),f=i.isNull(c.max)||i.isUndefined(c.max)?d[1]:new Date(c.max).getTime(),g=[Math.min(e,d[0]),Math.max(f,d[1])];return j.time.scale().domain(g).range(b)}},l=function(){var a=function(a,b){var c=function(a){return function(b){return b[a]}},d=function(b){var d=a[b]||{},e=d.value?c(d.value):function(a){return a},f=i.contains(["period","time"],d.scale);return f?i.compose(function(a){return new Date(a).getTime()},e):e},e=function(b){var c=a[b]||{};return c.order||null},f=function(a){var b={category:function(a,b,c){return c},order:function(a,b,c){var d=e(a);return d?i.union(d,c):i.sortBy(c,b)},measure:function(a,b,c){return i.sortBy(c,b)},"as-is":function(a,b,c){return c}};return b[a]||b["as-is"]},h=function(a){var b={category:f("category"),order:function(a,b,c){var d=e(a);return d?i.union(c,d):c},measure:f("measure"),"as-is":f("as-is")};return b[a]||b["as-is"]};this.fnDimension=function(b,c){var d=(c||{}).dimensions||{},e=a[b]||{},f=d[b]||{};return{scaleDim:b,scaleType:f.scale||e.scale,dimType:f.type||e.type}},this.fnSource=function(a){var c=i.map(a,function(a,b){return function(c){return d(b)(c[b])===a}});return i(b).filter(function(a){return i.every(c,function(b){return b(a)})})};var j=function(c,e){if(!a[c])return[null];var f=d(c),g=i(b).chain().pluck(c).uniq(f).value();return e(c,f,g)};this.fnDomain=function(b){var c=d(b),e=(a[b]||{}).type,g=j(b,f(e));return g.map(c)},this.fnScaleTo=function(b,e,f){var l=f||{},m=i.defaults({},a[b]),n=l.map?c(l.map):d(b),o=l.period?function(a){return g.get(l.period).cast(new Date(a))}:function(a){return a},p=j(b,h(m.type)).map(n),q=k[m.scale](p,e,l),r=function(a){return q(o(n(a)))};return Object.keys(q).forEach(function(a){return r[a]=q[a]}),r}};return f(a,null,{mix:{writable:!0,value:function(a){return a.dimension=this.fnDimension,a.source=this.fnSource,a.domain=this.fnDomain,a.scaleTo=this.fnScaleTo,a.partition=function(){return a.source(a.$where)},a}}}),a}();a.UnitDomainMixin=l}),e("units-registry",["exports"],function(a){var b={},c={add:function(a,c){var d={};return d.draw="function"==typeof c?c:c.draw,d.walk=c.walk||function(a){return a},b[a]=d,this},get:function(a){if(!b.hasOwnProperty(a))throw new Error("Unknown unit type: "+a);return b[a]}};a.UnitsRegistry=c}),e("dsl-reader",["exports","./utils/utils","./unit-domain-mixin","./units-registry"],function(a,b,c,d){var e=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},f=b.utils,g=c.UnitDomainMixin,h=d.UnitsRegistry,i=function(){var a=function(a,b,c){this.spec=f.clone(a),this.domain=new g(this.spec.dimensions,b),this.specEngine=c};return e(a,null,{buildGraph:{writable:!0,value:function(){var a=this,b=this.specEngine(this.spec,this.domain.mix({})),c=function(b){return h.get(b.type).walk(a.domain.mix(b),c)};return c(b.unit)}},calcLayout:{writable:!0,value:function(a,b,c){return a.options={top:0,left:0,width:c.width,height:c.height},b(a,this.domain)}},renderGraph:{writable:!0,value:function(a,b){var c=this;a.options.container=b;var d=function(a){return h.get(a.type).draw(c.domain.mix(a),d)};return d(a),a.options.container}}}),a}();a.DSLReader=i}),e("formatter-registry",["exports","d3"],function(b,c){var d=c,e={day:d.time.format("%d-%b-%Y"),week:d.time.format("%d-%b-%Y"),"week-range":function(a){var b=new Date(a),c=new Date(a),e=new Date(c.setDate(c.getDate()+7)),f=d.time.format("%d-%b-%Y");return f(b)+" - "+f(e)},month:function(a){var b=new Date(a),c=b.getMonth(),e=0===c?"%B, %Y":"%B";return d.time.format(e)(a)},"month-year":d.time.format("%B, %Y"),quarter:function(a){var b=new Date(a),c=b.getMonth(),d=(c-c%3)/3;return"Q"+(d+1)+" "+b.getFullYear()},year:d.time.format("%Y")},f={get:function(b){var c=e[b];return c||(c=function(c){var e=a.isDate(c)?d.time.format(b):d.format(b);return e(c)}),c},add:function(a,b){e[a]=b}};b.FormatterRegistry=f}),e("utils/utils-draw",["exports","../utils/utils","../formatter-registry"],function(c,d,e){var f=d.utils,g=e.FormatterRegistry,h=function(a,b){return"translate("+a+","+b+")"},i=function(a){return"rotate("+a+")"},j=function(b){return a.contains(["bottom","top"],b.toLowerCase())?"h":"v"},k=function(a,b,c){var d=a.selectAll(".tick line"),e=c/d[0].length,f=e/2;if("ordinal"===b.scaleType||"period"===b.scaleType){var g="h"===j(b.guide.scaleOrient),h=g?"x":"y",i=g?f:-f;d.attr(h+"1",i).attr(h+"2",i)}},l=function(a,b){var c="h"===j(b.guide.scaleOrient)?1:-1;a.append("text").attr("transform",i(b.guide.label.rotate)).attr("class","label").attr("x",c*b.guide.size*.5).attr("y",c*b.guide.label.padding).style("text-anchor",b.guide.label.textAnchor).text(b.guide.label.text)},m=function(a,b){a.selectAll(".tick text").attr("transform",i(b.guide.rotate)).style("text-anchor",b.guide.textAnchor)},n=function(c,d,e){var f=this;if(c.scaleDim){var i=b.svg.axis().scale(c.scaleObj).orient(c.guide.scaleOrient).ticks(a.max([Math.round(e/c.guide.density),4]));c.guide.tickFormat&&i.tickFormat(g.get(c.guide.tickFormat));var j=f.append("g").attr("class",c.guide.cssClass).attr("transform",h.apply(null,d)).call(i);k(j,c,e),m(j,c),l(j,c)}},o=function(c,d,e){var f=this,g=f.append("g").attr("class","grid").attr("transform",h(0,0)),i=(c.guide.showGridLines||"").toLowerCase();if(i.length>0){var j=g.append("g").attr("class","grid-lines");if(i.indexOf("x")>-1&&c.x.scaleDim){var l=c.x,m=b.svg.axis().scale(l.scaleObj).orient(l.guide.scaleOrient).tickSize(d).ticks(a.max([Math.round(e/l.guide.density),4])),n=j.append("g").attr("class","grid-lines-x").call(m);k(n,l,e)}if(i.indexOf("y")>-1&&c.y.scaleDim){var o=c.y,p=b.svg.axis().scale(o.scaleObj).orient(o.guide.scaleOrient).tickSize(-e).ticks(a.max([Math.round(d/o.guide.density),4])),q=j.append("g").attr("class","grid-lines-y").call(p);k(q,o,d)}j.selectAll("text").remove()}return g},p=function(c){var d,e,g=a.times(10,function(a){return"color10-"+(1+a)}),h=c.guide.color||{},i=c.color,j=i.scaleDim,k=h.brewer||g;return f.isArray(k)?(e=c.domain(j),d=k):(e=Object.keys(k),d=e.map(function(a){return k[a]})),{get:function(a){return b.scale.ordinal().range(d).domain(e)(a)},dimension:j}},q=function(b){return b.options=b.options||{},b.guide=b.guide||{},b.guide.padding=a.defaults(b.guide.padding||{},{l:0,b:0,r:0,t:0}),b.guide.x=a.defaults(b.guide.x||{},{label:"",padding:0,density:30,cssClass:"x axis",scaleOrient:"bottom",rotate:0,textAnchor:"middle",tickPeriod:null,tickFormat:null,autoScale:!0}),b.guide.x.label=a.isObject(b.guide.x.label)?b.guide.x.label:{text:b.guide.x.label},b.guide.x.label=a.defaults(b.guide.x.label,{padding:32,rotate:0,textAnchor:"middle"}),b.guide.x.tickFormat=b.guide.x.tickFormat||b.guide.x.tickPeriod,b.guide.y=a.defaults(b.guide.y||{},{label:"",padding:0,density:30,cssClass:"y axis",scaleOrient:"left",rotate:0,textAnchor:"end",tickPeriod:null,tickFormat:null,autoScale:!0}),b.guide.y.label=a.isObject(b.guide.y.label)?b.guide.y.label:{text:b.guide.y.label},b.guide.y.label=a.defaults(b.guide.y.label,{padding:32,rotate:-90,textAnchor:"middle"}),b.guide.y.tickFormat=b.guide.y.tickFormat||b.guide.y.tickPeriod,b},r={translate:h,rotate:i,getOrientation:j,fnDrawDimAxis:n,fnDrawGrid:o,generateColor:p,applyNodeDefaults:q};c.utilsDraw=r}),e("spec-engine-factory",["exports","./utils/utils-draw"],function(c,d){var e=this,f=d.utilsDraw,g=function(b,c){return b.guide=b.guide||{},b.guide.padding=b.guide.padding||{l:0,t:0,r:0,b:0},b=a.defaults(b,c),b.guide=a.defaults(b.guide,c.guide),b},h=function(c){var d=a.uniqueId("tauChartHelper"),e=['<svg class="graphical-report__svg">','<g class="graphical-report__cell cell">','<g class="x axis">','<g class="tick"><text><%= xTick %></text></g>',"</g>",'<g class="y axis">','<g class="tick"><text><%= xTick %></text></g>',"</g>","</g>","</svg>"].join(""),f=a.template(e),g=document.createElement("div");document.body.appendChild(g),g.outerHTML='<div id="'+d+'" style="position: absolute; width: 100px; height: 100px; border: 1px solid red"><div>',document.getElementById(d).innerHTML=f({xTick:c,yTick:c});var h=b.select("#"+d).selectAll(".x.axis .tick text");return console.log(h),console.log(h[0][0].clientWidth),h[0][0].clientWidth},i={DEFAULT:function(b){var c=function(b){var d=f.applyNodeDefaults(b),e=a.omit(d,"unit");return(d.unit||[]).forEach(function(a){return c(g(a,e))}),d};return c(b.unit),b},AUTO:function(b,c){var d=function(b,c){var e=f.applyNodeDefaults(b),h=e.unit||[],i=!e.hasOwnProperty("unit"),j=!h.some(function(a){return a.hasOwnProperty("unit")}),k={type:e.type,isLeaf:i,isLeafParent:!i&&j};e=c(k,e);var l=a.omit(e,"unit");return h.forEach(function(a){return d(g(a,l),c)}),e};return d(b.unit,function(b,d){if(b.isLeaf)return d;var e=b.isLeafParent?20:0,f=b.isLeafParent?20:0;d.guide.x.padding=e,d.guide.y.padding=f;var g=c.domain(d.y),i=a.max(g,function(a){return(a||"").toString().length}),j=6,k=15,l=h(i),m=j+k,n=j+l,o=2,p=1,q=15,r=15;d.guide.x.label.padding=d.guide.x.label.text?m+o*q:0,d.guide.y.label.padding=d.guide.y.label.text?n+p*r:0;var s=d.guide.x.label.text?m+(o+1)*q:m,t=d.guide.y.label.text?n+(p+1)*r:n;return d.guide.x.label.text=d.guide.x.label.text.toUpperCase(),d.guide.y.label.text=d.guide.y.label.text.toUpperCase(),d.guide.padding.b=e+s,d.guide.padding.l=f+t,d}),b}},j={get:function(a){return(i[a]||i.DEFAULT).bind(e)}};c.SpecEngineFactory=j}),e("matrix",["exports"],function(b){var c=function(){var b=function(b,c){var d,e=a.toArray(arguments);d=a.isArray(e[0])?e[0]:a.times(b,function(){return a.times(c,function(){return null})}),this.cube=d};return b.prototype={iterate:function(b){var c=this.cube;return a.each(c,function(c,d){a.each(c,function(a,c){b(d,c,a)})}),this},getRC:function(a,b){return this.cube[a][b]},setRC:function(a,b,c){return this.cube[a][b]=c,this},sizeR:function(){return this.cube.length},sizeC:function(){var a=this.cube[0]||[];return a.length}},b}();b.TMatrix=c}),e("layout-engine-factory",["exports","./utils/utils","./utils/utils-draw","./matrix"],function(b,c,d,e){var f=this,g=c.utils,h=d.utilsDraw,i=e.TMatrix,j=function(a,b){var c=b?b:{depth:-1,paddings:[]},d=(a.guide||{}).padding||{l:0,b:0,r:0,t:0};return c.depth+=1,c.paddings.unshift({l:d.l,b:d.b,r:d.r,t:d.t}),a.unit&&a.unit.length&&j(a.unit[0],c),c},k=function(b){var c=function(b){if(!b.$matrix)return b;var d,e=b.options,f=b.guide.padding,g=e.width-(f.l+f.r),h=e.height-(f.t+f.b),i=b.$matrix.sizeR(),j=b.$matrix.sizeC(),k=g/j,l=h/i;return d=b.guide.split?{calcHeight:function(a,b,c,d){return a/d},calcTop:function(a,b,c,d){return(b+1)*(a/d)*c}}:{calcHeight:function(a){return a},calcTop:function(a,b){return b*l}},b.$matrix.iterate(function(b,e,f){var g=f.length;a.each(f,function(a,f){a.options={width:k,left:e*k,height:d.calcHeight(l,b,f,g),top:d.calcTop(l,b,f,g)},c(a)})}),b};return c(b)},l={DEFAULT:k,EXTRACT:function(a,b){var c=function(a,b,d){var e=a,f=e.sizeR(),g=e.sizeC();e.iterate(function(a,e,h){h.forEach(function(c){return d(c,{firstRow:0===a,firstCol:0===e,lastRow:a===f-1,lastCol:e===g-1,depth:b})}),h.filter(function(a){return a.$matrix}).forEach(function(a){a.$matrix=new i(a.$matrix.cube),c(a.$matrix,b-1,d)})})},d=g.clone(a),e=new i([[[d]]]),f=j(d),l=f.paddings.reduce(function(a,b){return a.l+=b.l,a.b+=b.b,a},{l:0,b:0}),m=g.clone(l),n=f.paddings.reverse().map(function(a){return a.l=m.l-a.l,a.b=m.b-a.b,m={l:a.l,b:a.b},a});f.paddings=n.reverse();var o=h.applyNodeDefaults({type:"COORDS.RECT",options:g.clone(a.options),$matrix:new i([[[d]]]),guide:{padding:{l:l.l,b:l.b,r:0,t:0}}});return c(e,f.depth,function(a,b){var c=b.depth;a.guide.x.hide=!b.lastRow,a.guide.y.hide=!b.firstCol,a.guide.x.padding=f.paddings[c].b+a.guide.x.padding,a.guide.y.padding=f.paddings[c].l+a.guide.y.padding;var d=c>1?0:8;return a.guide.padding.l=d,a.guide.padding.b=d,a.guide.padding.r=d,a.guide.padding.t=d,a.guide.showGridLines=c>1?"":"xy",a}),k(o,b)}},m={get:function(a){return(l[a]||l.DEFAULT).bind(f)}};b.LayoutEngineFactory=m}),e("plugins",["exports"],function(a){{var c=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},d=function(){var a=function(a){this._plugins=a};return c(a,null,{_call:{writable:!0,value:function(a,b){for(var c=0;c<this._plugins.length;c++)"function"==typeof this._plugins[c][a]&&this._plugins[c][a].apply(this._plugins[c],b)}},render:{writable:!0,value:function(){this._call("render",arguments)}},click:{writable:!0,value:function(){this._call("click",arguments)}},mouseover:{writable:!0,value:function(){this._call("mouseover",arguments)}},mouseout:{writable:!0,value:function(){this._call("mouseout",arguments)}},mousemove:{writable:!0,value:function(){this._call("mousemove",arguments)}}}),a}(),e=function(a){return function(){this.on("click",function(c){a.click(new g(c),new f(b.select(this)))}).on("mouseover",function(c){a.mouseover(new g(c),new f(b.select(this)))}).on("mouseout",function(c){a.mouseout(new g(c),new f(b.select(this)))}).on("mousemove",function(c){a.mousemove(new g(c),new f(b.select(this)))})}},f=function(a){this.element=a},g=function(a){this.datum=a};!function(){var a=function(a,b){this.svg=a.svg,this.html=a.html,this.mapper=b};return c(a,null,{elements:{writable:!0,value:function(){return this.svg.selectAll(".i-role-datum")}}}),a}()}a.propagateDatumEvents=e,a.Plugins=d}),e("utils/utils-dom",["exports"],function(a){var b={getStyle:function(a,b){return window.getComputedStyle(a,void 0).getPropertyValue(b)},getContainerSize:function(a){var b=2*parseInt(this.getStyle(a,"padding")||0,10),c=a.getBoundingClientRect();return{width:c.width-b,height:c.height-b}}};a.utilsDom=b}),e("const",["exports"],function(a){a.CSS_PREFIX="graphical-report__"}),e("charts/tau.plot",["exports","../dsl-reader","../spec-engine-factory","../layout-engine-factory","../plugins","../utils/utils-dom","../const"],function(c,d,e,f,g,h,i){var j=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},k=d.DSLReader,l=e.SpecEngineFactory,m=f.LayoutEngineFactory,n=g.Plugins,o=g.propagateDatumEvents,p=h.utilsDom,q=i.CSS_PREFIX,r=function(){var c=function(b){var c=this.convertConfig(b);this.config=a.defaults(c,{spec:null,data:[],plugins:[]}),c.spec.dimensions=this._normalizeDimensions(c.spec.dimensions,c.data),this.plugins=this.config.plugins,this.spec=this.config.spec,this.data=this.config.data,this._plugins=new n(this.config.plugins)};return j(c,null,{renderTo:{writable:!0,value:function(c,d){var e=b.select(c),f=e[0][0];if(null===f)throw new Error("Target element not found");var g=a.defaults(d||{},p.getContainerSize(f));if(0!==this.data.length){f.innerHTML="";var h=e.append("svg").attr("class",q+"svg").attr("width",g.width).attr("height",g.height),i=new k(this.spec,this.data,l.get()),j=i.buildGraph(),n=m.get(this.config.layoutEngine||"EXTRACT"),r=i.calcLayout(j,n,g),s=i.renderGraph(r,h);s.selectAll(".i-role-datum").call(o(this._plugins)),this._plugins.render(s)}}},_autoDetectDimensions:{writable:!0,value:function(b){var c=function(b){var c;return c=a.isObject(b)?"order":a.isNumber(b)?"measure":"category"};return a.reduce(b,function(b,d){return a.each(d,function(a,d){var e=c(a);b[d]=b[d]||{type:e},b[d].type=b[d].type===e?e:"category"}),b},{})}},_autoAssignScales:{writable:!0,value:function(b){var c={category:"ordinal",order:"ordinal",measure:"linear"};return a.each(b,function(a){var b=a.type.toLowerCase();a.scale=a.scale||c[b]}),b}},_normalizeDimensions:{writable:!0,value:function(a,b){var c=a?a:this._autoDetectDimensions(b);return this._autoAssignScales(c)}},convertConfig:{writable:!0,value:function(a){return a}}}),c}();c.Plot=r}),e("charts/tau.chart",["exports","./tau.plot","../utils/utils"],function(b,c,d){function e(a){return a?a:null}function f(a){return m.isArray(a)?a:[a]}function g(a,b){return{type:a,x:b.x,y:b.y,color:b.color,guide:{color:b.colorGuide},flip:b.flip,size:b.size}}function h(a,b){return b.reduce(function(b,c,d){return"measure"===a[c].type&&(b.countMeasureAxis++,b.indexMeasureAxis.push(d)),"measure"!==a[c].type&&1===b.countMeasureAxis?b.status=n.WARNING:b.countMeasureAxis>1&&(b.status=n.FAIL),b},{status:n.SUCCESS,countMeasureAxis:0,indexMeasureAxis:[]})}function i(b,c){var d=f(c.x),i=f(c.y),j=h(c.dimensions,d),k=h(c.dimensions,i);d=o[j.status](d,j),i=o[k.status](i,k);for(var l=f(c.guide),m=Math.max(d.length,i.length),n={type:"COORDS.RECT",unit:[]},p=c.guide&&c.guide.color||{},q=m;q>0;q--){var r=d.pop(),s=i.pop(),t=l.pop()||{};q===m?(n.x=r,n.y=s,n.unit.push(g(b,{x:e(r),y:e(s),color:c.color,size:c.size,flip:c.flip,colorGuide:p})),n.guide=a.defaults(t,{padding:{l:45,b:45,r:24,t:24},showGridLines:"xy",x:{label:r},y:{label:s}})):n={type:"COORDS.RECT",x:e(r),y:e(s),unit:[n],guide:a.defaults(t,{padding:{l:45,b:45,r:0,t:0},x:{label:r},y:{label:s}})}}return c.spec={dimensions:c.dimensions,unit:n},c}var j=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},k=function(a,b){a.prototype=Object.create(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),a.__proto__=b},l=c.Plot,m=d.utils,n={SUCCESS:"SUCCESS",WARNING:"WARNING",FAIL:"FAIL"},o=function(b){return b[n.SUCCESS]=function(a){return a},b[n.FAIL]=function(){throw new Error("This configuration is not supported, See http://api.taucharts.com/basic/facet.html#easy-approach-for-creating-facet-chart")},b[n.WARNING]=function(b,c){var d=b[c.indexMeasureAxis[0]],e=a.without(b,d);return e.push(d),e},b}({}),p={scatterplot:function(a){return i("ELEMENT.POINT",a)},line:function(a){return i("ELEMENT.LINE",a)},bar:function(a){return a.flip=!1,i("ELEMENT.INTERVAL",a)},horizontalBar:function(a){return a.flip=!0,i("ELEMENT.INTERVAL",a)}},q=function(a){var b=function(){a.apply(this,arguments)};return k(b,a),j(b,null,{convertConfig:{writable:!0,value:function(a){return a.dimensions=this._normalizeDimensions(a.dimensions,a.data),p[a.type](a)}}}),b}(l);b.Chart=q}),e("elements/coords",["exports","../utils/utils-draw","../const","../utils/utils","../matrix"],function(b,c,d,e,f){var g=c.utilsDraw,h=d.CSS_PREFIX,i=e.utils,j=f.TMatrix,k={CROSS:function(b,c,d){var e=b.domain(c),f=b.domain(d).reverse();return a(f).map(function(b){return a(e).map(function(a){var e={};return c&&(e[c]=a),d&&(e[d]=b),e})})}},l=function(a){return k[a]||function(){return[[{}]]}},m=function(b,c,d){var e=a.defaults(i.clone(b),a.pick.apply(a,[c].concat(d)));return e.guide=a.extend(i.clone(c.guide||{}),e.guide||{}),e},n={walk:function(b,c){var d=a.defaults(b,{$where:{}}),e=a.any(d.unit,function(a){return 0===a.type.indexOf("COORDS.")}),f=l(e?"CROSS":""),g=new j(f(d,d.x,d.y)),h=new j(g.sizeR(),g.sizeC());return g.iterate(function(b,c,e){var f=a.extend({},d.$where,e),g=a(d.unit).map(function(b){return a.extend(m(b,d,["x","y"]),{$where:f})});h.setRC(b,c,g)}),d.$matrix=h,h.iterate(function(b,d,e){a.each(e,function(a){return c(a)})}),d},draw:function(b,c){var d=b.options,e=b.guide.padding;b.x.guide=b.guide.x,b.y.guide=b.guide.y;var f=d.left+e.l,i=d.top+e.t,j=d.width-(e.l+e.r),k=d.height-(e.t+e.b),l={map:b.x.guide.tickLabel,min:b.x.guide.tickMin,max:b.x.guide.tickMax,period:b.x.guide.tickPeriod,autoScale:b.x.guide.autoScale};b.x.scaleObj=b.x.scaleDim&&b.scaleTo(b.x.scaleDim,[0,j],l);var m={map:b.y.guide.tickLabel,min:b.y.guide.tickMin,max:b.y.guide.tickMax,period:b.y.guide.tickPeriod,autoScale:b.y.guide.autoScale};b.y.scaleObj=b.y.scaleDim&&b.scaleTo(b.y.scaleDim,[k,0],m),b.x.guide.size=j,b.y.guide.size=k;var n=[0,k+b.guide.x.padding],o=[0-b.guide.y.padding,0],p=d.container.append("g").attr("class",h+"cell cell").attr("transform",g.translate(f,i));b.x.guide.hide||g.fnDrawDimAxis.call(p,b.x,n,j),b.y.guide.hide||g.fnDrawDimAxis.call(p,b.y,o,k);var q=g.fnDrawGrid.call(p,b,k,j);b.$matrix.iterate(function(b,d,e){e.forEach(function(b){b.options=a.extend({container:q},b.options),c(b)})})}};b.coords=n}),e("utils/css-class-map",["exports","../const"],function(a,b){function c(a){return g[a-1]||g[5]}function d(a){var b=0;return a>=160&&320>a?b=1:a>=320&&480>a?b=2:a>=480&&640>a?b=3:a>=640&&(b=4),h[b]}var e=b.CSS_PREFIX,f=[1,2,3,4,5],g=f.map(function(a){return e+"line-opacity-"+a}),h=f.map(function(a){return e+"line-width-"+a});a.getLineClassesByWidth=d,a.getLineClassesByCount=c}),e("elements/line",["exports","../utils/utils-draw","../const","../utils/css-class-map"],function(a,c,d,e){var f=c.utilsDraw,g=d.CSS_PREFIX,h=e.getLineClassesByWidth,i=e.getLineClassesByCount,j=function(a){var c=a.options,d=c.xScale,e=c.yScale,j=f.generateColor(a),k=b.nest().key(function(a){return a[j.dimension]}).entries(a.partition()),l=h(c.width),m=i(k.length),n=function(){this.attr("class",function(a){return[g+"line","line",j.get(a.key),l,m].join(" ")});var a=this.selectAll("path").data(function(a){return[a.values]});a.call(q),a.enter().append("path").call(q),a.exit().remove()},o=function(b){var f=b.reduce(function(a,b){var c=b.values;return 1===c.length&&a.push(c[0]),a},[]),h=function(){return this.attr("r",1.5).attr("class",function(a){return g+"dot-line dot-line "+g+"dot i-role-datum "+j.get(a[j.dimension])}).attr("cx",function(b){return d(b[a.x.scaleDim])}).attr("cy",function(b){return e(b[a.y.scaleDim])})},i=c.container.selectAll(".dot-line").data(f);i.call(h),i.exit().remove(),i.enter().append("circle").call(h)},p=b.svg.line().x(function(b){return d(b[a.x.scaleDim])}).y(function(b){return e(b[a.y.scaleDim])}),q=function(){this.attr("d",p)};o(k);var r=c.container.selectAll(".line").data(k);r.call(n),r.enter().append("g").call(n),r.exit().remove()};a.line=j}),e("elements/size",["exports"],function(c){var d=function(c,d){c=a.filter(c,a.isFinite);var e=[Math.min.apply(null,c),Math.max.apply(null,c)],f=0===e[0]?e[1]:Math.max(1,e[1]/e[0]),g=[Math.max(1,d/(Math.log(f)+1)),d];return b.scale.linear().range(g).domain(e)};c.sizeScale=d}),e("elements/point",["exports","../utils/utils-draw","../const","./size"],function(b,c,d,e){var f=c.utilsDraw,g=d.CSS_PREFIX,h=e.sizeScale,i=function(b){var c=b.options,d=c.xScale,e=c.yScale,i=f.generateColor(b),j=a.max([c.width,c.height]),k=h(b.domain(b.size.scaleDim),j/100),l=function(){return this.attr("r",function(c){var d=k(c[b.size.scaleDim]);return a.isFinite(d)?d:j/100}).attr("class",function(a){return g+"dot dot i-role-datum "+i.get(a[i.dimension])}).attr("cx",function(a){return d(a[b.x.scaleDim])}).attr("cy",function(a){return e(a[b.y.scaleDim])})},m=c.container.selectAll(".dot").data(b.partition());m.call(l),m.exit().remove(),m.enter().append("circle").call(l)};b.point=i}),e("elements/interval",["exports","../utils/utils-draw","../const"],function(a,c,d){var e=c.utilsDraw,f=d.CSS_PREFIX,g="i-role-bar-group",h=function(a){return"measure"===a.dimType},i=function(a){var b,c,d;return h(a.dim)?(b=1,c=1,d=0):(b=a.size/a.domain(a.dim.scaleDim).length,c=b/(a.categories.length+1),d=c),{tickWidth:b,intervalWidth:c,offsetCategory:d}},j=function(a){var c,d,j,k,l,m=0,n=a.options,o=e.generateColor(a),p=a.partition(),q=b.nest().key(function(a){return a[o.dimension]}).entries(p),r=n.xScale,s=n.yScale;if(a.flip){var t=i({domain:a.domain,dim:a.y,categories:q,size:n.height}),u=t.tickWidth,v=t.intervalWidth,w=t.offsetCategory;c=h(a.x)?function(b){return r(Math.min(m,b[a.x.scaleDim]))}:0,d=function(b){return s(b[a.y.scaleDim])-u/2},j=h(a.x)?function(b){return Math.abs(r(b[a.x.scaleDim])-r(m))}:function(b){return r(b[a.x.scaleDim])},k=function(){return v},l=function(a,b){return e.translate(0,b*w+w/2)}}else{var x=i({domain:a.domain,dim:a.x,categories:q,size:n.width}),u=x.tickWidth,v=x.intervalWidth,w=x.offsetCategory;c=function(b){return r(b[a.x.scaleDim])-u/2},d=h(a.y)?function(b){return s(Math.max(m,b[a.y.scaleDim]))}:function(b){return s(b[a.y.scaleDim])},j=function(){return v},k=h(a.y)?function(b){return Math.abs(s(b[a.y.scaleDim])-s(m))}:function(b){return n.height-s(b[a.y.scaleDim])},l=function(a,b){return e.translate(b*w+w/2,0)}}var y=function(){return this.attr("class",function(a){return"i-role-datum bar "+f+"bar "+o.get(a[o.dimension])}).attr("x",c).attr("y",d).attr("width",j).attr("height",k)},z=function(){this.attr("class",g).attr("transform",l);var a=this.selectAll("bar").data(function(a){return a.values});a.call(y),a.enter().append("rect").call(y),a.exit().remove()},A=n.container.selectAll("."+g).data(q);A.call(z),A.enter().append("g").call(z),A.exit().remove()};a.interval=j}),e("elements/coords-parallel",["exports","../utils/utils-draw","../const","../utils/utils","../matrix"],function(c,d,e,f,g){var h=d.utilsDraw,i=(e.CSS_PREFIX,f.utils),j=g.TMatrix,k=function(b,c,d){var e=a.defaults(i.clone(b),a.pick.apply(a,[c].concat(d)));return e.guide=a.extend(i.clone(c.guide||{}),e.guide||{}),e},l={walk:function(b,c){var d=a.defaults(b,{$where:{}}),e=new j(1,1),f=new j(1,1);return e.iterate(function(b,c){var e=a.extend({},d.$where),g=a(d.unit).map(function(b){return a.extend(k(b,d,["x"]),{$where:e})});f.setRC(b,c,g)}),d.$matrix=f,f.iterate(function(b,d,e){a.each(e,function(a){return c(a)})}),d},draw:function(c,d){var e=c.options,f=c.guide.padding,g=e.left+f.l,i=e.top+f.t,j=e.width-(f.l+f.r),k=e.height-(f.t+f.b),l=c.x.map(function(a){return c.scaleTo(a,[k,0],{})}),m=e.container.append("g").attr("class","graphical-report__cell cell").attr("transform",h.translate(g,i)),n=function(a,b){return"translate("+a+","+b+")"},o=function(a){return"rotate("+a+")"},p=function(a,c){var d=this,e=b.svg.axis().scale(a).orient("left"),f=d.append("g").attr("class","y axis").attr("transform",n.apply(null,c)).call(e);f.selectAll(".tick text").attr("transform",o(0)).style("text-anchor","end")},q=j/(c.x.length-1);l.forEach(function(a,b){p.call(m,a,[b*q,0])});var r=m.append("g").attr("class","grid").attr("transform",n(0,0));c.$matrix.iterate(function(b,c,e){e.forEach(function(b){b.options=a.extend({container:r},b.options),d(b)})})}};c.CoordsParallel=l}),e("elements/coords-parallel-line",["exports","../utils/utils-draw","../const"],function(a,c,d){var e=c.utilsDraw,f=(d.CSS_PREFIX,{draw:function(a){a.color=a.dimension(a.color,a);var c=a.options,d=a.x.reduce(function(b,d){return b[d]=a.scaleTo(d,[c.height,0],{}),b},{}),f=e.generateColor(a),g=b.nest().key(function(a){return a[f.dimension]}).entries(a.partition()).map(function(b){var c=b.values[0],d=[];return a.x.forEach(function(a){d.push({key:a,val:c[a]})}),d}),h=function(){this.attr("class",function(){return"graphical-report__line line color10-9"
(function(e,t){if("function"==typeof define&&define.amd)define(["backbone","underscore"],function(i,n){return e.Marionette=e.Mn=t(e,i,n)});else if("undefined"!=typeof exports){var i=require("backbone"),n=require("underscore");module.exports=t(e,i,n)}else e.Marionette=e.Mn=t(e,e.Backbone,e._)})(this,function(e,t,i){"use strict";(function(e,t){var i=e.ChildViewContainer;return e.ChildViewContainer=function(e,t){var i=function(e){this._views={},this._indexByModel={},this._indexByCustom={},this._updateLength(),t.each(e,this.add,this)};t.extend(i.prototype,{add:function(e,t){var i=e.cid;return this._views[i]=e,e.model&&(this._indexByModel[e.model.cid]=i),t&&(this._indexByCustom[t]=i),this._updateLength(),this},findByModel:function(e){return this.findByModelCid(e.cid)},findByModelCid:function(e){var t=this._indexByModel[e];return this.findByCid(t)},findByCustom:function(e){var t=this._indexByCustom[e];return this.findByCid(t)},findByIndex:function(e){return t.values(this._views)[e]},findByCid:function(e){return this._views[e]},remove:function(e){var i=e.cid;return e.model&&delete this._indexByModel[e.model.cid],t.any(this._indexByCustom,function(e,t){return e===i?(delete this._indexByCustom[t],!0):void 0},this),delete this._views[i],this._updateLength(),this},call:function(e){this.apply(e,t.tail(arguments))},apply:function(e,i){t.each(this._views,function(n){t.isFunction(n[e])&&n[e].apply(n,i||[])})},_updateLength:function(){this.length=t.size(this._views)}});var n=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck","reduce"];return t.each(n,function(e){i.prototype[e]=function(){var i=t.values(this._views),n=[i].concat(t.toArray(arguments));return t[e].apply(t,n)}}),i}(e,t),e.ChildViewContainer.VERSION="0.1.6",e.ChildViewContainer.noConflict=function(){return e.ChildViewContainer=i,this},e.ChildViewContainer})(t,i),function(e,t){var i=e.Wreqr,n=e.Wreqr={};return e.Wreqr.VERSION="1.3.1",e.Wreqr.noConflict=function(){return e.Wreqr=i,this},n.Handlers=function(e,t){var i=function(e){this.options=e,this._wreqrHandlers={},t.isFunction(this.initialize)&&this.initialize(e)};return i.extend=e.Model.extend,t.extend(i.prototype,e.Events,{setHandlers:function(e){t.each(e,function(e,i){var n=null;t.isObject(e)&&!t.isFunction(e)&&(n=e.context,e=e.callback),this.setHandler(i,e,n)},this)},setHandler:function(e,t,i){var n={callback:t,context:i};this._wreqrHandlers[e]=n,this.trigger("handler:add",e,t,i)},hasHandler:function(e){return!!this._wreqrHandlers[e]},getHandler:function(e){var t=this._wreqrHandlers[e];if(t)return function(){var e=Array.prototype.slice.apply(arguments);return t.callback.apply(t.context,e)}},removeHandler:function(e){delete this._wreqrHandlers[e]},removeAllHandlers:function(){this._wreqrHandlers={}}}),i}(e,t),n.CommandStorage=function(){var i=function(e){this.options=e,this._commands={},t.isFunction(this.initialize)&&this.initialize(e)};return t.extend(i.prototype,e.Events,{getCommands:function(e){var t=this._commands[e];return t||(t={command:e,instances:[]},this._commands[e]=t),t},addCommand:function(e,t){var i=this.getCommands(e);i.instances.push(t)},clearCommands:function(e){var t=this.getCommands(e);t.instances=[]}}),i}(),n.Commands=function(e){return e.Handlers.extend({storageType:e.CommandStorage,constructor:function(t){this.options=t||{},this._initializeStorage(this.options),this.on("handler:add",this._executeCommands,this);var i=Array.prototype.slice.call(arguments);e.Handlers.prototype.constructor.apply(this,i)},execute:function(e,t){e=arguments[0],t=Array.prototype.slice.call(arguments,1),this.hasHandler(e)?this.getHandler(e).apply(this,t):this.storage.addCommand(e,t)},_executeCommands:function(e,i,n){var r=this.storage.getCommands(e);t.each(r.instances,function(e){i.apply(n,e)}),this.storage.clearCommands(e)},_initializeStorage:function(e){var i,n=e.storageType||this.storageType;i=t.isFunction(n)?new n:n,this.storage=i}})}(n),n.RequestResponse=function(e){return e.Handlers.extend({request:function(){var e=arguments[0],t=Array.prototype.slice.call(arguments,1);return this.hasHandler(e)?this.getHandler(e).apply(this,t):void 0}})}(n),n.EventAggregator=function(e,t){var i=function(){};return i.extend=e.Model.extend,t.extend(i.prototype,e.Events),i}(e,t),n.Channel=function(){var i=function(t){this.vent=new e.Wreqr.EventAggregator,this.reqres=new e.Wreqr.RequestResponse,this.commands=new e.Wreqr.Commands,this.channelName=t};return t.extend(i.prototype,{reset:function(){return this.vent.off(),this.vent.stopListening(),this.reqres.removeAllHandlers(),this.commands.removeAllHandlers(),this},connectEvents:function(e,t){return this._connect("vent",e,t),this},connectCommands:function(e,t){return this._connect("commands",e,t),this},connectRequests:function(e,t){return this._connect("reqres",e,t),this},_connect:function(e,i,n){if(i){n=n||this;var r="vent"===e?"on":"setHandler";t.each(i,function(i,s){this[e][r](s,t.bind(i,n))},this)}}}),i}(n),n.radio=function(e){var i=function(){this._channels={},this.vent={},this.commands={},this.reqres={},this._proxyMethods()};t.extend(i.prototype,{channel:function(e){if(!e)throw Error("Channel must receive a name");return this._getChannel(e)},_getChannel:function(t){var i=this._channels[t];return i||(i=new e.Channel(t),this._channels[t]=i),i},_proxyMethods:function(){t.each(["vent","commands","reqres"],function(e){t.each(n[e],function(t){this[e][t]=r(this,e,t)},this)},this)}});var n={vent:["on","off","trigger","once","stopListening","listenTo","listenToOnce"],commands:["execute","setHandler","setHandlers","removeHandler","removeAllHandlers"],reqres:["request","setHandler","setHandlers","removeHandler","removeAllHandlers"]},r=function(e,t,i){return function(n){var r=e._getChannel(n)[t],s=Array.prototype.slice.call(arguments,1);return r[i].apply(r,s)}};return new i}(n),e.Wreqr}(t,i);var n=e.Marionette,r=e.Mn,s=t.Marionette={};s.VERSION="2.4.1",s.noConflict=function(){return e.Marionette=n,e.Mn=r,this},t.Marionette=s,s.Deferred=t.$.Deferred,s.extend=t.Model.extend,s.isNodeAttached=function(e){return t.$.contains(document.documentElement,e)},s.mergeOptions=function(e,t){e&&i.extend(this,i.pick(e,t))},s.getOption=function(e,t){return e&&t?e.options&&void 0!==e.options[t]?e.options[t]:e[t]:void 0},s.proxyGetOption=function(e){return s.getOption(this,e)},s._getValue=function(e,t,n){return i.isFunction(e)&&(e=n?e.apply(t,n):e.call(t)),e},s.normalizeMethods=function(e){return i.reduce(e,function(e,t,n){return i.isFunction(t)||(t=this[t]),t&&(e[n]=t),e},{},this)},s.normalizeUIString=function(e,t){return e.replace(/@ui\.[a-zA-Z_$0-9]*/g,function(e){return t[e.slice(4)]})},s.normalizeUIKeys=function(e,t){return i.reduce(e,function(e,i,n){var r=s.normalizeUIString(n,t);return e[r]=i,e},{})},s.normalizeUIValues=function(e,t,n){return i.each(e,function(r,o){i.isString(r)?e[o]=s.normalizeUIString(r,t):i.isObject(r)&&i.isArray(n)&&(i.extend(r,s.normalizeUIValues(i.pick(r,n),t)),i.each(n,function(e){var n=r[e];i.isString(n)&&(r[e]=s.normalizeUIString(n,t))}))}),e},s.actAsCollection=function(e,t){var n=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck"];i.each(n,function(n){e[n]=function(){var e=i.values(i.result(this,t)),r=[e].concat(i.toArray(arguments));return i[n].apply(i,r)}})};var o=s.deprecate=function(e,t){i.isObject(e)&&(e=e.prev+" is going to be removed in the future. "+"Please use "+e.next+" instead."+(e.url?" See: "+e.url:"")),void 0!==t&&t||o._cache[e]||(o._warn("Deprecation warning: "+e),o._cache[e]=!0)};o._warn="undefined"!=typeof console&&(console.warn||console.log)||function(){},o._cache={},s._triggerMethod=function(){function e(e,t,i){return i.toUpperCase()}var t=/(^|:)(\w)/gi;return function(n,r,s){var o=3>arguments.length;o&&(s=r,r=s[0]);var h,a="on"+r.replace(t,e),l=n[a];return i.isFunction(l)&&(h=l.apply(n,o?i.rest(s):s)),i.isFunction(n.trigger)&&(o+s.length>1?n.trigger.apply(n,o?s:[r].concat(i.drop(s,0))):n.trigger(r)),h}}(),s.triggerMethod=function(){return s._triggerMethod(this,arguments)},s.triggerMethodOn=function(e){var t=i.isFunction(e.triggerMethod)?e.triggerMethod:s.triggerMethod;return t.apply(e,i.rest(arguments))},s.MonitorDOMRefresh=function(e){function t(){e._isShown=!0,r()}function n(){e._isRendered=!0,r()}function r(){e._isShown&&e._isRendered&&s.isNodeAttached(e.el)&&i.isFunction(e.triggerMethod)&&e.triggerMethod("dom:refresh")}e.on({show:t,render:n})},function(e){function t(t,n,r,s){var o=s.split(/\s+/);i.each(o,function(i){var s=t[i];if(!s)throw new e.Error('Method "'+i+'" was configured as an event handler, but does not exist.');t.listenTo(n,r,s)})}function n(e,t,i,n){e.listenTo(t,i,n)}function r(e,t,n,r){var s=r.split(/\s+/);i.each(s,function(i){var r=e[i];e.stopListening(t,n,r)})}function s(e,t,i,n){e.stopListening(t,i,n)}function o(t,n,r,s,o){if(n&&r){if(!i.isObject(r))throw new e.Error({message:"Bindings must be an object or function.",url:"marionette.functions.html#marionettebindentityevents"});r=e._getValue(r,t),i.each(r,function(e,r){i.isFunction(e)?s(t,n,r,e):o(t,n,r,e)})}}e.bindEntityEvents=function(e,i,r){o(e,i,r,n,t)},e.unbindEntityEvents=function(e,t,i){o(e,t,i,s,r)},e.proxyBindEntityEvents=function(t,i){return e.bindEntityEvents(this,t,i)},e.proxyUnbindEntityEvents=function(t,i){return e.unbindEntityEvents(this,t,i)}}(s);var h=["description","fileName","lineNumber","name","message","number"];return s.Error=s.extend.call(Error,{urlRoot:"http://marionettejs.com/docs/v"+s.VERSION+"/",constructor:function(e,t){i.isObject(e)?(t=e,e=t.message):t||(t={});var n=Error.call(this,e);i.extend(this,i.pick(n,h),i.pick(t,h)),this.captureStackTrace(),t.url&&(this.url=this.urlRoot+t.url)},captureStackTrace:function(){Error.captureStackTrace&&Error.captureStackTrace(this,s.Error)},toString:function(){return this.name+": "+this.message+(this.url?" See: "+this.url:"")}}),s.Error.extend=s.extend,s.Callbacks=function(){this._deferred=s.Deferred(),this._callbacks=[]},i.extend(s.Callbacks.prototype,{add:function(e,t){var n=i.result(this._deferred,"promise");this._callbacks.push({cb:e,ctx:t}),n.then(function(i){t&&(i.context=t),e.call(i.context,i.options)})},run:function(e,t){this._deferred.resolve({options:e,context:t})},reset:function(){var e=this._callbacks;this._deferred=s.Deferred(),this._callbacks=[],i.each(e,function(e){this.add(e.cb,e.ctx)},this)}}),s.Controller=function(e){this.options=e||{},i.isFunction(this.initialize)&&this.initialize(this.options)},s.Controller.extend=s.extend,i.extend(s.Controller.prototype,t.Events,{destroy:function(){return s._triggerMethod(this,"before:destroy",arguments),s._triggerMethod(this,"destroy",arguments),this.stopListening(),this.off(),this},triggerMethod:s.triggerMethod,mergeOptions:s.mergeOptions,getOption:s.proxyGetOption}),s.Object=function(e){this.options=i.extend({},i.result(this,"options"),e),this.initialize.apply(this,arguments)},s.Object.extend=s.extend,i.extend(s.Object.prototype,t.Events,{initialize:function(){},destroy:function(){return this.triggerMethod("before:destroy"),this.triggerMethod("destroy"),this.stopListening(),this},triggerMethod:s.triggerMethod,mergeOptions:s.mergeOptions,getOption:s.proxyGetOption,bindEntityEvents:s.proxyBindEntityEvents,unbindEntityEvents:s.proxyUnbindEntityEvents}),s.Region=s.Object.extend({constructor:function(e){if(this.options=e||{},this.el=this.getOption("el"),this.el=this.el instanceof t.$?this.el[0]:this.el,!this.el)throw new s.Error({name:"NoElError",message:'An "el" must be specified for a region.'});this.$el=this.getEl(this.el),s.Object.call(this,e)},show:function(e,t){if(this._ensureElement()){this._ensureViewIsIntact(e);var i=t||{},n=e!==this.currentView,r=!!i.preventDestroy,o=!!i.forceShow,h=!!this.currentView,a=n&&!r,l=n||o;if(h&&this.triggerMethod("before:swapOut",this.currentView,this,t),this.currentView&&delete this.currentView._parent,a?this.empty():h&&l&&this.currentView.off("destroy",this.empty,this),l){e.once("destroy",this.empty,this),e.render(),e._parent=this,h&&this.triggerMethod("before:swap",e,this,t),this.triggerMethod("before:show",e,this,t),s.triggerMethodOn(e,"before:show",e,this,t),h&&this.triggerMethod("swapOut",this.currentView,this,t);var d=s.isNodeAttached(this.el),u=[],c=i.triggerBeforeAttach||this.triggerBeforeAttach,g=i.triggerAttach||this.triggerAttach;return d&&c&&(u=this._displayedViews(e),this._triggerAttach(u,"before:")),this.attachHtml(e),this.currentView=e,d&&g&&(u=this._displayedViews(e),this._triggerAttach(u)),h&&this.triggerMethod("swap",e,this,t),this.triggerMethod("show",e,this,t),s.triggerMethodOn(e,"show",e,this,t),this}return this}},triggerBeforeAttach:!0,triggerAttach:!0,_triggerAttach:function(e,t){var n=(t||"")+"attach";i.each(e,function(e){s.triggerMethodOn(e,n,e,this)},this)},_displayedViews:function(e){return i.union([e],i.result(e,"_getNestedViews")||[])},_ensureElement:function(){if(i.isObject(this.el)||(this.$el=this.getEl(this.el),this.el=this.$el[0]),!this.$el||0===this.$el.length){if(this.getOption("allowMissingEl"))return!1;throw new s.Error('An "el" '+this.$el.selector+" must exist in DOM")}return!0},_ensureViewIsIntact:function(e){if(!e)throw new s.Error({name:"ViewNotValid",message:"The view passed is undefined and therefore invalid. You must pass a view instance to show."});if(e.isDestroyed)throw new s.Error({name:"ViewDestroyedError",message:'View (cid: "'+e.cid+'") has already been destroyed and cannot be used.'})},getEl:function(e){return t.$(e,s._getValue(this.options.parentEl,this))},attachHtml:function(e){this.$el.contents().detach(),this.el.appendChild(e.el)},empty:function(e){var t=this.currentView,i=s._getValue(e,"preventDestroy",this);return t?(t.off("destroy",this.empty,this),this.triggerMethod("before:empty",t),i||this._destroyView(),this.triggerMethod("empty",t),delete this.currentView,i&&this.$el.contents().detach(),this):void 0},_destroyView:function(){var e=this.currentView;e.destroy&&!e.isDestroyed?e.destroy():e.remove&&(e.remove(),e.isDestroyed=!0)},attachView:function(e){return this.currentView=e,this},hasView:function(){return!!this.currentView},reset:function(){return this.empty(),this.$el&&(this.el=this.$el.selector),delete this.$el,this}},{buildRegion:function(e,t){if(i.isString(e))return this._buildRegionFromSelector(e,t);if(e.selector||e.el||e.regionClass)return this._buildRegionFromObject(e,t);if(i.isFunction(e))return this._buildRegionFromRegionClass(e);throw new s.Error({message:"Improper region configuration type.",url:"marionette.region.html#region-configuration-types"})},_buildRegionFromSelector:function(e,t){return new t({el:e})},_buildRegionFromObject:function(e,t){var n=e.regionClass||t,r=i.omit(e,"selector","regionClass");return e.selector&&!r.el&&(r.el=e.selector),new n(r)},_buildRegionFromRegionClass:function(e){return new e}}),s.RegionManager=s.Controller.extend({constructor:function(e){this._regions={},this.length=0,s.Controller.call(this,e),this.addRegions(this.getOption("regions"))},addRegions:function(e,t){return e=s._getValue(e,this,arguments),i.reduce(e,function(e,n,r){return i.isString(n)&&(n={selector:n}),n.selector&&(n=i.defaults({},n,t)),e[r]=this.addRegion(r,n),e},{},this)},addRegion:function(e,t){var i;return i=t instanceof s.Region?t:s.Region.buildRegion(t,s.Region),this.triggerMethod("before:add:region",e,i),i._parent=this,this._store(e,i),this.triggerMethod("add:region",e,i),i},get:function(e){return this._regions[e]},getRegions:function(){return i.clone(this._regions)},removeRegion:function(e){var t=this._regions[e];return this._remove(e,t),t},removeRegions:function(){var e=this.getRegions();return i.each(this._regions,function(e,t){this._remove(t,e)},this),e},emptyRegions:function(){var e=this.getRegions();return i.invoke(e,"empty"),e},destroy:function(){return this.removeRegions(),s.Controller.prototype.destroy.apply(this,arguments)},_store:function(e,t){this._regions[e]||this.length++,this._regions[e]=t},_remove:function(e,t){this.triggerMethod("before:remove:region",e,t),t.empty(),t.stopListening(),delete t._parent,delete this._regions[e],this.length--,this.triggerMethod("remove:region",e,t)}}),s.actAsCollection(s.RegionManager.prototype,"_regions"),s.TemplateCache=function(e){this.templateId=e},i.extend(s.TemplateCache,{templateCaches:{},get:function(e,t){var i=this.templateCaches[e];return i||(i=new s.TemplateCache(e),this.templateCaches[e]=i),i.load(t)},clear:function(){var e,t=i.toArray(arguments),n=t.length;if(n>0)for(e=0;n>e;e++)delete this.templateCaches[t[e]];else this.templateCaches={}}}),i.extend(s.TemplateCache.prototype,{load:function(e){if(this.compiledTemplate)return this.compiledTemplate;var t=this.loadTemplate(this.templateId,e);return this.compiledTemplate=this.compileTemplate(t,e),this.compiledTemplate},loadTemplate:function(e){var i=t.$(e).html();if(!i||0===i.length)throw new s.Error({name:"NoTemplateError",message:'Could not find template: "'+e+'"'});return i},compileTemplate:function(e,t){return i.template(e,t)}}),s.Renderer={render:function(e,t){if(!e)throw new s.Error({name:"TemplateNotFoundError",message:"Cannot render the template since its false, null or undefined."});var n=i.isFunction(e)?e:s.TemplateCache.get(e);return n(t)}},s.View=t.View.extend({isDestroyed:!1,constructor:function(e){i.bindAll(this,"render"),e=s._getValue(e,this),this.options=i.extend({},i.result(this,"options"),e),this._behaviors=s.Behaviors(this),t.View.call(this,this.options),s.MonitorDOMRefresh(this)},getTemplate:function(){return this.getOption("template")},serializeModel:function(e){return e.toJSON.apply(e,i.rest(arguments))},mixinTemplateHelpers:function(e){e=e||{};var t=this.getOption("templateHelpers");return t=s._getValue(t,this),i.extend(e,t)},normalizeUIKeys:function(e){var t=i.result(this,"_uiBindings");return s.normalizeUIKeys(e,t||i.result(this,"ui"))},normalizeUIValues:function(e,t){var n=i.result(this,"ui"),r=i.result(this,"_uiBindings");return s.normalizeUIValues(e,r||n,t)},configureTriggers:function(){if(this.triggers){var e=this.normalizeUIKeys(i.result(this,"triggers"));return i.reduce(e,function(e,t,i){return e[i]=this._buildViewTrigger(t),e},{},this)}},delegateEvents:function(e){return this._delegateDOMEvents(e),this.bindEntityEvents(this.model,this.getOption("modelEvents")),this.bindEntityEvents(this.collection,this.getOption("collectionEvents")),i.each(this._behaviors,function(e){e.bindEntityEvents(this.model,e.getOption("modelEvents")),e.bindEntityEvents(this.collection,e.getOption("collectionEvents"))},this),this},_delegateDOMEvents:function(e){var n=s._getValue(e||this.events,this);n=this.normalizeUIKeys(n),i.isUndefined(e)&&(this.events=n);var r={},o=i.result(this,"behaviorEvents")||{},h=this.configureTriggers(),a=i.result(this,"behaviorTriggers")||{};i.extend(r,o,n,h,a),t.View.prototype.delegateEvents.call(this,r)},undelegateEvents:function(){return t.View.prototype.undelegateEvents.apply(this,arguments),this.unbindEntityEvents(this.model,this.getOption("modelEvents")),this.unbindEntityEvents(this.collection,this.getOption("collectionEvents")),i.each(this._behaviors,function(e){e.unbindEntityEvents(this.model,e.getOption("modelEvents")),e.unbindEntityEvents(this.collection,e.getOption("collectionEvents"))},this),this},_ensureViewIsIntact:function(){if(this.isDestroyed)throw new s.Error({name:"ViewDestroyedError",message:'View (cid: "'+this.cid+'") has already been destroyed and cannot be used.'})},destroy:function(){if(this.isDestroyed)return this;var e=i.toArray(arguments);return this.triggerMethod.apply(this,["before:destroy"].concat(e)),this.isDestroyed=!0,this.triggerMethod.apply(this,["destroy"].concat(e)),this.unbindUIElements(),this.isRendered=!1,this.remove(),i.invoke(this._behaviors,"destroy",e),this},bindUIElements:function(){this._bindUIElements(),i.invoke(this._behaviors,this._bindUIElements)},_bindUIElements:function(){if(this.ui){this._uiBindings||(this._uiBindings=this.ui);var e=i.result(this,"_uiBindings");this.ui={},i.each(e,function(e,t){this.ui[t]=this.$(e)},this)}},unbindUIElements:function(){this._unbindUIElements(),i.invoke(this._behaviors,this._unbindUIElements)},_unbindUIElements:function(){this.ui&&this._uiBindings&&(i.each(this.ui,function(e,t){delete this.ui[t]},this),this.ui=this._uiBindings,delete this._uiBindings)},_buildViewTrigger:function(e){var t=i.isObject(e),n=i.defaults({},t?e:{},{preventDefault:!0,stopPropagation:!0}),r=t?n.event:e;return function(e){e&&(e.preventDefault&&n.preventDefault&&e.preventDefault(),e.stopPropagation&&n.stopPropagation&&e.stopPropagation());var t={view:this,model:this.model,collection:this.collection};this.triggerMethod(r,t)}},setElement:function(){var e=t.View.prototype.setElement.apply(this,arguments);return i.invoke(this._behaviors,"proxyViewProperties",this),e},triggerMethod:function(){var e=s._triggerMethod(this,arguments);return this._triggerEventOnBehaviors(arguments),this._triggerEventOnParentLayout(arguments[0],i.rest(arguments)),e},_triggerEventOnBehaviors:function(e){for(var t=s._triggerMethod,i=this._behaviors,n=0,r=i&&i.length;r>n;n++)t(i[n],e)},_triggerEventOnParentLayout:function(e,t){var n=this._parentLayoutView();if(n){var r=s.getOption(n,"childViewEventPrefix"),o=r+":"+e;s._triggerMethod(n,[o,this].concat(t));var h=s.getOption(n,"childEvents"),a=n.normalizeMethods(h);a&&i.isFunction(a[e])&&a[e].apply(n,[this].concat(t))}},_getImmediateChildren:function(){return[]},_getNestedViews:function(){var e=this._getImmediateChildren();return e.length?i.reduce(e,function(e,t){return t._getNestedViews?e.concat(t._getNestedViews()):e},e):e},_getAncestors:function(){for(var e=[],t=this._parent;t;)e.push(t),t=t._parent;return e},_parentLayoutView:function(){var e=this._getAncestors();return i.find(e,function(e){return e instanceof s.LayoutView})},normalizeMethods:s.normalizeMethods,mergeOptions:s.mergeOptions,getOption:s.proxyGetOption,bindEntityEvents:s.proxyBindEntityEvents,unbindEntityEvents:s.proxyUnbindEntityEvents}),s.ItemView=s.View.extend({constructor:function(){s.View.apply(this,arguments)},serializeData:function(){if(!this.model&&!this.collection)return{};var e=[this.model||this.collection];return arguments.length&&e.push.apply(e,arguments),this.model?this.serializeModel.apply(this,e):{items:this.serializeCollection.apply(this,e)}},serializeCollection:function(e){return e.toJSON.apply(e,i.rest(arguments))},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderTemplate(),this.isRendered=!0,this.bindUIElements(),this.triggerMethod("render",this),this},_renderTemplate:function(){var e=this.getTemplate();if(e!==!1){if(!e)throw new s.Error({name:"UndefinedTemplateError",message:"Cannot render the template since it is null or undefined."});var t=this.mixinTemplateHelpers(this.serializeData()),i=s.Renderer.render(e,t,this);return this.attachElContent(i),this}},attachElContent:function(e){return this.$el.html(e),this}}),s.CollectionView=s.View.extend({childViewEventPrefix:"childview",sort:!0,constructor:function(){this.once("render",this._initialEvents),this._initChildViewStorage(),s.View.apply(this,arguments),this.on("show",this._onShowCalled),this.initRenderBuffer()},initRenderBuffer:function(){this._bufferedChildren=[]},startBuffering:function(){this.initRenderBuffer(),this.isBuffering=!0},endBuffering:function(){this.isBuffering=!1,this._triggerBeforeShowBufferedChildren(),this.attachBuffer(this,this._createBuffer()),this._triggerShowBufferedChildren(),this.initRenderBuffer()},_triggerBeforeShowBufferedChildren:function(){this._isShown&&i.each(this._bufferedChildren,i.partial(this._triggerMethodOnChild,"before:show"))},_triggerShowBufferedChildren:function(){this._isShown&&(i.each(this._bufferedChildren,i.partial(this._triggerMethodOnChild,"show")),this._bufferedChildren=[])},_triggerMethodOnChild:function(e,t){s.triggerMethodOn(t,e)},_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.getOption("sort")&&this.listenTo(this.collection,"sort",this._sortViews))},_onCollectionAdd:function(e,t,n){var r;if(r=void 0!==n.at?n.at:i.indexOf(this._filteredSortedModels(),e),this._shouldAddChild(e,r)){this.destroyEmptyView();var s=this.getChildView(e);this.addChild(e,s,r)}},_onCollectionRemove:function(e){var t=this.children.findByModel(e);this.removeChildView(t),this.checkEmpty()},_onShowCalled:function(){this.children.each(i.partial(this._triggerMethodOnChild,"show"))},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderChildren(),this.isRendered=!0,this.triggerMethod("render",this),this},reorder:function(){var e=this.children,t=this._filteredSortedModels(),n=i.find(t,function(t){return!e.findByModel(t)});if(n)this.render();else{var r=i.map(t,function(t){return e.findByModel(t).el});this.triggerMethod("before:reorder"),this._appendReorderedChildren(r),this.triggerMethod("reorder")}},resortView:function(){s.getOption(this,"reorderOnSort")?this.reorder():this.render()},_sortViews:function(){var e=this._filteredSortedModels(),t=i.find(e,function(e,t){var i=this.children.findByModel(e);return!i||i._index!==t},this);t&&this.resortView()},_emptyViewIndex:-1,_appendReorderedChildren:function(e){this.$el.append(e)},_renderChildren:function(){this.destroyEmptyView(),this.destroyChildren(),this.isEmpty(this.collection)?this.showEmptyView():(this.triggerMethod("before:render:collection",this),this.startBuffering(),this.showCollection(),this.endBuffering(),this.triggerMethod("render:collection",this),this.children.isEmpty()&&this.showEmptyView())},showCollection:function(){var e,t=this._filteredSortedModels();i.each(t,function(t,i){e=this.getChildView(t),this.addChild(t,e,i)},this)},_filteredSortedModels:function(){var e,t=this.getViewComparator();return e=t?i.isString(t)||1===t.length?this.collection.sortBy(t,this):i.clone(this.collection.models).sort(i.bind(t,this)):this.collection.models,this.getOption("filter")&&(e=i.filter(e,function(e,t){return this._shouldAddChild(e,t)},this)),e},showEmptyView:function(){var e=this.getEmptyView();if(e&&!this._showingEmptyView){this.triggerMethod("before:render:empty"),this._showingEmptyView=!0;var i=new t.Model;this.addEmptyView(i,e),this.triggerMethod("render:empty")}},destroyEmptyView:function(){this._showingEmptyView&&(this.triggerMethod("before:remove:empty"),this.destroyChildren(),delete this._showingEmptyView,this.triggerMethod("remove:empty"))},getEmptyView:function(){return this.getOption("emptyView")},addEmptyView:function(e,t){var n=this.getOption("emptyViewOptions")||this.getOption("childViewOptions");i.isFunction(n)&&(n=n.call(this,e,this._emptyViewIndex));var r=this.buildChildView(e,t,n);r._parent=this,this.proxyChildEvents(r),this._isShown&&s.triggerMethodOn(r,"before:show"),this.children.add(r),this.renderChildView(r,this._emptyViewIndex),this._isShown&&s.triggerMethodOn(r,"show")},getChildView:function(){var e=this.getOption("childView");if(!e)throw new s.Error({name:"NoChildViewError",message:'A "childView" must be specified'});return e},addChild:function(e,t,i){var n=this.getOption("childViewOptions");n=s._getValue(n,this,[e,i]);var r=this.buildChildView(e,t,n);return this._updateIndices(r,!0,i),this._addChildView(r,i),r._parent=this,r},_updateIndices:function(e,t,i){this.getOption("sort")&&(t&&(e._index=i),this.children.each(function(i){i._index>=e._index&&(i._index+=t?1:-1)}))},_addChildView:function(e,t){this.proxyChildEvents(e),this.triggerMethod("before:add:child",e),this._isShown&&!this.isBuffering&&s.triggerMethodOn(e,"before:show"),this.children.add(e),this.renderChildView(e,t),this._isShown&&!this.isBuffering&&s.triggerMethodOn(e,"show"),this.triggerMethod("add:child",e)},renderChildView:function(e,t){return e.render(),this.attachHtml(this,e,t),e},buildChildView:function(e,t,n){var r=i.extend({model:e},n);return new t(r)},removeChildView:function(e){return e&&(this.triggerMethod("before:remove:child",e),e.destroy?e.destroy():e.remove&&e.remove(),delete e._parent,this.stopListening(e),this.children.remove(e),this.triggerMethod("remove:child",e),this._updateIndices(e,!1)),e},isEmpty:function(){return!this.collection||0===this.collection.length},checkEmpty:function(){this.isEmpty(this.collection)&&this.showEmptyView()},attachBuffer:function(e,t){e.$el.append(t)},_createBuffer:function(){var e=document.createDocumentFragment();return i.each(this._bufferedChildren,function(t){e.appendChild(t.el)}),e},attachHtml:function(e,t,i){e.isBuffering?e._bufferedChildren.splice(i,0,t):e._insertBefore(t,i)||e._insertAfter(t)},_insertBefore:function(e,t){var i,n=this.getOption("sort")&&this.children.length-1>t;return n&&(i=this.children.find(function(e){return e._index===t+1})),i?(i.$el.before(e.el),!0):!1},_insertAfter:function(e){this.$el.append(e.el)},_initChildViewStorage:function(){this.children=new t.ChildViewContainer},destroy:function(){return this.isDestroyed?this:(this.triggerMethod("before:destroy:collection"),this.destroyChildren(),this.triggerMethod("destroy:collection"),s.View.prototype.destroy.apply(this,arguments))},destroyChildren:function(){var e=this.children.map(i.identity);return this.children.each(this.removeChildView,this),this.checkEmpty(),e},_shouldAddChild:function(e,t){var n=this.getOption("filter");return!i.isFunction(n)||n.call(this,e,t,this.collection)},proxyChildEvents:function(e){var t=this.getOption("childViewEventPrefix");this.listenTo(e,"all",function(){var n=i.toArray(arguments),r=n[0],s=this.normalizeMethods(i.result(this,"childEvents"));n[0]=t+":"+r,n.splice(1,0,e),s!==void 0&&i.isFunction(s[r])&&s[r].apply(this,n.slice(1)),this.triggerMethod.apply(this,n)})},_getImmediateChildren:function(){return i.values(this.children._views)},getViewComparator:function(){return this.getOption("viewComparator")}}),s.CompositeView=s.CollectionView.extend({constructor:function(){s.CollectionView.apply(this,arguments)},_initialEvents: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.getOption("sort")&&this.listenTo(this.collection,"sort",this._sortViews))},getChildView:function(){var e=this.getOption("childView")||this.constructor;return e},serializeData:function(){var e={};return this.model&&(e=i.partial(this.serializeModel,this.model).apply(this,arguments)),e},render:function(){return this._ensureViewIsIntact(),this._isRendering=!0,this.resetChildViewContainer(),this.triggerMethod("before:render",this),this._renderTemplate(),this._renderChildren(),this._isRendering=!1,this.isRendered=!0,this.triggerMethod("render",this),this},_renderChildren:function(){(this.isRendered||this._isRendering)&&s.CollectionView.prototype._renderChildren.call(this)},_renderTemplate:function(){var e={};e=this.serializeData(),e=this.mixinTemplateHelpers(e),this.triggerMethod("before:render:template");var t=this.getTemplate(),i=s.Renderer.render(t,e,this);this.attachElContent(i),this.bindUIElements(),this.triggerMethod("render:template")},attachElContent:function(e){return this.$el.html(e),this},attachBuffer:function(e,t){var i=this.getChildViewContainer(e);i.append(t)},_insertAfter:function(e){var t=this.getChildViewContainer(this,e);t.append(e.el)},_appendReorderedChildren:function(e){var t=this.getChildViewContainer(this);t.append(e)},getChildViewContainer:function(e){if("$childViewContainer"in e)return e.$childViewContainer;var t,i=s.getOption(e,"childViewContainer");if(i){var n=s._getValue(i,e);if(t="@"===n.charAt(0)&&e.ui?e.ui[n.substr(4)]:e.$(n),0>=t.length)throw new s.Error({name:"ChildViewContainerMissingError",message:'The specified "childViewContainer" was not found: '+e.childViewContainer})
Пример #6
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});
!function(a,b){if("function"==typeof define&&define.amd)define(["backbone","underscore"],function(c,d){return a.Marionette=a.Mn=b(a,c,d)});else if("undefined"!=typeof exports){var c=require("backbone"),d=require("underscore");module.exports=b(a,c,d)}else a.Marionette=a.Mn=b(a,a.Backbone,a._)}(this,function(a,b,c){"use strict";!function(a,b){var c=a.ChildViewContainer;return a.ChildViewContainer=function(a,b){var c=function(a){this._views={},this._indexByModel={},this._indexByCustom={},this._updateLength(),b.each(a,this.add,this)};b.extend(c.prototype,{add:function(a,b){var c=a.cid;return this._views[c]=a,a.model&&(this._indexByModel[a.model.cid]=c),b&&(this._indexByCustom[b]=c),this._updateLength(),this},findByModel:function(a){return this.findByModelCid(a.cid)},findByModelCid:function(a){var b=this._indexByModel[a];return this.findByCid(b)},findByCustom:function(a){var b=this._indexByCustom[a];return this.findByCid(b)},findByIndex:function(a){return b.values(this._views)[a]},findByCid:function(a){return this._views[a]},remove:function(a){var c=a.cid;return a.model&&delete this._indexByModel[a.model.cid],b.any(this._indexByCustom,function(a,b){return a===c?(delete this._indexByCustom[b],!0):void 0},this),delete this._views[c],this._updateLength(),this},call:function(a){this.apply(a,b.tail(arguments))},apply:function(a,c){b.each(this._views,function(d){b.isFunction(d[a])&&d[a].apply(d,c||[])})},_updateLength:function(){this.length=b.size(this._views)}});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","reduce"];return b.each(d,function(a){c.prototype[a]=function(){var c=b.values(this._views),d=[c].concat(b.toArray(arguments));return b[a].apply(b,d)}}),c}(a,b),a.ChildViewContainer.VERSION="0.1.11",a.ChildViewContainer.noConflict=function(){return a.ChildViewContainer=c,this},a.ChildViewContainer}(b,c),function(a,b){var c=a.Wreqr,d=a.Wreqr={};return a.Wreqr.VERSION="1.3.6",a.Wreqr.noConflict=function(){return a.Wreqr=c,this},d.Handlers=function(a,b){var c=function(a){this.options=a,this._wreqrHandlers={},b.isFunction(this.initialize)&&this.initialize(a)};return c.extend=a.Model.extend,b.extend(c.prototype,a.Events,{setHandlers:function(a){b.each(a,function(a,c){var d=null;b.isObject(a)&&!b.isFunction(a)&&(d=a.context,a=a.callback),this.setHandler(c,a,d)},this)},setHandler:function(a,b,c){var d={callback:b,context:c};this._wreqrHandlers[a]=d,this.trigger("handler:add",a,b,c)},hasHandler:function(a){return!!this._wreqrHandlers[a]},getHandler:function(a){var b=this._wreqrHandlers[a];if(b)return function(){return b.callback.apply(b.context,arguments)}},removeHandler:function(a){delete this._wreqrHandlers[a]},removeAllHandlers:function(){this._wreqrHandlers={}}}),c}(a,b),d.CommandStorage=function(){var c=function(a){this.options=a,this._commands={},b.isFunction(this.initialize)&&this.initialize(a)};return b.extend(c.prototype,a.Events,{getCommands:function(a){var b=this._commands[a];return b||(b={command:a,instances:[]},this._commands[a]=b),b},addCommand:function(a,b){var c=this.getCommands(a);c.instances.push(b)},clearCommands:function(a){var b=this.getCommands(a);b.instances=[]}}),c}(),d.Commands=function(a,b){return a.Handlers.extend({storageType:a.CommandStorage,constructor:function(b){this.options=b||{},this._initializeStorage(this.options),this.on("handler:add",this._executeCommands,this),a.Handlers.prototype.constructor.apply(this,arguments)},execute:function(a){a=arguments[0];var c=b.rest(arguments);this.hasHandler(a)?this.getHandler(a).apply(this,c):this.storage.addCommand(a,c)},_executeCommands:function(a,c,d){var e=this.storage.getCommands(a);b.each(e.instances,function(a){c.apply(d,a)}),this.storage.clearCommands(a)},_initializeStorage:function(a){var c,d=a.storageType||this.storageType;c=b.isFunction(d)?new d:d,this.storage=c}})}(d,b),d.RequestResponse=function(a,b){return a.Handlers.extend({request:function(a){return this.hasHandler(a)?this.getHandler(a).apply(this,b.rest(arguments)):void 0}})}(d,b),d.EventAggregator=function(a,b){var c=function(){};return c.extend=a.Model.extend,b.extend(c.prototype,a.Events),c}(a,b),d.Channel=function(c){var d=function(b){this.vent=new a.Wreqr.EventAggregator,this.reqres=new a.Wreqr.RequestResponse,this.commands=new a.Wreqr.Commands,this.channelName=b};return b.extend(d.prototype,{reset:function(){return this.vent.off(),this.vent.stopListening(),this.reqres.removeAllHandlers(),this.commands.removeAllHandlers(),this},connectEvents:function(a,b){return this._connect("vent",a,b),this},connectCommands:function(a,b){return this._connect("commands",a,b),this},connectRequests:function(a,b){return this._connect("reqres",a,b),this},_connect:function(a,c,d){if(c){d=d||this;var e="vent"===a?"on":"setHandler";b.each(c,function(c,f){this[a][e](f,b.bind(c,d))},this)}}}),d}(d),d.radio=function(a,b){var c=function(){this._channels={},this.vent={},this.commands={},this.reqres={},this._proxyMethods()};b.extend(c.prototype,{channel:function(a){if(!a)throw new Error("Channel must receive a name");return this._getChannel(a)},_getChannel:function(b){var c=this._channels[b];return c||(c=new a.Channel(b),this._channels[b]=c),c},_proxyMethods:function(){b.each(["vent","commands","reqres"],function(a){b.each(d[a],function(b){this[a][b]=e(this,a,b)},this)},this)}});var d={vent:["on","off","trigger","once","stopListening","listenTo","listenToOnce"],commands:["execute","setHandler","setHandlers","removeHandler","removeAllHandlers"],reqres:["request","setHandler","setHandlers","removeHandler","removeAllHandlers"]},e=function(a,c,d){return function(e){var f=a._getChannel(e)[c];return f[d].apply(f,b.rest(arguments))}};return new c}(d,b),a.Wreqr}(b,c);var d=a.Marionette,e=a.Mn,f=b.Marionette={};f.VERSION="2.4.5",f.noConflict=function(){return a.Marionette=d,a.Mn=e,this},b.Marionette=f,f.Deferred=b.$.Deferred,f.extend=b.Model.extend,f.isNodeAttached=function(a){return b.$.contains(document.documentElement,a)},f.mergeOptions=function(a,b){a&&c.extend(this,c.pick(a,b))},f.getOption=function(a,b){return a&&b?a.options&&void 0!==a.options[b]?a.options[b]:a[b]:void 0},f.proxyGetOption=function(a){return f.getOption(this,a)},f._getValue=function(a,b,d){return c.isFunction(a)&&(a=d?a.apply(b,d):a.call(b)),a},f.normalizeMethods=function(a){return c.reduce(a,function(a,b,d){return c.isFunction(b)||(b=this[b]),b&&(a[d]=b),a},{},this)},f.normalizeUIString=function(a,b){return a.replace(/@ui\.[a-zA-Z-_$0-9]*/g,function(a){return b[a.slice(4)]})},f.normalizeUIKeys=function(a,b){return c.reduce(a,function(a,c,d){var e=f.normalizeUIString(d,b);return a[e]=c,a},{})},f.normalizeUIValues=function(a,b,d){return c.each(a,function(e,g){c.isString(e)?a[g]=f.normalizeUIString(e,b):c.isObject(e)&&c.isArray(d)&&(c.extend(e,f.normalizeUIValues(c.pick(e,d),b)),c.each(d,function(a){var d=e[a];c.isString(d)&&(e[a]=f.normalizeUIString(d,b))}))}),a},f.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)}})};var g=f.deprecate=function(a,b){c.isObject(a)&&(a=a.prev+" is going to be removed in the future. Please use "+a.next+" instead."+(a.url?" See: "+a.url:"")),void 0!==b&&b||g._cache[a]||(g._warn("Deprecation warning: "+a),g._cache[a]=!0)};g._console="undefined"!=typeof console?console:{},g._warn=function(){var a=g._console.warn||g._console.log||function(){};return a.apply(g._console,arguments)},g._cache={},f._triggerMethod=function(){function a(a,b,c){return c.toUpperCase()}var b=/(^|:)(\w)/gi;return function(d,e,f){var g=arguments.length<3;g&&(f=e,e=f[0]);var h,i="on"+e.replace(b,a),j=d[i];return c.isFunction(j)&&(h=j.apply(d,g?c.rest(f):f)),c.isFunction(d.trigger)&&(g+f.length>1?d.trigger.apply(d,g?f:[e].concat(c.drop(f,0))):d.trigger(e)),h}}(),f.triggerMethod=function(a){return f._triggerMethod(this,arguments)},f.triggerMethodOn=function(a){var b=c.isFunction(a.triggerMethod)?a.triggerMethod:f.triggerMethod;return b.apply(a,c.rest(arguments))},f.MonitorDOMRefresh=function(a){function b(){a._isShown=!0,d()}function c(){a._isRendered=!0,d()}function d(){a._isShown&&a._isRendered&&f.isNodeAttached(a.el)&&f.triggerMethodOn(a,"dom:refresh",a)}a._isDomRefreshMonitored||(a._isDomRefreshMonitored=!0,a.on({show:b,render:c}))},function(a){function b(b,d,e,f){var g=f.split(/\s+/);c.each(g,function(c){var f=b[c];if(!f)throw new a.Error('Method "'+c+'" was configured as an event handler, but does not exist.');b.listenTo(d,e,f)})}function d(a,b,c,d){a.listenTo(b,c,d)}function e(a,b,d,e){var f=e.split(/\s+/);c.each(f,function(c){var e=a[c];a.stopListening(b,d,e)})}function f(a,b,c,d){a.stopListening(b,c,d)}function g(b,d,e,f,g){if(d&&e){if(!c.isObject(e))throw new a.Error({message:"Bindings must be an object or function.",url:"marionette.functions.html#marionettebindentityevents"});e=a._getValue(e,b),c.each(e,function(a,e){c.isFunction(a)?f(b,d,e,a):g(b,d,e,a)})}}a.bindEntityEvents=function(a,c,e){g(a,c,e,d,b)},a.unbindEntityEvents=function(a,b,c){g(a,b,c,f,e)},a.proxyBindEntityEvents=function(b,c){return a.bindEntityEvents(this,b,c)},a.proxyUnbindEntityEvents=function(b,c){return a.unbindEntityEvents(this,b,c)}}(f);var h=["description","fileName","lineNumber","name","message","number"];return f.Error=f.extend.call(Error,{urlRoot:"http://marionettejs.com/docs/v"+f.VERSION+"/",constructor:function(a,b){c.isObject(a)?(b=a,a=b.message):b||(b={});var d=Error.call(this,a);c.extend(this,c.pick(d,h),c.pick(b,h)),this.captureStackTrace(),b.url&&(this.url=this.urlRoot+b.url)},captureStackTrace:function(){Error.captureStackTrace&&Error.captureStackTrace(this,f.Error)},toString:function(){return this.name+": "+this.message+(this.url?" See: "+this.url:"")}}),f.Error.extend=f.extend,f.Callbacks=function(){this._deferred=f.Deferred(),this._callbacks=[]},c.extend(f.Callbacks.prototype,{add:function(a,b){var d=c.result(this._deferred,"promise");this._callbacks.push({cb:a,ctx:b}),d.then(function(c){b&&(c.context=b),a.call(c.context,c.options)})},run:function(a,b){this._deferred.resolve({options:a,context:b})},reset:function(){var a=this._callbacks;this._deferred=f.Deferred(),this._callbacks=[],c.each(a,function(a){this.add(a.cb,a.ctx)},this)}}),f.Controller=function(a){this.options=a||{},c.isFunction(this.initialize)&&this.initialize(this.options)},f.Controller.extend=f.extend,c.extend(f.Controller.prototype,b.Events,{destroy:function(){return f._triggerMethod(this,"before:destroy",arguments),f._triggerMethod(this,"destroy",arguments),this.stopListening(),this.off(),this},triggerMethod:f.triggerMethod,mergeOptions:f.mergeOptions,getOption:f.proxyGetOption}),f.Object=function(a){this.options=c.extend({},c.result(this,"options"),a),this.initialize.apply(this,arguments)},f.Object.extend=f.extend,c.extend(f.Object.prototype,b.Events,{initialize:function(){},destroy:function(a){return a=a||{},this.triggerMethod("before:destroy",a),this.triggerMethod("destroy",a),this.stopListening(),this},triggerMethod:f.triggerMethod,mergeOptions:f.mergeOptions,getOption:f.proxyGetOption,bindEntityEvents:f.proxyBindEntityEvents,unbindEntityEvents:f.proxyUnbindEntityEvents}),f.Region=f.Object.extend({constructor:function(a){if(this.options=a||{},this.el=this.getOption("el"),this.el=this.el instanceof b.$?this.el[0]:this.el,!this.el)throw new f.Error({name:"NoElError",message:'An "el" must be specified for a region.'});this.$el=this.getEl(this.el),f.Object.call(this,a)},show:function(a,b){if(this._ensureElement()){this._ensureViewIsIntact(a),f.MonitorDOMRefresh(a);var d=b||{},e=a!==this.currentView,g=!!d.preventDestroy,h=!!d.forceShow,i=!!this.currentView,j=e&&!g,k=e||h;if(i&&this.triggerMethod("before:swapOut",this.currentView,this,b),this.currentView&&e&&delete this.currentView._parent,j?this.empty():i&&k&&this.currentView.off("destroy",this.empty,this),k){a.once("destroy",this.empty,this),a._parent=this,this._renderView(a),i&&this.triggerMethod("before:swap",a,this,b),this.triggerMethod("before:show",a,this,b),f.triggerMethodOn(a,"before:show",a,this,b),i&&this.triggerMethod("swapOut",this.currentView,this,b);var l=f.isNodeAttached(this.el),m=[],n=c.extend({triggerBeforeAttach:this.triggerBeforeAttach,triggerAttach:this.triggerAttach},d);return l&&n.triggerBeforeAttach&&(m=this._displayedViews(a),this._triggerAttach(m,"before:")),this.attachHtml(a),this.currentView=a,l&&n.triggerAttach&&(m=this._displayedViews(a),this._triggerAttach(m)),i&&this.triggerMethod("swap",a,this,b),this.triggerMethod("show",a,this,b),f.triggerMethodOn(a,"show",a,this,b),this}return this}},triggerBeforeAttach:!0,triggerAttach:!0,_triggerAttach:function(a,b){var d=(b||"")+"attach";c.each(a,function(a){f.triggerMethodOn(a,d,a,this)},this)},_displayedViews:function(a){return c.union([a],c.result(a,"_getNestedViews")||[])},_renderView:function(a){a.supportsRenderLifecycle||f.triggerMethodOn(a,"before:render",a),a.render(),a.supportsRenderLifecycle||f.triggerMethodOn(a,"render",a)},_ensureElement:function(){if(c.isObject(this.el)||(this.$el=this.getEl(this.el),this.el=this.$el[0]),!this.$el||0===this.$el.length){if(this.getOption("allowMissingEl"))return!1;throw new f.Error('An "el" '+this.$el.selector+" must exist in DOM")}return!0},_ensureViewIsIntact:function(a){if(!a)throw new f.Error({name:"ViewNotValid",message:"The view passed is undefined and therefore invalid. You must pass a view instance to show."});if(a.isDestroyed)throw new f.Error({name:"ViewDestroyedError",message:'View (cid: "'+a.cid+'") has already been destroyed and cannot be used.'})},getEl:function(a){return b.$(a,f._getValue(this.options.parentEl,this))},attachHtml:function(a){this.$el.contents().detach(),this.el.appendChild(a.el)},empty:function(a){var b=this.currentView,c=a||{},d=!!c.preventDestroy;return b?(b.off("destroy",this.empty,this),this.triggerMethod("before:empty",b),d||this._destroyView(),this.triggerMethod("empty",b),delete this.currentView,d&&this.$el.contents().detach(),this):this},_destroyView:function(){var a=this.currentView;a.isDestroyed||(a.supportsDestroyLifecycle||f.triggerMethodOn(a,"before:destroy",a),a.destroy?a.destroy():(a.remove(),a.isDestroyed=!0),a.supportsDestroyLifecycle||f.triggerMethodOn(a,"destroy",a))},attachView:function(a){return this.currentView&&delete this.currentView._parent,a._parent=this,this.currentView=a,this},hasView:function(){return!!this.currentView},reset:function(){return this.empty(),this.$el&&(this.el=this.$el.selector),delete this.$el,this}},{buildRegion:function(a,b){if(c.isString(a))return this._buildRegionFromSelector(a,b);if(a.selector||a.el||a.regionClass)return this._buildRegionFromObject(a,b);if(c.isFunction(a))return this._buildRegionFromRegionClass(a);throw new f.Error({message:"Improper region configuration type.",url:"marionette.region.html#region-configuration-types"})},_buildRegionFromSelector:function(a,b){return new b({el:a})},_buildRegionFromObject:function(a,b){var d=a.regionClass||b,e=c.omit(a,"selector","regionClass");return a.selector&&!e.el&&(e.el=a.selector),new d(e)},_buildRegionFromRegionClass:function(a){return new a}}),f.RegionManager=f.Controller.extend({constructor:function(a){this._regions={},this.length=0,f.Controller.call(this,a),this.addRegions(this.getOption("regions"))},addRegions:function(a,b){return a=f._getValue(a,this,arguments),c.reduce(a,function(a,d,e){return c.isString(d)&&(d={selector:d}),d.selector&&(d=c.defaults({},d,b)),a[e]=this.addRegion(e,d),a},{},this)},addRegion:function(a,b){var c;return c=b instanceof f.Region?b:f.Region.buildRegion(b,f.Region),this.triggerMethod("before:add:region",a,c),c._parent=this,this._store(a,c),this.triggerMethod("add:region",a,c),c},get:function(a){return this._regions[a]},getRegions:function(){return c.clone(this._regions)},removeRegion:function(a){var b=this._regions[a];return this._remove(a,b),b},removeRegions:function(){var a=this.getRegions();return c.each(this._regions,function(a,b){this._remove(b,a)},this),a},emptyRegions:function(){var a=this.getRegions();return c.invoke(a,"empty"),a},destroy:function(){return this.removeRegions(),f.Controller.prototype.destroy.apply(this,arguments)},_store:function(a,b){this._regions[a]||this.length++,this._regions[a]=b},_remove:function(a,b){this.triggerMethod("before:remove:region",a,b),b.empty(),b.stopListening(),delete b._parent,delete this._regions[a],this.length--,this.triggerMethod("remove:region",a,b)}}),f.actAsCollection(f.RegionManager.prototype,"_regions"),f.TemplateCache=function(a){this.templateId=a},c.extend(f.TemplateCache,{templateCaches:{},get:function(a,b){var c=this.templateCaches[a];return c||(c=new f.TemplateCache(a),this.templateCaches[a]=c),c.load(b)},clear:function(){var a,b=c.toArray(arguments),d=b.length;if(d>0)for(a=0;d>a;a++)delete this.templateCaches[b[a]];else this.templateCaches={}}}),c.extend(f.TemplateCache.prototype,{load:function(a){if(this.compiledTemplate)return this.compiledTemplate;var b=this.loadTemplate(this.templateId,a);return this.compiledTemplate=this.compileTemplate(b,a),this.compiledTemplate},loadTemplate:function(a,c){var d=b.$(a);if(!d.length)throw new f.Error({name:"NoTemplateError",message:'Could not find template: "'+a+'"'});return d.html()},compileTemplate:function(a,b){return c.template(a,b)}}),f.Renderer={render:function(a,b){if(!a)throw new f.Error({name:"TemplateNotFoundError",message:"Cannot render the template since its false, null or undefined."});var d=c.isFunction(a)?a:f.TemplateCache.get(a);return d(b)}},f.View=b.View.extend({isDestroyed:!1,supportsRenderLifecycle:!0,supportsDestroyLifecycle:!0,constructor:function(a){this.render=c.bind(this.render,this),a=f._getValue(a,this),this.options=c.extend({},c.result(this,"options"),a),this._behaviors=f.Behaviors(this),b.View.call(this,this.options),f.MonitorDOMRefresh(this)},getTemplate:function(){return this.getOption("template")},serializeModel:function(a){return a.toJSON.apply(a,c.rest(arguments))},mixinTemplateHelpers:function(a){a=a||{};var b=this.getOption("templateHelpers");return b=f._getValue(b,this),c.extend(a,b)},normalizeUIKeys:function(a){var b=c.result(this,"_uiBindings");return f.normalizeUIKeys(a,b||c.result(this,"ui"))},normalizeUIValues:function(a,b){var d=c.result(this,"ui"),e=c.result(this,"_uiBindings");return f.normalizeUIValues(a,e||d,b)},configureTriggers:function(){if(this.triggers){var a=this.normalizeUIKeys(c.result(this,"triggers"));return c.reduce(a,function(a,b,c){return a[c]=this._buildViewTrigger(b),a},{},this)}},delegateEvents:function(a){return this._delegateDOMEvents(a),this.bindEntityEvents(this.model,this.getOption("modelEvents")),this.bindEntityEvents(this.collection,this.getOption("collectionEvents")),c.each(this._behaviors,function(a){a.bindEntityEvents(this.model,a.getOption("modelEvents")),a.bindEntityEvents(this.collection,a.getOption("collectionEvents"))},this),this},_delegateDOMEvents:function(a){var d=f._getValue(a||this.events,this);d=this.normalizeUIKeys(d),c.isUndefined(a)&&(this.events=d);var e={},g=c.result(this,"behaviorEvents")||{},h=this.configureTriggers(),i=c.result(this,"behaviorTriggers")||{};c.extend(e,g,d,h,i),b.View.prototype.delegateEvents.call(this,e)},undelegateEvents:function(){return b.View.prototype.undelegateEvents.apply(this,arguments),this.unbindEntityEvents(this.model,this.getOption("modelEvents")),this.unbindEntityEvents(this.collection,this.getOption("collectionEvents")),c.each(this._behaviors,function(a){a.unbindEntityEvents(this.model,a.getOption("modelEvents")),a.unbindEntityEvents(this.collection,a.getOption("collectionEvents"))},this),this},_ensureViewIsIntact:function(){if(this.isDestroyed)throw new f.Error({name:"ViewDestroyedError",message:'View (cid: "'+this.cid+'") has already been destroyed and cannot be used.'})},destroy:function(){if(this.isDestroyed)return this;var a=c.toArray(arguments);return this.triggerMethod.apply(this,["before:destroy"].concat(a)),this.isDestroyed=!0,this.triggerMethod.apply(this,["destroy"].concat(a)),this.unbindUIElements(),this.isRendered=!1,this.remove(),c.invoke(this._behaviors,"destroy",a),this},bindUIElements:function(){this._bindUIElements(),c.invoke(this._behaviors,this._bindUIElements)},_bindUIElements:function(){if(this.ui){this._uiBindings||(this._uiBindings=this.ui);var a=c.result(this,"_uiBindings");this.ui={},c.each(a,function(a,b){this.ui[b]=this.$(a)},this)}},unbindUIElements:function(){this._unbindUIElements(),c.invoke(this._behaviors,this._unbindUIElements)},_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)},_buildViewTrigger:function(a){var b=c.defaults({},a,{preventDefault:!0,stopPropagation:!0}),d=c.isObject(a)?b.event:a;return function(a){a&&(a.preventDefault&&b.preventDefault&&a.preventDefault(),a.stopPropagation&&b.stopPropagation&&a.stopPropagation());var c={view:this,model:this.model,collection:this.collection};this.triggerMethod(d,c)}},setElement:function(){var a=b.View.prototype.setElement.apply(this,arguments);return c.invoke(this._behaviors,"proxyViewProperties",this),a},triggerMethod:function(){var a=f._triggerMethod(this,arguments);return this._triggerEventOnBehaviors(arguments),this._triggerEventOnParentLayout(arguments[0],c.rest(arguments)),a},_triggerEventOnBehaviors:function(a){for(var b=f._triggerMethod,c=this._behaviors,d=0,e=c&&c.length;e>d;d++)b(c[d],a)},_triggerEventOnParentLayout:function(a,b){var d=this._parentLayoutView();if(d){var e=f.getOption(d,"childViewEventPrefix"),g=e+":"+a,h=[this].concat(b);f._triggerMethod(d,g,h);var i=f.getOption(d,"childEvents");i=f._getValue(i,d);var j=d.normalizeMethods(i);j&&c.isFunction(j[a])&&j[a].apply(d,h)}},_getImmediateChildren:function(){return[]},_getNestedViews:function(){var a=this._getImmediateChildren();return a.length?c.reduce(a,function(a,b){return b._getNestedViews?a.concat(b._getNestedViews()):a},a):a},_parentLayoutView:function(){for(var a=this._parent;a;){if(a instanceof f.LayoutView)return a;a=a._parent}},normalizeMethods:f.normalizeMethods,mergeOptions:f.mergeOptions,getOption:f.proxyGetOption,bindEntityEvents:f.proxyBindEntityEvents,unbindEntityEvents:f.proxyUnbindEntityEvents}),f.ItemView=f.View.extend({constructor:function(){f.View.apply(this,arguments)},serializeData:function(){if(!this.model&&!this.collection)return{};var a=[this.model||this.collection];return arguments.length&&a.push.apply(a,arguments),this.model?this.serializeModel.apply(this,a):{items:this.serializeCollection.apply(this,a)}},serializeCollection:function(a){return a.toJSON.apply(a,c.rest(arguments))},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderTemplate(),this.isRendered=!0,this.bindUIElements(),this.triggerMethod("render",this),this},_renderTemplate:function(){var a=this.getTemplate();if(a!==!1){if(!a)throw new f.Error({name:"UndefinedTemplateError",message:"Cannot render the template since it is null or undefined."});var b=this.mixinTemplateHelpers(this.serializeData()),c=f.Renderer.render(a,b,this);return this.attachElContent(c),this}},attachElContent:function(a){return this.$el.html(a),this}}),f.CollectionView=f.View.extend({childViewEventPrefix:"childview",sort:!0,constructor:function(a){this.once("render",this._initialEvents),this._initChildViewStorage(),f.View.apply(this,arguments),this.on({"before:show":this._onBeforeShowCalled,show:this._onShowCalled,"before:attach":this._onBeforeAttachCalled,attach:this._onAttachCalled}),this.initRenderBuffer()},initRenderBuffer:function(){this._bufferedChildren=[]},startBuffering:function(){this.initRenderBuffer(),this.isBuffering=!0},endBuffering:function(){var a,b=this._isShown&&f.isNodeAttached(this.el);this.isBuffering=!1,this._isShown&&this._triggerMethodMany(this._bufferedChildren,this,"before:show"),b&&this._triggerBeforeAttach&&(a=this._getNestedViews(),this._triggerMethodMany(a,this,"before:attach")),this.attachBuffer(this,this._createBuffer()),b&&this._triggerAttach&&(a=this._getNestedViews(),this._triggerMethodMany(a,this,"attach")),this._isShown&&this._triggerMethodMany(this._bufferedChildren,this,"show"),this.initRenderBuffer()},_triggerMethodMany:function(a,b,d){var e=c.drop(arguments,3);c.each(a,function(a){f.triggerMethodOn.apply(a,[a,d,a,b].concat(e))})},_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.getOption("sort")&&this.listenTo(this.collection,"sort",this._sortViews))},_onCollectionAdd:function(a,b,d){var e=void 0!==d.at&&(d.index||b.indexOf(a));if((this.getOption("filter")||e===!1)&&(e=c.indexOf(this._filteredSortedModels(e),a)),this._shouldAddChild(a,e)){this.destroyEmptyView();var f=this.getChildView(a);this.addChild(a,f,e)}},_onCollectionRemove:function(a){var b=this.children.findByModel(a);this.removeChildView(b),this.checkEmpty()},_onBeforeShowCalled:function(){this._triggerBeforeAttach=this._triggerAttach=!1,this.children.each(function(a){f.triggerMethodOn(a,"before:show",a)})},_onShowCalled:function(){this.children.each(function(a){f.triggerMethodOn(a,"show",a)})},_onBeforeAttachCalled:function(){this._triggerBeforeAttach=!0},_onAttachCalled:function(){this._triggerAttach=!0},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderChildren(),this.isRendered=!0,this.triggerMethod("render",this),this},reorder:function(){var a=this.children,b=this._filteredSortedModels(),d=c.some(b,function(b){return!a.findByModel(b)});if(d)this.render();else{var e=c.map(b,function(b,c){var d=a.findByModel(b);return d._index=c,d.el}),f=a.filter(function(a){return!c.contains(e,a.el)});this.triggerMethod("before:reorder"),this._appendReorderedChildren(e),c.each(f,this.removeChildView,this),this.checkEmpty(),this.triggerMethod("reorder")}},resortView:function(){f.getOption(this,"reorderOnSort")?this.reorder():this.render()},_sortViews:function(){var a=this._filteredSortedModels(),b=c.find(a,function(a,b){var c=this.children.findByModel(a);return!c||c._index!==b},this);b&&this.resortView()},_emptyViewIndex:-1,_appendReorderedChildren:function(a){this.$el.append(a)},_renderChildren:function(){this.destroyEmptyView(),this.destroyChildren({checkEmpty:!1}),this.isEmpty(this.collection)?this.showEmptyView():(this.triggerMethod("before:render:collection",this),this.startBuffering(),this.showCollection(),this.endBuffering(),this.triggerMethod("render:collection",this),this.children.isEmpty()&&this.getOption("filter")&&this.showEmptyView())},showCollection:function(){var a,b=this._filteredSortedModels();c.each(b,function(b,c){a=this.getChildView(b),this.addChild(b,a,c)},this)},_filteredSortedModels:function(a){var b=this.getViewComparator(),d=this.collection.models;if(a=Math.min(Math.max(a,0),d.length-1),b){var e;a&&(e=d[a],d=d.slice(0,a).concat(d.slice(a+1))),d=this._sortModelsBy(d,b),e&&d.splice(a,0,e)}return this.getOption("filter")&&(d=c.filter(d,function(a,b){return this._shouldAddChild(a,b)},this)),d},_sortModelsBy:function(a,b){return"string"==typeof b?c.sortBy(a,function(a){return a.get(b)},this):1===b.length?c.sortBy(a,b,this):a.sort(c.bind(b,this))},showEmptyView:function(){var a=this.getEmptyView();if(a&&!this._showingEmptyView){this.triggerMethod("before:render:empty"),this._showingEmptyView=!0;var c=new b.Model;this.addEmptyView(c,a),this.triggerMethod("render:empty")}},destroyEmptyView:function(){this._showingEmptyView&&(this.triggerMethod("before:remove:empty"),this.destroyChildren(),delete this._showingEmptyView,this.triggerMethod("remove:empty"))},getEmptyView:function(){return this.getOption("emptyView")},addEmptyView:function(a,b){var d,e=this._isShown&&!this.isBuffering&&f.isNodeAttached(this.el),g=this.getOption("emptyViewOptions")||this.getOption("childViewOptions");c.isFunction(g)&&(g=g.call(this,a,this._emptyViewIndex));var h=this.buildChildView(a,b,g);h._parent=this,this.proxyChildEvents(h),h.once("render",function(){this._isShown&&f.triggerMethodOn(h,"before:show",h),e&&this._triggerBeforeAttach&&(d=this._getViewAndNested(h),this._triggerMethodMany(d,this,"before:attach"))},this),this.children.add(h),this.renderChildView(h,this._emptyViewIndex),e&&this._triggerAttach&&(d=this._getViewAndNested(h),this._triggerMethodMany(d,this,"attach")),this._isShown&&f.triggerMethodOn(h,"show",h)},getChildView:function(a){var b=this.getOption("childView");if(!b)throw new f.Error({name:"NoChildViewError",message:'A "childView" must be specified'});return b},addChild:function(a,b,c){var d=this.getOption("childViewOptions");d=f._getValue(d,this,[a,c]);var e=this.buildChildView(a,b,d);return this._updateIndices(e,!0,c),this.triggerMethod("before:add:child",e),this._addChildView(e,c),this.triggerMethod("add:child",e),e._parent=this,e},_updateIndices:function(a,b,c){this.getOption("sort")&&(b&&(a._index=c),this.children.each(function(c){c._index>=a._index&&(c._index+=b?1:-1)}))},_addChildView:function(a,b){var c,d=this._isShown&&!this.isBuffering&&f.isNodeAttached(this.el);this.proxyChildEvents(a),a.once("render",function(){this._isShown&&!this.isBuffering&&f.triggerMethodOn(a,"before:show",a),d&&this._triggerBeforeAttach&&(c=this._getViewAndNested(a),this._triggerMethodMany(c,this,"before:attach"))},this),this.children.add(a),this.renderChildView(a,b),d&&this._triggerAttach&&(c=this._getViewAndNested(a),this._triggerMethodMany(c,this,"attach")),this._isShown&&!this.isBuffering&&f.triggerMethodOn(a,"show",a)},renderChildView:function(a,b){return a.supportsRenderLifecycle||f.triggerMethodOn(a,"before:render",a),a.render(),a.supportsRenderLifecycle||f.triggerMethodOn(a,"render",a),this.attachHtml(this,a,b),a},buildChildView:function(a,b,d){var e=c.extend({model:a},d),g=new b(e);return f.MonitorDOMRefresh(g),g},removeChildView:function(a){return a?(this.triggerMethod("before:remove:child",a),a.supportsDestroyLifecycle||f.triggerMethodOn(a,"before:destroy",a),a.destroy?a.destroy():a.remove(),a.supportsDestroyLifecycle||f.triggerMethodOn(a,"destroy",a),delete a._parent,this.stopListening(a),this.children.remove(a),this.triggerMethod("remove:child",a),this._updateIndices(a,!1),a):a},isEmpty:function(){return!this.collection||0===this.collection.length},checkEmpty:function(){this.isEmpty(this.collection)&&this.showEmptyView()},attachBuffer:function(a,b){a.$el.append(b)},_createBuffer:function(){var a=document.createDocumentFragment();return c.each(this._bufferedChildren,function(b){a.appendChild(b.el)}),a},attachHtml:function(a,b,c){a.isBuffering?a._bufferedChildren.splice(c,0,b):a._insertBefore(b,c)||a._insertAfter(b)},_insertBefore:function(a,b){var c,d=this.getOption("sort")&&b<this.children.length-1;return d&&(c=this.children.find(function(a){return a._index===b+1})),c?(c.$el.before(a.el),!0):!1},_insertAfter:function(a){this.$el.append(a.el)},_initChildViewStorage:function(){this.children=new b.ChildViewContainer},destroy:function(){return this.isDestroyed?this:(this.triggerMethod("before:destroy:collection"),this.destroyChildren({checkEmpty:!1}),this.triggerMethod("destroy:collection"),f.View.prototype.destroy.apply(this,arguments))},destroyChildren:function(a){var b=a||{},d=!0,e=this.children.map(c.identity);return c.isUndefined(b.checkEmpty)||(d=b.checkEmpty),this.children.each(this.removeChildView,this),d&&this.checkEmpty(),e},_shouldAddChild:function(a,b){var d=this.getOption("filter");return!c.isFunction(d)||d.call(this,a,b,this.collection)},proxyChildEvents:function(a){var b=this.getOption("childViewEventPrefix");this.listenTo(a,"all",function(){var d=c.toArray(arguments),e=d[0],f=this.normalizeMethods(c.result(this,"childEvents"));
d[0]=b+":"+e,d.splice(1,0,a),"undefined"!=typeof f&&c.isFunction(f[e])&&f[e].apply(this,d.slice(1)),this.triggerMethod.apply(this,d)})},_getImmediateChildren:function(){return c.values(this.children._views)},_getViewAndNested:function(a){return[a].concat(c.result(a,"_getNestedViews")||[])},getViewComparator:function(){return this.getOption("viewComparator")}}),f.CompositeView=f.CollectionView.extend({constructor:function(){f.CollectionView.apply(this,arguments)},_initialEvents: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.getOption("sort")&&this.listenTo(this.collection,"sort",this._sortViews))},getChildView:function(a){var b=this.getOption("childView")||this.constructor;return b},serializeData:function(){var a={};return this.model&&(a=c.partial(this.serializeModel,this.model).apply(this,arguments)),a},render:function(){return this._ensureViewIsIntact(),this._isRendering=!0,this.resetChildViewContainer(),this.triggerMethod("before:render",this),this._renderTemplate(),this._renderChildren(),this._isRendering=!1,this.isRendered=!0,this.triggerMethod("render",this),this},_renderChildren:function(){(this.isRendered||this._isRendering)&&f.CollectionView.prototype._renderChildren.call(this)},_renderTemplate:function(){var a={};a=this.serializeData(),a=this.mixinTemplateHelpers(a),this.triggerMethod("before:render:template");var b=this.getTemplate(),c=f.Renderer.render(b,a,this);this.attachElContent(c),this.bindUIElements(),this.triggerMethod("render:template")},attachElContent:function(a){return this.$el.html(a),this},attachBuffer:function(a,b){var c=this.getChildViewContainer(a);c.append(b)},_insertAfter:function(a){var b=this.getChildViewContainer(this,a);b.append(a.el)},_appendReorderedChildren:function(a){var b=this.getChildViewContainer(this);b.append(a)},getChildViewContainer:function(a,b){if(a.$childViewContainer)return a.$childViewContainer;var c,d=f.getOption(a,"childViewContainer");if(d){var e=f._getValue(d,a);if(c="@"===e.charAt(0)&&a.ui?a.ui[e.substr(4)]:a.$(e),c.length<=0)throw new f.Error({name:"ChildViewContainerMissingError",message:'The specified "childViewContainer" was not found: '+a.childViewContainer})}else c=a.$el;return a.$childViewContainer=c,c},resetChildViewContainer:function(){this.$childViewContainer&&(this.$childViewContainer=void 0)}}),f.LayoutView=f.ItemView.extend({regionClass:f.Region,options:{destroyImmediate:!1},childViewEventPrefix:"childview",constructor:function(a){a=a||{},this._firstRender=!0,this._initializeRegions(a),f.ItemView.call(this,a)},render:function(){return this._ensureViewIsIntact(),this._firstRender?this._firstRender=!1:this._reInitializeRegions(),f.ItemView.prototype.render.apply(this,arguments)},destroy:function(){return this.isDestroyed?this:(this.getOption("destroyImmediate")===!0&&this.$el.remove(),this.regionManager.destroy(),f.ItemView.prototype.destroy.apply(this,arguments))},showChildView:function(a,b,d){var e=this.getRegion(a);return e.show.apply(e,c.rest(arguments))},getChildView:function(a){return this.getRegion(a).currentView},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)},getRegions:function(){return this.regionManager.getRegions()},_buildRegions:function(a){var b={regionClass:this.getOption("regionClass"),parentEl:c.partial(c.result,this,"el")};return this.regionManager.addRegions(a,b)},_initializeRegions:function(a){var b;this._initRegionManager(),b=f._getValue(this.regions,this,[a])||{};var d=this.getOption.call(a,"regions");d=f._getValue(d,this,[a]),c.extend(b,d),b=this.normalizeUIValues(b,["selector","el"]),this.addRegions(b)},_reInitializeRegions:function(){this.regionManager.invoke("reset")},getRegionManager:function(){return new f.RegionManager},_initRegionManager:function(){this.regionManager=this.getRegionManager(),this.regionManager._parent=this,this.listenTo(this.regionManager,"before:add:region",function(a){this.triggerMethod("before:add:region",a)}),this.listenTo(this.regionManager,"add:region",function(a,b){this[a]=b,this.triggerMethod("add:region",a,b)}),this.listenTo(this.regionManager,"before:remove:region",function(a){this.triggerMethod("before:remove:region",a)}),this.listenTo(this.regionManager,"remove:region",function(a,b){delete this[a],this.triggerMethod("remove:region",a,b)})},_getImmediateChildren:function(){return c.chain(this.regionManager.getRegions()).pluck("currentView").compact().value()}}),f.Behavior=f.Object.extend({constructor:function(a,b){this.view=b,this.defaults=c.result(this,"defaults")||{},this.options=c.extend({},this.defaults,a),this.ui=c.extend({},c.result(b,"ui"),c.result(this,"ui")),f.Object.apply(this,arguments)},$:function(){return this.view.$.apply(this.view,arguments)},destroy:function(){return this.stopListening(),this},proxyViewProperties:function(a){this.$el=a.$el,this.el=a.el}}),f.Behaviors=function(a,b){function c(a,d){return b.isObject(a.behaviors)?(d=c.parseBehaviors(a,d||b.result(a,"behaviors")),c.wrap(a,d,b.keys(g)),d):{}}function d(a,b){this._view=a,this._behaviors=b,this._triggers={}}function e(a){return a._uiBindings||a.ui}var f=/^(\S+)\s*(.*)$/,g={behaviorTriggers:function(a,b){var c=new d(this,b);return c.buildBehaviorTriggers()},behaviorEvents:function(c,d){var g={};return b.each(d,function(c,d){var h={},i=b.clone(b.result(c,"events"))||{};i=a.normalizeUIKeys(i,e(c));var j=0;b.each(i,function(a,e){var g=e.match(f),i=g[1]+"."+[this.cid,d,j++," "].join(""),k=g[2],l=i+k,m=b.isFunction(a)?a:c[a];m&&(h[l]=b.bind(m,c))},this),g=b.extend(g,h)},this),g}};return b.extend(c,{behaviorsLookup:function(){throw new a.Error({message:"You must define where your behaviors are stored.",url:"marionette.behaviors.html#behaviorslookup"})},getBehaviorClass:function(b,d){return b.behaviorClass?b.behaviorClass:a._getValue(c.behaviorsLookup,this,[b,d])[d]},parseBehaviors:function(a,d){return b.chain(d).map(function(d,e){var f=c.getBehaviorClass(d,e),g=new f(d,a),h=c.parseBehaviors(a,b.result(g,"behaviors"));return[g].concat(h)}).flatten().value()},wrap:function(a,c,d){b.each(d,function(d){a[d]=b.partial(g[d],a[d],c)})}}),b.extend(d.prototype,{buildBehaviorTriggers:function(){return b.each(this._behaviors,this._buildTriggerHandlersForBehavior,this),this._triggers},_buildTriggerHandlersForBehavior:function(c,d){var f=b.clone(b.result(c,"triggers"))||{};f=a.normalizeUIKeys(f,e(c)),b.each(f,b.bind(this._setHandlerForBehavior,this,c,d))},_setHandlerForBehavior:function(a,b,c,d){var e=d.replace(/^\S+/,function(a){return a+".behaviortriggers"+b});this._triggers[e]=this._view._buildViewTrigger(c)}}),c}(f,c),f.AppRouter=b.Router.extend({constructor:function(a){this.options=a||{},b.Router.apply(this,arguments);var c=this.getOption("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){if(c.isFunction(this.onRoute)){var d=c.invert(this.getOption("appRoutes"))[a];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 this.getOption("controller")},_addAppRoute:function(a,b,d){var e=a[d];if(!e)throw new f.Error('Method "'+d+'" was not found on the controller');this.route(b,d,c.bind(e,a))},mergeOptions:f.mergeOptions,getOption:f.proxyGetOption,triggerMethod:f.triggerMethod,bindEntityEvents:f.proxyBindEntityEvents,unbindEntityEvents:f.proxyUnbindEntityEvents}),f.Application=f.Object.extend({constructor:function(a){this._initializeRegions(a),this._initCallbacks=new f.Callbacks,this.submodules={},c.extend(this,a),this._initChannel(),f.Object.apply(this,arguments)},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("before:start",a),this._initCallbacks.run(a,this),this.triggerMethod("start",a)},addRegions:function(a){return this._regionManager.addRegions(a)},emptyRegions:function(){return this._regionManager.emptyRegions()},removeRegion:function(a){return this._regionManager.removeRegion(a)},getRegion:function(a){return this._regionManager.get(a)},getRegions:function(){return this._regionManager.getRegions()},module:function(a,b){var d=f.Module.getClass(b),e=c.toArray(arguments);return e.unshift(this),d.create.apply(d,e)},getRegionManager:function(){return new f.RegionManager},_initializeRegions:function(a){var b=c.isFunction(this.regions)?this.regions(a):this.regions||{};this._initRegionManager();var d=f.getOption(a,"regions");return c.isFunction(d)&&(d=d.call(this,a)),c.extend(b,d),this.addRegions(b),this},_initRegionManager:function(){this._regionManager=this.getRegionManager(),this._regionManager._parent=this,this.listenTo(this._regionManager,"before:add:region",function(){f._triggerMethod(this,"before:add:region",arguments)}),this.listenTo(this._regionManager,"add:region",function(a,b){this[a]=b,f._triggerMethod(this,"add:region",arguments)}),this.listenTo(this._regionManager,"before:remove:region",function(){f._triggerMethod(this,"before:remove:region",arguments)}),this.listenTo(this._regionManager,"remove:region",function(a){delete this[a],f._triggerMethod(this,"remove:region",arguments)})},_initChannel:function(){this.channelName=c.result(this,"channelName")||"global",this.channel=c.result(this,"channel")||b.Wreqr.radio.channel(this.channelName),this.vent=c.result(this,"vent")||this.channel.vent,this.commands=c.result(this,"commands")||this.channel.commands,this.reqres=c.result(this,"reqres")||this.channel.reqres}}),f.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,c.isFunction(this.initialize)&&this.initialize(a,b,this.options)},f.Module.extend=f.extend,c.extend(f.Module.prototype,b.Events,{startWithParent:!0,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,this.triggerMethod("before:stop"),c.invoke(this.submodules,"stop"),this._finalizerCallbacks.run(void 0,this),this._initializerCallbacks.reset(),this._finalizerCallbacks.reset(),this.triggerMethod("stop"))},addDefinition:function(a,b){this._runModuleDefinition(a,b)},_runModuleDefinition:function(a,d){if(a){var e=c.flatten([this,this.app,b,f,b.$,c,d]);a.apply(this,e)}},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new f.Callbacks,this._finalizerCallbacks=new f.Callbacks},triggerMethod:f.triggerMethod}),c.extend(f.Module,{create:function(a,b,d){var e=a,f=c.drop(arguments,3);b=b.split(".");var g=b.length,h=[];return h[g-1]=d,c.each(b,function(b,c){var g=e;e=this._getModule(g,b,a,d),this._addModuleDefinition(g,e,h[c],f)},this),e},_getModule:function(a,b,d,e,f){var g=c.extend({},e),h=this.getClass(e),i=a[b];return i||(i=new h(b,d,g),a[b]=i,a.submodules[b]=i),i},getClass:function(a){var b=f.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 f.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 f.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)}))}}),f});
},proxyChildEvents:function(a){var b=this.getOption("childViewEventPrefix");this.listenTo(a,"all",function(){var d=c.toArray(arguments),e=d[0],f=this.normalizeMethods(c.result(this,"childEvents"));d[0]=b+":"+e,d.splice(1,0,a),"undefined"!=typeof f&&c.isFunction(f[e])&&f[e].apply(this,d.slice(1)),this.triggerMethod.apply(this,d)})},_getImmediateChildren:function(){return c.values(this.children._views)},_getViewAndNested:function(a){return[a].concat(c.result(a,"_getNestedViews")||[])},getViewComparator:function(){return this.getOption("viewComparator")}}),f.CompositeView=f.CollectionView.extend({constructor:function(){f.CollectionView.apply(this,arguments)},_initialEvents: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.getOption("sort")&&this.listenTo(this.collection,"sort",this._sortViews))},getChildView:function(a){var b=this.getOption("childView")||this.constructor;return b},serializeData:function(){var a={};return this.model&&(a=c.partial(this.serializeModel,this.model).apply(this,arguments)),a},render:function(){return this._ensureViewIsIntact(),this._isRendering=!0,this.resetChildViewContainer(),this.triggerMethod("before:render",this),this._renderTemplate(),this._renderChildren(),this._isRendering=!1,this.isRendered=!0,this.triggerMethod("render",this),this},_renderChildren:function(){(this.isRendered||this._isRendering)&&f.CollectionView.prototype._renderChildren.call(this)},_renderTemplate:function(){var a={};a=this.serializeData(),a=this.mixinTemplateHelpers(a),this.triggerMethod("before:render:template");var b=this.getTemplate(),c=f.Renderer.render(b,a,this);this.attachElContent(c),this.bindUIElements(),this.triggerMethod("render:template")},attachElContent:function(a){return this.$el.html(a),this},attachBuffer:function(a,b){var c=this.getChildViewContainer(a);c.append(b)},_insertAfter:function(a){var b=this.getChildViewContainer(this,a);b.append(a.el)},_appendReorderedChildren:function(a){var b=this.getChildViewContainer(this);b.append(a)},getChildViewContainer:function(a,b){if(a.$childViewContainer)return a.$childViewContainer;var c,d=f.getOption(a,"childViewContainer");if(d){var e=f._getValue(d,a);if(c="@"===e.charAt(0)&&a.ui?a.ui[e.substr(4)]:a.$(e),c.length<=0)throw new f.Error({name:"ChildViewContainerMissingError",message:'The specified "childViewContainer" was not found: '+a.childViewContainer})}else c=a.$el;return a.$childViewContainer=c,c},resetChildViewContainer:function(){this.$childViewContainer&&(this.$childViewContainer=void 0)}}),f.LayoutView=f.ItemView.extend({regionClass:f.Region,options:{destroyImmediate:!1},childViewEventPrefix:"childview",constructor:function(a){a=a||{},this._firstRender=!0,this._initializeRegions(a),f.ItemView.call(this,a)},render:function(){return this._ensureViewIsIntact(),this._firstRender?this._firstRender=!1:this._reInitializeRegions(),f.ItemView.prototype.render.apply(this,arguments)},destroy:function(){return this.isDestroyed?this:(this.getOption("destroyImmediate")===!0&&this.$el.remove(),this.regionManager.destroy(),f.ItemView.prototype.destroy.apply(this,arguments))},showChildView:function(a,b,d){var e=this.getRegion(a);return e.show.apply(e,c.rest(arguments))},getChildView:function(a){return this.getRegion(a).currentView},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)},getRegions:function(){return this.regionManager.getRegions()},_buildRegions:function(a){var b={regionClass:this.getOption("regionClass"),parentEl:c.partial(c.result,this,"el")};return this.regionManager.addRegions(a,b)},_initializeRegions:function(a){var b;this._initRegionManager(),b=f._getValue(this.regions,this,[a])||{};var d=this.getOption.call(a,"regions");d=f._getValue(d,this,[a]),c.extend(b,d),b=this.normalizeUIValues(b,["selector","el"]),this.addRegions(b)},_reInitializeRegions:function(){this.regionManager.invoke("reset")},getRegionManager:function(){return new f.RegionManager},_initRegionManager:function(){this.regionManager=this.getRegionManager(),this.regionManager._parent=this,this.listenTo(this.regionManager,"before:add:region",function(a){this.triggerMethod("before:add:region",a)}),this.listenTo(this.regionManager,"add:region",function(a,b){this[a]=b,this.triggerMethod("add:region",a,b)}),this.listenTo(this.regionManager,"before:remove:region",function(a){this.triggerMethod("before:remove:region",a)}),this.listenTo(this.regionManager,"remove:region",function(a,b){delete this[a],this.triggerMethod("remove:region",a,b)})},_getImmediateChildren:function(){return c.chain(this.regionManager.getRegions()).pluck("currentView").compact().value()}}),f.Behavior=f.Object.extend({constructor:function(a,b){this.view=b,this.defaults=c.result(this,"defaults")||{},this.options=c.extend({},this.defaults,a),this.ui=c.extend({},c.result(b,"ui"),c.result(this,"ui")),f.Object.apply(this,arguments)},$:function(){return this.view.$.apply(this.view,arguments)},destroy:function(){return this.stopListening(),this},proxyViewProperties:function(a){this.$el=a.$el,this.el=a.el}}),f.Behaviors=function(a,b){function c(a,d){return b.isObject(a.behaviors)?(d=c.parseBehaviors(a,d||b.result(a,"behaviors")),c.wrap(a,d,b.keys(g)),d):{}}function d(a,b){this._view=a,this._behaviors=b,this._triggers={}}function e(a){return a._uiBindings||a.ui}var f=/^(\S+)\s*(.*)$/,g={behaviorTriggers:function(a,b){var c=new d(this,b);return c.buildBehaviorTriggers()},behaviorEvents:function(c,d){var g={};return b.each(d,function(c,d){var h={},i=b.clone(b.result(c,"events"))||{};i=a.normalizeUIKeys(i,e(c));var j=0;b.each(i,function(a,e){var g=e.match(f),i=g[1]+"."+[this.cid,d,j++," "].join(""),k=g[2],l=i+k,m=b.isFunction(a)?a:c[a];m&&(h[l]=b.bind(m,c))},this),g=b.extend(g,h)},this),g}};return b.extend(c,{behaviorsLookup:function(){throw new a.Error({message:"You must define where your behaviors are stored.",url:"marionette.behaviors.html#behaviorslookup"})},getBehaviorClass:function(b,d){return b.behaviorClass?b.behaviorClass:a._getValue(c.behaviorsLookup,this,[b,d])[d]},parseBehaviors:function(a,d){return b.chain(d).map(function(d,e){var f=c.getBehaviorClass(d,e),g=new f(d,a),h=c.parseBehaviors(a,b.result(g,"behaviors"));return[g].concat(h)}).flatten().value()},wrap:function(a,c,d){b.each(d,function(d){a[d]=b.partial(g[d],a[d],c)})}}),b.extend(d.prototype,{buildBehaviorTriggers:function(){return b.each(this._behaviors,this._buildTriggerHandlersForBehavior,this),this._triggers},_buildTriggerHandlersForBehavior:function(c,d){var f=b.clone(b.result(c,"triggers"))||{};f=a.normalizeUIKeys(f,e(c)),b.each(f,b.bind(this._setHandlerForBehavior,this,c,d))},_setHandlerForBehavior:function(a,b,c,d){var e=d.replace(/^\S+/,function(a){return a+".behaviortriggers"+b});this._triggers[e]=this._view._buildViewTrigger(c)}}),c}(f,c),f.AppRouter=b.Router.extend({constructor:function(a){this.options=a||{},b.Router.apply(this,arguments);var c=this.getOption("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){if(c.isFunction(this.onRoute)){var d=c.invert(this.getOption("appRoutes"))[a];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 this.getOption("controller")},_addAppRoute:function(a,b,d){var e=a[d];if(!e)throw new f.Error('Method "'+d+'" was not found on the controller');this.route(b,d,c.bind(e,a))},mergeOptions:f.mergeOptions,getOption:f.proxyGetOption,triggerMethod:f.triggerMethod,bindEntityEvents:f.proxyBindEntityEvents,unbindEntityEvents:f.proxyUnbindEntityEvents}),f.Application=f.Object.extend({constructor:function(a){this._initializeRegions(a),this._initCallbacks=new f.Callbacks,this.submodules={},c.extend(this,a),this._initChannel(),f.Object.apply(this,arguments)},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("before:start",a),this._initCallbacks.run(a,this),this.triggerMethod("start",a)},addRegions:function(a){return this._regionManager.addRegions(a)},emptyRegions:function(){return this._regionManager.emptyRegions()},removeRegion:function(a){return this._regionManager.removeRegion(a)},getRegion:function(a){return this._regionManager.get(a)},getRegions:function(){return this._regionManager.getRegions()},module:function(a,b){var d=f.Module.getClass(b),e=c.toArray(arguments);return e.unshift(this),d.create.apply(d,e)},getRegionManager:function(){return new f.RegionManager},_initializeRegions:function(a){var b=c.isFunction(this.regions)?this.regions(a):this.regions||{};this._initRegionManager();var d=f.getOption(a,"regions");return c.isFunction(d)&&(d=d.call(this,a)),c.extend(b,d),this.addRegions(b),this},_initRegionManager:function(){this._regionManager=this.getRegionManager(),this._regionManager._parent=this,this.listenTo(this._regionManager,"before:add:region",function(){f._triggerMethod(this,"before:add:region",arguments)}),this.listenTo(this._regionManager,"add:region",function(a,b){this[a]=b,f._triggerMethod(this,"add:region",arguments)}),this.listenTo(this._regionManager,"before:remove:region",function(){f._triggerMethod(this,"before:remove:region",arguments)}),this.listenTo(this._regionManager,"remove:region",function(a){delete this[a],f._triggerMethod(this,"remove:region",arguments)})},_initChannel:function(){this.channelName=c.result(this,"channelName")||"global",this.channel=c.result(this,"channel")||b.Wreqr.radio.channel(this.channelName),this.vent=c.result(this,"vent")||this.channel.vent,this.commands=c.result(this,"commands")||this.channel.commands,this.reqres=c.result(this,"reqres")||this.channel.reqres}}),f.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,c.isFunction(this.initialize)&&this.initialize(a,b,this.options)},f.Module.extend=f.extend,c.extend(f.Module.prototype,b.Events,{startWithParent:!0,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,this.triggerMethod("before:stop"),c.invoke(this.submodules,"stop"),this._finalizerCallbacks.run(void 0,this),this._initializerCallbacks.reset(),this._finalizerCallbacks.reset(),this.triggerMethod("stop"))},addDefinition:function(a,b){this._runModuleDefinition(a,b)},_runModuleDefinition:function(a,d){if(a){var e=c.flatten([this,this.app,b,f,b.$,c,d]);a.apply(this,e)}},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new f.Callbacks,this._finalizerCallbacks=new f.Callbacks},triggerMethod:f.triggerMethod}),c.extend(f.Module,{create:function(a,b,d){var e=a,f=c.drop(arguments,3);b=b.split(".");var g=b.length,h=[];return h[g-1]=d,c.each(b,function(b,c){var g=e;e=this._getModule(g,b,a,d),this._addModuleDefinition(g,e,h[c],f)},this),e},_getModule:function(a,b,d,e,f){var g=c.extend({},e),h=this.getClass(e),i=a[b];return i||(i=new h(b,d,g),a[b]=i,a.submodules[b]=i),i},getClass:function(a){var b=f.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 f.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 f.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)}))}}),f});
Пример #9
0
!function(a){"use strict"}(window),function(a){var b="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global;if("function"==typeof define&&define.amd)define(["underscore","jquery","exports"],function(c,d,e){b.Backbone=a(b,e,c,d)});else if("undefined"!=typeof exports){var c,d=require("underscore");try{c=require("jquery")}catch(e){}a(b,exports,d,c)}else b.Backbone=a(b,{},b._,b.jQuery||b.Zepto||b.ender||b.$)}(function(a,b,c,d){var e=a.Backbone,f=Array.prototype.slice;b.VERSION="1.2.3",b.$=d,b.noConflict=function(){return a.Backbone=e,this},b.emulateHTTP=!1,b.emulateJSON=!1;var g=function(a,b,d){switch(a){case 1:return function(){return c[b](this[d])};case 2:return function(a){return c[b](this[d],a)};case 3:return function(a,e){return c[b](this[d],i(a,this),e)};case 4:return function(a,e,f){return c[b](this[d],i(a,this),e,f)};default:return function(){var a=f.call(arguments);return a.unshift(this[d]),c[b].apply(c,a)}}},h=function(a,b,d){c.each(b,function(b,e){c[e]&&(a.prototype[e]=g(b,e,d))})},i=function(a,b){return c.isFunction(a)?a:c.isObject(a)&&!b._isModel(a)?j(a):c.isString(a)?function(b){return b.get(a)}:a},j=function(a){var b=c.matches(a);return function(a){return b(a.attributes)}},k=b.Events={},l=/\s+/,m=function(a,b,d,e,f){var g,h=0;if(d&&"object"==typeof d){void 0!==e&&"context"in f&&void 0===f.context&&(f.context=e);for(g=c.keys(d);h<g.length;h++)b=m(a,b,g[h],d[g[h]],f)}else if(d&&l.test(d))for(g=d.split(l);h<g.length;h++)b=a(b,g[h],e,f);else b=a(b,d,e,f);return b};k.on=function(a,b,c){return n(this,a,b,c)};var n=function(a,b,c,d,e){if(a._events=m(o,a._events||{},b,c,{context:d,ctx:a,listening:e}),e){var f=a._listeners||(a._listeners={});f[e.id]=e}return a};k.listenTo=function(a,b,d){if(!a)return this;var e=a._listenId||(a._listenId=c.uniqueId("l")),f=this._listeningTo||(this._listeningTo={}),g=f[e];if(!g){var h=this._listenId||(this._listenId=c.uniqueId("l"));g=f[e]={obj:a,objId:e,id:h,listeningTo:f,count:0}}return n(a,b,d,this,g),this};var o=function(a,b,c,d){if(c){var e=a[b]||(a[b]=[]),f=d.context,g=d.ctx,h=d.listening;h&&h.count++,e.push({callback:c,context:f,ctx:f||g,listening:h})}return a};k.off=function(a,b,c){return this._events?(this._events=m(p,this._events,a,b,{context:c,listeners:this._listeners}),this):this},k.stopListening=function(a,b,d){var e=this._listeningTo;if(!e)return this;for(var f=a?[a._listenId]:c.keys(e),g=0;g<f.length;g++){var h=e[f[g]];if(!h)break;h.obj.off(b,d,this)}return c.isEmpty(e)&&(this._listeningTo=void 0),this};var p=function(a,b,d,e){if(a){var f,g=0,h=e.context,i=e.listeners;if(b||d||h){for(var j=b?[b]:c.keys(a);g<j.length;g++){b=j[g];var k=a[b];if(!k)break;for(var l=[],m=0;m<k.length;m++){var n=k[m];d&&d!==n.callback&&d!==n.callback._callback||h&&h!==n.context?l.push(n):(f=n.listening,f&&0===--f.count&&(delete i[f.id],delete f.listeningTo[f.objId]))}l.length?a[b]=l:delete a[b]}return c.size(a)?a:void 0}for(var o=c.keys(i);g<o.length;g++)f=i[o[g]],delete i[f.id],delete f.listeningTo[f.objId]}};k.once=function(a,b,d){var e=m(q,{},a,b,c.bind(this.off,this));return this.on(e,void 0,d)},k.listenToOnce=function(a,b,d){var e=m(q,{},b,d,c.bind(this.stopListening,this,a));return this.listenTo(a,e)};var q=function(a,b,d,e){if(d){var f=a[b]=c.once(function(){e(b,f),d.apply(this,arguments)});f._callback=d}return a};k.trigger=function(a){if(!this._events)return this;for(var b=Math.max(0,arguments.length-1),c=Array(b),d=0;b>d;d++)c[d]=arguments[d+1];return m(r,this._events,a,void 0,c),this};var r=function(a,b,c,d){if(a){var e=a[b],f=a.all;e&&f&&(f=f.slice()),e&&s(e,d),f&&s(f,[b].concat(d))}return a},s=function(a,b){var c,d=-1,e=a.length,f=b[0],g=b[1],h=b[2];switch(b.length){case 0:for(;++d<e;)(c=a[d]).callback.call(c.ctx);return;case 1:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f);return;case 2:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f,g);return;case 3:for(;++d<e;)(c=a[d]).callback.call(c.ctx,f,g,h);return;default:for(;++d<e;)(c=a[d]).callback.apply(c.ctx,b);return}};k.bind=k.on,k.unbind=k.off,c.extend(b,k);var t=b.Model=function(a,b){var d=a||{};b||(b={}),this.cid=c.uniqueId(this.cidPrefix),this.attributes={},b.collection&&(this.collection=b.collection),b.parse&&(d=this.parse(d,b)||{}),d=c.defaults({},d,c.result(this,"defaults")),this.set(d,b),this.changed={},this.initialize.apply(this,arguments)};c.extend(t.prototype,k,{changed:null,validationError:null,idAttribute:"id",cidPrefix:"c",initialize:function(){},toJSON:function(a){return c.clone(this.attributes)},sync:function(){return b.sync.apply(this,arguments)},get:function(a){return this.attributes[a]},escape:function(a){return c.escape(this.get(a))},has:function(a){return null!=this.get(a)},matches:function(a){return!!c.iteratee(a,this)(this.attributes)},set:function(a,b,d){if(null==a)return this;var e;if("object"==typeof a?(e=a,d=b):(e={})[a]=b,d||(d={}),!this._validate(e,d))return!1;var f=d.unset,g=d.silent,h=[],i=this._changing;this._changing=!0,i||(this._previousAttributes=c.clone(this.attributes),this.changed={});var j=this.attributes,k=this.changed,l=this._previousAttributes;for(var m in e)b=e[m],c.isEqual(j[m],b)||h.push(m),c.isEqual(l[m],b)?delete k[m]:k[m]=b,f?delete j[m]:j[m]=b;if(this.idAttribute in e&&(this.id=this.get(this.idAttribute)),!g){h.length&&(this._pending=d);for(var n=0;n<h.length;n++)this.trigger("change:"+h[n],this,j[h[n]],d)}if(i)return this;if(!g)for(;this._pending;)d=this._pending,this._pending=!1,this.trigger("change",this,d);return this._pending=!1,this._changing=!1,this},unset:function(a,b){return this.set(a,void 0,c.extend({},b,{unset:!0}))},clear:function(a){var b={};for(var d in this.attributes)b[d]=void 0;return this.set(b,c.extend({},a,{unset:!0}))},hasChanged:function(a){return null==a?!c.isEmpty(this.changed):c.has(this.changed,a)},changedAttributes:function(a){if(!a)return this.hasChanged()?c.clone(this.changed):!1;var b=this._changing?this._previousAttributes:this.attributes,d={};for(var e in a){var f=a[e];c.isEqual(b[e],f)||(d[e]=f)}return c.size(d)?d:!1},previous:function(a){return null!=a&&this._previousAttributes?this._previousAttributes[a]:null},previousAttributes:function(){return c.clone(this._previousAttributes)},fetch:function(a){a=c.extend({parse:!0},a);var b=this,d=a.success;return a.success=function(c){var e=a.parse?b.parse(c,a):c;return b.set(e,a)?(d&&d.call(a.context,b,c,a),void b.trigger("sync",b,c,a)):!1},P(this,a),this.sync("read",this,a)},save:function(a,b,d){var e;null==a||"object"==typeof a?(e=a,d=b):(e={})[a]=b,d=c.extend({validate:!0,parse:!0},d);var f=d.wait;if(e&&!f){if(!this.set(e,d))return!1}else if(!this._validate(e,d))return!1;var g=this,h=d.success,i=this.attributes;d.success=function(a){g.attributes=i;var b=d.parse?g.parse(a,d):a;return f&&(b=c.extend({},e,b)),b&&!g.set(b,d)?!1:(h&&h.call(d.context,g,a,d),void g.trigger("sync",g,a,d))},P(this,d),e&&f&&(this.attributes=c.extend({},i,e));var j=this.isNew()?"create":d.patch?"patch":"update";"patch"!==j||d.attrs||(d.attrs=e);var k=this.sync(j,this,d);return this.attributes=i,k},destroy:function(a){a=a?c.clone(a):{};var b=this,d=a.success,e=a.wait,f=function(){b.stopListening(),b.trigger("destroy",b,b.collection,a)};a.success=function(c){e&&f(),d&&d.call(a.context,b,c,a),b.isNew()||b.trigger("sync",b,c,a)};var g=!1;return this.isNew()?c.defer(a.success):(P(this,a),g=this.sync("delete",this,a)),e||f(),g},url:function(){var a=c.result(this,"urlRoot")||c.result(this.collection,"url")||O();if(this.isNew())return a;var b=this.get(this.idAttribute);return a.replace(/[^\/]$/,"$&/")+encodeURIComponent(b)},parse:function(a,b){return a},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return!this.has(this.idAttribute)},isValid:function(a){return this._validate({},c.defaults({validate:!0},a))},_validate:function(a,b){if(!b.validate||!this.validate)return!0;a=c.extend({},this.attributes,a);var d=this.validationError=this.validate(a,b)||null;return d?(this.trigger("invalid",this,d,c.extend(b,{validationError:d})),!1):!0}});var u={keys:1,values:1,pairs:1,invert:1,pick:0,omit:0,chain:1,isEmpty:1};h(t,u,"attributes");var v=b.Collection=function(a,b){b||(b={}),b.model&&(this.model=b.model),void 0!==b.comparator&&(this.comparator=b.comparator),this._reset(),this.initialize.apply(this,arguments),a&&this.reset(a,c.extend({silent:!0},b))},w={add:!0,remove:!0,merge:!0},x={add:!0,remove:!1},y=function(a,b,c){c=Math.min(Math.max(c,0),a.length);var d,e=Array(a.length-c),f=b.length;for(d=0;d<e.length;d++)e[d]=a[d+c];for(d=0;f>d;d++)a[d+c]=b[d];for(d=0;d<e.length;d++)a[d+f+c]=e[d]};c.extend(v.prototype,k,{model:t,initialize:function(){},toJSON:function(a){return this.map(function(b){return b.toJSON(a)})},sync:function(){return b.sync.apply(this,arguments)},add:function(a,b){return this.set(a,c.extend({merge:!1},b,x))},remove:function(a,b){b=c.extend({},b);var d=!c.isArray(a);a=d?[a]:a.slice();var e=this._removeModels(a,b);return!b.silent&&e.length&&this.trigger("update",this,b),d?e[0]:e},set:function(a,b){if(null!=a){b=c.defaults({},b,w),b.parse&&!this._isModel(a)&&(a=this.parse(a,b)||[]);var d=!c.isArray(a);a=d?[a]:a.slice();var e=b.at;null!=e&&(e=+e),0>e&&(e+=this.length+1);var f,g,h=[],i=[],j=[],k={},l=b.add,m=b.merge,n=b.remove,o=!1,p=this.comparator&&null==e&&b.sort!==!1,q=c.isString(this.comparator)?this.comparator:null;for(g=0;g<a.length;g++){f=a[g];var r=this.get(f);if(r){if(m&&f!==r){var s=this._isModel(f)?f.attributes:f;b.parse&&(s=r.parse(s,b)),r.set(s,b),p&&!o&&(o=r.hasChanged(q))}k[r.cid]||(k[r.cid]=!0,h.push(r)),a[g]=r}else l&&(f=a[g]=this._prepareModel(f,b),f&&(i.push(f),this._addReference(f,b),k[f.cid]=!0,h.push(f)))}if(n){for(g=0;g<this.length;g++)f=this.models[g],k[f.cid]||j.push(f);j.length&&this._removeModels(j,b)}var t=!1,u=!p&&l&&n;if(h.length&&u?(t=this.length!==h.length||c.some(this.models,function(a,b){return a!==h[b]}),this.models.length=0,y(this.models,h,0),this.length=this.models.length):i.length&&(p&&(o=!0),y(this.models,i,null==e?this.length:e),this.length=this.models.length),o&&this.sort({silent:!0}),!b.silent){for(g=0;g<i.length;g++)null!=e&&(b.index=e+g),f=i[g],f.trigger("add",f,this,b);(o||t)&&this.trigger("sort",this,b),(i.length||j.length)&&this.trigger("update",this,b)}return d?a[0]:a}},reset:function(a,b){b=b?c.clone(b):{};for(var d=0;d<this.models.length;d++)this._removeReference(this.models[d],b);return b.previousModels=this.models,this._reset(),a=this.add(a,c.extend({silent:!0},b)),b.silent||this.trigger("reset",this,b),a},push:function(a,b){return this.add(a,c.extend({at:this.length},b))},pop:function(a){var b=this.at(this.length-1);return this.remove(b,a)},unshift:function(a,b){return this.add(a,c.extend({at:0},b))},shift:function(a){var b=this.at(0);return this.remove(b,a)},slice:function(){return f.apply(this.models,arguments)},get:function(a){if(null==a)return void 0;var b=this.modelId(this._isModel(a)?a.attributes:a);return this._byId[a]||this._byId[b]||this._byId[a.cid]},has:function(a){return null!=this.get(a)},at:function(a){return 0>a&&(a+=this.length),this.models[a]},where:function(a,b){return this[b?"find":"filter"](a)},findWhere:function(a){return this.where(a,!0)},sort:function(a){var b=this.comparator;if(!b)throw new Error("Cannot sort a set without a comparator");a||(a={});var d=b.length;return c.isFunction(b)&&(b=c.bind(b,this)),1===d||c.isString(b)?this.models=this.sortBy(b):this.models.sort(b),a.silent||this.trigger("sort",this,a),this},pluck:function(a){return this.map(a+"")},fetch:function(a){a=c.extend({parse:!0},a);var b=a.success,d=this;return a.success=function(c){var e=a.reset?"reset":"set";d[e](c,a),b&&b.call(a.context,d,c,a),d.trigger("sync",d,c,a)},P(this,a),this.sync("read",this,a)},create:function(a,b){b=b?c.clone(b):{};var d=b.wait;if(a=this._prepareModel(a,b),!a)return!1;d||this.add(a,b);var e=this,f=b.success;return b.success=function(a,b,c){d&&e.add(a,c),f&&f.call(c.context,a,b,c)},a.save(null,b),a},parse:function(a,b){return a},clone:function(){return new this.constructor(this.models,{model:this.model,comparator:this.comparator})},modelId:function(a){return a[this.model.prototype.idAttribute||"id"]},_reset:function(){this.length=0,this.models=[],this._byId={}},_prepareModel:function(a,b){if(this._isModel(a))return a.collection||(a.collection=this),a;b=b?c.clone(b):{},b.collection=this;var d=new this.model(a,b);return d.validationError?(this.trigger("invalid",this,d.validationError,b),!1):d},_removeModels:function(a,b){for(var c=[],d=0;d<a.length;d++){var e=this.get(a[d]);if(e){var f=this.indexOf(e);this.models.splice(f,1),this.length--,delete this._byId[e.cid];var g=this.modelId(e.attributes);null!=g&&delete this._byId[g],b.silent||(b.index=f,e.trigger("remove",e,this,b)),c.push(e),this._removeReference(e,b)}}return c},_isModel:function(a){return a instanceof t},_addReference:function(a,b){this._byId[a.cid]=a;var c=this.modelId(a.attributes);null!=c&&(this._byId[c]=a),a.on("all",this._onModelEvent,this)},_removeReference:function(a,b){delete this._byId[a.cid];var c=this.modelId(a.attributes);null!=c&&delete this._byId[c],this===a.collection&&delete a.collection,a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,b,c,d){if(b){if(("add"===a||"remove"===a)&&c!==this)return;if("destroy"===a&&this.remove(b,d),"change"===a){var e=this.modelId(b.previousAttributes()),f=this.modelId(b.attributes);e!==f&&(null!=e&&delete this._byId[e],null!=f&&(this._byId[f]=b))}}this.trigger.apply(this,arguments)}});var z={forEach:3,each:3,map:3,collect:3,reduce:0,foldl:0,inject:0,reduceRight:0,foldr:0,find:3,detect:3,filter:3,select:3,reject:3,every:3,all:3,some:3,any:3,include:3,includes:3,contains:3,invoke:0,max:3,min:3,toArray:1,size:1,first:3,head:3,take:3,initial:3,rest:3,tail:3,drop:3,last:3,without:0,difference:0,indexOf:3,shuffle:1,lastIndexOf:3,isEmpty:1,chain:1,sample:3,partition:3,groupBy:3,countBy:3,sortBy:3,indexBy:3,findIndex:3,findLastIndex:3};h(v,z,"models");var A=b.View=function(a){this.cid=c.uniqueId("view"),c.extend(this,c.pick(a,C)),this._ensureElement(),this.initialize.apply(this,arguments)},B=/^(\S+)\s*(.*)$/,C=["model","collection","el","id","attributes","className","tagName","events"];c.extend(A.prototype,k,{tagName:"div",$:function(a){return this.$el.find(a)},initialize:function(){},render:function(){return this},remove:function(){return this._removeElement(),this.stopListening(),this},_removeElement:function(){this.$el.remove()},setElement:function(a){return this.undelegateEvents(),this._setElement(a),this.delegateEvents(),this},_setElement:function(a){this.$el=a instanceof b.$?a:b.$(a),this.el=this.$el[0]},delegateEvents:function(a){if(a||(a=c.result(this,"events")),!a)return this;this.undelegateEvents();for(var b in a){var d=a[b];if(c.isFunction(d)||(d=this[d]),d){var e=b.match(B);this.delegate(e[1],e[2],c.bind(d,this))}}return this},delegate:function(a,b,c){return this.$el.on(a+".delegateEvents"+this.cid,b,c),this},undelegateEvents:function(){return this.$el&&this.$el.off(".delegateEvents"+this.cid),this},undelegate:function(a,b,c){return this.$el.off(a+".delegateEvents"+this.cid,b,c),this},_createElement:function(a){return document.createElement(a)},_ensureElement:function(){if(this.el)this.setElement(c.result(this,"el"));else{var a=c.extend({},c.result(this,"attributes"));this.id&&(a.id=c.result(this,"id")),this.className&&(a["class"]=c.result(this,"className")),this.setElement(this._createElement(c.result(this,"tagName"))),this._setAttributes(a)}},_setAttributes:function(a){this.$el.attr(a)}}),b.sync=function(a,d,e){var f=D[a];c.defaults(e||(e={}),{emulateHTTP:b.emulateHTTP,emulateJSON:b.emulateJSON});var g={type:f,dataType:"json"};if(e.url||(g.url=c.result(d,"url")||O()),null!=e.data||!d||"create"!==a&&"update"!==a&&"patch"!==a||(g.contentType="application/json",g.data=JSON.stringify(e.attrs||d.toJSON(e))),e.emulateJSON&&(g.contentType="application/x-www-form-urlencoded",g.data=g.data?{model:g.data}:{}),e.emulateHTTP&&("PUT"===f||"DELETE"===f||"PATCH"===f)){g.type="POST",e.emulateJSON&&(g.data._method=f);var h=e.beforeSend;e.beforeSend=function(a){return a.setRequestHeader("X-HTTP-Method-Override",f),h?h.apply(this,arguments):void 0}}"GET"===g.type||e.emulateJSON||(g.processData=!1);var i=e.error;e.error=function(a,b,c){e.textStatus=b,e.errorThrown=c,i&&i.call(e.context,a,b,c)};var j=e.xhr=b.ajax(c.extend(g,e));return d.trigger("request",d,j,e),j};var D={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};b.ajax=function(){return b.$.ajax.apply(b.$,arguments)};var E=b.Router=function(a){a||(a={}),a.routes&&(this.routes=a.routes),this._bindRoutes(),this.initialize.apply(this,arguments)},F=/\((.*?)\)/g,G=/(\(\?)?:\w+/g,H=/\*\w+/g,I=/[\-{}\[\]+?.,\\\^$|#\s]/g;c.extend(E.prototype,k,{initialize:function(){},route:function(a,d,e){c.isRegExp(a)||(a=this._routeToRegExp(a)),c.isFunction(d)&&(e=d,d=""),e||(e=this[d]);var f=this;return b.history.route(a,function(c){var g=f._extractParameters(a,c);f.execute(e,g,d)!==!1&&(f.trigger.apply(f,["route:"+d].concat(g)),f.trigger("route",d,g),b.history.trigger("route",f,d,g))}),this},execute:function(a,b,c){a&&a.apply(this,b)},navigate:function(a,c){return b.history.navigate(a,c),this},_bindRoutes:function(){if(this.routes){this.routes=c.result(this,"routes");for(var a,b=c.keys(this.routes);null!=(a=b.pop());)this.route(a,this.routes[a])}},_routeToRegExp:function(a){return a=a.replace(I,"\\$&").replace(F,"(?:$1)?").replace(G,function(a,b){return b?a:"([^/?]+)"}).replace(H,"([^?]*?)"),new RegExp("^"+a+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(a,b){var d=a.exec(b).slice(1);return c.map(d,function(a,b){return b===d.length-1?a||null:a?decodeURIComponent(a):null})}});var J=b.History=function(){this.handlers=[],this.checkUrl=c.bind(this.checkUrl,this),"undefined"!=typeof window&&(this.location=window.location,this.history=window.history)},K=/^[#\/]|\s+$/g,L=/^\/+|\/+$/g,M=/#.*$/;J.started=!1,c.extend(J.prototype,k,{interval:50,atRoot:function(){var a=this.location.pathname.replace(/[^\/]$/,"$&/");return a===this.root&&!this.getSearch()},matchRoot:function(){var a=this.decodeFragment(this.location.pathname),b=a.slice(0,this.root.length-1)+"/";return b===this.root},decodeFragment:function(a){return decodeURI(a.replace(/%25/g,"%2525"))},getSearch:function(){var a=this.location.href.replace(/#.*/,"").match(/\?.+/);return a?a[0]:""},getHash:function(a){var b=(a||this).location.href.match(/#(.*)$/);return b?b[1]:""},getPath:function(){var a=this.decodeFragment(this.location.pathname+this.getSearch()).slice(this.root.length-1);return"/"===a.charAt(0)?a.slice(1):a},getFragment:function(a){return null==a&&(a=this._usePushState||!this._wantsHashChange?this.getPath():this.getHash()),a.replace(K,"")},start:function(a){if(J.started)throw new Error("Backbone.history has already been started");if(J.started=!0,this.options=c.extend({root:"/"},this.options,a),this.root=this.options.root,this._wantsHashChange=this.options.hashChange!==!1,this._hasHashChange="onhashchange"in window&&(void 0===document.documentMode||document.documentMode>7),this._useHashChange=this._wantsHashChange&&this._hasHashChange,this._wantsPushState=!!this.options.pushState,this._hasPushState=!(!this.history||!this.history.pushState),this._usePushState=this._wantsPushState&&this._hasPushState,this.fragment=this.getFragment(),this.root=("/"+this.root+"/").replace(L,"/"),this._wantsHashChange&&this._wantsPushState){if(!this._hasPushState&&!this.atRoot()){var b=this.root.slice(0,-1)||"/";return this.location.replace(b+"#"+this.getPath()),!0}this._hasPushState&&this.atRoot()&&this.navigate(this.getHash(),{replace:!0})}if(!this._hasHashChange&&this._wantsHashChange&&!this._usePushState){this.iframe=document.createElement("iframe"),this.iframe.src="javascript:0",this.iframe.style.display="none",this.iframe.tabIndex=-1;var d=document.body,e=d.insertBefore(this.iframe,d.firstChild).contentWindow;e.document.open(),e.document.close(),e.location.hash="#"+this.fragment}var f=window.addEventListener||function(a,b){return attachEvent("on"+a,b)};return this._usePushState?f("popstate",this.checkUrl,!1):this._useHashChange&&!this.iframe?f("hashchange",this.checkUrl,!1):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,this.interval)),this.options.silent?void 0:this.loadUrl()},stop:function(){var a=window.removeEventListener||function(a,b){return detachEvent("on"+a,b)};this._usePushState?a("popstate",this.checkUrl,!1):this._useHashChange&&!this.iframe&&a("hashchange",this.checkUrl,!1),this.iframe&&(document.body.removeChild(this.iframe),this.iframe=null),this._checkUrlInterval&&clearInterval(this._checkUrlInterval),J.started=!1},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(a){var b=this.getFragment();return b===this.fragment&&this.iframe&&(b=this.getHash(this.iframe.contentWindow)),b===this.fragment?!1:(this.iframe&&this.navigate(b),void this.loadUrl())},loadUrl:function(a){return this.matchRoot()?(a=this.fragment=this.getFragment(a),c.some(this.handlers,function(b){return b.route.test(a)?(b.callback(a),!0):void 0})):!1},navigate:function(a,b){if(!J.started)return!1;b&&b!==!0||(b={trigger:!!b}),a=this.getFragment(a||"");var c=this.root;(""===a||"?"===a.charAt(0))&&(c=c.slice(0,-1)||"/");var d=c+a;if(a=this.decodeFragment(a.replace(M,"")),this.fragment!==a){if(this.fragment=a,this._usePushState)this.history[b.replace?"replaceState":"pushState"]({},document.title,d);else{if(!this._wantsHashChange)return this.location.assign(d);if(this._updateHash(this.location,a,b.replace),this.iframe&&a!==this.getHash(this.iframe.contentWindow)){var e=this.iframe.contentWindow;b.replace||(e.document.open(),e.document.close()),this._updateHash(e.location,a,b.replace)}}return b.trigger?this.loadUrl(a):void 0}},_updateHash:function(a,b,c){if(c){var d=a.href.replace(/(javascript:|#).*$/,"");a.replace(d+"#"+b)}else a.hash="#"+b}}),b.history=new J;var N=function(a,b){var d,e=this;return d=a&&c.has(a,"constructor")?a.constructor:function(){return e.apply(this,arguments)},c.extend(d,e,b),d.prototype=c.create(e.prototype,a),d.prototype.constructor=d,d.__super__=e.prototype,d};t.extend=v.extend=E.extend=A.extend=J.extend=N;var O=function(){throw new Error('A "url" property or function must be specified')},P=function(a,b){var c=b.error;b.error=function(d){c&&c.call(b.context,a,d,b),a.trigger("error",a,d,b)}};return b}),function(){var a="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this,b=a._,c=Array.prototype,d=Object.prototype,e=c.push,f=c.slice,g=d.toString,h=d.hasOwnProperty,i=Array.isArray,j=Object.keys,k=Object.create,l=function(){},m=function(a){return a instanceof m?a:this instanceof m?void(this._wrapped=a):new m(a)};"undefined"==typeof exports||exports.nodeType?a._=m:("undefined"!=typeof module&&!module.nodeType&&module.exports&&(exports=module.exports=m),exports._=m),m.VERSION="1.8.3";var n=function(a,b,c){if(void 0===b)return a;switch(null==c?3:c){case 1:return function(c){return a.call(b,c)};case 3:return function(c,d,e){return a.call(b,c,d,e)};case 4:return function(c,d,e,f){return a.call(b,c,d,e,f)}}return function(){return a.apply(b,arguments)}},o=function(a,b,c){return null==a?m.identity:m.isFunction(a)?n(a,b,c):m.isObject(a)?m.matcher(a):m.property(a)};m.iteratee=function(a,b){return o(a,b,1/0)};var p=function(a,b){return b=null==b?a.length-1:+b,function(){for(var c=Math.max(arguments.length-b,0),d=Array(c),e=0;c>e;e++)d[e]=arguments[e+b];switch(b){case 0:return a.call(this,d);case 1:return a.call(this,arguments[0],d);case 2:return a.call(this,arguments[0],arguments[1],d)}var f=Array(b+1);for(e=0;b>e;e++)f[e]=arguments[e];return f[b]=d,a.apply(this,f)}},q=function(a){if(!m.isObject(a))return{};if(k)return k(a);l.prototype=a;var b=new l;return l.prototype=null,b},r=function(a){return function(b){return null==b?void 0:b[a]}},s=Math.pow(2,53)-1,t=r("length"),u=function(a){var b=t(a);return"number"==typeof b&&b>=0&&s>=b};m.each=m.forEach=function(a,b,c){b=n(b,c);var d,e;if(u(a))for(d=0,e=a.length;e>d;d++)b(a[d],d,a);else{var f=m.keys(a);for(d=0,e=f.length;e>d;d++)b(a[f[d]],f[d],a)}return a},m.map=m.collect=function(a,b,c){b=o(b,c);for(var d=!u(a)&&m.keys(a),e=(d||a).length,f=Array(e),g=0;e>g;g++){var h=d?d[g]:g;f[g]=b(a[h],h,a)}return f};var v=function(a){var b=function(b,c,d,e){var f=!u(b)&&m.keys(b),g=(f||b).length,h=a>0?0:g-1;for(e||(d=b[f?f[h]:h],h+=a);h>=0&&g>h;h+=a){var i=f?f[h]:h;d=c(d,b[i],i,b)}return d};return function(a,c,d,e){var f=arguments.length>=3;return b(a,n(c,e,4),d,f)}};m.reduce=m.foldl=m.inject=v(1),m.reduceRight=m.foldr=v(-1),m.find=m.detect=function(a,b,c){var d;return d=u(a)?m.findIndex(a,b,c):m.findKey(a,b,c),void 0!==d&&-1!==d?a[d]:void 0},m.filter=m.select=function(a,b,c){var d=[];return b=o(b,c),m.each(a,function(a,c,e){b(a,c,e)&&d.push(a)}),d},m.reject=function(a,b,c){return m.filter(a,m.negate(o(b)),c)},m.every=m.all=function(a,b,c){b=o(b,c);for(var d=!u(a)&&m.keys(a),e=(d||a).length,f=0;e>f;f++){var g=d?d[f]:f;if(!b(a[g],g,a))return!1}return!0},m.some=m.any=function(a,b,c){b=o(b,c);for(var d=!u(a)&&m.keys(a),e=(d||a).length,f=0;e>f;f++){var g=d?d[f]:f;if(b(a[g],g,a))return!0}return!1},m.contains=m.includes=m.include=function(a,b,c,d){return u(a)||(a=m.values(a)),("number"!=typeof c||d)&&(c=0),m.indexOf(a,b,c)>=0},m.invoke=p(function(a,b,c){var d=m.isFunction(b);return m.map(a,function(a){var e=d?b:a[b];return null==e?e:e.apply(a,c)})}),m.pluck=function(a,b){return m.map(a,m.property(b))},m.where=function(a,b){return m.filter(a,m.matcher(b))},m.findWhere=function(a,b){return m.find(a,m.matcher(b))},m.max=function(a,b,c){var d,e,f=-(1/0),g=-(1/0);if(null==b||"number"==typeof b&&"object"!=typeof a[0]&&null!=a){a=u(a)?a:m.values(a);for(var h=0,i=a.length;i>h;h++)d=a[h],null!=d&&d>f&&(f=d)}else b=o(b,c),m.each(a,function(a,c,d){e=b(a,c,d),(e>g||e===-(1/0)&&f===-(1/0))&&(f=a,g=e)});return f},m.min=function(a,b,c){var d,e,f=1/0,g=1/0;if(null==b||"number"==typeof b&&"object"!=typeof a[0]&&null!=a){a=u(a)?a:m.values(a);for(var h=0,i=a.length;i>h;h++)d=a[h],null!=d&&f>d&&(f=d)}else b=o(b,c),m.each(a,function(a,c,d){e=b(a,c,d),(g>e||e===1/0&&f===1/0)&&(f=a,g=e)});return f},m.shuffle=function(a){return m.sample(a,1/0)},m.sample=function(a,b,c){if(null==b||c)return u(a)||(a=m.values(a)),a[m.random(a.length-1)];var d=u(a)?m.clone(a):m.values(a),e=t(d);b=Math.max(Math.min(b,e),0);for(var f=e-1,g=0;b>g;g++){var h=m.random(g,f),i=d[g];d[g]=d[h],d[h]=i}return d.slice(0,b)},m.sortBy=function(a,b,c){var d=0;return b=o(b,c),m.pluck(m.map(a,function(a,c,e){return{value:a,index:d++,criteria:b(a,c,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;if(c!==d){if(c>d||void 0===c)return 1;if(d>c||void 0===d)return-1}return a.index-b.index}),"value")};var w=function(a,b){return function(c,d,e){var f=b?[[],[]]:{};return d=o(d,e),m.each(c,function(b,e){var g=d(b,e,c);a(f,b,g)}),f}};m.groupBy=w(function(a,b,c){m.has(a,c)?a[c].push(b):a[c]=[b]}),m.indexBy=w(function(a,b,c){a[c]=b}),m.countBy=w(function(a,b,c){m.has(a,c)?a[c]++:a[c]=1});var x=/[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;m.toArray=function(a){return a?m.isArray(a)?f.call(a):m.isString(a)?a.match(x):u(a)?m.map(a,m.identity):m.values(a):[]},m.size=function(a){return null==a?0:u(a)?a.length:m.keys(a).length},m.partition=w(function(a,b,c){a[c?0:1].push(b)},!0),m.first=m.head=m.take=function(a,b,c){return null==a?void 0:null==b||c?a[0]:m.initial(a,a.length-b)},m.initial=function(a,b,c){return f.call(a,0,Math.max(0,a.length-(null==b||c?1:b)))},m.last=function(a,b,c){return null==a?void 0:null==b||c?a[a.length-1]:m.rest(a,Math.max(0,a.length-b))},m.rest=m.tail=m.drop=function(a,b,c){return f.call(a,null==b||c?1:b)},m.compact=function(a){return m.filter(a,m.identity)};var y=function(a,b,c,d){d=d||[];for(var e=d.length,f=0,g=t(a);g>f;f++){var h=a[f];if(u(h)&&(m.isArray(h)||m.isArguments(h)))if(b)for(var i=0,j=h.length;j>i;)d[e++]=h[i++];else y(h,b,c,d),e=d.length;else c||(d[e++]=h)}return d};m.flatten=function(a,b){return y(a,b,!1)},m.without=p(function(a,b){return m.difference(a,b)}),m.uniq=m.unique=function(a,b,c,d){m.isBoolean(b)||(d=c,c=b,b=!1),null!=c&&(c=o(c,d));for(var e=[],f=[],g=0,h=t(a);h>g;g++){var i=a[g],j=c?c(i,g,a):i;b?(g&&f===j||e.push(i),f=j):c?m.contains(f,j)||(f.push(j),e.push(i)):m.contains(e,i)||e.push(i)}return e},m.union=p(function(a){return m.uniq(y(a,!0,!0))}),m.intersection=function(a){for(var b=[],c=arguments.length,d=0,e=t(a);e>d;d++){var f=a[d];if(!m.contains(b,f)){var g;for(g=1;c>g&&m.contains(arguments[g],f);g++);g===c&&b.push(f)}}return b},m.difference=p(function(a,b){return b=y(b,!0,!0),m.filter(a,function(a){return!m.contains(b,a)})}),m.unzip=function(a){for(var b=a&&m.max(a,t).length||0,c=Array(b),d=0;b>d;d++)c[d]=m.pluck(a,d);return c},m.zip=p(m.unzip),m.object=function(a,b){for(var c={},d=0,e=t(a);e>d;d++)b?c[a[d]]=b[d]:c[a[d][0]]=a[d][1];return c};var z=function(a){return function(b,c,d){c=o(c,d);for(var e=t(b),f=a>0?0:e-1;f>=0&&e>f;f+=a)if(c(b[f],f,b))return f;return-1}};m.findIndex=z(1),m.findLastIndex=z(-1),m.sortedIndex=function(a,b,c,d){c=o(c,d,1);for(var e=c(b),f=0,g=t(a);g>f;){var h=Math.floor((f+g)/2);c(a[h])<e?f=h+1:g=h}return f};var A=function(a,b,c){return function(d,e,g){var h=0,i=t(d);if("number"==typeof g)a>0?h=g>=0?g:Math.max(g+i,h):i=g>=0?Math.min(g+1,i):g+i+1;else if(c&&g&&i)return g=c(d,e),d[g]===e?g:-1;if(e!==e)return g=b(f.call(d,h,i),m.isNaN),g>=0?g+h:-1;for(g=a>0?h:i-1;g>=0&&i>g;g+=a)if(d[g]===e)return g;return-1}};m.indexOf=A(1,m.findIndex,m.sortedIndex),m.lastIndexOf=A(-1,m.findLastIndex),m.range=function(a,b,c){null==b&&(b=a||0,a=0),c||(c=a>b?-1:1);for(var d=Math.max(Math.ceil((b-a)/c),0),e=Array(d),f=0;d>f;f++,a+=c)e[f]=a;return e},m.chunk=function(a,b){if(null==b||1>b)return[];for(var c=[],d=0,e=a.length;e>d;)c.push(f.call(a,d,d+=b));return c};var B=function(a,b,c,d,e){if(!(d instanceof b))return a.apply(c,e);var f=q(a.prototype),g=a.apply(f,e);return m.isObject(g)?g:f};m.bind=p(function(a,b,c){if(!m.isFunction(a))throw new TypeError("Bind must be called on a function");var d=p(function(e){return B(a,d,b,this,c.concat(e))});return d}),m.partial=p(function(a,b){var c=m.partial.placeholder,d=function(){for(var e=0,f=b.length,g=Array(f),h=0;f>h;h++)g[h]=b[h]===c?arguments[e++]:b[h];for(;e<arguments.length;)g.push(arguments[e++]);return B(a,d,this,this,g)};return d}),m.partial.placeholder=m,m.bindAll=p(function(a,b){b=y(b,!1,!1);var c=b.length;if(1>c)throw new Error("bindAll must be passed function names");for(;c--;){var d=b[c];a[d]=m.bind(a[d],a)}}),m.memoize=function(a,b){var c=function(d){var e=c.cache,f=""+(b?b.apply(this,arguments):d);return m.has(e,f)||(e[f]=a.apply(this,arguments)),e[f]};return c.cache={},c},m.delay=p(function(a,b,c){return setTimeout(function(){return a.apply(null,c)},b)}),m.defer=m.partial(m.delay,m,1),m.throttle=function(a,b,c){var d,e,f,g,h=0;c||(c={});var i=function(){h=c.leading===!1?0:m.now(),d=null,g=a.apply(e,f),d||(e=f=null)},j=function(){var j=m.now();h||c.leading!==!1||(h=j);var k=b-(j-h);return e=this,f=arguments,0>=k||k>b?(d&&(clearTimeout(d),d=null),h=j,g=a.apply(e,f),d||(e=f=null)):d||c.trailing===!1||(d=setTimeout(i,k)),g};return j.cancel=function(){clearTimeout(d),h=0,d=e=f=null},j},m.debounce=function(a,b,c){var d,e,f=function(b,c){d=null,c&&(e=a.apply(b,c))},g=p(function(g){var h=c&&!d;return d&&clearTimeout(d),h?(d=setTimeout(f,b),e=a.apply(this,g)):c||(d=m.delay(f,b,this,g)),e});return g.cancel=function(){clearTimeout(d),d=null},g},m.wrap=function(a,b){return m.partial(b,a)},m.negate=function(a){return function(){return!a.apply(this,arguments)}},m.compose=function(){var a=arguments,b=a.length-1;return function(){for(var c=b,d=a[b].apply(this,arguments);c--;)d=a[c].call(this,d);return d}},m.after=function(a,b){return function(){return--a<1?b.apply(this,arguments):void 0}},m.before=function(a,b){var c;return function(){return--a>0&&(c=b.apply(this,arguments)),1>=a&&(b=null),
(function(e,t){if("function"==typeof define&&define.amd)define(["backbone","underscore","backbone.wreqr","backbone.babysitter"],function(i,n){return e.Marionette=e.Mn=t(e,i,n)});else if("undefined"!=typeof exports){var i=require("backbone"),n=require("underscore");require("backbone.wreqr"),require("backbone.babysitter"),module.exports=t(e,i,n)}else e.Marionette=e.Mn=t(e,e.Backbone,e._)})(this,function(e,t,i){"use strict";var n=e.Marionette,r=e.Mn,s=t.Marionette={};s.VERSION="2.3.2",s.noConflict=function(){return e.Marionette=n,e.Mn=r,this},s.Deferred=t.$.Deferred,s.extend=t.Model.extend,s.isNodeAttached=function(e){return t.$.contains(document.documentElement,e)},s.getOption=function(e,t){return e&&t?e.options&&void 0!==e.options[t]?e.options[t]:e[t]:void 0},s.proxyGetOption=function(e){return s.getOption(this,e)},s._getValue=function(e,t,n){return i.isFunction(e)&&(n=n||[],e=e.apply(t,n)),e},s.normalizeMethods=function(e){return i.reduce(e,function(e,t,n){return i.isFunction(t)||(t=this[t]),t&&(e[n]=t),e},{},this)},s.normalizeUIString=function(e,t){return e.replace(/@ui\.[a-zA-Z_$0-9]*/g,function(e){return t[e.slice(4)]})},s.normalizeUIKeys=function(e,t){return i.reduce(e,function(e,i,n){var r=s.normalizeUIString(n,t);return e[r]=i,e},{})},s.normalizeUIValues=function(e,t){return i.each(e,function(n,r){i.isString(n)&&(e[r]=s.normalizeUIString(n,t))}),e},s.actAsCollection=function(e,t){var n=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck"];i.each(n,function(n){e[n]=function(){var e=i.values(i.result(this,t)),r=[e].concat(i.toArray(arguments));return i[n].apply(i,r)}})};var o=s.deprecate=function(e,t){i.isObject(e)&&(e=e.prev+" is going to be removed in the future. "+"Please use "+e.next+" instead."+(e.url?" See: "+e.url:"")),void 0!==t&&t||o._cache[e]||(o._warn("Deprecation warning: "+e),o._cache[e]=!0)};o._warn="undefined"!=typeof console&&(console.warn||console.log)||function(){},o._cache={},s._triggerMethod=function(){function e(e,t,i){return i.toUpperCase()}var t=/(^|:)(\w)/gi;return function(n,r,s){var o=3>arguments.length;o&&(s=r,r=s[0]);var h,a="on"+r.replace(t,e),l=n[a];return i.isFunction(l)&&(h=l.apply(n,o?i.rest(s):s)),i.isFunction(n.trigger)&&(o+s.length>1?n.trigger.apply(n,o?s:[r].concat(i.rest(s,0))):n.trigger(r)),h}}(),s.triggerMethod=function(){return s._triggerMethod(this,arguments)},s.triggerMethodOn=function(e){var t=i.isFunction(e.triggerMethod)?e.triggerMethod:s.triggerMethod;return t.apply(e,i.rest(arguments))},s.MonitorDOMRefresh=function(e){function t(){e._isShown=!0,r()}function n(){e._isRendered=!0,r()}function r(){e._isShown&&e._isRendered&&s.isNodeAttached(e.el)&&i.isFunction(e.triggerMethod)&&e.triggerMethod("dom:refresh")}e.on({show:t,render:n})},function(e){function t(t,n,r,s){var o=s.split(/\s+/);i.each(o,function(i){var s=t[i];if(!s)throw new e.Error('Method "'+i+'" was configured as an event handler, but does not exist.');t.listenTo(n,r,s)})}function n(e,t,i,n){e.listenTo(t,i,n)}function r(e,t,n,r){var s=r.split(/\s+/);i.each(s,function(i){var r=e[i];e.stopListening(t,n,r)})}function s(e,t,i,n){e.stopListening(t,i,n)}function o(t,n,r,s,o){if(n&&r){if(!i.isObject(r))throw new e.Error({message:"Bindings must be an object or function.",url:"marionette.functions.html#marionettebindentityevents"});r=e._getValue(r,t),i.each(r,function(e,r){i.isFunction(e)?s(t,n,r,e):o(t,n,r,e)})}}e.bindEntityEvents=function(e,i,r){o(e,i,r,n,t)},e.unbindEntityEvents=function(e,t,i){o(e,t,i,s,r)},e.proxyBindEntityEvents=function(t,i){return e.bindEntityEvents(this,t,i)},e.proxyUnbindEntityEvents=function(t,i){return e.unbindEntityEvents(this,t,i)}}(s);var h=["description","fileName","lineNumber","name","message","number"];return s.Error=s.extend.call(Error,{urlRoot:"http://marionettejs.com/docs/v"+s.VERSION+"/",constructor:function(e,t){i.isObject(e)?(t=e,e=t.message):t||(t={});var n=Error.call(this,e);i.extend(this,i.pick(n,h),i.pick(t,h)),this.captureStackTrace(),t.url&&(this.url=this.urlRoot+t.url)},captureStackTrace:function(){Error.captureStackTrace&&Error.captureStackTrace(this,s.Error)},toString:function(){return this.name+": "+this.message+(this.url?" See: "+this.url:"")}}),s.Error.extend=s.extend,s.Callbacks=function(){this._deferred=s.Deferred(),this._callbacks=[]},i.extend(s.Callbacks.prototype,{add:function(e,t){var n=i.result(this._deferred,"promise");this._callbacks.push({cb:e,ctx:t}),n.then(function(i){t&&(i.context=t),e.call(i.context,i.options)})},run:function(e,t){this._deferred.resolve({options:e,context:t})},reset:function(){var e=this._callbacks;this._deferred=s.Deferred(),this._callbacks=[],i.each(e,function(e){this.add(e.cb,e.ctx)},this)}}),s.Controller=function(e){this.options=e||{},i.isFunction(this.initialize)&&this.initialize(this.options)},s.Controller.extend=s.extend,i.extend(s.Controller.prototype,t.Events,{destroy:function(){return s._triggerMethod(this,"before:destroy",arguments),s._triggerMethod(this,"destroy",arguments),this.stopListening(),this.off(),this},triggerMethod:s.triggerMethod,getOption:s.proxyGetOption}),s.Object=function(e){this.options=i.extend({},i.result(this,"options"),e),this.initialize.apply(this,arguments)},s.Object.extend=s.extend,i.extend(s.Object.prototype,t.Events,{initialize:function(){},destroy:function(){this.triggerMethod("before:destroy"),this.triggerMethod("destroy"),this.stopListening()},triggerMethod:s.triggerMethod,getOption:s.proxyGetOption,bindEntityEvents:s.proxyBindEntityEvents,unbindEntityEvents:s.proxyUnbindEntityEvents}),s.Region=s.Object.extend({constructor:function(e){if(this.options=e||{},this.el=this.getOption("el"),this.el=this.el instanceof t.$?this.el[0]:this.el,!this.el)throw new s.Error({name:"NoElError",message:'An "el" must be specified for a region.'});this.$el=this.getEl(this.el),s.Object.call(this,e)},show:function(e,t){if(this._ensureElement()){this._ensureViewIsIntact(e);var i=t||{},n=e!==this.currentView,r=!!i.preventDestroy,o=!!i.forceShow,h=!!this.currentView,a=n&&!r,l=n||o;if(h&&this.triggerMethod("before:swapOut",this.currentView,this,t),this.currentView&&delete this.currentView._parent,a?this.empty():h&&l&&this.currentView.off("destroy",this.empty,this),l){e.once("destroy",this.empty,this),e.render(),e._parent=this,h&&this.triggerMethod("before:swap",e,this,t),this.triggerMethod("before:show",e,this,t),s.triggerMethodOn(e,"before:show",e,this,t),h&&this.triggerMethod("swapOut",this.currentView,this,t);var u=s.isNodeAttached(this.el),d=[],c=i.triggerBeforeAttach||this.triggerBeforeAttach,g=i.triggerAttach||this.triggerAttach;return u&&c&&(d=this._displayedViews(e),this._triggerAttach(d,"before:")),this.attachHtml(e),this.currentView=e,u&&g&&(d=this._displayedViews(e),this._triggerAttach(d)),h&&this.triggerMethod("swap",e,this,t),this.triggerMethod("show",e,this,t),s.triggerMethodOn(e,"show",e,this,t),this}return this}},triggerBeforeAttach:!0,triggerAttach:!0,_triggerAttach:function(e,t){var n=(t||"")+"attach";i.each(e,function(e){s.triggerMethodOn(e,n,e,this)},this)},_displayedViews:function(e){return i.union([e],i.result(e,"_getNestedViews")||[])},_ensureElement:function(){if(i.isObject(this.el)||(this.$el=this.getEl(this.el),this.el=this.$el[0]),!this.$el||0===this.$el.length){if(this.getOption("allowMissingEl"))return!1;throw new s.Error('An "el" '+this.$el.selector+" must exist in DOM")}return!0},_ensureViewIsIntact:function(e){if(!e)throw new s.Error({name:"ViewNotValid",message:"The view passed is undefined and therefore invalid. You must pass a view instance to show."});if(e.isDestroyed)throw new s.Error({name:"ViewDestroyedError",message:'View (cid: "'+e.cid+'") has already been destroyed and cannot be used.'})},getEl:function(e){return t.$(e,s._getValue(this.options.parentEl,this))},attachHtml:function(e){this.$el.contents().detach(),this.el.appendChild(e.el)},empty:function(){var e=this.currentView;if(e)return e.off("destroy",this.empty,this),this.triggerMethod("before:empty",e),this._destroyView(),this.triggerMethod("empty",e),delete this.currentView,this},_destroyView:function(){var e=this.currentView;e.destroy&&!e.isDestroyed?e.destroy():e.remove&&(e.remove(),e.isDestroyed=!0)},attachView:function(e){return this.currentView=e,this},hasView:function(){return!!this.currentView},reset:function(){return this.empty(),this.$el&&(this.el=this.$el.selector),delete this.$el,this}},{buildRegion:function(e,t){if(i.isString(e))return this._buildRegionFromSelector(e,t);if(e.selector||e.el||e.regionClass)return this._buildRegionFromObject(e,t);if(i.isFunction(e))return this._buildRegionFromRegionClass(e);throw new s.Error({message:"Improper region configuration type.",url:"marionette.region.html#region-configuration-types"})},_buildRegionFromSelector:function(e,t){return new t({el:e})},_buildRegionFromObject:function(e,t){var n=e.regionClass||t,r=i.omit(e,"selector","regionClass");return e.selector&&!r.el&&(r.el=e.selector),new n(r)},_buildRegionFromRegionClass:function(e){return new e}}),s.RegionManager=s.Controller.extend({constructor:function(e){this._regions={},s.Controller.call(this,e),this.addRegions(this.getOption("regions"))},addRegions:function(e,t){return e=s._getValue(e,this,arguments),i.reduce(e,function(e,n,r){return i.isString(n)&&(n={selector:n}),n.selector&&(n=i.defaults({},n,t)),e[r]=this.addRegion(r,n),e},{},this)},addRegion:function(e,t){var i;return i=t instanceof s.Region?t:s.Region.buildRegion(t,s.Region),this.triggerMethod("before:add:region",e,i),i._parent=this,this._store(e,i),this.triggerMethod("add:region",e,i),i},get:function(e){return this._regions[e]},getRegions:function(){return i.clone(this._regions)},removeRegion:function(e){var t=this._regions[e];return this._remove(e,t),t},removeRegions:function(){var e=this.getRegions();return i.each(this._regions,function(e,t){this._remove(t,e)},this),e},emptyRegions:function(){var e=this.getRegions();return i.invoke(e,"empty"),e},destroy:function(){return this.removeRegions(),s.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 t._parent,delete this._regions[e],this._setLength(),this.triggerMethod("remove:region",e,t)},_setLength:function(){this.length=i.size(this._regions)}}),s.actAsCollection(s.RegionManager.prototype,"_regions"),s.TemplateCache=function(e){this.templateId=e},i.extend(s.TemplateCache,{templateCaches:{},get:function(e){var t=this.templateCaches[e];return t||(t=new s.TemplateCache(e),this.templateCaches[e]=t),t.load()},clear:function(){var e,t=i.toArray(arguments),n=t.length;if(n>0)for(e=0;n>e;e++)delete this.templateCaches[t[e]];else this.templateCaches={}}}),i.extend(s.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 i=t.$(e).html();if(!i||0===i.length)throw new s.Error({name:"NoTemplateError",message:'Could not find template: "'+e+'"'});return i},compileTemplate:function(e){return i.template(e)}}),s.Renderer={render:function(e,t){if(!e)throw new s.Error({name:"TemplateNotFoundError",message:"Cannot render the template since its false, null or undefined."});var n=i.isFunction(e)?e:s.TemplateCache.get(e);return n(t)}},s.View=t.View.extend({isDestroyed:!1,constructor:function(e){i.bindAll(this,"render"),e=s._getValue(e,this),this.options=i.extend({},i.result(this,"options"),e),this._behaviors=s.Behaviors(this),t.View.apply(this,arguments),s.MonitorDOMRefresh(this),this.on("show",this.onShowCalled)},getTemplate:function(){return this.getOption("template")},serializeModel:function(e){return e.toJSON.apply(e,i.rest(arguments))},mixinTemplateHelpers:function(e){e=e||{};var t=this.getOption("templateHelpers");return t=s._getValue(t,this),i.extend(e,t)},normalizeUIKeys:function(e){var t=i.result(this,"_uiBindings");return s.normalizeUIKeys(e,t||i.result(this,"ui"))},normalizeUIValues:function(e){var t=i.result(this,"ui"),n=i.result(this,"_uiBindings");return s.normalizeUIValues(e,n||t)},configureTriggers:function(){if(this.triggers){var e=this.normalizeUIKeys(i.result(this,"triggers"));return i.reduce(e,function(e,t,i){return e[i]=this._buildViewTrigger(t),e},{},this)}},delegateEvents:function(e){return this._delegateDOMEvents(e),this.bindEntityEvents(this.model,this.getOption("modelEvents")),this.bindEntityEvents(this.collection,this.getOption("collectionEvents")),i.each(this._behaviors,function(e){e.bindEntityEvents(this.model,e.getOption("modelEvents")),e.bindEntityEvents(this.collection,e.getOption("collectionEvents"))},this),this},_delegateDOMEvents:function(e){var n=s._getValue(e||this.events,this);n=this.normalizeUIKeys(n),i.isUndefined(e)&&(this.events=n);var r={},o=i.result(this,"behaviorEvents")||{},h=this.configureTriggers(),a=i.result(this,"behaviorTriggers")||{};i.extend(r,o,n,h,a),t.View.prototype.delegateEvents.call(this,r)},undelegateEvents:function(){return t.View.prototype.undelegateEvents.apply(this,arguments),this.unbindEntityEvents(this.model,this.getOption("modelEvents")),this.unbindEntityEvents(this.collection,this.getOption("collectionEvents")),i.each(this._behaviors,function(e){e.unbindEntityEvents(this.model,e.getOption("modelEvents")),e.unbindEntityEvents(this.collection,e.getOption("collectionEvents"))},this),this},onShowCalled:function(){},_ensureViewIsIntact:function(){if(this.isDestroyed)throw new s.Error({name:"ViewDestroyedError",message:'View (cid: "'+this.cid+'") has already been destroyed and cannot be used.'})},destroy:function(){if(!this.isDestroyed){var e=i.toArray(arguments);return this.triggerMethod.apply(this,["before:destroy"].concat(e)),this.isDestroyed=!0,this.triggerMethod.apply(this,["destroy"].concat(e)),this.unbindUIElements(),this.remove(),i.invoke(this._behaviors,"destroy",e),this}},bindUIElements:function(){this._bindUIElements(),i.invoke(this._behaviors,this._bindUIElements)},_bindUIElements:function(){if(this.ui){this._uiBindings||(this._uiBindings=this.ui);var e=i.result(this,"_uiBindings");this.ui={},i.each(e,function(e,t){this.ui[t]=this.$(e)},this)}},unbindUIElements:function(){this._unbindUIElements(),i.invoke(this._behaviors,this._unbindUIElements)},_unbindUIElements:function(){this.ui&&this._uiBindings&&(i.each(this.ui,function(e,t){delete this.ui[t]},this),this.ui=this._uiBindings,delete this._uiBindings)},_buildViewTrigger:function(e){var t=i.isObject(e),n=i.defaults({},t?e:{},{preventDefault:!0,stopPropagation:!0}),r=t?n.event:e;return function(e){e&&(e.preventDefault&&n.preventDefault&&e.preventDefault(),e.stopPropagation&&n.stopPropagation&&e.stopPropagation());var t={view:this,model:this.model,collection:this.collection};this.triggerMethod(r,t)}},setElement:function(){var e=t.View.prototype.setElement.apply(this,arguments);return i.invoke(this._behaviors,"proxyViewProperties",this),e},triggerMethod:function(){for(var e=s._triggerMethod,t=e(this,arguments),i=this._behaviors,n=0,r=i&&i.length;r>n;n++)e(i[n],arguments);return t},_getImmediateChildren:function(){return[]},_getNestedViews:function(){var e=this._getImmediateChildren();return e.length?i.reduce(e,function(e,t){return t._getNestedViews?e.concat(t._getNestedViews()):e},e):e},normalizeMethods:s.normalizeMethods,getOption:s.proxyGetOption,bindEntityEvents:s.proxyBindEntityEvents,unbindEntityEvents:s.proxyUnbindEntityEvents}),s.ItemView=s.View.extend({constructor:function(){s.View.apply(this,arguments)},serializeData:function(){if(!this.model&&!this.collection)return{};var e=[this.model||this.collection];return arguments.length&&e.push.apply(e,arguments),this.model?this.serializeModel.apply(this,e):{items:this.serializeCollection.apply(this,e)}},serializeCollection:function(e){return e.toJSON.apply(e,i.rest(arguments))},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderTemplate(),this.bindUIElements(),this.triggerMethod("render",this),this},_renderTemplate:function(){var e=this.getTemplate();if(e!==!1){if(!e)throw new s.Error({name:"UndefinedTemplateError",message:"Cannot render the template since it is null or undefined."});var t=this.serializeData();t=this.mixinTemplateHelpers(t);var i=s.Renderer.render(e,t,this);return this.attachElContent(i),this}},attachElContent:function(e){return this.$el.html(e),this}}),s.CollectionView=s.View.extend({childViewEventPrefix:"childview",constructor:function(e){var t=e||{};i.isUndefined(this.sort)&&(this.sort=i.isUndefined(t.sort)?!0:t.sort),this.once("render",this._initialEvents),this._initChildViewStorage(),s.View.apply(this,arguments),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&&i.each(this._bufferedChildren,i.partial(this._triggerMethodOnChild,"before:show"))},_triggerShowBufferedChildren:function(){this._isShown&&(i.each(this._bufferedChildren,i.partial(this._triggerMethodOnChild,"show")),this._bufferedChildren=[])},_triggerMethodOnChild:function(e,t){s.triggerMethodOn(t,e)},_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){this.destroyEmptyView();var t=this.getChildView(e),i=this.collection.indexOf(e);this.addChild(e,t,i)},_onCollectionRemove:function(e){var t=this.children.findByModel(e);this.removeChildView(t),this.checkEmpty()},onShowCalled:function(){this.children.each(i.partial(this._triggerMethodOnChild,"show"))},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderChildren(),this.triggerMethod("render",this),this},resortView:function(){this.render()},_sortViews:function(){var e=this.collection.find(function(e,t){var i=this.children.findByModel(e);return!i||i._index!==t},this);e&&this.resortView()},_emptyViewIndex:-1,_renderChildren:function(){this.destroyEmptyView(),this.destroyChildren(),this.isEmpty(this.collection)?this.showEmptyView():(this.triggerMethod("before:render:collection",this),this.startBuffering(),this.showCollection(),this.endBuffering(),this.triggerMethod("render:collection",this))},showCollection:function(){var e;this.collection.each(function(t,i){e=this.getChildView(t),this.addChild(t,e,i)},this)},showEmptyView:function(){var e=this.getEmptyView();if(e&&!this._showingEmptyView){this.triggerMethod("before:render:empty"),this._showingEmptyView=!0;var i=new t.Model;this.addEmptyView(i,e),this.triggerMethod("render:empty")}},destroyEmptyView:function(){this._showingEmptyView&&(this.triggerMethod("before:remove:empty"),this.destroyChildren(),delete this._showingEmptyView,this.triggerMethod("remove:empty"))},getEmptyView:function(){return this.getOption("emptyView")},addEmptyView:function(e,t){var n=this.getOption("emptyViewOptions")||this.getOption("childViewOptions");i.isFunction(n)&&(n=n.call(this,e,this._emptyViewIndex));var r=this.buildChildView(e,t,n);r._parent=this,this.proxyChildEvents(r),this._isShown&&s.triggerMethodOn(r,"before:show"),this.children.add(r),this.renderChildView(r,this._emptyViewIndex),this._isShown&&s.triggerMethodOn(r,"show")},getChildView:function(){var e=this.getOption("childView");if(!e)throw new s.Error({name:"NoChildViewError",message:'A "childView" must be specified'});return e},addChild:function(e,t,i){var n=this.getOption("childViewOptions");n=s._getValue(n,this,[e,i]);var r=this.buildChildView(e,t,n);return this._updateIndices(r,!0,i),this._addChildView(r,i),r._parent=this,r},_updateIndices:function(e,t,i){this.sort&&(t&&(e._index=i),this.children.each(function(i){i._index>=e._index&&(i._index+=t?1:-1)}))},_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&&s.triggerMethodOn(e,"show"),this.triggerMethod("add:child",e)},renderChildView:function(e,t){return e.render(),this.attachHtml(this,e,t),e},buildChildView:function(e,t,n){var r=i.extend({model:e},n);return new t(r)},removeChildView:function(e){return e&&(this.triggerMethod("before:remove:child",e),e.destroy?e.destroy():e.remove&&e.remove(),delete e._parent,this.stopListening(e),this.children.remove(e),this.triggerMethod("remove:child",e),this._updateIndices(e,!1)),e},isEmpty:function(){return!this.collection||0===this.collection.length},checkEmpty:function(){this.isEmpty(this.collection)&&this.showEmptyView()},attachBuffer:function(e,t){e.$el.append(t)},attachHtml:function(e,t,i){e.isBuffering?(e.elBuffer.appendChild(t.el),e._bufferedChildren.push(t)):e._insertBefore(t,i)||e._insertAfter(t)},_insertBefore:function(e,t){var i,n=this.sort&&this.children.length-1>t;return n&&(i=this.children.find(function(e){return e._index===t+1})),i?(i.$el.before(e.el),!0):!1},_insertAfter:function(e){this.$el.append(e.el)},_initChildViewStorage:function(){this.children=new t.ChildViewContainer},destroy:function(){return this.isDestroyed?void 0:(this.triggerMethod("before:destroy:collection"),this.destroyChildren(),this.triggerMethod("destroy:collection"),s.View.prototype.destroy.apply(this,arguments))},destroyChildren:function(){var e=this.children.map(i.identity);return this.children.each(this.removeChildView,this),this.checkEmpty(),e},proxyChildEvents:function(e){var t=this.getOption("childViewEventPrefix");this.listenTo(e,"all",function(){var n=i.toArray(arguments),r=n[0],s=this.normalizeMethods(i.result(this,"childEvents"));n[0]=t+":"+r,n.splice(1,0,e),s!==void 0&&i.isFunction(s[r])&&s[r].apply(this,n.slice(1)),this.triggerMethod.apply(this,n)},this)},_getImmediateChildren:function(){return i.values(this.children._views)}}),s.CompositeView=s.CollectionView.extend({constructor:function(){s.CollectionView.apply(this,arguments)},_initialEvents: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(){var e=this.getOption("childView")||this.constructor;return e},serializeData:function(){var e={};return this.model&&(e=i.partial(this.serializeModel,this.model).apply(this,arguments)),e},render:function(){return this._ensureViewIsIntact(),this.isRendered=!0,this.resetChildViewContainer(),this.triggerMethod("before:render",this),this._renderTemplate(),this._renderChildren(),this.triggerMethod("render",this),this},_renderChildren:function(){this.isRendered&&s.CollectionView.prototype._renderChildren.call(this)},_renderTemplate:function(){var e={};e=this.serializeData(),e=this.mixinTemplateHelpers(e),this.triggerMethod("before:render:template");var t=this.getTemplate(),i=s.Renderer.render(t,e,this);this.attachElContent(i),this.bindUIElements(),this.triggerMethod("render:template")},attachElContent:function(e){return this.$el.html(e),this},attachBuffer:function(e,t){var i=this.getChildViewContainer(e);i.append(t)},_insertAfter:function(e){var t=this.getChildViewContainer(this,e);t.append(e.el)},getChildViewContainer:function(e){if("$childViewContainer"in e)return e.$childViewContainer;var t,i=s.getOption(e,"childViewContainer");if(i){var n=s._getValue(i,e);if(t="@"===n.charAt(0)&&e.ui?e.ui[n.substr(4)]:e.$(n),0>=t.length)throw new s.Error({name:"ChildViewContainerMissingError",message:'The specified "childViewContainer" was not found: '+e.childViewContainer})}else t=e.$el;return e.$childViewContainer=t,t},resetChildViewContainer:function(){this.$childViewContainer&&delete this.$childViewContainer}}),s.LayoutView=s.ItemView.extend({regionClass:s.Region,constructor:function(e){e=e||{},this._firstRender=!0,this._initializeRegions(e),s.ItemView.call(this,e)},render:function(){return this._ensureViewIsIntact(),this._firstRender?this._firstRender=!1:this._reInitializeRegions(),s.ItemView.prototype.render.apply(this,arguments)},destroy:function(){return this.isDestroyed?this:(this.regionManager.destroy(),s.ItemView.prototype.destroy.apply(this,arguments))},addRegion:function(e,t){var i={};return i[e]=t,this._buildRegions(i)[e]},addRegions:function(e){return this.regions=i.extend({},this.regions,e),this._buildRegions(e)},removeRegion:function(e){return 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={regionClass:this.getOption("regionClass"),parentEl:i.partial(i.result,this,"el")};return this.regionManager.addRegions(e,t)},_initializeRegions:function(e){var t;this._initRegionManager(),t=s._getValue(this.regions,this,[e])||{};var n=this.getOption.call(e,"regions");n=s._getValue(n,this,[e]),i.extend(t,n),t=this.normalizeUIValues(t),this.addRegions(t)},_reInitializeRegions:function(){this.regionManager.invoke("reset")},getRegionManager:function(){return new s.RegionManager},_initRegionManager:function(){this.regionManager=this.getRegionManager(),this.regionManager._parent=this,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)})},_getImmediateChildren:function(){return i.chain(this.regionManager.getRegions()).pluck("currentView").compact().value()}}),s.Behavior=s.Object.extend({constructor:function(e,t){this.view=t,this.defaults=i.result(this,"defaults")||{},this.options=i.extend({},this.defaults,e),s.Object.apply(this,arguments)},$:function(){return this.view.$.apply(this.view,arguments)},destroy:function(){this.stopListening()},proxyViewProperties:function(e){this.$el=e.$el,this.el=e.el}}),s.Behaviors=function(e,t){function i(e,n){return t.isObject(e.behaviors)?(n=i.parseBehaviors(e,n||t.result(e,"behaviors")),i.wrap(e,n,t.keys(s)),n):{}}function n(e,i){this._view=e,this._viewUI=t.result(e,"ui"),this._behaviors=i,this._triggers={}}var r=/^(\S+)\s*(.*)$/,s={behaviorTriggers:function(e,t){var i=new n(this,t);return i.buildBehaviorTriggers()},behaviorEvents:function(i,n){var s={},o=this._uiBindings||t.result(this,"ui");return t.each(n,function(i,n){var h={},a=t.clone(t.result(i,"events"))||{},l=i._uiBindings||t.result(i,"ui"),u=t.extend({},o,l);a=e.normalizeUIKeys(a,u);var d=0;t.each(a,function(e,s){var o=s.match(r),a=o[1]+"."+[this.cid,n,d++," "].join(""),l=o[2],u=a+l,c=t.isFunction(e)?e:i[e];h[u]=t.bind(c,i)},this),s=t.extend(s,h)},this),s}};return t.extend(i,{behaviorsLookup:function(){throw new e.Error({message:"You must define where your behaviors are stored.",url:"marionette.behaviors.html#behaviorslookup"})},getBehaviorClass:function(t,n){return t.behaviorClass?t.behaviorClass:e._getValue(i.behaviorsLookup,this,[t,n])[n]},parseBehaviors:function(e,n){return t.chain(n).map(function(n,r){var s=i.getBehaviorClass(n,r),o=new s(n,e),h=i.parseBehaviors(e,t.result(o,"behaviors"));return[o].concat(h)}).flatten().value()},wrap:function(e,i,n){t.each(n,function(n){e[n]=t.partial(s[n],e[n],i)})}}),t.extend(n.prototype,{buildBehaviorTriggers:function(){return t.each(this._behaviors,this._buildTriggerHandlersForBehavior,this),this._triggers},_buildTriggerHandlersForBehavior:function(i,n){var r=t.extend({},this._viewUI,t.result(i,"ui")),s=t.clone(t.result(i,"triggers"))||{};s=e.normalizeUIKeys(s,r),t.each(s,t.bind(this._setHandlerForBehavior,this,i,n))},_setHandlerForBehavior:function(e,t,i,n){var r=n.replace(/^\S+/,function(e){return e+"."+"behaviortriggers"+t});this._triggers[r]=this._view._buildViewTrigger(i)}}),i}(s,i),s.AppRouter=t.Router.extend({constructor:function(e){this.options=e||{},t.Router.apply(this,arguments);var i=this.getOption("appRoutes"),n=this._getController();this.processAppRoutes(n,i),this.on("route",this._processOnRoute,this)},appRoute:function(e,t){var i=this._getController();this._addAppRoute(i,e,t)},_processOnRoute:function(e,t){if(i.isFunction(this.onRoute)){var n=i.invert(this.getOption("appRoutes"))[e];this.onRoute(e,n,t)}},processAppRoutes:function(e,t){if(t){var n=i.keys(t).reverse();i.each(n,function(i){this._addAppRoute(e,i,t[i])},this)}},_getController:function(){return this.getOption("controller")},_addAppRoute:function(e,t,n){var r=e[n];if(!r)throw new s.Error('Method "'+n+'" was not found on the controller');this.route(t,n,i.bind(r,e))},getOption:s.proxyGetOption,triggerMethod:s.triggerMethod,bindEntityEvents:s.proxyBindEntityEvents,unbindEntityEvents:s.proxyUnbindEntityEvents}),s.Application=s.Object.extend({constructor:function(e){this._initializeRegions(e),this._initCallbacks=new s.Callbacks,this.submodules={},i.extend(this,e),this._initChannel(),s.Object.call(this,e)},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(){return this._regionManager.emptyRegions()},removeRegion:function(e){return this._regionManager.removeRegion(e)},getRegion:function(e){return this._regionManager.get(e)},getRegions:function(){return this._regionManager.getRegions()},module:function(e,t){var n=s.Module.getClass(t),r=i.toArray(arguments);return r.unshift(this),n.create.apply(n,r)},getRegionManager:function(){return new s.RegionManager},_initializeRegions:function(e){var t=i.isFunction(this.regions)?this.regions(e):this.regions||{};this._initRegionManager();var n=s.getOption(e,"regions");return i.isFunction(n)&&(n=n.call(this,e)),i.extend(t,n),this.addRegions(t),this},_initRegionManager:function(){this._regionManager=this.getRegionManager(),this._regionManager._parent=this,this.listenTo(this._regionManager,"before:add:region",function(){s._triggerMethod(this,"before:add:region",arguments)}),this.listenTo(this._regionManager,"add:region",function(e,t){this[e]=t,s._triggerMethod(this,"add:region",arguments)}),this.listenTo(this._regionManager,"before:remove:region",function(){s._triggerMethod(this,"before:remove:region",arguments)}),this.listenTo(this._regionManager,"remove:region",function(e){delete this[e],s._triggerMethod(this,"remove:region",arguments)})},_initChannel:function(){this.channelName=i.result(this,"channelName")||"global",this.channel=i.result(this,"channel")||t.Wreqr.radio.channel(this.channelName),this.vent=i.result(this,"vent")||this.channel.vent,this.commands=i.result(this,"commands")||this.channel.commands,this.reqres=i.result(this,"reqres")||this.channel.reqres}}),s.Module=function(e,t,n){this.moduleName=e,this.options=i.extend({},this.options,n),this.initialize=n.initialize||this.initialize,this.submodules={},this._setupInitializersAndFinalizers(),this.app=t,i.isFunction(this.initialize)&&this.initialize(e,t,this.options)},s.Module.extend=s.extend,i.extend(s.Module.prototype,t.Events,{startWithParent:!0,initialize:function(){},addInitializer:function(e){this._initializerCallbacks.add(e)
Пример #11
0
var captures = lib.captures = function(re, str, callback) {
  var m = re.exec(str);
  if (!m) { return callback(); }

  return callback.apply(this, [m].concat(_.slice(m)));
};