!function(a,b,c){"use strict";var d={$:c.$,extend:c.Model.extend};a.Andamio=c.Andamio=d,d.Utils={render:function(a,b){if(!a)throw new Error("Cannot render the template since it's false, null or undefined.");return a(b)}},function(a){function c(a,b,c,d,e){if(!d)throw new Error('Method "'+e+'" was configured as an event handler, but does not exist.');a.listenTo(b,c,d)}function d(a,b,c,d){a.stopListening(b,c,d)}function e(a,c,d,e,f){b.each(e,function(b){var e=a[b];f(a,c,d,e,b)})}function f(a,c,d,f){c&&d&&b.each(d,function(b,d){var h=b.split(g);e(a,c,d,h,f)})}var g=/\s+/;a.bindEvents=function(a,b,d){f(a,b,d,c)},a.unbindEvents=function(a,b,c){f(a,b,c,d)}}(d),d.Region=function(a){if(b.extend(this,a),!this.el&&!this.$el)throw new Error('An "el" or "$el" property must be specified for a region');this.initialize&&this.initialize.apply(this,arguments)},b.extend(d.Region.prototype,c.Events,{show:function(a){var c;this._ensureEl(),c=a!==this.currentView,c&&this.close(),a.render(),(c||a.isClosed)&&this.open(a),this.currentView=a,this.trigger.call(this,"show",a),b.isFunction(this.onShow)&&this.onShow.apply(this,b.tail(arguments))},open:function(a){this.$el.empty().append(a.el)},close:function(){var a=this.currentView;a&&!a.isClosed&&(a.close?a.close():a.remove&&a.remove(),b.isFunction(this.onClose)&&this.onClose(),delete this.currentView)},_ensureEl:function(){this.$el&&0!==this.$el.length||(this.$el=$('[data-region="'+this.el+'"]'))},reset:function(){this.close(),delete this.$el}}),d.View=c.View.extend({constructor:function(){b.bindAll(this,"render"),c.View.prototype.constructor.apply(this,arguments)},_bindRegions:function(){var a=this.$("[data-region]");a.length&&(this.regions={},b.each(a,function(a){var b=$(a),c=b.attr("data-region");this.regions[c]=new d.Region({$el:b})},this))},_unbindRegions:function(){this.regions&&this._deleteProp("regions")},addSubview:function(a,c){this.subviews||(this.subviews={}),this.subviews[a]=b.isFunction(c)?new c:c},_createSubViews:function(){this.subviews&&(this._subviews||(this._subviews=this.subviews),this.subviews={},b.each(b.keys(this._subviews),function(a){this.addSubview(a,this._subviews[a])},this))},_removeSubviews:function(){this.subviews&&(b.invoke(this.subviews,"close"),this._deleteProp("subviews"),this.subviews=this._subviews,delete this._subviews)},_bindUIElements:function(){this.ui&&(this._ui||(this._ui=this.ui),this.ui=b.object(b.map(this._ui,function(a,b){return[b,this.$(a)]},this)))},_unbindUIElements:function(){this.ui&&(this._deleteProp("ui"),this.ui=this._ui,delete this._ui)},close:function(){this.isClosed||(this.isClosed=!0,this._removeSubviews(),this._unbindRegions(),this._unbindUIElements(),this.remove())},delegateEvents:function(a){c.View.prototype.delegateEvents.call(this,a),d.bindEvents(this,this.model,this.modelEvents),d.bindEvents(this,this.collection,this.collectionEvents)},undelegateEvents:function(){c.View.prototype.undelegateEvents.apply(this,arguments),d.unbindEvents(this,this.model,this.modelEvents),d.unbindEvents(this,this.collection,this.collectionEvents)},_deleteProp:function(a){var c=this[a];b.each(c,function(a,b){delete c[b]},this),delete this[a]}}),d.ItemView=d.View.extend({constructor:function(){var a;b.isFunction(this.model)&&(this.model=new this.model),b.isFunction(this.collection)&&(this.collection=new this.collection),d.View.prototype.constructor.apply(this,arguments),this.collectionView&&this.collection&&(a=new this.collectionView({collection:this.collection}),this.addSubview("collectionView",a))},render:function(){var a,c;return this.isClosed=!1,a=this.serializeData(),c=d.Utils.render(this.template,a),this.$el.html(c),this._createSubViews(),this._bindRegions(),this._bindUIElements(),b.isFunction(this.afterRender)&&this.afterRender(),this},serializeData:function(){return this.model?this.model.toJSON():this.collection?{items:this.collection.toJSON()}:{}}}),d.CollectionView=d.View.extend({constructor:function(){b.isFunction(this.collection)&&(this.collection=new this.collection),this.children=[],d.View.prototype.constructor.apply(this,arguments),this._initialEvents(),this.initRenderBuffer()},initRenderBuffer:function(){this.elBuffer=document.createDocumentFragment(),this._bufferedChildren=[]},startBuffering:function(){this.initRenderBuffer(),this.isBuffering=!0},endBuffering:function(){this.isBuffering=!1,this.appendBuffer(this,this.elBuffer),this._bufferedChildren=[],this.initRenderBuffer()},_initialEvents:function(){this.collection&&(this.listenTo(this.collection,"add",this.addChildView,this),this.listenTo(this.collection,"remove",this.removeItemView,this),this.listenTo(this.collection,"reset",this.render,this))},addChildView:function(a){var b=this._getItemView(a),c=this.collection.indexOf(a);this.addItemView(a,b,c)},_getItemView:function(){if(!this.itemView)throw"An `itemView` must be specified";return this.itemView},removeItemView:function(a){var c=b.findWhere(this.children,{model:a});this.removeChildView(c)},removeChildView:function(a){a&&(this.stopListening(a),a.close?a.close():a.remove&&a.remove(),this.children=b.without(this.children,a))},render:function(){return this.isClosed=!1,this._renderChildren(),b.isFunction(this.afterRender)&&this.afterRender(),this},addItemView:function(a,b,c){var d=this.buildItemView(a,b,this.itemViewOptions);return this.children.push(d),this.renderItemView(d,c),d},renderItemView:function(a,b){a.render(),this.appendHtml(this,a,b)},buildItemView:function(a,c,d){var e=b.extend({model:a},d);return new c(e)},appendBuffer:function(a,b){a.$el.append(b)},appendHtml:function(a,b){a.isBuffering?(a.elBuffer.appendChild(b.el),a._bufferedChildren.push(b)):a.$el.append(b.el)},isEmpty:function(){return!this.collection||0===this.collection.length},_renderChildren:function(){this.startBuffering(),this.closeChildren(),this.isEmpty()||this.showCollection(),this.endBuffering()},showCollection:function(){this.collection.each(function(a,b){this.addItemView(a,this.itemView,b)},this)},close:function(){this.isClosed||(this.closeChildren(),d.View.prototype.close.apply(this,arguments))},closeChildren:function(){b.each(this.children,function(a){this.removeChildView(a)},this)}}),d.Model=c.Model.extend({constructor:function(a,b){this.configure(b),c.Model.apply(this,arguments),this._mixinComputedProperties()},configure:function(a){b.extend(this.defaults,this.constructor.__super__.defaults),this.options=a||{}},defaults:{ready:!1},isReady:function(){return!0},setReady:function(){this.set("ready",!0)},_mixinComputedProperties:function(){var a=this.attributes||{};return b.extend(a,this.computedProperties)},load:function(){}}),d.Collection=c.Collection.extend({model:d.Model,load:function(){}}),d.Router=c.Router.extend({_bindRoutes:function(){this.routes&&(this.routes=b.result(this,"routes"),b.each(this.routes,function(a){var c,d=b.isArray(a.url)?a.url:[a.url];b.each(d,function(b){c=c||this._createCallback(b,a),this.route(b,a.name,c)},this)},this))},_createCallback:function(a,d){var e,f=this;return e=d.redirectTo?function(){c.history.navigate(d.redirectTo,{trigger:!0,replace:!0})}:function(){var c=[].slice.call(arguments),e=new d.view,g=e.model||e.collection;g&&b.isFunction(g.load)&&(g.urlParams=c,g.load.apply(g,c)),f.trigger("navigate",e,a,c)}}}),d.Application=function(a){b.extend(this,a),this.vent=b.extend({},c.Events)},b.extend(d.Application.prototype,c.Events,{container:"main",el:"page",start:function(a){a.appView&&this._initAppView(a.appView),a.router&&this._initRouter(a.router),this.initialize.apply(this,arguments)},initialize:function(){},_initRouter:function(a){if(this.router=b.isFunction(a)?new a:a,this._initAppRegion(),c.history.start(),!c.history.fragment){var d=b.findWhere(this.router.routes,{"default":!0});d&&this.router.navigate(d.url,{trigger:!0})}},_initAppRegion:function(){var a=this;this.appRegion=new d.Region({el:this.el,initialize:function(){this.listenTo(a.router,"navigate",this.show)},onShow:function(){a.vent.trigger("navigate",this.currentView)}})},_initAppView:function(a){this.appView=b.isFunction(a)?new a:a,$(this.container).empty().append(this.appView.render().el)}}),d.Application.extend=d.extend,function(a,b){if("object"==typeof exports){var c=require("underscore"),d=require("backbone");module.exports=b(c,d)}else"function"==typeof define&&define.amd&&define(["underscore","backbone"],b)}(this,function(){return d})}(this,_,Backbone);
(function(e,t){if(typeof exports=="object"){var n=require("jquery"),r=require("underscore"),i=require("backbone"),s=require("backbone.eventbinder"),o=require("backbone.wreqr");module.exports=t(n,r,i,s,o)}else typeof define=="function"&&define.amd&&define(["jquery","underscore","backbone","backbone.wreqr","backbone.eventbinder"],t)})(this,function(e,t,n){return n.Marionette=Marionette=function(e,t,n){var r={},i=Array.prototype.slice;return r.extend=e.Model.extend,r.getOption=function(e,t){if(!e||!t)return;var n;return e.options&&e.options[t]?n=e.options[t]:n=e[t],n},r.createObject=function(){function t(){}var e;return typeof Object.create=="function"?e=Object.create:e=function(e){t.prototype=e;var n=new t;return t.prototype=null,n},e}(),r.triggerMethod=function(){var e=Array.prototype.slice.apply(arguments),n=e[0],r=n.split(":"),i,s,o="on";for(var u=0;u<r.length;u++)i=r[u],s=i.charAt(0).toUpperCase(),o+=s+i.slice(1);this.trigger.apply(this,e);if(t.isFunction(this[o]))return e.shift(),this[o].apply(this,e)},r.EventBinder=e.EventBinder.extend(),r.addEventBinder=function(e){var n=new r.EventBinder;e.eventBinder=n,e.bindTo=function(t,r,i,s){s=s||e,n.bindTo(t,r,i,s)},e.unbindFrom=t.bind(n.unbindFrom,n),e.unbindAll=t.bind(n.unbindAll,n)},r.EventAggregator=e.Wreqr.EventAggregator.extend({constructor:function(){r.addEventBinder(this);var t=Array.prototype.slice.apply(arguments);e.Wreqr.EventAggregator.prototype.constructor.apply(this,t)}}),r.bindEntityEvents=function(){function e(e,n,r,i){var s=i.split(/\s+/);t.each(s,function(t){var i=e[t];if(!i)throw new Error("Method '"+t+"' was configured as an event handler, but does not exist.");e.bindTo(n,r,i,e)})}function n(e,t,n,r){e.bindTo(t,n,r,e)}return function(r,i,s){if(!i||!s)return;t.each(s,function(s,o){t.isFunction(s)?n(r,i,o,s):e(r,i,o,s)})}}(),r.Callbacks=function(){this._deferred=n.Deferred(),this._callbacks=[]},t.extend(r.Callbacks.prototype,{add:function(e,t){this._callbacks.push({cb:e,ctx:t}),this._deferred.done(function(n,r){t&&(n=t),e.call(n,r)})},run:function(e,t){this._deferred.resolve(t,e)},reset:function(){var e=this,r=this._callbacks;this._deferred=n.Deferred(),this._callbacks=[],t.each(r,function(t){e.add(t.cb,t.ctx)})}}),r.TemplateCache=function(e){this.templateId=e},t.extend(r.TemplateCache,{templateCaches:{},get:function(e){var t=this,n=this.templateCaches[e];return n||(n=new r.TemplateCache(e),this.templateCaches[e]=n),n.load()},clear:function(){var e,t=Array.prototype.slice.apply(arguments),n=t.length;if(n>0)for(e=0;e<n;e++)delete this.templateCaches[t[e]];else this.templateCaches={}}}),t.extend(r.TemplateCache.prototype,{load:function(){var e=this;if(this.compiledTemplate)return this.compiledTemplate;var t=this.loadTemplate(this.templateId);return this.compiledTemplate=this.compileTemplate(t),this.compiledTemplate},loadTemplate:function(e){var t=n(e).html();if(!t||t.length===0){var r="Could not find template: '"+e+"'",i=new Error(r);throw i.name="NoTemplateError",i}return t},compileTemplate:function(e){return t.template(e)}}),r.Renderer={render:function(e,t){var n=typeof e=="function"?e:r.TemplateCache.get(e),i=n(t);return i}},r.Controller=function(e){this.triggerMethod=r.triggerMethod,this.options=e||{},r.addEventBinder(this),t.isFunction(this.initialize)&&this.initialize(this.options)},r.Controller.extend=r.extend,t.extend(r.Controller.prototype,e.Events,{close:function(){this.unbindAll(),this.triggerMethod("close"),this.unbind()}}),r.Region=function(e){this.options=e||{},r.addEventBinder(this),this.el=r.getOption(this,"el");if(!this.el){var t=new Error("An 'el' must be specified for a region.");throw t.name="NoElError",t}if(this.initialize){var n=Array.prototype.slice.apply(arguments);this.initialize.apply(this,n)}},t.extend(r.Region,{buildRegion:function(e,t){var n=typeof e=="string",r=typeof e.selector=="string",i=typeof e.regionType=="undefined",s=typeof e=="function";if(!s&&!n&&!r)throw new Error("Region must be specified as a Region type, a selector string or an object with selector property");var o,u;n&&(o=e),e.selector&&(o=e.selector),s&&(u=e),!s&&i&&(u=t),e.regionType&&(u=e.regionType);var a=new u({el:o});return a}}),t.extend(r.Region.prototype,e.Events,{show:function(e){this.ensureEl(),this.close(),e.render(),this.open(e),r.triggerMethod.call(e,"show"),r.triggerMethod.call(this,"show",e),this.currentView=e},ensureEl:function(){if(!this.$el||this.$el.length===0)this.$el=this.getEl(this.el)},getEl:function(e){return n(e)},open:function(e){this.$el.empty().append(e.el)},close:function(){var e=this.currentView;if(!e||e.isClosed)return;e.close&&e.close(),r.triggerMethod.call(this,"close"),delete this.currentView},attachView:function(e){this.currentView=e},reset:function(){this.close(),delete this.$el}}),r.Region.extend=r.extend,r.View=e.View.extend({constructor:function(){t.bindAll(this,"render"),r.addEventBinder(this);var n=Array.prototype.slice.apply(arguments);e.View.prototype.constructor.apply(this,n),r.bindEntityEvents(this,this.model,r.getOption(this,"modelEvents")),r.bindEntityEvents(this,this.collection,r.getOption(this,"collectionEvents")),this.bindTo(this,"show",this.onShowCalled,this)},triggerMethod:r.triggerMethod,getTemplate:function(){return r.getOption(this,"template")},mixinTemplateHelpers:function(e){e=e||{};var n=this.templateHelpers;return t.isFunction(n)&&(n=n.call(this)),t.extend(e,n)},configureTriggers:function(){if(!this.triggers)return;var e=this,n={},r=t.result(this,"triggers");return t.each(r,function(t,r){n[r]=function(n){n&&n.preventDefault&&n.preventDefault(),n&&n.stopPropagation&&n.stopPropagation(),e.trigger(t)}}),n},delegateEvents:function(n){n=n||this.events,t.isFunction(n)&&(n=n.call(this));var r={},i=this.configureTriggers();t.extend(r,n,i),e.View.prototype.delegateEvents.call(this,r)},onShowCalled:function(){},close:function(){if(this.isClosed)return;var e=this.triggerMethod("before:close");if(e===!1)return;this.remove(),this.triggerMethod("close"),this.isClosed=!0,this.unbindAll()},bindUIElements:function(){if(!this.ui)return;var e=this;this.uiBindings||(this.uiBindings=this.ui),this.ui={},t.each(t.keys(this.uiBindings),function(t){var n=e.uiBindings[t];e.ui[t]=e.$(n)})}}),r.ItemView=r.View.extend({constructor:function(){var e=Array.prototype.slice.apply(arguments);r.View.prototype.constructor.apply(this,e),this.initialEvents&&this.initialEvents(),this.bindTo(this,"show",this._handleShow,this),this.bindTo(this,"render",this._handleRender,this)},_handleShow:function(){this._isShown=!0,this.triggerDOMRefresh()},_handleRender:function(){this._isRendered=!0,this.triggerDOMRefresh()},triggerDOMRefresh:function(){this._isShown&&this._isRendered&&this.triggerMethod("dom:refresh")},serializeData:function(){var e={};return this.model?e=this.model.toJSON():this.collection&&(e={items:this.collection.toJSON()}),e},render:function(){this.isClosed=!1,this.triggerMethod("before:render",this),this.triggerMethod("item:before:render",this);var e=this.serializeData();e=this.mixinTemplateHelpers(e);var t=this.getTemplate(),n=r.Renderer.render(t,e);return this.$el.html(n),this.bindUIElements(),this.triggerMethod("render",this),this.triggerMethod("item:rendered",this),this},close:function(){if(this.isClosed)return;this.triggerMethod("item:before:close");var e=Array.prototype.slice.apply(arguments);r.View.prototype.close.apply(this,e),this.triggerMethod("item:closed")}}),r.CollectionView=r.View.extend({itemViewEventPrefix:"itemview",constructor:function(e){this.initChildViewStorage();var t=Array.prototype.slice.apply(arguments);r.View.prototype.constructor.apply(this,t),this.initialEvents(),this.onShowCallbacks=new r.Callbacks},initialEvents:function(){this.collection&&(this.bindTo(this.collection,"add",this.addChildView,this),this.bindTo(this.collection,"remove",this.removeItemView,this),this.bindTo(this.collection,"reset",this.render,this))},addChildView:function(e,t,n){this.closeEmptyView();var r=this.getItemView(e),i;return n&&n.index?i=n.index:i=0,this.addItemView(e,r,i)},onShowCalled:function(){this.onShowCallbacks.run()},triggerBeforeRender:function(){this.triggerMethod("before:render",this),this.triggerMethod("collection:before:render",this)},triggerRendered:function(){this.triggerMethod("render",this),this.triggerMethod("collection:rendered",this)},render:function(){return this.isClosed=!1,this.triggerBeforeRender(),this.closeEmptyView(),this.closeChildren(),this.collection&&this.collection.length>0?this.showCollection():this.showEmptyView(),this.triggerRendered(),this},showCollection:function(){var e=this,t;this.collection.each(function(n,r){t=e.getItemView(n),e.addItemView(n,t,r)})},showEmptyView:function(){var t=r.getOption(this,"emptyView");if(t&&!this._showingEmptyView){this._showingEmptyView=!0;var n=new e.Model;this.addItemView(n,t,0)}},closeEmptyView:function(){this._showingEmptyView&&(this.closeChildren(),delete this._showingEmptyView)},getItemView:function(e){var t=r.getOption(this,"itemView");if(!t){var n=new Error("An `itemView` must be specified");throw n.name="NoItemViewError",n}return t},addItemView:function(e,n,i){var s=this,o=r.getOption(this,"itemViewOptions");t.isFunction(o)&&(o=o.call(this,e));var u=this.buildItemView(e,n,o);this.addChildViewEventForwarding(u),this.children.add(u);var a=this.renderItemView(u,i);return this.triggerMethod("item:added",u),u.onShow&&this.onShowCallbacks.add(u.onShow,u),a},addChildViewEventForwarding:function(e){var t=r.getOption(this,"itemViewEventPrefix"),n=this.bindTo(e,"all",function(){var n=i.call(arguments);n[0]=t+":"+n[0],n.splice(1,0,e),this.triggerMethod.apply(this,n)},this);this._childBindings=this._childBindings||{},this._childBindings[e.cid]=n},renderItemView:function(e,t){e.render(),this.appendHtml(this,e,t)},buildItemView:function(e,n,r){var i=t.extend({model:e},r),s=new n(i);return s},removeItemView:function(e){var t=this.children.findByModel(e);if(t){var n=this._childBindings[t.cid];n&&(this.unbindFrom(n),delete this._childBindings[t.cid]),t.close&&t.close(),this.children.remove(t)}(!this.collection||this.collection.length===0)&&this.showEmptyView(),this.triggerMethod("item:removed",t)},appendHtml:function(e,t,n){e.$el.append(t.el)},initChildViewStorage:function(){this.children=new e.ChildViewContainer},close:function(){if(this.isClosed)return;this.triggerMethod("collection:before:close"),this.closeChildren(),this.triggerMethod("collection:closed");var e=Array.prototype.slice.apply(arguments);r.View.prototype.close.apply(this,e)},closeChildren:function(){var e=this;this.children.apply("close"),this.initChildViewStorage()}}),r.CompositeView=r.CollectionView.extend({constructor:function(e){var t=Array.prototype.slice.apply(arguments);r.CollectionView.apply(this,t),this.itemView=this.getItemView()},initialEvents:function(){this.collection&&(this.bindTo(this.collection,"add",this.addChildView,this),this.bindTo(this.collection,"remove",this.removeItemView,this),this.bindTo(this.collection,"reset",this.renderCollection,this))},getItemView:function(e){var t=r.getOption(this,"itemView")||this.constructor;if(!t){var n=new Error("An `itemView` must be specified");throw n.name="NoItemViewError",n}return t},serializeData:function(){var e={};return this.model&&(e=this.model.toJSON()),e},render:function(){this.isClosed=!1,this.resetItemViewContainer();var e=this.renderModel();return this.$el.html(e),this.bindUIElements(),this.triggerMethod("composite:model:rendered"),this.renderCollection(),this.triggerMethod("composite:rendered"),this},renderCollection:function(){var e=Array.prototype.slice.apply(arguments);r.CollectionView.prototype.render.apply(this,e),this.triggerMethod("composite:collection:rendered")},renderModel:function(){var e={};e=this.serializeData(),e=this.mixinTemplateHelpers(e);var t=this.getTemplate();return r.Renderer.render(t,e)},appendHtml:function(e,t){var n=this.getItemViewContainer(e);n.append(t.el)},getItemViewContainer:function(e){if("$itemViewContainer"in e)return e.$itemViewContainer;var n;if(e.itemViewContainer){var r=t.result(e,"itemViewContainer");n=e.$(r);if(n.length<=0){var i=new Error("The specified `itemViewContainer` was not found: "+e.itemViewContainer);throw i.name="ItemViewContainerMissingError",i}}else n=e.$el;return e.$itemViewContainer=n,n},resetItemViewContainer:function(){this.$itemViewContainer&&delete this.$itemViewContainer}}),r.Layout=r.ItemView.extend({regionType:r.Region,constructor:function(){this._firstRender=!0,this.initializeRegions();var t=Array.prototype.slice.apply(arguments);e.Marionette.ItemView.apply(this,t)},render:function(){this._firstRender?this._firstRender=!1:(this.closeRegions(),this.reInitializeRegions());var e=Array.prototype.slice.apply(arguments),t=r.ItemView.prototype.render.apply(this,e);return t},close:function(){if(this.isClosed)return;this.closeRegions(),this.destroyRegions();var t=Array.prototype.slice.apply(arguments);e.Marionette.ItemView.prototype.close.apply(this,t)},initializeRegions:function(){this.regionManagers||(this.regionManagers={});var e=this,n=this.regions||{};t.each(n,function(t,n){var i=r.Region.buildRegion(t,e.regionType);i.getEl=function(t){return e.$(t)},e.regionManagers[n]=i,e[n]=i})},reInitializeRegions:function(){this.regionManagers&&t.size(this.regionManagers)===0?this.initializeRegions():t.each(this.regionManagers,function(e){e.reset()})},closeRegions:function(){var e=this;t.each(this.regionManagers,function(e,t){e.close()})},destroyRegions:function(){var e=this;t.each(this.regionManagers,function(t,n){delete e[n]}),this.regionManagers={}}}),r.AppRouter=e.Router.extend({constructor:function(t){var n=Array.prototype.slice.apply(arguments);e.Router.prototype.constructor.apply(this,n),this.options=t;if(this.appRoutes){var i=r.getOption(this,"controller");this.processAppRoutes(i,this.appRoutes)}},processAppRoutes:function(e,n){var r,i,s,o,u,a=[],f=this;for(s in n)n.hasOwnProperty(s)&&a.unshift([s,n[s]]);o=a.length;for(u=0;u<o;u++){s=a[u][0],i=a[u][1],r=e[i];if(!r){var l="Method '"+i+"' was not found on the controller",c=new Error(l);throw c.name="NoMethodError",c}r=t.bind(r,e),f.route(s,i,r)}}}),r.Application=function(n){this.initCallbacks=new r.Callbacks,this.vent=new r.EventAggregator,this.commands=new e.Wreqr.Commands,this.reqres=new e.Wreqr.RequestResponse,this.submodules={},t.extend(this,n),r.addEventBinder(this),this.triggerMethod=r.triggerMethod},t.extend(r.Application.prototype,e.Events,{execute:function(){var e=Array.prototype.slice.apply(arguments);this.commands.execute.apply(this.commands,e)},request:function(){var e=Array.prototype.slice.apply(arguments);return this.reqres.request.apply(this.reqres,e)},addInitializer:function(e){this.initCallbacks.add(e)},start:function(e){this.triggerMethod("initialize:before",e),this.initCallbacks.run(e,this),this.triggerMethod("initialize:after",e),this.triggerMethod("start",e)},addRegions:function(e){var n=this;t.each(e,function(e,t){var i=r.Region.buildRegion(e,r.Region);n[t]=i})},removeRegion:function(e){this[e].close(),delete this[e]},module:function(e,t){var n=i.call(arguments);return n.unshift(this),r.Module.create.apply(r.Module,n)}}),r.Application.extend=r.extend,r.Module=function(e,t){this.moduleName=e,this.submodules={},this._setupInitializersAndFinalizers(),this.config={},this.config.app=t,r.addEventBinder(this),this.triggerMethod=r.triggerMethod},t.extend(r.Module.prototype,e.Events,{addInitializer:function(e){this._initializerCallbacks.add(e)},addFinalizer:function(e){this._finalizerCallbacks.add(e)},start:function(e){if(this._isInitialized)return;t.each(this.submodules,function(t){var n=!0;t.config&&t.config.options&&(n=t.config.options.startWithParent),n&&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,r.triggerMethod.call(this,"before:stop"),t.each(this.submodules,function(e){e.stop()}),this._finalizerCallbacks.run(),this._initializerCallbacks.reset(),this._finalizerCallbacks.reset(),r.triggerMethod.call(this,"stop")},addDefinition:function(e,t){this._runModuleDefinition(e,t)},_runModuleDefinition:function(i,s){if(!i)return;var o=t.flatten([this,this.config.app,e,r,n,t,s]);i.apply(this,o)},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new r.Callbacks,this._finalizerCallbacks=new r.Callbacks}}),t.extend(r.Module,{create:function(e,n,r){var s=this,o=e;n=n.split(".");var u=i.apply(arguments);u.splice(0,3);var a=n.length;return t.each(n,function(t,n){var i=n===a-1,f=n===0,l=s._getModuleDefinition(o,t,e);i&&(l.config.options=s._getModuleOptions(l,o,r),l.config.options.hasDefinition&&l.addDefinition(l.config.options.definition,u)),f&&i&&s._configureStartWithApp(e,l),o=l}),o},_configureStartWithApp:function(e,t){if(t.config.startWithAppIsConfigured)return;e.addInitializer(function(e){t.config.options.startWithParent&&t.start(e)}),t.config.startWithAppIsConfigured=!0},_getModuleDefinition:function(e,t,n){var i=e[t];return i||(i=new r.Module(t,n),e[t]=i,e.submodules[t]=i),i},_getModuleOptions:function(e,n,r){var i=!0;e.config.options&&!e.config.options.startWithParent&&(i=!1);var s={startWithParent:i,hasDefinition:!!r};return s.hasDefinition?(t.isFunction(r)?s.definition=r:(s.hasDefinition=!!r.define,s.definition=r.define,r.hasOwnProperty("startWithParent")&&(s.startWithParent=r.startWithParent)),s):s}}),r}(n,t,e||window.jQuery||window.Zepto||window.ender),n.Marionette});
Example #3
0
(function(a,b){if(typeof exports=="object"){var c=require("jquery"),d=require("underscore"),e=require("backbone");module.exports=b(c,d,e)}else typeof define=="function"&&define.amd&&define(["jquery","underscore","backbone"],b)})(this,function(a,b,c){return c.Marionette=function(a,b,c){var d={};d.version="0.8.0",d.View=a.View.extend({getTemplateSelector:function(){var a;return this.options&&this.options.template?a=this.options.template:a=this.template,b.isFunction(a)&&(a=a.call(this)),a},serializeData:function(){var a;return this.model?a=this.model.toJSON():this.collection&&(a={items:this.collection.toJSON()}),a=this.mixinTemplateHelpers(a),a},mixinTemplateHelpers:function(a){a=a||{};var c=this.templateHelpers;return b.isFunction(c)&&(c=c.call(this)),b.extend(a,c)},close:function(){this.beforeClose&&this.beforeClose(),this.unbindAll(),this.remove(),this.onClose&&this.onClose(),this.trigger("close"),this.unbind()}}),d.ItemView=d.View.extend({constructor:function(){var a=e.call(arguments);d.View.prototype.constructor.apply(this,a),b.bindAll(this,"render"),this.initialEvents()},initialEvents:function(){this.collection&&this.bindTo(this.collection,"reset",this.render,this)},render:function(){var a=this,b=c.Deferred(),d=function(){a.trigger("before:render",a),a.trigger("item:before:render",a);var b=a.serializeData();c.when(b).then(e)},e=function(b){var d=a.renderHtml(b);c.when(d).then(f)},f=function(b){a.$el.html(b),g(a.onRender,h,a)},h=function(){a.trigger("render",a),a.trigger("item:rendered",a),b.resolve()};return g(this.beforeRender,d,this),b.promise()},renderHtml:function(a){var b=this.getTemplateSelector();return d.Renderer.render(b,a)},close:function(){this.trigger("item:before:close"),d.View.prototype.close.apply(this,arguments),this.trigger("item:closed")}}),d.CollectionView=d.View.extend({constructor:function(){d.View.prototype.constructor.apply(this,arguments),b.bindAll(this,"addItemView","render"),this.initialEvents()},initialEvents:function(){this.collection&&(this.bindTo(this.collection,"add",this.addChildView,this),this.bindTo(this.collection,"remove",this.removeItemView,this),this.bindTo(this.collection,"reset",this.render,this))},addChildView:function(a){var b=this.getItemView();return this.addItemView(a,b)},render:function(){var a=this,b=c.Deferred(),d=[],e=this.getItemView();return this.beforeRender&&this.beforeRender(),this.trigger("collection:before:render",this),this.closeChildren(),this.collection&&this.collection.each(function(b){var c=a.addItemView(b,e);d.push(c)}),b.done(function(){this.onRender&&this.onRender(),this.trigger("collection:rendered",this)}),c.when.apply(this,d).then(function(){b.resolveWith(a)}),b.promise()},getItemView:function(){var a=this.options.itemView||this.itemView;if(!a){var b=new Error("An `itemView` must be specified");throw b.name="NoItemViewError",b}return a},addItemView:function(a,b){var d=this,f=this.buildItemView(a,b);this.bindTo(f,"all",function(){var a=e.call(arguments);a[0]="itemview:"+a[0],a.splice(1,0,f),d.trigger.apply(d,a)}),this.storeChild(f),this.trigger("item:added",f);var g=f.render();return c.when(g).then(function(){d.appendHtml(d,f)}),g},buildItemView:function(a,b){var c=new b({model:a});return c},removeItemView:function(a){var b=this.children[a.cid];b&&(b.close(),delete this.children[a.cid]),this.trigger("item:removed",b)},appendHtml:function(a,b){a.$el.append(b.el)},storeChild:function(a){this.children||(this.children={}),this.children[a.model.cid]=a},close:function(){this.trigger("collection:before:close"),this.closeChildren(),d.View.prototype.close.apply(this,arguments),this.trigger("collection:closed")},closeChildren:function(){this.children&&b.each(this.children,function(a){a.close()})}}),d.CompositeView=d.CollectionView.extend({constructor:function(a){d.CollectionView.apply(this,arguments),this.itemView=this.getItemView()},getItemView:function(){return this.itemView||this.constructor},render:function(){var a=this,b=c.Deferred(),d=this.renderModel();return c.when(d).then(function(d){a.$el.html(d),a.trigger("composite:model:rendered"),a.trigger("render");var e=a.renderCollection();c.when(e).then(function(){b.resolve()})}),b.done(function(){a.trigger("composite:rendered")}),b.promise()},renderCollection:function(){var a=d.CollectionView.prototype.render.apply(this,arguments);return a.done(function(){this.trigger("composite:collection:rendered")}),a.promise()},renderModel:function(){var a={};a=this.serializeData();var b=this.getTemplateSelector();return d.Renderer.render(b,a)}}),d.Region=function(a){this.options=a||{},b.extend(this,a);if(!this.el){var c=new Error("An 'el' must be specified");throw c.name="NoElError",c}this.initialize&&this.initialize.apply(this,arguments)},b.extend(d.Region.prototype,a.Events,{show:function(a,b){this.ensureEl(),this.close(),this.open(a,b),this.currentView=a},ensureEl:function(){if(!this.$el||this.$el.length===0)this.$el=this.getEl(this.el)},getEl:function(a){return c(a)},open:function(a,b){var d=this;b=b||"html",c.when(a.render()).then(function(){d.$el[b](a.el),a.onShow&&a.onShow(),d.onShow&&d.onShow(a),a.trigger("show"),d.trigger("view:show",a)})},close:function(){var a=this.currentView;if(!a)return;a.close&&a.close(),this.trigger("view:closed",a),delete this.currentView},attachView:function(a){this.currentView=a}}),d.Layout=d.ItemView.extend({constructor:function(){this.vent=new a.Marionette.EventAggregator,a.Marionette.ItemView.apply(this,arguments),this.regionManagers={}},render:function(){return this.initializeRegions(),a.Marionette.ItemView.prototype.render.call(this,arguments)},close:function(){this.closeRegions(),a.Marionette.ItemView.prototype.close.call(this,arguments)},initializeRegions:function(){var c=this;b.each(this.regions,function(b,d){var e=new a.Marionette.Region({el:b,getEl:function(a){return c.$(a)}});c.regionManagers[d]=e,c[d]=e})},closeRegions:function(){var a=this;b.each(this.regionManagers,function(b,c){b.close(),delete a[c]}),this.regionManagers={}}}),d.AppRouter=a.Router.extend({constructor:function(b){a.Router.prototype.constructor.call(this,b);if(this.appRoutes){var c=this.controller;b&&b.controller&&(c=b.controller),this.processAppRoutes(c,this.appRoutes)}},processAppRoutes:function(a,c){var d,e,f,g,h,i=[],j=this;for(f in c)c.hasOwnProperty(f)&&i.unshift([f,c[f]]);g=i.length;for(h=0;h<g;h++){f=i[h][0],e=i[h][1],d=a[e];if(!d){var k="Method '"+e+"' was not found on the controller",l=new Error(k);throw l.name="NoMethodError",l}d=b.bind(d,a),j.route(f,e,d)}}}),d.Application=function(a){this.initCallbacks=new d.Callbacks,this.vent=new d.EventAggregator,b.extend(this,a)},b.extend(d.Application.prototype,a.Events,{addInitializer:function(a){this.initCallbacks.add(a)},start:function(a){this.trigger("initialize:before",a),this.initCallbacks.run(this,a),this.trigger("initialize:after",a),this.trigger("start",a)},addRegions:function(a){var b,c,e;for(e in a)a.hasOwnProperty(e)&&(b=a[e],typeof b=="string"?c=new d.Region({el:b}):c=new b,this[e]=c)},module:function(c,e){var f,g,h,i=this,c=c.split("."),j=c.length;for(var k=0;k<j;k++)f=c[k],g=i[f],g||(g=new d.Application,e&&(h=e(g,this,a,d,jQuery,b),h&&(g=h)),i[f]=g),i=g;return g}}),d.BindTo={bindTo:function(a,b,c,d){d=d||this,a.on(b,c,d),this.bindings||(this.bindings=[]);var e={obj:a,eventName:b,callback:c,context:d};return this.bindings.push(e),e},unbindFrom:function(a){a.obj.off(a.eventName,a.callback),this.bindings=b.reject(this.bindings,function(b){return b===a})},unbindAll:function(){var a=this,c=b.map(this.bindings,b.identity);b.each(c,function(b,c){a.unbindFrom(b)})}},d.Callbacks=function(){this.deferred=c.Deferred(),this.promise=this.deferred.promise()},b.extend(d.Callbacks.prototype,{add:function(a){this.promise.done(function(b,c){a.call(b,c)})},run:function(a,b){this.deferred.resolve(a,b)}}),d.EventAggregator=function(a){b.extend(this,a)},b.extend(d.EventAggregator.prototype,a.Events,d.BindTo,{bindTo:function(a,b,c){return d.BindTo.bindTo.call(this,this,a,b,c)}}),d.TemplateCache={templates:{},loaders:{},get:function(a){var b=this,d=c.Deferred(),e=this.templates[a];if(e)d.resolve(e);else{var f=this.loaders[a];f?d=f:(this.loaders[a]=d,this.loadTemplate(a,function(c){delete b.loaders[a],b.templates[a]=c,d.resolve(c)}))}return d.promise()},loadTemplate:function(a,b){var d=c(a).html();if(!d||d.length===0){var e="Could not find template: '"+a+"'",f=new Error(e);throw f.name="NoTemplateError",f}d=this.compileTemplate(d),b.call(this,d)},compileTemplate:function(a){return b.template(a)},clear:function(){var a,b=arguments.length;if(b>0)for(a=0;a<b;a++)delete this.templates[arguments[a]];else this.templates={}}},d.Renderer={render:function(a,b){var e=this,f=c.Deferred(),g=d.TemplateCache.get(a);return c.when(g).then(function(a){var c=e.renderTemplate(a,b);f.resolve(c)}),f.promise()},renderTemplate:function(a,b){var c=a(b);return c}};var e=Array.prototype.slice,f=d.View.extend;d.Region.extend=f,d.Application.extend=f,b.extend(d.View.prototype,d.BindTo),b.extend(d.Application.prototype,d.BindTo),b.extend(d.Region.prototype,d.BindTo);var g=function(a,b,d){var e;a&&(e=a.call(d)),c.when(e).then(b)};return d}(c,b,window.jQuery||window.Zepto||window.ender),c.Marionette})
Example #4
0
(function(e,t){if(typeof exports=="object"){var n=require("jquery"),r=require("underscore"),i=require("backbone");module.exports=t(n,r,i)}else typeof define=="function"&&define.amd&&define(["jquery","underscore","backbone"],t)})(this,function(e,t,n){return n.Marionette=function(e,t,n){var r={};r.EventBinder=function(){this._eventBindings=[]},t.extend(r.EventBinder.prototype,{bindTo:function(e,t,n,r){r=r||this,e.on(t,n,r);var i={obj:e,eventName:t,callback:n,context:r};return this._eventBindings.push(i),i},unbindFrom:function(e){e.obj.off(e.eventName,e.callback,e.context),this._eventBindings=t.reject(this._eventBindings,function(t){return t===e})},unbindAll:function(){var e=this,n=t.map(this._eventBindings,t.identity);t.each(n,function(t,n){e.unbindFrom(t)})}}),r.EventBinder.extend=e.View.extend,r.View=e.View.extend({constructor:function(){var n=new r.EventBinder;t.extend(this,n),e.View.prototype.constructor.apply(this,arguments),this.bindBackboneEntityTo(this.model,this.modelEvents),this.bindBackboneEntityTo(this.collection,this.collectionEvents),this.bindTo(this,"show",this.onShowCalled,this)},getTemplate:function(){var e;return this.options&&this.options.template?e=this.options.template:e=this.template,e},serializeData:function(){var e;return this.model?e=this.model.toJSON():this.collection&&(e={items:this.collection.toJSON()}),e=this.mixinTemplateHelpers(e),e},mixinTemplateHelpers:function(e){e=e||{};var n=this.templateHelpers;return t.isFunction(n)&&(n=n.call(this)),t.extend(e,n)},configureTriggers:function(){if(!this.triggers)return;var e=this.triggers,n=this,r={};return t.isFunction(e)&&(e=e.call(this)),t.each(e,function(e,t){r[t]=function(t){t&&t.preventDefault&&t.preventDefault(),t&&t.stopPropagation&&t.stopPropagation(),n.trigger(e)}}),r},delegateEvents:function(n){n=n||this.events,t.isFunction(n)&&(n=n.call(this));var r={},i=this.configureTriggers();t.extend(r,n,i),e.View.prototype.delegateEvents.call(this,r)},onShowCalled:function(){},close:function(){this.beforeClose&&this.beforeClose(),this.remove(),this.onClose&&this.onClose(),this.trigger("close"),this.unbindAll(),this.unbind()},bindUIElements:function(){if(!this.ui)return;var e=this;this.uiBindings||(this.uiBindings=this.ui),this.ui={},t.each(t.keys(this.uiBindings),function(t){var n=e.uiBindings[t];e.ui[t]=e.$(n)})},bindBackboneEntityTo:function(e,n){if(!e||!n)return;var r=this;t.each(n,function(t,n){var i=r[t];if(!i)throw new Error("View method '"+t+"' was configured as an event handler, but does not exist.");r.bindTo(e,n,i,r)})}}),r.ItemView=r.View.extend({constructor:function(){r.View.prototype.constructor.apply(this,arguments),this.initialEvents&&this.initialEvents()},render:function(){this.beforeRender&&this.beforeRender(),this.trigger("before:render",this),this.trigger("item:before:render",this);var e=this.serializeData(),t=this.getTemplate(),n=r.Renderer.render(t,e);return this.$el.html(n),this.bindUIElements(),this.onRender&&this.onRender(),this.trigger("render",this),this.trigger("item:rendered",this),this},close:function(){this.trigger("item:before:close"),r.View.prototype.close.apply(this,arguments),this.trigger("item:closed")}}),r.CollectionView=r.View.extend({constructor:function(){r.View.prototype.constructor.apply(this,arguments),this.initChildViewStorage(),this.initialEvents(),this.onShowCallbacks=new r.Callbacks},initialEvents:function(){this.collection&&(this.bindTo(this.collection,"add",this.addChildView,this),this.bindTo(this.collection,"remove",this.removeItemView,this),this.bindTo(this.collection,"reset",this.render,this))},addChildView:function(e,t,n){this.closeEmptyView();var r=this.getItemView(e);return this.addItemView(e,r,n.index)},onShowCalled:function(){this.onShowCallbacks.run()},triggerBeforeRender:function(){this.beforeRender&&this.beforeRender(),this.trigger("before:render",this),this.trigger("collection:before:render",this)},triggerRendered:function(){this.onRender&&this.onRender(),this.trigger("render",this),this.trigger("collection:rendered",this)},render:function(){return this.triggerBeforeRender(),this.closeEmptyView(),this.closeChildren(),this.collection&&this.collection.length>0?this.showCollection():this.showEmptyView(),this.triggerRendered(),this},showCollection:function(){var e=this,t;this.collection.each(function(n,r){t=e.getItemView(n),e.addItemView(n,t,r)})},showEmptyView:function(){var t=this.options.emptyView||this.emptyView;if(t&&!this._showingEmptyView){this._showingEmptyView=!0;var n=new e.Model;this.addItemView(n,t,0)}},closeEmptyView:function(){this._showingEmptyView&&(this.closeChildren(),delete this._showingEmptyView)},getItemView:function(e){var t=this.options.itemView||this.itemView;if(!t){var n=new Error("An `itemView` must be specified");throw n.name="NoItemViewError",n}return t},addItemView:function(e,t,n){var r=this,s=this.buildItemView(e,t);this.storeChild(s),this.onItemAdded&&this.onItemAdded(s),this.trigger("item:added",s);var o=this.renderItemView(s,n);s.onShow&&this.onShowCallbacks.add(s.onShow,s);var u=this.bindTo(s,"all",function(){var e=i.call(arguments);e[0]="itemview:"+e[0],e.splice(1,0,s),r.trigger.apply(r,e)});return this.childBindings=this.childBindings||{},this.childBindings[s.cid]=u,o},renderItemView:function(e,t){e.render(),this.appendHtml(this,e,t)},buildItemView:function(e,n){var r;t.isFunction(this.itemViewOptions)?r=this.itemViewOptions(e):r=this.itemViewOptions;var i=t.extend({model:e},r),s=new n(i);return s},removeItemView:function(e){var t=this.children[e.cid];if(t){var n=this.childBindings[t.cid];n&&(this.unbindFrom(n),delete this.childBindings[t.cid]),t.close(),delete this.children[e.cid]}(!this.collection||this.collection.length===0)&&this.showEmptyView(),this.trigger("item:removed",t)},appendHtml:function(e,t,n){e.$el.append(t.el)},storeChild:function(e){this.children[e.model.cid]=e},initChildViewStorage:function(){this.children={}},close:function(){this.trigger("collection:before:close"),this.closeChildren(),this.trigger("collection:closed"),r.View.prototype.close.apply(this,arguments)},closeChildren:function(){var e=this;this.children&&t.each(t.clone(this.children),function(t){e.removeItemView(t.model)})}}),r.CompositeView=r.CollectionView.extend({constructor:function(e){r.CollectionView.apply(this,arguments),this.itemView=this.getItemView()},initialEvents:function(){this.collection&&(this.bindTo(this.collection,"add",this.addChildView,this),this.bindTo(this.collection,"remove",this.removeItemView,this),this.bindTo(this.collection,"reset",this.renderCollection,this))},getItemView:function(e){var t=this.options.itemView||this.itemView||this.constructor;if(!t){var n=new Error("An `itemView` must be specified");throw n.name="NoItemViewError",n}return t},render:function(){var e=this;this.resetItemViewContainer();var t=this.renderModel();return this.$el.html(t),this.bindUIElements(),this.trigger("composite:model:rendered"),this.trigger("render"),this.renderCollection(),this.trigger("composite:rendered"),this},renderCollection:function(){r.CollectionView.prototype.render.apply(this,arguments),this.trigger("composite:collection:rendered")},renderModel:function(){var e={};e=this.serializeData();var t=this.getTemplate();return r.Renderer.render(t,e)},appendHtml:function(e,t){var n=this.getItemViewContainer(e);n.append(t.el)},getItemViewContainer:function(e){var n;if("$itemViewContainer"in e)n=e.$itemViewContainer;else{if(e.itemViewContainer){n=e.$(t.result(e,"itemViewContainer"));if(n.length<=0){var r=new Error("Missing `itemViewContainer`");throw r.name="ItemViewContainerMissingError",r}}else n=e.$el;e.$itemViewContainer=n}return n},resetItemViewContainer:function(){this.$itemViewContainer&&delete this.$itemViewContainer}}),r.Region=function(e){this.options=e||{};var n=new r.EventBinder;t.extend(this,n,e);if(!this.el){var i=new Error("An 'el' must be specified");throw i.name="NoElError",i}this.initialize&&this.initialize.apply(this,arguments)},t.extend(r.Region.prototype,e.Events,{show:function(e){this.ensureEl(),this.close(),e.render(),this.open(e),e.onShow&&e.onShow(),e.trigger("show"),this.onShow&&this.onShow(e),this.trigger("view:show",e),this.currentView=e},ensureEl:function(){if(!this.$el||this.$el.length===0)this.$el=this.getEl(this.el)},getEl:function(e){return n(e)},open:function(e){this.$el.html(e.el)},close:function(){var e=this.currentView;if(!e)return;e.close&&e.close(),this.trigger("view:closed",e),delete this.currentView},attachView:function(e){this.currentView=e},reset:function(){this.close(),delete this.$el}}),r.Region.extend=e.View.extend,r.Layout=r.ItemView.extend({regionType:r.Region,constructor:function(){this.initializeRegions(),e.Marionette.ItemView.apply(this,arguments)},render:function(){var e=r.ItemView.prototype.render.apply(this,arguments);return this.render=function(){this.closeRegions(),this.reInitializeRegions();var e=r.ItemView.prototype.render.apply(this,arguments);return e},e},close:function(){this.closeRegions(),this.destroyRegions(),e.Marionette.ItemView.prototype.close.call(this,arguments)},initializeRegions:function(){this.regionManagers||(this.regionManagers={});var e=this;t.each(this.regions,function(t,n){var r=typeof t=="string",i=typeof t.selector=="string",s=typeof t.regionType=="undefined";if(!r&&!i)throw new Error("Region must be specified as a selector string or an object with selector property");var o,u;r?o=t:o=t.selector,s?u=e.regionType:u=t.regionType;var a=new u({el:o,getEl:function(t){return e.$(t)}});e.regionManagers[n]=a,e[n]=a})},reInitializeRegions:function(){this.regionManagers&&t.size(this.regionManagers)===0?this.initializeRegions():t.each(this.regionManagers,function(e){e.reset()})},closeRegions:function(){var e=this;t.each(this.regionManagers,function(e,t){e.close()})},destroyRegions:function(){var e=this;t.each(this.regionManagers,function(t,n){delete e[n]}),this.regionManagers={}}}),r.Application=function(e){this.initCallbacks=new r.Callbacks,this.vent=new r.EventAggregator,this.submodules={};var n=new r.EventBinder;t.extend(this,n,e)},t.extend(r.Application.prototype,e.Events,{addInitializer:function(e){this.initCallbacks.add(e)},start:function(e){this.trigger("initialize:before",e),this.initCallbacks.run(e,this),this.trigger("initialize:after",e),this.trigger("start",e)},addRegions:function(e){var t,n,i;for(i in e)e.hasOwnProperty(i)&&(t=e[i],typeof t=="string"?n=new r.Region({el:t}):n=new t,this[i]=n)},removeRegion:function(e){this[e].close(),delete this[e]},module:function(e,t){var n=i.call(arguments);return n.unshift(this),r.Module.create.apply(r.Module,n)}}),r.Application.extend=e.View.extend,r.AppRouter=e.Router.extend({constructor:function(t){e.Router.prototype.constructor.call(this,t);if(this.appRoutes){var n=this.controller;t&&t.controller&&(n=t.controller),this.processAppRoutes(n,this.appRoutes)}},processAppRoutes:function(e,n){var r,i,s,o,u,a=[],f=this;for(s in n)n.hasOwnProperty(s)&&a.unshift([s,n[s]]);o=a.length;for(u=0;u<o;u++){s=a[u][0],i=a[u][1],r=e[i];if(!r){var l="Method '"+i+"' was not found on the controller",c=new Error(l);throw c.name="NoMethodError",c}r=t.bind(r,e),f.route(s,i,r)}}}),r.Module=function(e,n,i){this.moduleName=e,this.submodules={},this._setupInitializersAndFinalizers(),this.config={},this.config.app=n,this.config.customArgs=i,this.config.definitions=[];var s=new r.EventBinder;t.extend(this,s)},t.extend(r.Module.prototype,e.Events,{addInitializer:function(e){this._initializerCallbacks.add(e)},addFinalizer:function(e){this._finalizerCallbacks.add(e)},start:function(e){if(this._isInitialized)return;t.each(this.submodules,function(t){t.config.options.startWithParent&&t.start(e)}),this._initializerCallbacks.run(e,this),this._isInitialized=!0},stop:function(){if(!this._isInitialized)return;this._isInitialized=!1,t.each(this.submodules,function(e){e.stop()}),this._finalizerCallbacks.run(),this._initializerCallbacks.reset(),this._finalizerCallbacks.reset()},addDefinition:function(e){this._runModuleDefinition(e)},_runModuleDefinition:function(i){if(!i)return;var s=t.flatten([this,this.config.app,e,r,n,t,this.config.customArgs]);i.apply(this,s)},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new r.Callbacks,this._finalizerCallbacks=new r.Callbacks}}),t.extend(r.Module,{create:function(e,n,r){var s=this,o=e;n=n.split(".");var u=i.apply(arguments);u.splice(0,3);var a=n.length;return t.each(n,function(t,n){var i=n===a-1,f=s._getModuleDefinition(o,t,e,u);f.config.options=s._getModuleOptions(o,r),i&&s._configureAutoStart(e,f),i&&f.config.options.hasDefinition&&f.addDefinition(f.config.options.definition),o=f}),o},_configureAutoStart:function(e,t){t.config.options.startWithParent&&!t.config.autoStartConfigured&&e.addInitializer(function(e){t.start(e)}),t.config.autoStartConfigured=!0},_getModuleDefinition:function(e,t,n,i){var s=e[t];return s||(s=new r.Module(t,n,i),e[t]=s,e.submodules[t]=s),s},_getModuleOptions:function(e,n){var r={startWithParent:!0,hasDefinition:!!n};return r.hasDefinition?(t.isFunction(n)?r.definition=n:(r.hasDefinition=!!n.define,r.definition=n.define,n.hasOwnProperty("startWithParent")&&(r.startWithParent=n.startWithParent)),r):r}}),r.TemplateCache=function(e){this.templateId=e},t.extend(r.TemplateCache,{templateCaches:{},get:function(e){var t=this,n=this.templateCaches[e];return n||(n=new r.TemplateCache(e),this.templateCaches[e]=n),n.load()},clear:function(){var e,t=arguments.length;if(t>0)for(e=0;e<t;e++)delete this.templateCaches[arguments[e]];else this.templateCaches={}}}),t.extend(r.TemplateCache.prototype,{load:function(){var e=this;if(this.compiledTemplate)return this.compiledTemplate;var t=this.loadTemplate(this.templateId);return this.compiledTemplate=this.compileTemplate(t),this.compiledTemplate},loadTemplate:function(e){var t=n(e).html();if(!t||t.length===0){var r="Could not find template: '"+e+"'",i=new Error(r);throw i.name="NoTemplateError",i}return t},compileTemplate:function(e){return t.template(e)}}),r.Renderer={render:function(e,t){var n=typeof e=="function"?e:r.TemplateCache.get(e),i=n(t);return i}},r.Callbacks=function(){this._deferred=n.Deferred(),this._callbacks=[]},t.extend(r.Callbacks.prototype,{add:function(e,t){this._callbacks.push({cb:e,ctx:t}),this._deferred.done(function(n,r){t&&(n=t),e.call(n,r)})},run:function(e,t){this._deferred.resolve(t,e)},reset:function(){var e=this;this._deferred=n.Deferred(),t.each(this._callbacks,function(t){e.add(t.cb,t.ctx)})}}),r.EventAggregator=r.EventBinder.extend({constructor:function(e){r.EventBinder.apply(this,arguments),t.extend(this,e)},bindTo:function(e,t,n){return r.EventBinder.prototype.bindTo.call(this,this,e,t,n)}}),t.extend(r.EventAggregator.prototype,e.Events),r.EventAggregator.extend=e.View.extend;var i=Array.prototype.slice;return r}(n,t,window.jQuery||window.Zepto||window.ender),n.Marionette});
(function(e,t){if(typeof exports=="object"){var n=require("jquery"),r=require("underscore"),i=require("backbone"),s=require("backbone.eventbinder"),o=require("backbone.wreqr");module.exports=t(n,r,i,s,o)}else typeof define=="function"&&define.amd&&define(["jquery","underscore","backbone","backbone.wreqr","backbone.eventbinder"],t)})(this,function(e,t,n){return n.Mario=Mario=function(e,t,n){var r={},i=Array.prototype.slice;return r.extend=e.Model.extend,r.getOption=function(e,t){if(!e||!t)return;var n;return e.options&&e.options[t]?n=e.options[t]:n=e[t],n},r.createObject=function(){function t(){}var e;return typeof Object.create=="function"?e=Object.create:e=function(e){t.prototype=e;var n=new t;return t.prototype=null,n},e}(),r.triggerMethod=function(){var e=Array.prototype.slice.apply(arguments),n=e[0],r=n.split(":"),i,s,o="on";for(var u=0;u<r.length;u++)i=r[u],s=i.charAt(0).toUpperCase(),o+=s+i.slice(1);this.trigger.apply(this,arguments);if(t.isFunction(this[o]))return e.shift(),this[o].apply(this,e)},r.EventBinder=e.EventBinder.extend({augment:function(e){var n=new r.EventBinder;e.eventBinder=n,e.bindTo=t.bind(n.bindTo,n),e.unbindFrom=t.bind(n.unbindFrom,n),e.unbindAll=t.bind(n.unbindAll,n)}}),r.addEventBinder=function(e){var n=new r.EventBinder;e.eventBinder=n,e.bindTo=t.bind(n.bindTo,n),e.unbindFrom=t.bind(n.unbindFrom,n),e.unbindAll=t.bind(n.unbindAll,n)},r.EventAggregator=e.Wreqr.EventAggregator.extend({constructor:function(){r.addEventBinder(this),e.Wreqr.EventAggregator.prototype.constructor.apply(this,arguments)}}),r.Callbacks=function(){this._deferred=n.Deferred(),this._callbacks=[]},t.extend(r.Callbacks.prototype,{add:function(e,t){this._callbacks.push({cb:e,ctx:t}),this._deferred.done(function(n,r){t&&(n=t),e.call(n,r)})},run:function(e,t){this._deferred.resolve(t,e)},reset:function(){var e=this,r=this._callbacks;this._deferred=n.Deferred(),this._callbacks=[],t.each(r,function(t){e.add(t.cb,t.ctx)})}}),r.TemplateCache=function(e){this.templateId=e},t.extend(r.TemplateCache,{templateCaches:{},get:function(e){var t=this,n=this.templateCaches[e];return n||(n=new r.TemplateCache(e),this.templateCaches[e]=n),n.load()},clear:function(){var e,t=arguments.length;if(t>0)for(e=0;e<t;e++)delete this.templateCaches[arguments[e]];else this.templateCaches={}}}),t.extend(r.TemplateCache.prototype,{load:function(){var e=this;if(this.compiledTemplate)return this.compiledTemplate;var t=this.loadTemplate(this.templateId);return this.compiledTemplate=this.compileTemplate(t),this.compiledTemplate},loadTemplate:function(e){var t=n(e).html();if(!t||t.length===0){var r="Could not find template: '"+e+"'",i=new Error(r);throw i.name="NoTemplateError",i}return t},compileTemplate:function(e){return t.template(e)}}),r.Renderer={render:function(e,t){var n=typeof e=="function"?e:r.TemplateCache.get(e),i=n(t);return i}},r.Controller=function(e){this.triggerMethod=r.triggerMethod,this.options=e||{},r.addEventBinder(this),t.isFunction(this.initialize)&&this.initialize(this.options)},r.Controller.extend=r.extend,t.extend(r.Controller.prototype,e.Events,{close:function(){this.unbindAll(),this.triggerMethod("close"),this.unbind()}}),r.Region=function(e){this.options=e||{},r.addEventBinder(this),this.el=r.getOption(this,"el");if(!this.el){var t=new Error("An 'el' must be specified for a region.");throw t.name="NoElError",t}this.initialize&&this.initialize.apply(this,arguments)},t.extend(r.Region,{buildRegion:function(e,t){var n=typeof e=="string",r=typeof e.selector=="string",i=typeof e.regionType=="undefined",s=typeof e=="function";if(!s&&!n&&!r)throw new Error("Region must be specified as a Region type, a selector string or an object with selector property");var o,u;n&&(o=e),e.selector&&(o=e.selector),s&&(u=e),!s&&i&&(u=t),e.regionType&&(u=e.regionType);var a=new u({el:o});return a}}),t.extend(r.Region.prototype,e.Events,{show:function(e){this.ensureEl(),this.close(),e.render(),this.open(e),r.triggerMethod.call(e,"show"),r.triggerMethod.call(this,"show",e),this.currentView=e},ensureEl:function(){if(!this.$el||this.$el.length===0)this.$el=this.getEl(this.el)},getEl:function(e){return n(e)},open:function(e){this.$el.empty().append(e.el)},close:function(){var e=this.currentView;if(!e||e.isClosed)return;e.close&&e.close(),r.triggerMethod.call(this,"close"),delete this.currentView},attachView:function(e){this.currentView=e},reset:function(){this.close(),delete this.$el}}),r.Region.extend=r.extend,r.View=e.View.extend({constructor:function(){t.bindAll(this,"render"),r.addEventBinder(this),e.View.prototype.constructor.apply(this,arguments),this.bindBackboneEntityTo(this.model,this.modelEvents),this.bindBackboneEntityTo(this.collection,this.collectionEvents),this.bindTo(this,"show",this.onShowCalled,this)},triggerMethod:r.triggerMethod,getTemplate:function(){return r.getOption(this,"template")},mixinTemplateHelpers:function(e){e=e||{};var n=this.templateHelpers;return t.isFunction(n)&&(n=n.call(this)),t.extend(e,n)},configureTriggers:function(){if(!this.triggers)return;var e=this,n={},r=t.result(this,"triggers");return t.each(r,function(t,r){n[r]=function(n){n&&n.preventDefault&&n.preventDefault(),n&&n.stopPropagation&&n.stopPropagation(),e.trigger(t)}}),n},delegateEvents:function(n){n=n||this.events,t.isFunction(n)&&(n=n.call(this));var r={},i=this.configureTriggers();t.extend(r,n,i),e.View.prototype.delegateEvents.call(this,r)},onShowCalled:function(){},close:function(){if(this.isClosed)return;this.triggerMethod("before:close"),this.remove(),this.unbindAll(),this.triggerMethod("close"),this.isClosed=!0},bindUIElements:function(){if(!this.ui)return;var e=this;this.uiBindings||(this.uiBindings=this.ui),this.ui={},t.each(t.keys(this.uiBindings),function(t){var n=e.uiBindings[t];e.ui[t]=e.$(n)})},bindBackboneEntityTo:function(e,n){if(!e||!n)return;var r=this;t.each(n,function(t,n){var i=r[t];if(!i)throw new Error("View method '"+t+"' was configured as an event handler, but does not exist.");r.bindTo(e,n,i,r)})}}),r.ItemView=r.View.extend({constructor:function(){r.View.prototype.constructor.apply(this,arguments),this.initialEvents&&this.initialEvents()},serializeData:function(){var e={};return this.model?e=this.model.toJSON():this.collection&&(e={items:this.collection.toJSON()}),e},render:function(){this.isClosed=!1,this.triggerMethod("before:render",this),this.triggerMethod("item:before:render",this);var e=this.serializeData();e=this.mixinTemplateHelpers(e);var t=this.getTemplate(),n=r.Renderer.render(t,e);return this.$el.html(n),this.bindUIElements(),this.triggerMethod("render",this),this.triggerMethod("item:rendered",this),this},close:function(){if(this.isClosed)return;this.triggerMethod("item:before:close"),r.View.prototype.close.apply(this,arguments),this.triggerMethod("item:closed")}}),r.CollectionView=r.View.extend({constructor:function(e){this.initChildViewStorage(),r.View.prototype.constructor.apply(this,arguments),this.initialEvents(),this.onShowCallbacks=new r.Callbacks,e&&e.itemViewOptions&&(this.itemViewOptions=e.itemViewOptions)},initialEvents:function(){this.collection&&(this.bindTo(this.collection,"add",this.addChildView,this),this.bindTo(this.collection,"remove",this.removeItemView,this),this.bindTo(this.collection,"reset",this.render,this))},addChildView:function(e,t,n){this.closeEmptyView();var r=this.getItemView(e),i;return n&&n.index?i=n.index:i=0,this.addItemView(e,r,i)},onShowCalled:function(){this.onShowCallbacks.run()},triggerBeforeRender:function(){this.triggerMethod("before:render",this),this.triggerMethod("collection:before:render",this)},triggerRendered:function(){this.triggerMethod("render",this),this.triggerMethod("collection:rendered",this)},render:function(){return this.isClosed=!1,this.triggerBeforeRender(),this.closeEmptyView(),this.closeChildren(),this.collection&&this.collection.length>0?this.showCollection():this.showEmptyView(),this.triggerRendered(),this},showCollection:function(){var e=this,t;this.collection.each(function(n,r){t=e.getItemView(n),e.addItemView(n,t,r)})},showEmptyView:function(){var t=r.getOption(this,"emptyView");if(t&&!this._showingEmptyView){this._showingEmptyView=!0;var n=new e.Model;this.addItemView(n,t,0)}},closeEmptyView:function(){this._showingEmptyView&&(this.closeChildren(),delete this._showingEmptyView)},getItemView:function(e){var t=r.getOption(this,"itemView");if(!t){var n=new Error("An `itemView` must be specified");throw n.name="NoItemViewError",n}return t},addItemView:function(e,n,r){var s=this,o;t.isFunction(this.itemViewOptions)?o=this.itemViewOptions(e):o=this.itemViewOptions;var u=this.buildItemView(e,n,o);this.children.add(u),this.triggerMethod("item:added",u);var a=this.bindTo(u,"all",function(){var e=i.call(arguments);e[0]="itemview:"+e[0],e.splice(1,0,u),s.triggerMethod.apply(s,e)});this.childBindings=this.childBindings||{},this.childBindings[u.cid]=a;var f=this.renderItemView(u,r);return u.onShow&&this.onShowCallbacks.add(u.onShow,u),f},renderItemView:function(e,t){e.render(),this.appendHtml(this,e,t)},buildItemView:function(e,n,r){var i=t.extend({model:e},r),s=new n(i);return s},removeItemView:function(e){var t=this.children.findByModel(e);if(t){var n=this.childBindings[t.cid];n&&(this.unbindFrom(n),delete this.childBindings[t.cid]),t.close&&t.close(),this.children.remove(t)}(!this.collection||this.collection.length===0)&&this.showEmptyView(),this.triggerMethod("item:removed",t)},appendHtml:function(e,t,n){e.$el.append(t.el)},initChildViewStorage:function(){this.children=new e.ChildViewContainer},close:function(){if(this.isClosed)return;this.triggerMethod("collection:before:close"),this.closeChildren(),this.triggerMethod("collection:closed"),r.View.prototype.close.apply(this,arguments)},closeChildren:function(){var e=this;this.children.apply("close"),this.initChildViewStorage()}}),r.CompositeView=r.CollectionView.extend({constructor:function(e){r.CollectionView.apply(this,arguments),this.itemView=this.getItemView()},initialEvents:function(){this.collection&&(this.bindTo(this.collection,"add",this.addChildView,this),this.bindTo(this.collection,"remove",this.removeItemView,this),this.bindTo(this.collection,"reset",this.renderCollection,this))},getItemView:function(e){var t=r.getOption(this,"itemView")||this.constructor;if(!t){var n=new Error("An `itemView` must be specified");throw n.name="NoItemViewError",n}return t},serializeData:function(){var e={};return this.model&&(e=this.model.toJSON()),e},render:function(){this.isClosed=!1,this.resetItemViewContainer();var e=this.renderModel();return this.$el.html(e),this.bindUIElements(),this.triggerMethod("composite:model:rendered"),this.renderCollection(),this.triggerMethod("composite:rendered"),this},renderCollection:function(){r.CollectionView.prototype.render.apply(this,arguments),this.triggerMethod("composite:collection:rendered")},renderModel:function(){var e={};e=this.serializeData(),e=this.mixinTemplateHelpers(e);var t=this.getTemplate();return r.Renderer.render(t,e)},appendHtml:function(e,t){var n=this.getItemViewContainer(e);n.append(t.el)},getItemViewContainer:function(e){if("$itemViewContainer"in e)return e.$itemViewContainer;var n;if(e.itemViewContainer){var r=t.result(e,"itemViewContainer");n=e.$(r);if(n.length<=0){var i=new Error("The specified `itemViewContainer` was not found: "+e.itemViewContainer);throw i.name="ItemViewContainerMissingError",i}}else n=e.$el;return e.$itemViewContainer=n,n},resetItemViewContainer:function(){this.$itemViewContainer&&delete this.$itemViewContainer}}),r.Layout=r.ItemView.extend({regionType:r.Region,constructor:function(){this._firstRender=!0,this.initializeRegions(),e.Mario.ItemView.apply(this,arguments)},render:function(){this._firstRender?this._firstRender=!1:(this.closeRegions(),this.reInitializeRegions());var e=r.ItemView.prototype.render.apply(this,arguments);return e},close:function(){if(this.isClosed)return;this.closeRegions(),this.destroyRegions(),e.Mario.ItemView.prototype.close.call(this,arguments)},initializeRegions:function(){this.regionManagers||(this.regionManagers={});var e=this,n=this.regions||{};t.each(n,function(t,n){var i=r.Region.buildRegion(t,e.regionType);i.getEl=function(t){return e.$(t)},e.regionManagers[n]=i,e[n]=i})},reInitializeRegions:function(){this.regionManagers&&t.size(this.regionManagers)===0?this.initializeRegions():t.each(this.regionManagers,function(e){e.reset()})},closeRegions:function(){var e=this;t.each(this.regionManagers,function(e,t){e.close()})},destroyRegions:function(){var e=this;t.each(this.regionManagers,function(t,n){delete e[n]}),this.regionManagers={}}}),r.FormView=r.ItemView.extend({defaults:{field:{validateOn:"submit"}},rules:{},fields:{},constructor:function(){r.ItemView.prototype.constructor.apply(this,arguments);if(!this.fields)throw new Error("Fields Must Be Provided");this.model||(this.model=new e.Model),this.bindTo(this.model,"change",this.changeFieldVal,this),this.data&&this.model.set(this.data),this.template||this.runInitializers(),this.on("item:rendered",this.runInitializers,this)},reconfig:function(e){this.model=e.model||this.model,this.fields=e.fields||this.fields,this.runInitializers()},changeFieldVal:function(e,t){var n=Object.keys(t.changes),r=this.fields[n],i=this.$(r.el);i&&i.val(this.model.get(n))},populateFields:function(){t(this.fields).each(function(e,t){var n=this.model.get(t);this.$(e.el).data("model-attribute",t),typeof n=="undefined"&&(n=""),this.$(e.el).val(n)},this)},serializeFormData:function(){function n(t,n){var r=this.$(t.el);r&&(e[n]=this.getInputVal(r))}var e={};return t.each(this.fields,t(n).bind(this)),e},beforeFormSubmit:function(e){var n=this.validate(),r=t.isEmpty(n);if(!r)return t.isFunction(this.onSubmitFail)&&this.onSubmitFail.apply(this,[n]),e.stopImmediatePropagation(),!1;if(t.isFunction(this.onSubmit))return this.onSubmit.apply(this,[e])},onFieldEvent:function(e){this.handleFieldEvent(e,e.type)},handleFieldEvent:function(e,r){var i=e.target||e.srcElement,s=n(i).data("model-attribute"),o=this.fields[s];if(o&&o.validateOn===r){var u=this.validateField(s);!t.isEmpty(u)&&t.isFunction(this.onValidationFail)&&this.onValidationFail(u)}},validate:function(){var e={},n=t(this.fields).keys();return t(n).each(function(n){var r=this.validateField(n);t.isEmpty(r)||(e[n]=r)},this),e},validateField:function(e){var n=this.fields[e],r=n&&n.validations?n.validations:{},i=[],s=!0,o=this.$(n.el),u=this.getInputVal(o);if(n.required){s=this.validateRule(u,"required");var a=typeof n.required=="string"?n.required:"This field is required";s||i.push(a)}s&&r&&t.each(r,function(e,t){s=this.validateRule(u,t),s||i.push(e)},this);if(!t.isEmpty(i)){var f={field:e,el:this.fields[e].el,error:i};return f}},getInputVal:function(e){if(!e)return"";e.jQuery||(e=this.$(e));var t;if(e.is("input")){var r=e.attr("type").toLowerCase();switch(r){case"radio":case"checkbox":t=e.is(":checked");break;default:t=n.trim(e.val())}}else e.is("textarea")&&(t=e.text()),e.is("select")&&(t=n.trim(e.val()));return t},validateRule:function(e,n){var i;if(!n)throw new Error("Not passed a validation to test");return n==="required"?r.FormView.Validator.required(e):(n.indexOf(":")!==-1&&(i=n.split(":"),n=i.shift()),this.rules&&this.rules[n]?t(this.rules[n]).bind(this)(e):t(r.FormView.Validator.validate).bind(this)(n,e,i))},submit:function(){this.form.submit()},bindFormEvents:function(){var e=this.$el.is("form")?this.$el:this.$("form").first();this.form=e,this.$("input").blur(t(this.onFieldEvent).bind(this)).keyup(t(this.onFieldEvent).bind(this)).keydown(t(this.onFieldEvent).bind(this)).change(t(this.onFieldEvent).bind(this)),e.submit(t(this.beforeFormSubmit).bind(this))},runInitializers:function(){this.populateFields(),this.bindFormEvents(),t.isFunction(this.onReady)&&this.onReady()}}),r.FormView.Validator={regex:{email:/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,alpha:/^[a-zA-Z]+$/,alphanum:/^[a-zA-Z0-9]+$/},validate:function(e,n,i){if(t.isFunction(r.FormView.Validator[e]))return t(r.FormView.Validator[e]).bind(this)(n,i);throw new Error("Validator does not exist : "+e)},matches:function(e,t){var n=this.fields[t[0]].el;return e==this.getInputVal(n)},min:function(e,t){return e.length<t?!1:!0},max:function(e,t){return e.length>t?!1:!0},numeric:function(e){return t.isNumber(e)},alpha:function(e){return r.FormView.Validator.regex.alpha.test(e)},alphanum:function(e){return r.FormView.Validator.regex.alphanum.test(e)},email:function(e){return r.FormView.Validator.regex.email.test(e)},required:function(e){return e===!1||t.isNull(e)||t.isUndefined(e)||t.isString(e)&&e.length===0?!1:!0},"boolean":function(e){return t.isBoolean(e)}},r.AppRouter=e.Router.extend({constructor:function(t){e.Router.prototype.constructor.apply(this,arguments),this.options=t;if(this.appRoutes){var n=r.getOption(this,"controller");this.processAppRoutes(n,this.appRoutes)}},processAppRoutes:function(e,n){var r,i,s,o,u,a=[],f=this;for(s in n)n.hasOwnProperty(s)&&a.unshift([s,n[s]]);o=a.length;for(u=0;u<o;u++){s=a[u][0],i=a[u][1],r=e[i];if(!r){var l="Method '"+i+"' was not found on the controller",c=new Error(l);throw c.name="NoMethodError",c}r=t.bind(r,e),f.route(s,i,r)}}}),r.Application=function(n){this.initCallbacks=new r.Callbacks,this.vent=new r.EventAggregator,this.commands=new e.Wreqr.Commands,this.reqres=new e.Wreqr.RequestResponse,this.submodules={},t.extend(this,n),r.addEventBinder(this),this.triggerMethod=r.triggerMethod},t.extend(r.Application.prototype,e.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("initialize:before",e),this.initCallbacks.run(e,this),this.triggerMethod("initialize:after",e),this.triggerMethod("start",e)},addRegions:function(e){var n=this;t.each(e,function(e,t){var i=r.Region.buildRegion(e,r.Region);n[t]=i})},removeRegion:function(e){this[e].close(),delete this[e]},module:function(e,t){var n=i.call(arguments);return n.unshift(this),r.Module.create.apply(r.Module,n)}}),r.Application.extend=r.extend,r.Module=function(e,t){this.moduleName=e,this.submodules={},this._setupInitializersAndFinalizers(),this.config={},this.config.app=t,r.addEventBinder(this),this.triggerMethod=r.triggerMethod},t.extend(r.Module.prototype,e.Events,{addInitializer:function(e){this._initializerCallbacks.add(e)},addFinalizer:function(e){this._finalizerCallbacks.add(e)},start:function(e){if(this._isInitialized)return;t.each(this.submodules,function(t){var n=!0;t.config&&t.config.options&&(n=t.config.options.startWithParent),n&&t.start(e)}),this.triggerMethod("initialize:before",e),this._initializerCallbacks.run(e,this),this._isInitialized=!0,this.triggerMethod("initialize:after",e)},stop:function(){if(!this._isInitialized)return;this._isInitialized=!1,t.each(this.submodules,function(e){e.stop()}),this._finalizerCallbacks.run(),this._initializerCallbacks.reset(),this._finalizerCallbacks.reset()},addDefinition:function(e,t){this._runModuleDefinition(e,t)},_runModuleDefinition:function(i,s){if(!i)return;var o=t.flatten([this,this.config.app,e,r,n,t,s]);i.apply(this,o)},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new r.Callbacks,this._finalizerCallbacks=new r.Callbacks}}),t.extend(r.Module,{create:function(e,n,r){var s=this,o=e;n=n.split(".");var u=i.apply(arguments);u.splice(0,3);var a=n.length;return t.each(n,function(t,n){var i=n===a-1,f=n===0,l=s._getModuleDefinition(o,t,e);i&&(l.config.options=s._getModuleOptions(l,o,r),l.config.options.hasDefinition&&l.addDefinition(l.config.options.definition,u)),f&&i&&s._configureStartWithApp(e,l),o=l}),o},_configureStartWithApp:function(e,t){if(t.config.startWithAppIsConfigured)return;e.addInitializer(function(e){t.config.options.startWithParent&&t.start(e)}),t.config.startWithAppIsConfigured=!0},_getModuleDefinition:function(e,t,n){var i=e[t];return i||(i=new r.Module(t,n),e[t]=i,e.submodules[t]=i),i},_getModuleOptions:function(e,n,r){var i=!0;e.config.options&&!e.config.options.startWithParent&&(i=!1);var s={startWithParent:i,hasDefinition:!!r};return s.hasDefinition?(t.isFunction(r)?s.definition=r:(s.hasDefinition=!!r.define,s.definition=r.define,r.hasOwnProperty("startWithParent")&&(s.startWithParent=r.startWithParent)),s):s}}),r}(n,t,e||window.jQuery||window.Zepto||window.ender),n.Mario});
Example #6
0
(function(a,b){if(typeof exports=="object"){var c=require("jquery"),d=require("underscore"),e=require("backbone");module.exports=b(c,d,e)}else typeof define=="function"&&define.amd&&define(["jquery","underscore","backbone"],b)})(this,function(a,b,c){return c.Marionette=function(a,b,c){var d={};d.EventBinder=function(){this._eventBindings=[]},b.extend(d.EventBinder.prototype,{bindTo:function(a,b,c,d){d=d||this,a.on(b,c,d);var e={obj:a,eventName:b,callback:c,context:d};return this._eventBindings.push(e),e},unbindFrom:function(a){a.obj.off(a.eventName,a.callback,a.context),this._eventBindings=b.reject(this._eventBindings,function(b){return b===a})},unbindAll:function(){var a=this,c=b.map(this._eventBindings,b.identity);b.each(c,function(b,c){a.unbindFrom(b)})}}),d.EventBinder.extend=a.View.extend,d.View=a.View.extend({constructor:function(){var c=new d.EventBinder;b.extend(this,c),a.View.prototype.constructor.apply(this,arguments),this.bindTo(this,"show",this.onShowCalled,this)},getTemplate:function(){var a;return this.options&&this.options.template?a=this.options.template:a=this.template,a},serializeData:function(){var a;return this.model?a=this.model.toJSON():this.collection&&(a={items:this.collection.toJSON()}),a=this.mixinTemplateHelpers(a),a},mixinTemplateHelpers:function(a){a=a||{};var c=this.templateHelpers;return b.isFunction(c)&&(c=c.call(this)),b.extend(a,c)},configureTriggers:function(){if(!this.triggers)return;var a=this.triggers,c=this,d={};return b.isFunction(a)&&(a=a.call(this)),b.each(a,function(a,b){d[b]=function(b){b&&b.preventDefault&&b.preventDefault(),b&&b.stopPropagation&&b.stopPropagation(),c.trigger(a)}}),d},delegateEvents:function(c){c=c||this.events,b.isFunction(c)&&(c=c.call(this));var d={},e=this.configureTriggers();b.extend(d,c,e),a.View.prototype.delegateEvents.call(this,d)},onShowCalled:function(){},close:function(){this.beforeClose&&this.beforeClose(),this.remove(),this.onClose&&this.onClose(),this.trigger("close"),this.unbindAll(),this.unbind()},bindUIElements:function(){if(!this.ui)return;var a=this;this.uiBindings||(this.uiBindings=this.ui),this.ui={},b.each(b.keys(this.uiBindings),function(b){var c=a.uiBindings[b];a.ui[b]=a.$(c)})}}),d.ItemView=d.View.extend({constructor:function(){d.View.prototype.constructor.apply(this,arguments),this.initialEvents&&this.initialEvents()},render:function(){this.beforeRender&&this.beforeRender(),this.trigger("before:render",this),this.trigger("item:before:render",this);var a=this.serializeData(),b=this.getTemplate(),c=d.Renderer.render(b,a);return this.$el.html(c),this.bindUIElements(),this.onRender&&this.onRender(),this.trigger("render",this),this.trigger("item:rendered",this),this},close:function(){this.trigger("item:before:close"),d.View.prototype.close.apply(this,arguments),this.trigger("item:closed")}}),d.CollectionView=d.View.extend({constructor:function(){d.View.prototype.constructor.apply(this,arguments),this.initChildViewStorage(),this.initialEvents(),this.onShowCallbacks=new d.Callbacks},initialEvents:function(){this.collection&&(this.bindTo(this.collection,"add",this.addChildView,this),this.bindTo(this.collection,"remove",this.removeItemView,this),this.bindTo(this.collection,"reset",this.render,this))},addChildView:function(a,b,c){this.closeEmptyView();var d=this.getItemView();return this.addItemView(a,d,c.index)},onShowCalled:function(){this.onShowCallbacks.run()},triggerBeforeRender:function(){this.beforeRender&&this.beforeRender(),this.trigger("before:render",this),this.trigger("collection:before:render",this)},triggerRendered:function(){this.onRender&&this.onRender(),this.trigger("render",this),this.trigger("collection:rendered",this)},render:function(){return this.triggerBeforeRender(),this.closeEmptyView(),this.closeChildren(),this.collection&&this.collection.length>0?this.showCollection():this.showEmptyView(),this.triggerRendered(),this},showCollection:function(){var a=this,b=this.getItemView();this.collection.each(function(c,d){a.addItemView(c,b,d)})},showEmptyView:function(){var b=this.options.emptyView||this.emptyView;if(b&&!this._showingEmptyView){this._showingEmptyView=!0;var c=new a.Model;this.addItemView(c,b,0)}},closeEmptyView:function(){this._showingEmptyView&&(this.closeChildren(),delete this._showingEmptyView)},getItemView:function(){var a=this.options.itemView||this.itemView;if(!a){var b=new Error("An `itemView` must be specified");throw b.name="NoItemViewError",b}return a},addItemView:function(a,b,c){var d=this,f=this.buildItemView(a,b);this.storeChild(f),this.onItemAdded&&this.onItemAdded(f),this.trigger("item:added",f);var g=this.renderItemView(f,c);f.onShow&&this.onShowCallbacks.add(f.onShow,f);var h=this.bindTo(f,"all",function(){var a=e.call(arguments);a[0]="itemview:"+a[0],a.splice(1,0,f),d.trigger.apply(d,a)});return this.childBindings=this.childBindings||{},this.childBindings[f.cid]=h,g},renderItemView:function(a,b){a.render(),this.appendHtml(this,a,b)},buildItemView:function(a,c){var d=b.result(this,"itemViewOptions"),e=b.extend({model:a},d),f=new c(e);return f},removeItemView:function(a){var b=this.children[a.cid];if(b){var c=this.childBindings[b.cid];c&&(this.unbindFrom(c),delete this.childBindings[b.cid]),b.close(),delete this.children[a.cid]}(!this.collection||this.collection.length===0)&&this.showEmptyView(),this.trigger("item:removed",b)},appendHtml:function(a,b,c){a.$el.append(b.el)},storeChild:function(a){this.children[a.model.cid]=a},initChildViewStorage:function(){this.children={}},close:function(){this.trigger("collection:before:close"),this.closeChildren(),d.View.prototype.close.apply(this,arguments),this.trigger("collection:closed")},closeChildren:function(){var a=this;this.children&&b.each(b.clone(this.children),function(b){a.removeItemView(b.model)})}}),d.CompositeView=d.CollectionView.extend({constructor:function(a){d.CollectionView.apply(this,arguments),this.itemView=this.getItemView()},initialEvents:function(){this.collection&&(this.bindTo(this.collection,"add",this.addChildView,this),this.bindTo(this.collection,"remove",this.removeItemView,this),this.bindTo(this.collection,"reset",this.renderCollection,this))},getItemView:function(){return this.itemView||this.constructor},render:function(){var a=this;this.resetItemViewContainer();var b=this.renderModel();return this.$el.html(b),this.bindUIElements(),this.trigger("composite:model:rendered"),this.trigger("render"),this.renderCollection(),this.trigger("composite:rendered"),this},renderCollection:function(){d.CollectionView.prototype.render.apply(this,arguments),this.trigger("composite:collection:rendered")},renderModel:function(){var a={};a=this.serializeData();var b=this.getTemplate();return d.Renderer.render(b,a)},appendHtml:function(a,b){var c=this.getItemViewContainer(a);c.append(b.el)},getItemViewContainer:function(a){var c;if("$itemViewContainer"in a)c=a.$itemViewContainer;else{if(a.itemViewContainer){c=a.$(b.result(a,"itemViewContainer"));if(c.length<=0){var d=new Error("Missing `itemViewContainer`");throw d.name="ItemViewContainerMissingError",d}}else c=a.$el;a.$itemViewContainer=c}return c},resetItemViewContainer:function(){this.$itemViewContainer&&delete this.$itemViewContainer}}),d.Region=function(a){this.options=a||{};var c=new d.EventBinder;b.extend(this,c,a);if(!this.el){var e=new Error("An 'el' must be specified");throw e.name="NoElError",e}this.initialize&&this.initialize.apply(this,arguments)},b.extend(d.Region.prototype,a.Events,{show:function(a){this.ensureEl(),this.close(),a.render(),this.open(a),a.onShow&&a.onShow(),a.trigger("show"),this.onShow&&this.onShow(a),this.trigger("view:show",a),this.currentView=a},ensureEl:function(){if(!this.$el||this.$el.length===0)this.$el=this.getEl(this.el)},getEl:function(a){return c(a)},open:function(a){this.$el.html(a.el)},close:function(){var a=this.currentView;if(!a)return;a.close&&a.close(),this.trigger("view:closed",a),delete this.currentView},attachView:function(a){this.currentView=a},reset:function(){this.close(),delete this.$el}}),d.Region.extend=a.View.extend,d.Layout=d.ItemView.extend({regionType:d.Region,constructor:function(){a.Marionette.ItemView.apply(this,arguments),this.initializeRegions()},render:function(){var a=d.ItemView.prototype.render.apply(this,arguments);return this.render=function(){this.closeRegions(),this.reInitializeRegions();var a=d.ItemView.prototype.render.apply(this,arguments);return a},a},close:function(){this.closeRegions(),this.destroyRegions(),a.Marionette.ItemView.prototype.close.call(this,arguments)},initializeRegions:function(){this.regionManagers||(this.regionManagers={});var a=this;b.each(this.regions,function(b,c){if(typeof b!="string"&&typeof b.selector!="string")throw new Exception("Region must be specified as a selector string or an object with selector property");selector=typeof b=="string"?b:b.selector;var d=typeof b.regionType=="undefined"?a.regionType:b.regionType,e=new d({el:selector,getEl:function(b){return a.$(b)}});a.regionManagers[c]=e,a[c]=e})},reInitializeRegions:function(){this.regionManagers&&b.size(this.regionManagers)===0?this.initializeRegions():b.each(this.regionManagers,function(a){a.reset()})},closeRegions:function(){var a=this;b.each(this.regionManagers,function(a,b){a.close()})},destroyRegions:function(){var a=this;b.each(this.regionManagers,function(b,c){delete a[c]}),this.regionManagers={}}}),d.Application=function(a){this.initCallbacks=new d.Callbacks,this.vent=new d.EventAggregator,this.submodules={};var c=new d.EventBinder;b.extend(this,c,a)},b.extend(d.Application.prototype,a.Events,{addInitializer:function(a){this.initCallbacks.add(a)},start:function(a){this.trigger("initialize:before",a),this.initCallbacks.run(a,this),this.trigger("initialize:after",a),this.trigger("start",a)},addRegions:function(a){var b,c,e;for(e in a)a.hasOwnProperty(e)&&(b=a[e],typeof b=="string"?c=new d.Region({el:b}):c=new b,this[e]=c)},removeRegion:function(a){this[a].close(),delete this[a]},module:function(a,b){var c=e.call(arguments);return c.unshift(this),d.Module.create.apply(d.Module,c)}}),d.Application.extend=a.View.extend,d.AppRouter=a.Router.extend({constructor:function(b){a.Router.prototype.constructor.call(this,b);if(this.appRoutes){var c=this.controller;b&&b.controller&&(c=b.controller),this.processAppRoutes(c,this.appRoutes)}},processAppRoutes:function(a,c){var d,e,f,g,h,i=[],j=this;for(f in c)c.hasOwnProperty(f)&&i.unshift([f,c[f]]);g=i.length;for(h=0;h<g;h++){f=i[h][0],e=i[h][1],d=a[e];if(!d){var k="Method '"+e+"' was not found on the controller",l=new Error(k);throw l.name="NoMethodError",l}d=b.bind(d,a),j.route(f,e,d)}}}),d.Module=function(a,c,e){this.moduleName=a,this.submodules={},this._setupInitializersAndFinalizers(),this._config={},this._config.app=c,this._config.customArgs=e,this._config.definitions=[];var f=new d.EventBinder;b.extend(this,f)},b.extend(d.Module.prototype,a.Events,{addInitializer:function(a){this._initializerCallbacks.add(a)},addFinalizer:function(a){this._finalizerCallbacks.add(a)},start:function(a){if(this._isInitialized)return;this._runModuleDefinition(),this._initializerCallbacks.run(a,this),this._isInitialized=!0,this.submodules&&b.each(this.submodules,function(b){b.start(a)})},stop:function(){if(!this._isInitialized)return;this._isInitialized=!1,this._finalizerCallbacks.run(),this._setupInitializersAndFinalizers(),b.each(this.submodules,function(a){a.stop()})},addDefinition:function(a){this._config.definitions.push(a)},_runModuleDefinition:function(){if(this._config.definitions.length===0)return;var e=b.flatten([this,this._config.app,a,d,c,b,this._config.customArgs]),f=this._config.definitions.length-1;for(var g=0;g<=f;g++){var h=this._config.definitions[g];h.apply(this,e)}},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new d.Callbacks,this._finalizerCallbacks=new d.Callbacks}}),b.extend(d.Module,{create:function(a,c,f){var g=this,h=a;c=c.split(".");var i=e.apply(arguments);i.splice(0,3);var j=c.length;return b.each(c,function(b,c){var e=c===j-1,k=h[b];k||(k=new d.Module(b,a,i),h[b]=k,h.submodules[b]=k),e&&g._createModuleDefinition(k,f,a),h=k}),h},_createModuleDefinition:function(a,b,c){var d=this._getModuleDefinitionOptions(b);d.definition&&a.addDefinition(d.definition),d.startWithApp&&c.addInitializer(function(b){a.start(b)})},_getModuleDefinitionOptions:function(a){var c={startWithApp:!0};return a?(b.isFunction(a)?c.definition=a:(c.definition=a.define,a.hasOwnProperty("startWithApp")&&(c.startWithApp=a.startWithApp)),c):c}}),d.TemplateCache=function(a){this.templateId=a},b.extend(d.TemplateCache,{templateCaches:{},get:function(a){var b=this,c=this.templateCaches[a];return c||(c=new d.TemplateCache(a),this.templateCaches[a]=c),c.load()},clear:function(){var a,b=arguments.length;if(b>0)for(a=0;a<b;a++)delete this.templateCaches[arguments[a]];else this.templateCaches={}}}),b.extend(d.TemplateCache.prototype,{load:function(){var a=this;if(this.compiledTemplate)return this.compiledTemplate;var b=this.loadTemplate(this.templateId);return this.compiledTemplate=this.compileTemplate(b),this.compiledTemplate},loadTemplate:function(a){var b=c(a).html();if(!b||b.length===0){var d="Could not find template: '"+a+"'",e=new Error(d);throw e.name="NoTemplateError",e}return b},compileTemplate:function(a){return b.template(a)}}),d.Renderer={render:function(a,b){var c=typeof a=="function"?a:d.TemplateCache.get(a),e=c(b);return e}},d.Callbacks=function(){this.deferred=c.Deferred(),this.promise=this.deferred.promise()},b.extend(d.Callbacks.prototype,{add:function(a,b){this.promise.done(function(c,d){b&&(c=b),a.call(c,d)})},run:function(a,b){this.deferred.resolve(b,a)}}),d.EventAggregator=d.EventBinder.extend({constructor:function(a){d.EventBinder.apply(this,arguments),b.extend(this,a)},bindTo:function(a,b,c){return d.EventBinder.prototype.bindTo.call(this,this,a,b,c)}}),b.extend(d.EventAggregator.prototype,a.Events),d.EventAggregator.extend=a.View.extend;var e=Array.prototype.slice;return d}(c,b,window.jQuery||window.Zepto||window.ender),c.Marionette});
!function(t,i){if("function"==typeof define&&define.amd)define(["underscore","backbone","jquery","exports"],function(e,n,s,o){n.Hexer=i(t,o,e,n,s)});else if("undefined"!=typeof exports){var e,n=require("underscore"),s=require("backbone");try{e=require("jquery")}catch(o){}i(t,exports,n,s,e)}else t.Backbone.Hexer=i(t,{},t._,t.Backbone,t.jQuery||t.Zepto||t.ender||t.$)}(this,function(t,i,e,n,s){function o(t){return e.isString(t)?parseFloat(t.replace(/\D+$/g,"")):1*t}function h(t){return t+3>5?t-3:t+3}function a(t,i){var n,s=null;return e.each(i,function(i,o){e.isNull(s)&&i.options.distance==t&&(s=o),e.isNull(n)&&!e.isNull(s)&&i.options.distance>t&&(n=o)}),i.slice(s,n)}i=n.Hexer=n.HexGridView=n.View.extend({tagName:"div",className:"bbh-container",defaults:{depth:2,color:"#999999",size:"6em",spacing:"0.5em",center:{x:0,y:0}},events:{},hexes:[],animateTimeout:null,initialize:function(t){this.options=e.extend({},this.defaults,t),this.options.unit=this.options.size.replace(/^\d+/g,""),""==this.options.unit&&(this.options.unit="em"),this.options.size=o(this.options.size),this.options.spacing=o(this.options.spacing),this.options.center.x=o(this.options.center.x),this.options.center.y=o(this.options.center.y),e.bindAll(this,"addAdjacentHexes");var i=s('<svg width="0" height="0"><defs><clipPath id="bbh-hexclip" clipPathUnits="objectBoundingBox"><polygon points="0.5 0 1 0.25 1 0.75 0.5 1 0 0.75 0 0.25"/></clipPath></defs></svg>');document.body.insertBefore(i[0],document.body.childNodes[0]),this.createHexViews()},render:function(){return e.each(this.hexes,function(t,i){t.render()}),this},createHexViews:function(){for(var t="fill"==this.options.depth?10:this.options.depth,i=0;t>i;i++)switch(i){case 0:this.addHex({distance:0,x:this.options.center.x,y:this.options.center.y});break;default:var n=a(i-1,this.hexes);e.each(n,function(t,i){this.addAdjacentHexes(t,0,6)}.bind(this))}},addHex:function(t){t=e.extend({size:this.options.size+this.options.unit,color:this.options.color},t);var i=new r(t);return this.hexes.push(i),this.$el.append(i.$el),i},addAdjacentHex:function(t,i,n){var s=0==i?0:2*Math.PI/6*i,o=this.options.size+this.options.spacing,a=t.options.x+Math.cos(s)*o,r=t.options.y+Math.sin(s)*o,c=t.options.distance+1,d=h(i),p={};p[d]=t;var u=this.addHex(e.extend({x:a,y:r,distance:c,neighbors:p},n));t.addNeighbor(i,u,!0);var l=i-1>=0?i-1:i+5,f=6>i+1?i+1:i-5;e.has(t.options.neighbors,l)&&u.addNeighbor(l-1,t.options.neighbors[l],!0),e.has(t.options.neighbors,f)&&u.addNeighbor(f+1,t.options.neighbors[f],!0)},addAdjacentHexes:function(t,i,n){n>6&&(n=6),i>5&&(i-=6);for(var s=i;i+n>s;s++)(e.isUndefined(t.options.neighbors[s])||e.isNull(t.options.neighbors[s]))&&this.addAdjacentHex(t,s,{})},animate:function(t){var i=e.extend({animateFunction:function(t){},animateQueue:[this.hexes],delay:50},t),n=function(t,e,s){for(var o=t.shift(),h=0;h<o.length;h++)e(o[h]);t.length&&(this.animateTimeout=setTimeout(function(){n(t,e,s)},i.delay))};n(e.clone(i.animateQueue),i.animateFunction,i.delay)}});var r=n.View.extend({tagName:"div",className:"bbh-hex",defaults:{x:0,y:0,size:"3em",color:"#999999",content:"",neighbors:{}},neighbors:{},initialize:function(t){this.options=e.extend({},this.defaults,t),this.options.unit=this.options.size.replace(/^\d+/g,""),this.options.size=o(this.options.size),e.isFunction(this.options.content)&&(this.content=this.options.content)},render:function(){var t={clipPath:"url(#bbh-hexclip)",webkitClipPath:"url(#bbh-hexclip)",transform:"translateX("+this.options.x+this.options.unit+") translateY("+this.options.y+this.options.unit+")",webkitTransform:"translateX("+this.options.x+this.options.unit+" translateY("+this.options.y+this.options.unit+")",width:Math.sqrt(3)/2*this.options.size+this.options.unit,height:this.options.size+this.options.unit};return e.isNull(this.options.color)&&(t.background=this.options.color),this.$el.css(t),this.$el.html('<div class="content"><span>'+this.content.call(this)+"</span></div>"),this},content:function(){return this.options.content},addNeighbor:function(t,i,n){n=e.isUndefined(n)?!1:n,t=t>5?t-6:t,t=0>t?t+6:t,this.options.neighbors[t]=i,n===!0&&i.addNeighbor(h(t),this,!1)}});return i.VERSION="0.0.1",i});