Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

build targets

  • Loading branch information...
commit 7f9a561dde2507b93c79c0c773a281bad8574f68 1 parent 4fd3b4c
@jsoverson jsoverson authored
View
10 lib/amd/backbone.marionette.js
@@ -1,7 +1,9 @@
-// Backbone.Marionette, v1.0.0-beta1
-// Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
-// Distributed under MIT license
-// http://github.com/marionettejs/backbone.marionette
+/*!
+ * Backbone.Marionette, v1.0.0-beta1
+ * Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
+ * Distributed under MIT license
+ * http://github.com/marionettejs/backbone.marionette
+*/
(function (root, factory) {
if (typeof exports === 'object') {
View
10 lib/amd/backbone.marionette.min.js
@@ -1,5 +1,7 @@
-// Backbone.Marionette, v1.0.0-beta1
-// Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
-// Distributed under MIT license
-// http://github.com/marionettejs/backbone.marionette
+/*!
+ * Backbone.Marionette, v1.0.0-beta1
+ * Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
+ * Distributed under MIT license
+ * http://github.com/marionettejs/backbone.marionette
+*/
(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=Marionette=function(e,t,n){var r={},i=Array.prototype.slice;return r.extend=e.Model.extend,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),t.isFunction(this[o])&&(e.shift(),this[o].apply(this,e))},r.EventBinder=e.EventBinder,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.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(){var e;return this.options&&this.options.template?e=this.options.template:e=this.template,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(){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=this.mixinTemplateHelpers(e),e},render:function(){this.isClosed=!1,this.triggerMethod("before:render",this),this.triggerMethod("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.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(){this.initChildViewStorage(),r.View.prototype.constructor.apply(this,arguments),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=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.triggerMethod("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.triggerMethod.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.triggerMethod("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(){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&&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},serializeData:function(){var e={};return this.model&&(e=this.model.toJSON()),e=this.mixinTemplateHelpers(e),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.triggerMethod("render"),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();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.Region=function(e){this.options=e||{};var t=this.options.el;delete this.options.el,r.addEventBinder(this),t&&(this.el=t);if(!this.el){var n=new Error("An 'el' must be specified for a region.");throw n.name="NoElError",n}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),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||e.isClosed)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=r.extend,r.Layout=r.ItemView.extend({regionType:r.Region,constructor:function(){this.initializeRegions(),e.Marionette.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.Marionette.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.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)},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.trigger("initialize:before",e),this.initCallbacks.run(e,this),this.trigger("initialize:after",e),this.trigger("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.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,t){this.moduleName=e,this.submodules={},this._setupInitializersAndFinalizers(),this.config={},this.config.app=t,r.addEventBinder(this)},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,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=s._getModuleDefinition(o,t,e);f.config.options=s._getModuleOptions(o,r),i&&s._configureAutoStart(e,f),i&&f.config.options.hasDefinition&&f.addDefinition(f.config.options.definition,u),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){var i=e[t];return i||(i=new r.Module(t,n),e[t]=i,e.submodules[t]=i),i},_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,r=this._callbacks;this._deferred=n.Deferred(),this._callbacks=[],t.each(r,function(t){e.add(t.cb,t.ctx)})}}),r.EventAggregator=e.Wreqr.EventAggregator,r}(n,t,e||window.jQuery||window.Zepto||window.ender),n.Marionette});
View
10 lib/backbone.marionette.js
@@ -1,7 +1,9 @@
-// Backbone.Marionette, v1.0.0-beta1
-// Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
-// Distributed under MIT license
-// http://github.com/marionettejs/backbone.marionette
+/*!
+ * Backbone.Marionette, v1.0.0-beta1
+ * Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
+ * Distributed under MIT license
+ * http://github.com/marionettejs/backbone.marionette
+*/
Backbone.Marionette = Marionette = (function(Backbone, _, $){
var Marionette = {};
View
10 lib/backbone.marionette.min.js
@@ -1,5 +1,7 @@
-// Backbone.Marionette, v1.0.0-beta1
-// Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
-// Distributed under MIT license
-// http://github.com/marionettejs/backbone.marionette
+/*!
+ * Backbone.Marionette, v1.0.0-beta1
+ * Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
+ * Distributed under MIT license
+ * http://github.com/marionettejs/backbone.marionette
+*/
Backbone.Marionette=Marionette=function(e,t,n){var r={},i=Array.prototype.slice;return r.extend=e.Model.extend,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),t.isFunction(this[o])&&(e.shift(),this[o].apply(this,e))},r.EventBinder=e.EventBinder,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.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(){var e;return this.options&&this.options.template?e=this.options.template:e=this.template,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(){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=this.mixinTemplateHelpers(e),e},render:function(){this.isClosed=!1,this.triggerMethod("before:render",this),this.triggerMethod("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.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(){this.initChildViewStorage(),r.View.prototype.constructor.apply(this,arguments),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=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.triggerMethod("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.triggerMethod.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.triggerMethod("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(){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&&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},serializeData:function(){var e={};return this.model&&(e=this.model.toJSON()),e=this.mixinTemplateHelpers(e),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.triggerMethod("render"),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();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.Region=function(e){this.options=e||{};var t=this.options.el;delete this.options.el,r.addEventBinder(this),t&&(this.el=t);if(!this.el){var n=new Error("An 'el' must be specified for a region.");throw n.name="NoElError",n}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),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||e.isClosed)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=r.extend,r.Layout=r.ItemView.extend({regionType:r.Region,constructor:function(){this.initializeRegions(),e.Marionette.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.Marionette.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.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)},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.trigger("initialize:before",e),this.initCallbacks.run(e,this),this.trigger("initialize:after",e),this.trigger("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.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,t){this.moduleName=e,this.submodules={},this._setupInitializersAndFinalizers(),this.config={},this.config.app=t,r.addEventBinder(this)},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,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=s._getModuleDefinition(o,t,e);f.config.options=s._getModuleOptions(o,r),i&&s._configureAutoStart(e,f),i&&f.config.options.hasDefinition&&f.addDefinition(f.config.options.definition,u),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){var i=e[t];return i||(i=new r.Module(t,n),e[t]=i,e.submodules[t]=i),i},_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,r=this._callbacks;this._deferred=n.Deferred(),this._callbacks=[],t.each(r,function(t){e.add(t.cb,t.ctx)})}}),r.EventAggregator=e.Wreqr.EventAggregator,r}(Backbone,_,$||window.jQuery||window.Zepto||window.ender);
View
4,287 lib/bundles/marionette.backbone_underscore.js
4,287 additions, 0 deletions not shown
View
19 lib/bundles/marionette.backbone_underscore.min.js
@@ -0,0 +1,19 @@
+/*!
+ * Backbone.Marionette, v1.0.0-beta1
+ * Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
+ * Distributed under MIT license
+ * http://github.com/marionettejs/backbone.marionette
+*/
+/*!
+ * Includes Wreqr
+ * https://github.com/marionettejs/backbone.wreqr/
+ * Includes EventBinder
+ * https://github.com/marionettejs/backbone.eventbinder
+ */
+/*!
+ * Includes Backbone
+ * http://backbonejs.org/
+ * Includes underscore
+ * http://underscore.org/
+ */
+(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.4.1";var N=T.each=T.forEach=function(e,t,r){if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i<s;i++)if(t.call(r,e[i],i,e)===n)return}else for(var o in e)if(T.has(e,o)&&t.call(r,e[o],o,e)===n)return};T.map=T.collect=function(e,t,n){var r=[];return p&&e.map===p?e.map(t,n):(N(e,function(e,i,s){r[r.length]=t.call(n,e,i,s)}),r)},T.reduce=T.foldl=T.inject=function(e,t,n,r){var i=arguments.length>2;if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o<r.computed&&(r={value:e,computed:o})}),r.value},T.shuffle=function(e){var t,n=0,r=[];return N(e,function(e){t=T.random(n++),r[n-1]=r[t],r[t]=e}),r};var k=function(e){return T.isFunction(e)?e:function(t){return t[e]}};T.sortBy=function(e,t,n){var r=k(t);return T.pluck(T.map(e,function(e,t,i){return{value:e,index:t,criteria:r.call(n,e,t,i)}}).sort(function(e,t){var n=e.criteria,r=t.criteria;if(n!==r){if(n>r||n===void 0)return 1;if(n<r||r===void 0)return-1}return e.index<t.index?-1:1}),"value")};var L=function(e,t,n,r){var i={},s=k(t);return N(e,function(t,o){var u=s.call(n,t,o,e);r(i,u,t)}),i};T.groupBy=function(e,t,n){return L(e,t,n,function(e,t,n){(T.has(e,t)?e[t]:e[t]=[]).push(n)})},T.countBy=function(e,t,n){return L(e,t,n,function(e,t,n){T.has(e,t)||(e[t]=0),e[t]++})},T.sortedIndex=function(e,t,n,r){n=n==null?T.identity:k(n);var i=n.call(r,t),s=0,o=e.length;while(s<o){var u=s+o>>>1;n.call(r,e[u])<i?s=u+1:o=u}return s},T.toArray=function(e){return e?e.length===+e.length?u.call(e):T.values(e):[]},T.size=function(e){return e.length===+e.length?e.length:T.keys(e).length},T.first=T.head=T.take=function(e,t,n){return t!=null&&!n?u.call(e,0,t):e[0]},T.initial=function(e,t,n){return u.call(e,0,e.length-(t==null||n?1:t))},T.last=function(e,t,n){return t!=null&&!n?u.call(e,Math.max(e.length-t,0)):e[e.length-1]},T.rest=T.tail=T.drop=function(e,t,n){return u.call(e,t==null||n?1:t)},T.compact=function(e){return T.filter(e,function(e){return!!e})};var A=function(e,t,n){return N(e,function(e){T.isArray(e)?t?o.apply(n,e):A(e,t,n):n.push(e)}),n};T.flatten=function(e,t){return A(e,t,[])},T.without=function(e){return T.difference(e,u.call(arguments,1))},T.uniq=T.unique=function(e,t,n,r){var i=n?T.map(e,n,r):e,s=[],o=[];return N(i,function(n,r){if(t?!r||o[o.length-1]!==n:!T.contains(o,n))o.push(n),s.push(e[r])}),s},T.union=function(){return T.uniq(a.apply(r,arguments))},T.intersection=function(e){var t=u.call(arguments,1);return T.filter(T.uniq(e),function(e){return T.every(t,function(t){return T.indexOf(t,e)>=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r<t;r++)n[r]=T.pluck(e,""+r);return n},T.object=function(e,t){var n={};for(var r=0,i=e.length;r<i;r++)t?n[e[r]]=t[r]:n[e[r][0]]=e[r][1];return n},T.indexOf=function(e,t,n){var r=0,i=e.length;if(n){if(typeof n!="number")return r=T.sortedIndex(e,t),e[r]===t?r:-1;r=n<0?Math.max(0,i+n):n}if(b&&e.indexOf===b)return e.indexOf(t,n);for(;r<i;r++)if(e[r]===t)return r;return-1},T.lastIndexOf=function(e,t,n){var r=n!=null;if(w&&e.lastIndexOf===w)return r?e.lastIndexOf(t,n):e.lastIndexOf(t);var i=r?n:e.length;while(i--)if(e[i]===t)return i;return-1},T.range=function(e,t,n){arguments.length<=1&&(t=e||0,e=0),n=arguments[2]||1;var r=Math.max(Math.ceil((t-e)/n),0),i=0,s=new Array(r);while(i<r)s[i++]=e,e+=n;return s};var O=function(){};T.bind=function(t,n){var r,i;if(t.bind===x&&x)return x.apply(t,u.call(arguments,1));if(!T.isFunction(t))throw new TypeError;return i=u.call(arguments,2),r=function(){if(this instanceof r){O.prototype=t.prototype;var e=new O,s=t.apply(e,i.concat(u.call(arguments)));return Object(s)===s?s:e}return t.apply(n,i.concat(u.call(arguments)))}},T.bindAll=function(e){var t=u.call(arguments,1);return t.length==0&&(t=T.functions(e)),N(t,function(t){e[t]=T.bind(e[t],e)}),e},T.memoize=function(e,t){var n={};return t||(t=T.identity),function(){var r=t.apply(this,arguments);return T.has(n,r)?n[r]:n[r]=e.apply(this,arguments)}},T.delay=function(e,t){var n=u.call(arguments,2);return setTimeout(function(){return e.apply(null,n)},t)},T.defer=function(e){return T.delay.apply(T,[e,1].concat(u.call(arguments,1)))},T.throttle=function(e,t){var n,r,i,s,o,u,a=T.debounce(function(){o=s=!1},t);return function(){n=this,r=arguments;var f=function(){i=null,o&&(u=e.apply(n,r)),a()};return i||(i=setTimeout(f,t)),s?o=!0:(s=!0,u=e.apply(n,r)),a(),u}},T.debounce=function(e,t,n){var r,i;return function(){var s=this,o=arguments,u=function(){r=null,n||(i=e.apply(s,o))},a=n&&!r;return clearTimeout(r),r=setTimeout(u,t),a&&(i=e.apply(s,o)),i}},T.once=function(e){var t=!1,n;return function(){return t?n:(t=!0,n=e.apply(this,arguments),e=null,n)}},T.wrap=function(e,t){return function(){var n=[e];return o.apply(n,arguments),t.apply(this,n)}},T.compose=function(){var e=arguments;return function(){var t=arguments;for(var n=e.length-1;n>=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r<e;r++)t.call(n,r)},T.random=function(e,t){return t==null&&(t=e,e=0),e+(0|Math.random()*(t-e+1))};var _={escape:{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this),function(){var e=this,t=e.Backbone,n=Array.prototype.slice,r=Array.prototype.splice,i;typeof exports!="undefined"?i=exports:i=e.Backbone={},i.VERSION="0.9.2";var s=e._;!s&&typeof require!="undefined"&&(s=require("underscore"));var o=e.jQuery||e.Zepto||e.ender;i.setDomLibrary=function(e){o=e},i.noConflict=function(){return e.Backbone=t,this},i.emulateHTTP=!1,i.emulateJSON=!1;var u=/\s+/,a=i.Events={on:function(e,t,n){var r,i,s,o,a;if(!t)return this;e=e.split(u),r=this._callbacks||(this._callbacks={});while(i=e.shift())a=r[i],s=a?a.tail:{},s.next=o={},s.context=n,s.callback=t,r[i]={tail:o,next:a?a.next:s};return this},off:function(e,t,n){var r,i,o,a,f,l;if(!(i=this._callbacks))return;if(!(e||t||n))return delete this._callbacks,this;e=e?e.split(u):s.keys(i);while(r=e.shift()){o=i[r],delete i[r];if(!o||!t&&!n)continue;a=o.tail;while((o=o.next)!==a)f=o.callback,l=o.context,(t&&f!==t||n&&l!==n)&&this.on(r,f,l)}return this},trigger:function(e){var t,r,i,s,o,a,f;if(!(i=this._callbacks))return this;a=i.all,e=e.split(u),f=n.call(arguments,1);while(t=e.shift()){if(r=i[t]){s=r.tail;while((r=r.next)!==s)r.callback.apply(r.context||this,f)}if(r=a){s=r.tail,o=[t].concat(f);while((r=r.next)!==s)r.callback.apply(r.context||this,o)}}return this}};a.bind=a.on,a.unbind=a.off;var f=i.Model=function(e,t){var n;e||(e={}),t&&t.parse&&(e=this.parse(e));if(n=C(this,"defaults"))e=s.extend({},n,e);t&&t.collection&&(this.collection=t.collection),this.attributes={},this._escapedAttributes={},this.cid=s.uniqueId("c"),this.changed={},this._silent={},this._pending={},this.set(e,{silent:!0}),this.changed={},this._silent={},this._pending={},this._previousAttributes=s.clone(this.attributes),this.initialize.apply(this,arguments)};s.extend(f.prototype,a,{changed:null,_silent:null,_pending:null,idAttribute:"id",initialize:function(){},toJSON:function(e){return s.clone(this.attributes)},get:function(e){return this.attributes[e]},escape:function(e){var t;if(t=this._escapedAttributes[e])return t;var n=this.get(e);return this._escapedAttributes[e]=s.escape(n==null?"":""+n)},has:function(e){return this.get(e)!=null},set:function(e,t,n){var r,i,o;s.isObject(e)||e==null?(r=e,n=t):(r={},r[e]=t),n||(n={});if(!r)return this;r instanceof f&&(r=r.attributes);if(n.unset)for(i in r)r[i]=void 0;if(!this._validate(r,n))return!1;this.idAttribute in r&&(this.id=r[this.idAttribute]);var u=n.changes={},a=this.attributes,l=this._escapedAttributes,c=this._previousAttributes||{};for(i in r){o=r[i];if(!s.isEqual(a[i],o)||n.unset&&s.has(a,i))delete l[i],(n.silent?this._silent:u)[i]=!0;n.unset?delete a[i]:a[i]=o,!s.isEqual(c[i],o)||s.has(a,i)!=s.has(c,i)?(this.changed[i]=o,n.silent||(this._pending[i]=!0)):(delete this.changed[i],delete this._pending[i])}return n.silent||this.change(n),this},unset:function(e,t){return(t||(t={})).unset=!0,this.set(e,null,t)},clear:function(e){return(e||(e={})).unset=!0,this.set(s.clone(this.attributes),e)},fetch:function(e){e=e?s.clone(e):{};var t=this,n=e.success;return e.success=function(r,i,s){if(!t.set(t.parse(r,s),e))return!1;n&&n(t,r)},e.error=i.wrapError(e.error,t,e),(this.sync||i.sync).call(this,"read",this,e)},save:function(e,t,n){var r,o;s.isObject(e)||e==null?(r=e,n=t):(r={},r[e]=t),n=n?s.clone(n):{};if(n.wait){if(!this._validate(r,n))return!1;o=s.clone(this.attributes)}var u=s.extend({},n,{silent:!0});if(r&&!this.set(r,n.wait?u:n))return!1;var a=this,f=n.success;n.success=function(e,t,i){var o=a.parse(e,i);n.wait&&(delete n.wait,o=s.extend(r||{},o));if(!a.set(o,n))return!1;f?f(a,e):a.trigger("sync",a,e,n)},n.error=i.wrapError(n.error,a,n);var l=this.isNew()?"create":"update",c=(this.sync||i.sync).call(this,l,this,n);return n.wait&&this.set(o,u),c},destroy:function(e){e=e?s.clone(e):{};var t=this,n=e.success,r=function(){t.trigger("destroy",t,t.collection,e)};if(this.isNew())return r(),!1;e.success=function(i){e.wait&&r(),n?n(t,i):t.trigger("sync",t,i,e)},e.error=i.wrapError(e.error,t,e);var o=(this.sync||i.sync).call(this,"delete",this,e);return e.wait||r(),o},url:function(){var e=C(this,"urlRoot")||C(this.collection,"url")||k();return this.isNew()?e:e+(e.charAt(e.length-1)=="/"?"":"/")+encodeURIComponent(this.id)},parse:function(e,t){return e},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return this.id==null},change:function(e){e||(e={});var t=this._changing;this._changing=!0;for(var n in this._silent)this._pending[n]=!0;var r=s.extend({},e.changes,this._silent);this._silent={};for(var n in r)this.trigger("change:"+n,this,this.get(n),e);if(t)return this;while(!s.isEmpty(this._pending)){this._pending={},this.trigger("change",this,e);for(var n in this.changed){if(this._pending[n]||this._silent[n])continue;delete this.changed[n]}this._previousAttributes=s.clone(this.attributes)}return this._changing=!1,this},hasChanged:function(e){return arguments.length?s.has(this.changed,e):!s.isEmpty(this.changed)},changedAttributes:function(e){if(!e)return this.hasChanged()?s.clone(this.changed):!1;var t,n=!1,r=this._previousAttributes;for(var i in e){if(s.isEqual(r[i],t=e[i]))continue;(n||(n={}))[i]=t}return n},previous:function(e){return!arguments.length||!this._previousAttributes?null:this._previousAttributes[e]},previousAttributes:function(){return s.clone(this._previousAttributes)},isValid:function(){return!this.validate(this.attributes)},_validate:function(e,t){if(t.silent||!this.validate)return!0;e=s.extend({},this.attributes,e);var n=this.validate(e,t);return n?(t&&t.error?t.error(this,n,t):this.trigger("error",this,n,t),!1):!0}});var l=i.Collection=function(e,t){t||(t={}),t.model&&(this.model=t.model),t.comparator&&(this.comparator=t.comparator),this._reset(),this.initialize.apply(this,arguments),e&&this.reset(e,{silent:!0,parse:t.parse})};s.extend(l.prototype,a,{model:f,initialize:function(){},toJSON:function(e){return this.map(function(t){return t.toJSON(e)})},add:function(e,t){var n,i,o,u,a,f,l={},c={},h=[];t||(t={}),e=s.isArray(e)?e.slice():[e];for(n=0,o=e.length;n<o;n++){if(!(u=e[n]=this._prepareModel(e[n],t)))throw new Error("Can't add an invalid model to a collection");a=u.cid,f=u.id;if(l[a]||this._byCid[a]||f!=null&&(c[f]||this._byId[f])){h.push(n);continue}l[a]=c[f]=u}n=h.length;while(n--)e.splice(h[n],1);for(n=0,o=e.length;n<o;n++)(u=e[n]).on("all",this._onModelEvent,this),this._byCid[u.cid]=u,u.id!=null&&(this._byId[u.id]=u);this.length+=o,i=t.at!=null?t.at:this.models.length,r.apply(this.models,[i,0].concat(e)),this.comparator&&this.sort({silent:!0});if(t.silent)return this;for(n=0,o=this.models.length;n<o;n++){if(!l[(u=this.models[n]).cid])continue;t.index=n,u.trigger("add",u,this,t)}return this},remove:function(e,t){var n,r,i,o;t||(t={}),e=s.isArray(e)?e.slice():[e];for(n=0,r=e.length;n<r;n++){o=this.getByCid(e[n])||this.get(e[n]);if(!o)continue;delete this._byId[o.id],delete this._byCid[o.cid],i=this.indexOf(o),this.models.splice(i,1),this.length--,t.silent||(t.index=i,o.trigger("remove",o,this,t)),this._removeReference(o)}return this},push:function(e,t){return e=this._prepareModel(e,t),this.add(e,t),e},pop:function(e){var t=this.at(this.length-1);return this.remove(t,e),t},unshift:function(e,t){return e=this._prepareModel(e,t),this.add(e,s.extend({at:0},t)),e},shift:function(e){var t=this.at(0);return this.remove(t,e),t},get:function(e){return e==null?void 0:this._byId[e.id!=null?e.id:e]},getByCid:function(e){return e&&this._byCid[e.cid||e]},at:function(e){return this.models[e]},where:function(e){return s.isEmpty(e)?[]:this.filter(function(t){for(var n in e)if(e[n]!==t.get(n))return!1;return!0})},sort:function(e){e||(e={});if(!this.comparator)throw new Error("Cannot sort a set without a comparator");var t=s.bind(this.comparator,this);return this.comparator.length==1?this.models=this.sortBy(t):this.models.sort(t),e.silent||this.trigger("reset",this,e),this},pluck:function(e){return s.map(this.models,function(t){return t.get(e)})},reset:function(e,t){e||(e=[]),t||(t={});for(var n=0,r=this.models.length;n<r;n++)this._removeReference(this.models[n]);return this._reset(),this.add(e,s.extend({silent:!0},t)),t.silent||this.trigger("reset",this,t),this},fetch:function(e){e=e?s.clone(e):{},e.parse===undefined&&(e.parse=!0);var t=this,n=e.success;return e.success=function(r,i,s){t[e.add?"add":"reset"](t.parse(r,s),e),n&&n(t,r)},e.error=i.wrapError(e.error,t,e),(this.sync||i.sync).call(this,"read",this,e)},create:function(e,t){var n=this;t=t?s.clone(t):{},e=this._prepareModel(e,t);if(!e)return!1;t.wait||n.add(e,t);var r=t.success;return t.success=function(i,s,o){t.wait&&n.add(i,t),r?r(i,s):i.trigger("sync",e,s,t)},e.save(null,t),e},parse:function(e,t){return e},chain:function(){return s(this.models).chain()},_reset:function(e){this.length=0,this.models=[],this._byId={},this._byCid={}},_prepareModel:function(e,t){t||(t={});if(e instanceof f)e.collection||(e.collection=this);else{var n=e;t.collection=this,e=new this.model(n,t),e._validate(e.attributes,t)||(e=!1)}return e},_removeReference:function(e){this==e.collection&&delete e.collection,e.off("all",this._onModelEvent,this)},_onModelEvent:function(e,t,n,r){if((e=="add"||e=="remove")&&n!=this)return;e=="destroy"&&this.remove(t,r),t&&e==="change:"+t.idAttribute&&(delete this._byId[t.previous(t.idAttribute)],this._byId[t.id]=t),this.trigger.apply(this,arguments)}});var c=["forEach","each","map","reduce","reduceRight","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","sortBy","sortedIndex","toArray","size","first","initial","rest","last","without","indexOf","shuffle","lastIndexOf","isEmpty","groupBy"];s.each(c,function(e){l.prototype[e]=function(){return s[e].apply(s,[this.models].concat(s.toArray(arguments)))}});var h=i.Router=function(e){e||(e={}),e.routes&&(this.routes=e.routes),this._bindRoutes(),this.initialize.apply(this,arguments)},p=/:\w+/g,d=/\*\w+/g,v=/[-[\]{}()+?.,\\^$|#\s]/g;s.extend(h.prototype,a,{initialize:function(){},route:function(e,t,n){return i.history||(i.history=new m),s.isRegExp(e)||(e=this._routeToRegExp(e)),n||(n=this[t]),i.history.route(e,s.bind(function(r){var s=this._extractParameters(e,r);n&&n.apply(this,s),this.trigger.apply(this,["route:"+t].concat(s)),i.history.trigger("route",this,t,s)},this)),this},navigate:function(e,t){i.history.navigate(e,t)},_bindRoutes:function(){if(!this.routes)return;var e=[];for(var t in this.routes)e.unshift([t,this.routes[t]]);for(var n=0,r=e.length;n<r;n++)this.route(e[n][0],e[n][1],this[e[n][1]])},_routeToRegExp:function(e){return e=e.replace(v,"\\$&").replace(p,"([^/]+)").replace(d,"(.*?)"),new RegExp("^"+e+"$")},_extractParameters:function(e,t){return e.exec(t).slice(1)}});var m=i.History=function(){this.handlers=[],s.bindAll(this,"checkUrl")},g=/^[#\/]/,y=/msie [\w.]+/;m.started=!1,s.extend(m.prototype,a,{interval:50,getHash:function(e){var t=e?e.location:window.location,n=t.href.match(/#(.*)$/);return n?n[1]:""},getFragment:function(e,t){if(e==null)if(this._hasPushState||t){e=window.location.pathname;var n=window.location.search;n&&(e+=n)}else e=this.getHash();return e.indexOf(this.options.root)||(e=e.substr(this.options.root.length)),e.replace(g,"")},start:function(e){if(m.started)throw new Error("Backbone.history has already been started");m.started=!0,this.options=s.extend({},{root:"/"},this.options,e),this._wantsHashChange=this.options.hashChange!==!1,this._wantsPushState=!!this.options.pushState,this._hasPushState=!!(this.options.pushState&&window.history&&window.history.pushState);var t=this.getFragment(),n=document.documentMode,r=y.exec(navigator.userAgent.toLowerCase())&&(!n||n<=7);r&&(this.iframe=o('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(t)),this._hasPushState?o(window).bind("popstate",this.checkUrl):this._wantsHashChange&&"onhashchange"in window&&!r?o(window).bind("hashchange",this.checkUrl):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,this.interval)),this.fragment=t;var i=window.location,u=i.pathname==this.options.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!u)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;this._wantsPushState&&this._hasPushState&&u&&i.hash&&(this.fragment=this.getHash().replace(g,""),window.history.replaceState({},document.title,i.protocol+"//"+i.host+this.options.root+this.fragment));if(!this.options.silent)return this.loadUrl()},stop:function(){o(window).unbind("popstate",this.checkUrl).unbind("hashchange",this.checkUrl),clearInterval(this._checkUrlInterval),m.started=!1},route:function(e,t){this.handlers.unshift({route:e,callback:t})},checkUrl:function(e){var t=this.getFragment();t==this.fragment&&this.iframe&&(t=this.getFragment(this.getHash(this.iframe)));if(t==this.fragment)return!1;this.iframe&&this.navigate(t),this.loadUrl()||this.loadUrl(this.getHash())},loadUrl:function(e){var t=this.fragment=this.getFragment(e),n=s.any(this.handlers,function(e){if(e.route.test(t))return e.callback(t),!0});return n},navigate:function(e,t){if(!m.started)return!1;if(!t||t===!0)t={trigger:t};var n=(e||"").replace(g,"");if(this.fragment==n)return;this._hasPushState?(n.indexOf(this.options.root)!=0&&(n=this.options.root+n),this.fragment=n,window.history[t.replace?"replaceState":"pushState"]({},document.title,n)):this._wantsHashChange?(this.fragment=n,this._updateHash(window.location,n,t.replace),this.iframe&&n!=this.getFragment(this.getHash(this.iframe))&&(t.replace||this.iframe.document.open().close(),this._updateHash(this.iframe.location,n,t.replace))):window.location.assign(this.options.root+e),t.trigger&&this.loadUrl(e)},_updateHash:function(e,t,n){n?e.replace(e.toString().replace(/(javascript:|#).*$/,"")+"#"+t):e.hash=t}});var b=i.View=function(e){this.cid=s.uniqueId("view"),this._configure(e||{}),this._ensureElement(),this.initialize.apply(this,arguments),this.delegateEvents()},w=/^(\S+)\s*(.*)$/,E=["model","collection","el","id","attributes","className","tagName"];s.extend(b.prototype,a,{tagName:"div",$:function(e){return this.$el.find(e)},initialize:function(){},render:function(){return this},remove:function(){return this.$el.remove(),this},make:function(e,t,n){var r=document.createElement(e);return t&&o(r).attr(t),n&&o(r).html(n),r},setElement:function(e,t){return this.$el&&this.undelegateEvents(),this.$el=e instanceof o?e:o(e),this.el=this.$el[0],t!==!1&&this.delegateEvents(),this},delegateEvents:function(e){if(!e&&!(e=C(this,"events")))return;this.undelegateEvents();for(var t in e){var n=e[t];s.isFunction(n)||(n=this[e[t]]);if(!n)throw new Error('Method "'+e[t]+'" does not exist');var r=t.match(w),i=r[1],o=r[2];n=s.bind(n,this),i+=".delegateEvents"+this.cid,o===""?this.$el.bind(i,n):this.$el.delegate(o,i,n)}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+this.cid)},_configure:function(e){this.options&&(e=s.extend({},this.options,e));for(var t=0,n=E.length;t<n;t++){var r=E[t];e[r]&&(this[r]=e[r])}this.options=e},_ensureElement:function(){if(!this.el){var e=C(this,"attributes")||{};this.id&&(e.id=this.id),this.className&&(e["class"]=this.className),this.setElement(this.make(this.tagName,e),!1)}else this.setElement(this.el,!1)}});var S=function(e,t){var n=N(this,e,t);return n.extend=this.extend,n};f.extend=l.extend=h.extend=b.extend=S;var x={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};i.sync=function(e,t,n){var r=x[e];n||(n={});var u={type:r,dataType:"json"};return n.url||(u.url=C(t,"url")||k()),!n.data&&t&&(e=="create"||e=="update")&&(u.contentType="application/json",u.data=JSON.stringify(t.toJSON())),i.emulateJSON&&(u.contentType="application/x-www-form-urlencoded",u.data=u.data?{model:u.data}:{}),i.emulateHTTP&&(r==="PUT"||r==="DELETE")&&(i.emulateJSON&&(u.data._method=r),u.type="POST",u.beforeSend=function(e){e.setRequestHeader("X-HTTP-Method-Override",r)}),u.type!=="GET"&&!i.emulateJSON&&(u.processData=!1),o.ajax(s.extend(u,n))},i.wrapError=function(e,t,n){return function(r,i){i=r===t?i:r,e?e(t,i,n):t.trigger("error",t,i,n)}};var T=function(){},N=function(e,t,n){var r;return t&&t.hasOwnProperty("constructor")?r=t.constructor:r=function(){e.apply(this,arguments)},s.extend(r,e),T.prototype=e.prototype,r.prototype=new T,t&&s.extend(r.prototype,t),n&&s.extend(r,n),r.prototype.constructor=r,r.__super__=e.prototype,r},C=function(e,t){return!e||!e[t]?null:s.isFunction(e[t])?e[t]():e[t]},k=function(){throw new Error('A "url" property or function must be specified')}}.call(this),Backbone.EventBinder=function(e,t){var n=function(){this._eventBindings=[]};return n.extend=e.View.extend,t.extend(n.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)})}}),n}(Backbone,_),Backbone.Wreqr=function(e,t,n){"option strict";var r={};return r.Handlers=function(e,t){var n=function(){"use strict";this._handlers={}};return n.extend=e.Model.extend,t.extend(n.prototype,{addHandler:function(e,t,n){var r={callback:t,context:n};this._handlers[e]=r},getHandler:function(e){var t=this._handlers[e];if(!t)throw new Error("Handler not found for '"+e+"'");return function(){return t.callback.apply(t.context,arguments)}},removeHandler:function(e){delete this._handlers[e]},removeAllHandlers:function(){this._handlers={}}}),n}(e,n),r.Commands=function(e){return e.Handlers.extend({execute:function(e,t){this.getHandler(e)(t)}})}(r),r.RequestResponse=function(e){return e.Handlers.extend({request:function(e,t){return this.getHandler(e)(t)}})}(r),r.EventAggregator=function(e,t){var n=function(){};return n.extend=e.Model.extend,t.extend(n.prototype,e.Events),n}(e,n),r}(Backbone,Backbone.Marionette,_),Backbone.Marionette=Marionette=function(e,t,n){var r={},i=Array.prototype.slice;return r.extend=e.Model.extend,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),t.isFunction(this[o])&&(e.shift(),this[o].apply(this,e))},r.EventBinder=e.EventBinder,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.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(){var e;return this.options&&this.options.template?e=this.options.template:e=this.template,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(){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=this.mixinTemplateHelpers(e),e},render:function(){this.isClosed=!1,this.triggerMethod("before:render",this),this.triggerMethod("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.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(){this.initChildViewStorage(),r.View.prototype.constructor.apply(this,arguments),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=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.triggerMethod("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.triggerMethod.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.triggerMethod("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(){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&&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},serializeData:function(){var e={};return this.model&&(e=this.model.toJSON()),e=this.mixinTemplateHelpers(e),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.triggerMethod("render"),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();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.Region=function(e){this.options=e||{};var t=this.options.el;delete this.options.el,r.addEventBinder(this),t&&(this.el=t);if(!this.el){var n=new Error("An 'el' must be specified for a region.");throw n.name="NoElError",n}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),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||e.isClosed)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=r.extend,r.Layout=r.ItemView.extend({regionType:r.Region,constructor:function(){this.initializeRegions(),e.Marionette.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.Marionette.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.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)},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.trigger("initialize:before",e),this.initCallbacks.run(e,this),this.trigger("initialize:after",e),this.trigger("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.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,t){this.moduleName=e,this.submodules={},this._setupInitializersAndFinalizers(),this.config={},this.config.app=t,r.addEventBinder(this)},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,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=s._getModuleDefinition(o,t,e);f.config.options=s._getModuleOptions(o,r),i&&s._configureAutoStart(e,f),i&&f.config.options.hasDefinition&&f.addDefinition(f.config.options.definition,u),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){var i=e[t];return i||(i=new r.Module(t,n),e[t]=i,e.submodules[t]=i),i},_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,r=this._callbacks;this._deferred=n.Deferred(),this._callbacks=[],t.each(r,function(t){e.add(t.cb,t.ctx)})}}),r.EventAggregator=e.Wreqr.EventAggregator,r}(Backbone,_,$||window.jQuery||window.Zepto||window.ender);
View
13,728 lib/bundles/marionette.backbone_underscore_jquery.js
13,728 additions, 0 deletions not shown
View
23 lib/bundles/marionette.backbone_underscore_jquery.min.js
23 additions, 0 deletions not shown
View
1,665 lib/bundles/marionette.core.js
@@ -0,0 +1,1665 @@
+// Backbone.EventBinder, v0.0.0
+// Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
+// Distributed under MIT license
+// http://github.com/marionettejs/backbone.eventbinder
+// EventBinder
+// -----------
+//
+// The event binder facilitates the binding and unbinding of events
+// from objects that extend `Backbone.Events`. It makes
+// unbinding events, even with anonymous callback functions,
+// easy.
+//
+// Inspired by [Johnny Oshika](http://stackoverflow.com/questions/7567404/backbone-js-repopulate-or-recreate-the-view/7607853#7607853)
+
+Backbone.EventBinder = (function(Backbone, _){
+
+ // Constructor function
+ var EventBinder = function(){
+ this._eventBindings = [];
+ };
+
+ // Copy the `extend` function used by Backbone's classes
+ EventBinder.extend = Backbone.View.extend;
+
+ // Extend the EventBinder with additional methods
+ _.extend(EventBinder.prototype, {
+ // Store the event binding in array so it can be unbound
+ // easily, at a later point in time.
+ bindTo: function (obj, eventName, callback, context) {
+ context = context || this;
+ obj.on(eventName, callback, context);
+
+ var binding = {
+ obj: obj,
+ eventName: eventName,
+ callback: callback,
+ context: context
+ };
+
+ this._eventBindings.push(binding);
+
+ return binding;
+ },
+
+ // Unbind from a single binding object. Binding objects are
+ // returned from the `bindTo` method call.
+ unbindFrom: function(binding){
+ binding.obj.off(binding.eventName, binding.callback, binding.context);
+ this._eventBindings = _.reject(this._eventBindings, function(bind){return bind === binding;});
+ },
+
+ // Unbind all of the events that we have stored.
+ unbindAll: function () {
+ var that = this;
+
+ // The `unbindFrom` call removes elements from the array
+ // while it is being iterated, so clone it first.
+ var bindings = _.map(this._eventBindings, _.identity);
+ _.each(bindings, function (binding, index) {
+ that.unbindFrom(binding);
+ });
+ }
+ });
+
+ return EventBinder;
+})(Backbone, _);
+
+// Backbone.Wreqr, v0.0.0
+// Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
+// Distributed under MIT license
+// http://github.com/marionettejs/backbone.wreqr
+Backbone.Wreqr = (function(Backbone, Marionette, _){
+ "option strict";
+ var Wreqr = {};
+
+ Wreqr.Handlers = (function(Backbone, _){
+ "option strict";
+
+ var Handlers = function(){
+ "use strict";
+ this._handlers = {};
+ };
+
+ Handlers.extend = Backbone.Model.extend;
+
+ _.extend(Handlers.prototype, {
+ addHandler: function(name, handler, context){
+ var config = {
+ callback: handler,
+ context: context
+ };
+
+ this._handlers[name] = config;
+ },
+
+ getHandler: function(name){
+ var config = this._handlers[name];
+
+ if (!config){
+ throw new Error("Handler not found for '" + name + "'");
+ }
+
+ return function(){
+ return config.callback.apply(config.context, arguments);
+ };
+ },
+
+ removeHandler: function(name){
+ delete this._handlers[name];
+ },
+
+ removeAllHandlers: function(){
+ this._handlers = {};
+ }
+ });
+
+ return Handlers;
+ })(Backbone, _);
+
+ // Wreqr.Commands
+ // --------------
+ //
+ // A simple command pattern implementation. Register a command
+ // handler and execute it.
+ Wreqr.Commands = (function(Wreqr){
+ "option strict";
+
+ return Wreqr.Handlers.extend({
+ execute: function(name, args){
+ this.getHandler(name)(args);
+ }
+ });
+
+ })(Wreqr);
+
+ // Wreqr.RequestResponse
+ // ---------------------
+ //
+ // A simple request/response implementation. Register a
+ // request handler, and return a response from it
+ Wreqr.RequestResponse = (function(Wreqr){
+ "option strict";
+
+ return Wreqr.Handlers.extend({
+ request: function(name, args){
+ return this.getHandler(name)(args);
+ }
+ });
+
+ })(Wreqr);
+
+ // Event Aggregator
+ // ----------------
+ // A pub-sub object that can be used to decouple various parts
+ // of an application through event-driven architecture.
+
+ Wreqr.EventAggregator = (function(Backbone, _){
+ "option strict";
+ var EA = function(){};
+
+ // Copy the `extend` function used by Backbone's classes
+ EA.extend = Backbone.Model.extend;
+
+ // Copy the basic Backbone.Events on to the event aggregator
+ _.extend(EA.prototype, Backbone.Events);
+
+ return EA;
+ })(Backbone, _);
+
+
+ return Wreqr;
+})(Backbone, Backbone.Marionette, _);
+
+/*!
+ * Backbone.Marionette, v1.0.0-beta1
+ * Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
+ * Distributed under MIT license
+ * http://github.com/marionettejs/backbone.marionette
+*/
+Backbone.Marionette = Marionette = (function(Backbone, _, $){
+ var Marionette = {};
+
+// Helpers
+// -------
+
+// For slicing `arguments` in functions
+var slice = Array.prototype.slice;
+
+// Borrow the Backbone `extend` method so we can use it as needed
+Marionette.extend = Backbone.Model.extend;
+
+// Trigger an event and a corresponding method name. Examples:
+//
+// `this.triggerMethod("foo")` will trigger the "foo" event and
+// call the "onFoo" method.
+//
+// `this.triggerMethod("foo:bar") will trigger the "foo:bar" event and
+// call the "onFooBar" method.
+Marionette.triggerMethod = function(){
+ var args = Array.prototype.slice.apply(arguments);
+ var eventName = args[0];
+ var segments = eventName.split(":");
+ var segment, capLetter, methodName = "on";
+
+ for (var i = 0; i < segments.length; i++){
+ segment = segments[i];
+ capLetter = segment.charAt(0).toUpperCase();
+ methodName += capLetter + segment.slice(1);
+ }
+
+ this.trigger.apply(this, arguments);
+
+ if (_.isFunction(this[methodName])){
+ args.shift();
+ this[methodName].apply(this, args);
+ }
+};
+
+// EventBinder
+// -----------
+// Import the event binder from it's new home
+// https://github.com/marionettejs/backbone.eventbinder
+Marionette.EventBinder = Backbone.EventBinder;
+
+// Add the EventBinder methods to the view directly,
+// but keep them bound to the EventBinder instance so they work properly.
+// This allows the event binder's implementation to vary independently
+// of it being attached to the view... for example the internal structure
+// used to store the events can change without worry about it interfering
+// with Marionette's views.
+Marionette.addEventBinder = function(target){
+ var eventBinder = new Marionette.EventBinder();
+ target.eventBinder = eventBinder;
+ target.bindTo = _.bind(eventBinder.bindTo, eventBinder);
+ target.unbindFrom = _.bind(eventBinder.unbindFrom, eventBinder);
+ target.unbindAll = _.bind(eventBinder.unbindAll, eventBinder);
+};
+
+// Marionette.View
+// ---------------
+
+// The core view type that other Marionette views extend from.
+Marionette.View = Backbone.View.extend({
+
+ constructor: function(){
+ _.bindAll(this, "render");
+ Marionette.addEventBinder(this);
+
+ Backbone.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);
+ },
+
+ // import the "triggerMethod" to trigger events with corresponding
+ // methods if the method exists
+ triggerMethod: Marionette.triggerMethod,
+
+ // Get the template for this view
+ // instance. You can set a `template` attribute in the view
+ // definition or pass a `template: "whatever"` parameter in
+ // to the constructor options.
+ getTemplate: function(){
+ var template;
+
+ // Get the template from `this.options.template` or
+ // `this.template`. The `options` takes precedence.
+ if (this.options && this.options.template){
+ template = this.options.template;
+ } else {
+ template = this.template;
+ }
+
+ return template;
+ },
+
+ // Mix in template helper methods. Looks for a
+ // `templateHelpers` attribute, which can either be an
+ // object literal, or a function that returns an object
+ // literal. All methods and attributes from this object
+ // are copies to the object passed in.
+ mixinTemplateHelpers: function(target){
+ target = target || {};
+ var templateHelpers = this.templateHelpers;
+ if (_.isFunction(templateHelpers)){
+ templateHelpers = templateHelpers.call(this);
+ }
+ return _.extend(target, templateHelpers);
+ },
+
+ // Configure `triggers` to forward DOM events to view
+ // events. `triggers: {"click .foo": "do:foo"}`
+ configureTriggers: function(){
+ if (!this.triggers) { return; }
+
+ var triggers = this.triggers;
+ var that = this;
+ var triggerEvents = {};
+
+ // Allow `triggers` to be configured as a function
+ if (_.isFunction(triggers)){ triggers = triggers.call(this); }
+
+ // Configure the triggers, prevent default
+ // action and stop propagation of DOM events
+ _.each(triggers, function(value, key){
+
+ triggerEvents[key] = function(e){
+ if (e && e.preventDefault){ e.preventDefault(); }
+ if (e && e.stopPropagation){ e.stopPropagation(); }
+ that.trigger(value);
+ };
+
+ });
+
+ return triggerEvents;
+ },
+
+ // Overriding Backbone.View's delegateEvents specifically
+ // to handle the `triggers` configuration
+ delegateEvents: function(events){
+ events = events || this.events;
+ if (_.isFunction(events)){ events = events.call(this); }
+
+ var combinedEvents = {};
+ var triggers = this.configureTriggers();
+ _.extend(combinedEvents, events, triggers);
+
+ Backbone.View.prototype.delegateEvents.call(this, combinedEvents);
+ },
+
+ // Internal method, handles the `show` event.
+ onShowCalled: function(){},
+
+ // Default `close` implementation, for removing a view from the
+ // DOM and unbinding it. Regions will call this method
+ // for you. You can specify an `onClose` method in your view to
+ // add custom code that is called after the view is closed.
+ close: function(){
+ if (this.isClosed) { return; }
+
+ this.triggerMethod("before:close");
+
+ this.remove();
+ this.unbindAll();
+
+ this.triggerMethod("close");
+ this.isClosed = true;
+ },
+
+ // This method binds the elements specified in the "ui" hash inside the view's code with
+ // the associated jQuery selectors.
+ bindUIElements: function(){
+ if (!this.ui) { return; }
+
+ var that = this;
+
+ if (!this.uiBindings) {
+ // We want to store the ui hash in uiBindings, since afterwards the values in the ui hash
+ // will be overridden with jQuery selectors.
+ this.uiBindings = this.ui;
+ }
+
+ // refreshing the associated selectors since they should point to the newly rendered elements.
+ this.ui = {};
+ _.each(_.keys(this.uiBindings), function(key) {
+ var selector = that.uiBindings[key];
+ that.ui[key] = that.$(selector);
+ });
+ },
+
+ // This method is used to bind a backbone "entity" (collection/model) to methods on the view.
+ bindBackboneEntityTo: function(entity, bindings){
+ if (!entity || !bindings) { return; }
+
+ var view = this;
+ _.each(bindings, function(methodName, evt){
+
+ var method = view[methodName];
+ if(!method) {
+ throw new Error("View method '"+ methodName +"' was configured as an event handler, but does not exist.");
+ }
+
+ view.bindTo(entity, evt, method, view);
+ });
+ }
+});
+
+// Item View
+// ---------
+
+// A single item view implementation that contains code for rendering
+// with underscore.js templates, serializing the view's model or collection,
+// and calling several methods on extended views, such as `onRender`.
+Marionette.ItemView = Marionette.View.extend({
+ constructor: function(){
+ Marionette.View.prototype.constructor.apply(this, arguments);
+
+ if (this.initialEvents){
+ this.initialEvents();
+ }
+ },
+
+ // Serialize the model or collection for the view. If a model is
+ // found, `.toJSON()` is called. If a collection is found, `.toJSON()`
+ // is also called, but is used to populate an `items` array in the
+ // resulting data. If both are found, defaults to the model.
+ // You can override the `serializeData` method in your own view
+ // definition, to provide custom serialization for your view's data.
+ serializeData: function(){
+ var data;
+
+ if (this.model) {
+ data = this.model.toJSON();
+ }
+ else if (this.collection) {
+ data = { items: this.collection.toJSON() };
+ }
+
+ data = this.mixinTemplateHelpers(data);
+
+ return data;
+ },
+
+ // Render the view, defaulting to underscore.js templates.
+ // You can override this in your view definition to provide
+ // a very specific rendering for your view. In general, though,
+ // you should override the `Marionette.Renderer` object to
+ // change how Marionette renders views.
+ render: function(){
+ this.isClosed = false;
+
+ this.triggerMethod("before:render", this);
+ this.triggerMethod("item:before:render", this);
+
+ var data = this.serializeData();
+ var template = this.getTemplate();
+ var html = Marionette.Renderer.render(template, data);
+ this.$el.html(html);
+ this.bindUIElements();
+
+ this.triggerMethod("render", this);
+ this.triggerMethod("item:rendered", this);
+
+ return this;
+ },
+
+ // Override the default close event to add a few
+ // more events that are triggered.
+ close: function(){
+ if (this.isClosed){ return; }
+
+ this.triggerMethod('item:before:close');
+ Marionette.View.prototype.close.apply(this, arguments);
+ this.triggerMethod('item:closed');
+ }
+});
+
+// Collection View
+// ---------------
+
+// A view that iterates over a Backbone.Collection
+// and renders an individual ItemView for each model.
+Marionette.CollectionView = Marionette.View.extend({
+ constructor: function(){
+ this.initChildViewStorage();
+ Marionette.View.prototype.constructor.apply(this, arguments);
+ this.initialEvents();
+ this.onShowCallbacks = new Marionette.Callbacks();
+ },
+
+ // Configured the initial events that the collection view
+ // binds to. Override this method to prevent the initial
+ // events, or to add your own initial events.
+ initialEvents: function(){
+ if (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);
+ }
+ },
+
+ // Handle a child item added to the collection
+ addChildView: function(item, collection, options){
+ this.closeEmptyView();
+ var ItemView = this.getItemView(item);
+
+ var index;
+ if(options && options.index){
+ index = options.index;
+ } else {
+ index = 0;
+ }
+
+ return this.addItemView(item, ItemView, index);
+ },
+
+ // Override from `Marionette.View` to guarantee the `onShow` method
+ // of child views is called.
+ onShowCalled: function(){
+ this.onShowCallbacks.run();
+ },
+
+ // Internal method to trigger the before render callbacks
+ // and events
+ triggerBeforeRender: function(){
+ this.triggerMethod("before:render", this);
+ this.triggerMethod("collection:before:render", this);
+ },
+
+ // Internal method to trigger the rendered callbacks and
+ // events
+ triggerRendered: function(){
+ this.triggerMethod("render", this);
+ this.triggerMethod("collection:rendered", this);
+ },
+
+ // Render the collection of items. Override this method to
+ // provide your own implementation of a render function for
+ // the collection view.
+ render: function(){
+ this.isClosed = false;
+
+ this.triggerBeforeRender();
+ this.closeEmptyView();
+ this.closeChildren();
+
+ if (this.collection && this.collection.length > 0) {
+ this.showCollection();
+ } else {
+ this.showEmptyView();
+ }
+
+ this.triggerRendered();
+ return this;
+ },
+
+ // Internal method to loop through each item in the
+ // collection view and show it
+ showCollection: function(){
+ var that = this;
+ var ItemView;
+ this.collection.each(function(item, index){
+ ItemView = that.getItemView(item);
+ that.addItemView(item, ItemView, index);
+ });
+ },
+
+ // Internal method to show an empty view in place of
+ // a collection of item views, when the collection is
+ // empty
+ showEmptyView: function(){
+ var EmptyView = this.options.emptyView || this.emptyView;
+ if (EmptyView && !this._showingEmptyView){
+ this._showingEmptyView = true;
+ var model = new Backbone.Model();
+ this.addItemView(model, EmptyView, 0);
+ }
+ },
+
+ // Internal method to close an existing emptyView instance
+ // if one exists. Called when a collection view has been
+ // rendered empty, and then an item is added to the collection.
+ closeEmptyView: function(){
+ if (this._showingEmptyView){
+ this.closeChildren();
+ delete this._showingEmptyView;
+ }
+ },
+
+ // Retrieve the itemView type, either from `this.options.itemView`
+ // or from the `itemView` in the object definition. The "options"
+ // takes precedence.
+ getItemView: function(item){
+ var itemView = this.options.itemView || this.itemView;
+
+ if (!itemView){
+ var err = new Error("An `itemView` must be specified");
+ err.name = "NoItemViewError";
+ throw err;
+ }
+
+ return itemView;
+ },
+
+ // Render the child item's view and add it to the
+ // HTML for the collection view.
+ addItemView: function(item, ItemView, index){
+ var that = this;
+
+ var view = this.buildItemView(item, ItemView);
+
+ // Store the child view itself so we can properly
+ // remove and/or close it later
+ this.storeChild(view);
+ this.triggerMethod("item:added", view);
+
+ // Render it and show it
+ var renderResult = this.renderItemView(view, index);
+
+ // call onShow for child item views
+ if (view.onShow){
+ this.onShowCallbacks.add(view.onShow, view);
+ }
+
+ // Forward all child item view events through the parent,
+ // prepending "itemview:" to the event name
+ var childBinding = this.bindTo(view, "all", function(){
+ var args = slice.call(arguments);
+ args[0] = "itemview:" + args[0];
+ args.splice(1, 0, view);
+
+ that.triggerMethod.apply(that, args);
+ });
+
+ // Store all child event bindings so we can unbind
+ // them when removing / closing the child view
+ this.childBindings = this.childBindings || {};
+ this.childBindings[view.cid] = childBinding;
+
+ return renderResult;
+ },
+
+ // render the item view
+ renderItemView: function(view, index) {
+ view.render();
+ this.appendHtml(this, view, index);
+ },
+
+ // Build an `itemView` for every model in the collection.
+ buildItemView: function(item, ItemView){
+ var itemViewOptions;
+
+ if (_.isFunction(this.itemViewOptions)){
+ itemViewOptions = this.itemViewOptions(item);
+ } else {
+ itemViewOptions = this.itemViewOptions;
+ }
+
+ var options = _.extend({model: item}, itemViewOptions);
+ var view = new ItemView(options);
+ return view;
+ },
+
+ // Remove the child view and close it
+ removeItemView: function(item){
+ var view = this.children[item.cid];
+ if (view){
+ var childBinding = this.childBindings[view.cid];
+ if (childBinding) {
+ this.unbindFrom(childBinding);
+ delete this.childBindings[view.cid];
+ }
+ view.close();
+ delete this.children[item.cid];
+ }
+
+ if (!this.collection || this.collection.length === 0){
+ this.showEmptyView();
+ }
+
+ this.triggerMethod("item:removed", view);
+ },
+
+ // Append the HTML to the collection's `el`.
+ // Override this method to do something other
+ // then `.append`.
+ appendHtml: function(collectionView, itemView, index){
+ collectionView.$el.append(itemView.el);
+ },
+
+ // Store references to all of the child `itemView`
+ // instances so they can be managed and cleaned up, later.
+ storeChild: function(view){
+ this.children[view.model.cid] = view;
+ },
+
+ // Internal method to set up the `children` object for
+ // storing all of the child views
+ initChildViewStorage: function(){
+ this.children = {};
+ },
+
+ // Handle cleanup and other closing needs for
+ // the collection of views.
+ close: function(){
+ if (this.isClosed){ return; }
+
+ this.triggerMethod("collection:before:close");
+ this.closeChildren();
+ this.triggerMethod("collection:closed");
+ Marionette.View.prototype.close.apply(this, arguments);
+ },
+
+ // Close the child views that this collection view
+ // is holding on to, if any
+ closeChildren: function(){
+ var that = this;
+ if (this.children){
+ _.each(_.clone(this.children), function(childView){
+ that.removeItemView(childView.model);
+ });
+ }
+ }
+});
+
+
+// Composite View
+// --------------
+
+// Used for rendering a branch-leaf, hierarchical structure.
+// Extends directly from CollectionView and also renders an
+// an item view as `modelView`, for the top leaf
+Marionette.CompositeView = Marionette.CollectionView.extend({
+ constructor: function(options){
+ Marionette.CollectionView.apply(this, arguments);
+ this.itemView = this.getItemView();
+ },
+
+ // Configured the initial events that the composite view
+ // binds to. Override this method to prevent the initial
+ // events, or to add your own initial events.
+ initialEvents: function(){
+ if (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);
+ }
+ },
+
+ // Retrieve the `itemView` to be used when rendering each of
+ // the items in the collection. The default is to return
+ // `this.itemView` or Marionette.CompositeView if no `itemView`
+ // has been defined
+ getItemView: function(item){
+ var itemView = this.options.itemView || this.itemView || this.constructor;
+
+ if (!itemView){
+ var err = new Error("An `itemView` must be specified");
+ err.name = "NoItemViewError";
+ throw err;
+ }
+
+ return itemView;
+ },
+
+ // Serialize the collection for the view.
+ // You can override the `serializeData` method in your own view
+ // definition, to provide custom serialization for your view's data.
+ serializeData: function(){
+ var data = {};
+
+ if (this.model){
+ data = this.model.toJSON();
+ }
+
+ data = this.mixinTemplateHelpers(data);
+
+ return data;
+ },
+
+ // Renders the model once, and the collection once. Calling
+ // this again will tell the model's view to re-render itself
+ // but the collection will not re-render.
+ render: function(){
+ this.isClosed = false;
+
+ this.resetItemViewContainer();
+
+ var html = this.renderModel();
+ this.$el.html(html);
+
+ // the ui bindings is done here and not at the end of render since they
+ // will not be available until after the model is rendered, but should be
+ // available before the collection is rendered.
+ this.bindUIElements();
+
+ this.triggerMethod("composite:model:rendered");
+ this.triggerMethod("render");
+
+ this.renderCollection();
+ this.triggerMethod("composite:rendered");
+ return this;
+ },
+
+ // Render the collection for the composite view
+ renderCollection: function(){
+ Marionette.CollectionView.prototype.render.apply(this, arguments);
+ this.triggerMethod("composite:collection:rendered");
+ },
+
+ // Render an individual model, if we have one, as
+ // part of a composite view (branch / leaf). For example:
+ // a treeview.
+ renderModel: function(){
+ var data = {};
+ data = this.serializeData();
+
+ var template = this.getTemplate();
+ return Marionette.Renderer.render(template, data);
+ },
+
+ // Appends the `el` of itemView instances to the specified
+ // `itemViewContainer` (a jQuery selector). Override this method to
+ // provide custom logic of how the child item view instances have their
+ // HTML appended to the composite view instance.
+ appendHtml: function(cv, iv){
+ var $container = this.getItemViewContainer(cv);
+ $container.append(iv.el);
+ },
+
+ // Internal method to ensure an `$itemViewContainer` exists, for the
+ // `appendHtml` method to use.
+ getItemViewContainer: function(containerView){
+ if ("$itemViewContainer" in containerView){
+ return containerView.$itemViewContainer;
+ }
+
+ var container;
+ if (containerView.itemViewContainer){
+
+ var selector = _.result(containerView, "itemViewContainer");
+ container = containerView.$(selector);
+ if (container.length <= 0) {
+ var err = new Error("The specified `itemViewContainer` was not found: " + containerView.itemViewContainer);
+ err.name = "ItemViewContainerMissingError";
+ throw err;
+ }
+
+ } else {
+ container = containerView.$el;
+ }
+
+ containerView.$itemViewContainer = container;
+ return container;
+ },
+
+ // Internal method to reset the `$itemViewContainer` on render
+ resetItemViewContainer: function(){
+ if (this.$itemViewContainer){
+ delete this.$itemViewContainer;
+ }
+ }
+});
+
+
+// Region
+// ------
+//
+// Manage the visual regions of your composite application. See
+// http://lostechies.com/derickbailey/2011/12/12/composite-js-apps-regions-and-region-managers/
+
+Marionette.Region = function(options){
+ this.options = options || {};
+
+ var el = this.options.el;
+ delete this.options.el;
+
+ Marionette.addEventBinder(this);
+
+ if (el){
+ this.el = el;
+ }
+
+ if (!this.el){
+ var err = new Error("An 'el' must be specified for a region.");
+ err.name = "NoElError";
+ throw err;
+ }
+
+ if (this.initialize){
+ this.initialize.apply(this, arguments);
+ }
+};
+
+
+// Region Type methods
+// -------------------
+
+_.extend(Marionette.Region, {
+
+ // Build an instance of a region by passing in a configuration object
+ // and a default region type to use if none is specified in the config.
+ //
+ // The config object should either be a string as a jQuery DOM selector,
+ // a Region type directly, or an object literal that specifies both
+ // a selector and regionType:
+ //
+ // ```js
+ // {
+ // selector: "#foo",
+ // regionType: MyCustomRegion
+ // }
+ // ```
+ //
+ buildRegion: function(regionConfig, defaultRegionType){
+ var regionIsString = (typeof regionConfig === "string");
+ var regionSelectorIsString = (typeof regionConfig.selector === "string");
+ var regionTypeIsUndefined = (typeof regionConfig.regionType === "undefined");
+ var regionIsType = (typeof regionConfig === "function");
+
+ if (!regionIsType && !regionIsString && !regionSelectorIsString) {
+ throw new Error("Region must be specified as a Region type, a selector string or an object with selector property");
+ }
+
+ var selector, RegionType;
+
+ // get the selector for the region
+
+ if (regionIsString) {
+ selector = regionConfig;
+ }
+
+ if (regionConfig.selector) {
+ selector = regionConfig.selector;
+ }
+
+ // get the type for the region
+
+ if (regionIsType){
+ RegionType = regionConfig;
+ }
+
+ if (!regionIsType && regionTypeIsUndefined) {
+ RegionType = defaultRegionType;
+ }
+
+ if (regionConfig.regionType) {
+ RegionType = regionConfig.regionType;
+ }
+
+ // build the region instance
+
+ var regionManager = new RegionType({
+ el: selector
+ });
+
+ return regionManager;
+ }
+
+});
+
+// Region Instance Methods
+// -----------------------
+
+_.extend(Marionette.Region.prototype, Backbone.Events, {
+
+ // Displays a backbone view instance inside of the region.
+ // Handles calling the `render` method for you. Reads content
+ // directly from the `el` attribute. Also calls an optional
+ // `onShow` and `close` method on your view, just after showing
+ // or just before closing the view, respectively.
+ show: function(view){
+
+ this.ensureEl();
+ this.close();
+
+ view.render();
+ this.open(view);
+
+ if (view.onShow) { view.onShow(); }
+ view.trigger("show");
+
+ if (this.onShow) { this.onShow(view); }
+ this.trigger("view:show", view);
+
+ this.currentView = view;
+ },
+
+ ensureEl: function(){
+ if (!this.$el || this.$el.length === 0){
+ this.$el = this.getEl(this.el);
+ }
+ },
+
+ // Override this method to change how the region finds the
+ // DOM element that it manages. Return a jQuery selector object.
+ getEl: function(selector){
+ return $(selector);
+ },
+
+ // Override this method to change how the new view is
+ // appended to the `$el` that the region is managing
+ open: function(view){
+ this.$el.html(view.el);
+ },
+
+ // Close the current view, if there is one. If there is no
+ // current view, it does nothing and returns immediately.
+ close: function(){
+ var view = this.currentView;
+ if (!view || view.isClosed){ return; }
+
+ if (view.close) { view.close(); }
+ this.trigger("view:closed", view);
+
+ delete this.currentView;
+ },
+
+ // Attach an existing view to the region. This
+ // will not call `render` or `onShow` for the new view,
+ // and will not replace the current HTML for the `el`
+ // of the region.
+ attachView: function(view){
+ this.currentView = view;
+ },
+
+ // Reset the region by closing any existing view and
+ // clearing out the cached `$el`. The next time a view
+ // is shown via this region, the region will re-query the
+ // DOM for the region's `el`.
+ reset: function(){
+ this.close();
+ delete this.$el;
+ }
+});
+
+// Copy the `extend` function used by Backbone's classes
+Marionette.Region.extend = Marionette.extend;
+
+// Layout
+// ------
+
+// Used for managing application layouts, nested layouts and
+// multiple regions within an application or sub-application.
+//
+// A specialized view type that renders an area of HTML and then
+// attaches `Region` instances to the specified `regions`.
+// Used for composite view management and sub-application areas.
+Marionette.Layout = Marionette.ItemView.extend({
+ regionType: Marionette.Region,
+
+ // Ensure the regions are avialable when the `initialize` method
+ // is called.
+ constructor: function () {
+ this.initializeRegions();
+ Backbone.Marionette.ItemView.apply(this, arguments);
+ },
+
+ // Layout's render will use the existing region objects the
+ // first time it is called. Subsequent calls will close the
+ // views that the regions are showing and then reset the `el`
+ // for the regions to the newly rendered DOM elements.
+ render: function(){
+ // If this is not the first render call, then we need to
+ // re-initializing the `el` for each region
+ if (!this._firstRender){
+ this.closeRegions();
+ this.reInitializeRegions();
+ } else {
+ this._firstRender = false;
+ }
+
+ var result = Marionette.ItemView.prototype.render.apply(this, arguments);
+ return result;
+ },
+
+ // Handle closing regions, and then close the view itself.
+ close: function () {
+ if (this.isClosed){ return; }
+
+ this.closeRegions();
+ this.destroyRegions();
+ Backbone.Marionette.ItemView.prototype.close.call(this, arguments);
+ },
+
+ // Initialize the regions that have been defined in a
+ // `regions` attribute on this layout. The key of the
+ // hash becomes an attribute on the layout object directly.
+ // For example: `regions: { menu: ".menu-container" }`
+ // will product a `layout.menu` object which is a region
+ // that controls the `.menu-container` DOM element.
+ initializeRegions: function () {
+ if (!this.regionManagers){
+ this.regionManagers = {};
+ }
+
+ var that = this;
+ var regions = this.regions || {};
+ _.each(regions, function (region, name) {
+
+ var regionManager = Marionette.Region.buildRegion(region, that.regionType);
+ regionManager.getEl = function(selector){
+ return that.$(selector);
+ };
+
+ that.regionManagers[name] = regionManager;
+ that[name] = regionManager;
+ });
+
+ },
+
+ // Re-initialize all of the regions by updating the `el` that
+ // they point to
+ reInitializeRegions: function(){
+ if (this.regionManagers && _.size(this.regionManagers)===0){
+ this.initializeRegions();
+ } else {
+ _.each(this.regionManagers, function(region){
+ region.reset();
+ });
+ }
+ },
+
+ // Close all of the regions that have been opened by
+ // this layout. This method is called when the layout
+ // itself is closed.
+ closeRegions: function () {
+ var that = this;
+ _.each(this.regionManagers, function (manager, name) {
+ manager.close();
+ });
+ },
+
+ // Destroys all of the regions by removing references
+ // from the Layout
+ destroyRegions: function(){
+ var that = this;
+ _.each(this.regionManagers, function (manager, name) {
+ delete that[name];
+ });
+ this.regionManagers = {};
+ }
+});
+
+
+// Application
+// -----------
+
+// Contain and manage the composite application as a whole.
+// Stores and starts up `Region` objects, includes an
+// event aggregator as `app.vent`
+Marionette.Application = function(options){
+ this.initCallbacks = new Marionette.Callbacks();
+ this.vent = new Marionette.EventAggregator();
+ this.commands = new Backbone.Wreqr.Commands();
+ this.reqres = new Backbone.Wreqr.RequestResponse();
+ this.submodules = {};
+
+ _.extend(this, options);
+
+ Marionette.addEventBinder(this);
+};
+
+_.extend(Marionette.Application.prototype, Backbone.Events, {
+ // Command execution, facilitated by Backbone.Wreqr.Commands
+ execute: function(){
+ this.commands.execute.apply(this.commands, arguments);
+ },
+
+ // Request/response, facilitated by Backbone.Wreqr.RequestResponse
+ request: function(){
+ return this.reqres.request.apply(this.reqres, arguments);
+ },
+
+ // Add an initializer that is either run at when the `start`
+ // method is called, or run immediately if added after `start`
+ // has already been called.
+ addInitializer: function(initializer){
+ this.initCallbacks.add(initializer);
+ },
+
+ // kick off all of the application's processes.
+ // initializes all of the regions that have been added
+ // to the app, and runs all of the initializer functions
+ start: function(options){
+ this.trigger("initialize:before", options);
+ this.initCallbacks.run(options, this);
+ this.trigger("initialize:after", options);
+
+ this.trigger("start", options);
+ },
+
+ // Add regions to your app.
+ // Accepts a hash of named strings or Region objects
+ // addRegions({something: "#someRegion"})
+ // addRegions{{something: Region.extend({el: "#someRegion"}) });
+ addRegions: function(regions){
+ var that = this;
+ _.each(regions, function (region, name) {
+ var regionManager = Marionette.Region.buildRegion(region, Marionette.Region);
+ that[name] = regionManager;
+ });
+ },
+
+ // Removes a region from your app.
+ // Accepts the regions name
+ // removeRegion('myRegion')
+ removeRegion: function(region) {
+ this[region].close();
+ delete this[region];
+ },
+
+ // Create a module, attached to the application
+ module: function(moduleNames, moduleDefinition){
+ // slice the args, and add this application object as the
+ // first argument of the array
+ var args = slice.call(arguments);
+ args.unshift(this);
+
+ // see the Marionette.Module object for more information
+ return Marionette.Module.create.apply(Marionette.Module, args);
+ }
+});
+
+// Copy the `extend` function used by Backbone's classes
+Marionette.Application.extend = Marionette.extend;
+
+// AppRouter
+// ---------
+
+// Reduce the boilerplate code of handling route events
+// and then calling a single method on another object.
+// Have your routers configured to call the method on
+// your object, directly.
+//
+// Configure an AppRouter with `appRoutes`.
+//
+// App routers can only take one `controller` object.
+// It is recommended that you divide your controller
+// objects in to smaller peices of related functionality
+// and have multiple routers / controllers, instead of
+// just one giant router and controller.
+//
+// You can also add standard routes to an AppRouter.
+
+Marionette.AppRouter = Backbone.Router.extend({
+
+ constructor: function(options){
+ Backbone.Router.prototype.constructor.call(this, options);
+
+ if (this.appRoutes){
+ var controller = this.controller;
+ if (options && options.controller) {
+ controller = options.controller;
+ }
+ this.processAppRoutes(controller, this.appRoutes);
+ }
+ },
+
+ // Internal method to process the `appRoutes` for the
+ // router, and turn them in to routes that trigger the
+ // specified method on the specified `controller`.
+ processAppRoutes: function(controller, appRoutes){
+ var method, methodName;
+ var route, routesLength, i;
+ var routes = [];
+ var router = this;
+
+ for(route in appRoutes){
+ if (appRoutes.hasOwnProperty(route)){
+ routes.unshift([route, appRoutes[route]]);
+ }
+ }
+
+ routesLength = routes.length;
+ for (i = 0; i < routesLength; i++){
+ route = routes[i][0];
+ methodName = routes[i][1];
+ method = controller[methodName];
+
+ if (!method){
+ var msg = "Method '" + methodName + "' was not found on the controller";
+ var err = new Error(msg);
+ err.name = "NoMethodError";
+ throw err;
+ }
+
+ method = _.bind(method, controller);
+ router.route(route, methodName, method);
+ }
+ }
+});
+
+
+// Module
+// ------
+
+// A simple module system, used to create privacy and encapsulation in
+// Marionette applications
+Marionette.Module = function(moduleName, app){
+ this.moduleName = moduleName;
+
+ // store sub-modules
+ this.submodules = {};
+
+ this._setupInitializersAndFinalizers();
+
+ // store the configuration for this module
+ this.config = {};
+ this.config.app = app;
+
+ // extend this module with an event binder
+ Marionette.addEventBinder(this);
+};
+
+// Extend the Module prototype with events / bindTo, so that the module
+// can be used as an event aggregator or pub/sub.
+_.extend(Marionette.Module.prototype, Backbone.Events, {
+
+ // Initializer for a specific module. Initializers are run when the
+ // module's `start` method is called.
+ addInitializer: function(callback){
+ this._initializerCallbacks.add(callback);
+ },
+
+ // Finalizers are run when a module is stopped. They are used to teardown
+ // and finalize any variables, references, events and other code that the
+ // module had set up.
+ addFinalizer: function(callback){
+ this._finalizerCallbacks.add(callback);
+ },
+
+ // Start the module, and run all of it's initializers
+ start: function(options){
+ // Prevent re-start the module
+ if (this._isInitialized){ return; }
+
+ // start the sub-modules (depth-first hierarchy)
+ _.each(this.submodules, function(mod){
+ if (mod.config.options.startWithParent){
+ mod.start(options);
+ }
+ });
+
+ // run the callbacks to "start" the current module
+ this._initializerCallbacks.run(options, this);
+ this._isInitialized = true;
+ },
+
+ // Stop this module by running its finalizers and then stop all of
+ // the sub-modules for this module
+ stop: function(){
+ // if we are not initialized, don't bother finalizing
+ if (!this._isInitialized){ return; }
+ this._isInitialized = false;
+
+ // stop the sub-modules; depth-first, to make sure the
+ // sub-modules are stopped / finalized before parents
+ _.each(this.submodules, function(mod){ mod.stop(); });
+
+ // run the finalizers
+ this._finalizerCallbacks.run();
+
+ // reset the initializers and finalizers
+ this._initializerCallbacks.reset();
+ this._finalizerCallbacks.reset();
+ },
+
+ // Configure the module with a definition function and any custom args
+ // that are to be passed in to the definition function
+ addDefinition: function(moduleDefinition, customArgs){
+ this._runModuleDefinition(moduleDefinition, customArgs);
+ },
+
+ // Internal method: run the module definition function with the correct
+ // arguments
+ _runModuleDefinition: function(definition, customArgs){
+ if (!definition){ return; }
+
+ // build the correct list of arguments for the module definition
+ var args = _.flatten([
+ this,
+ this.config.app,
+ Backbone,
+ Marionette,
+ $, _,
+ customArgs
+ ]);
+
+ definition.apply(this, args);
+ },
+
+ // Internal method: set up new copies of initializers and finalizers.
+ // Calling this method will wipe out all existing initializers and
+ // finalizers.
+ _setupInitializersAndFinalizers: function(){
+ this._initializerCallbacks = new Marionette.Callbacks();
+ this._finalizerCallbacks = new Marionette.Callbacks();
+ }
+});
+
+// Function level methods to create modules
+_.extend(Marionette.Module, {
+
+ // Create a module, hanging off the app parameter as the parent object.
+ create: function(app, moduleNames, moduleDefinition){
+ var that = this;
+ var parentModule = app;
+ moduleNames = moduleNames.split(".");
+
+ // get the custom args passed in after the module definition and
+ // get rid of the module name and definition function
+ var customArgs = slice.apply(arguments);
+ customArgs.splice(0, 3);
+
+ // Loop through all the parts of the module definition
+ var length = moduleNames.length;
+ _.each(moduleNames, function(moduleName, i){
+ var isLastModuleInChain = (i === length-1);
+
+ var module = that._getModuleDefinition(parentModule, moduleName, app);
+ module.config.options = that._getModuleOptions(parentModule, moduleDefinition);
+
+ // if it's the first module in the chain, configure it
+ // for auto-start, as specified by the options
+ if (isLastModuleInChain){
+ that._configureAutoStart(app, module);
+ }
+
+ // Only add a module definition and initializer when this is
+ // the last module in a "parent.child.grandchild" hierarchy of
+ // module names
+ if (isLastModuleInChain && module.config.options.hasDefinition){
+ module.addDefinition(module.config.options.definition, customArgs);
+ }
+
+ // Reset the parent module so that the next child
+ // in the list will be added to the correct parent
+ parentModule = module;
+ });
+
+ // Return the last module in the definition chain
+ return parentModule;
+ },
+
+ _configureAutoStart: function(app, module){
+ // Only add the initializer if it's the first module, and
+ // if it is set to auto-start, and if it has not yet been added
+ if (module.config.options.startWithParent && !module.config.autoStartConfigured){
+ // start the module when the app starts
+ app.addInitializer(function(options){
+ module.start(options);
+ });
+ }
+
+ // prevent this module from being configured for
+ // auto start again. the first time the module
+ // is defined, determines it's auto-start
+ module.config.autoStartConfigured = true;
+ },
+
+ _getModuleDefinition: function(parentModule, moduleName, app){
+ // Get an existing module of this name if we have one
+ var module = parentModule[moduleName];
+
+ if (!module){
+ // Create a new module if we don't have one
+ module = new Marionette.Module(moduleName, app);
+ parentModule[moduleName] = module;
+ // store the module on the parent
+ parentModule.submodules[moduleName] = module;
+ }
+
+ return module;
+ },
+
+ _getModuleOptions: function(parentModule, moduleDefinition){
+ // default to starting the module with the app
+ var options = {
+ startWithParent: true,
+ hasDefinition: !!moduleDefinition
+ };
+
+ // short circuit if we don't have a module definition
+ if (!options.hasDefinition){ return options; }
+
+ if (_.isFunction(moduleDefinition)){
+ // if the definition is a function, assign it directly
+ // and use the defaults
+ options.definition = moduleDefinition;
+
+ } else {
+
+ // the definition is an object.
+
+ // grab the "define" attribute
+ options.hasDefinition = !!moduleDefinition.define;
+ options.definition = moduleDefinition.define;
+
+ // grab the "startWithParent" attribute if one exists
+ if (moduleDefinition.hasOwnProperty("startWithParent")){
+ options.startWithParent = moduleDefinition.startWithParent;
+ }
+ }
+
+ return options;
+ }
+});
+
+// Template Cache
+// --------------
+
+// Manage templates stored in `<script>` blocks,
+// caching them for faster access.
+Marionette.TemplateCache = function(templateId){
+ this.templateId = templateId;
+};
+
+// TemplateCache object-level methods. Manage the template
+// caches from these method calls instead of creating
+// your own TemplateCache instances
+_.extend(Marionette.TemplateCache, {
+ templateCaches: {},
+
+ // Get the specified template by id. Either
+ // retrieves the cached version, or loads it
+ // from the DOM.
+ get: function(templateId){
+ var that = this;
+ var cachedTemplate = this.templateCaches[templateId];
+
+ if (!cachedTemplate){
+ cachedTemplate = new Marionette.TemplateCache(templateId);
+ this.templateCaches[templateId] = cachedTemplate;
+ }
+
+ return cachedTemplate.load();
+ },
+
+ // Clear templates from the cache. If no arguments
+ // are specified, clears all templates:
+ // `clear()`
+ //
+ // If arguments are specified, clears each of the
+ // specified templates from the cache:
+ // `clear("#t1", "#t2", "...")`
+ clear: function(){
+ var i;
+ var length = arguments.length;
+
+ if (length > 0){
+ for(i=0; i<length; i++){
+ delete this.templateCaches[arguments[i]];
+ }
+ } else {
+ this.templateCaches = {};
+ }
+ }
+});
+
+// TemplateCache instance methods, allowing each
+// template cache object to manage it's own state
+// and know whether or not it has been loaded
+_.extend(Marionette.TemplateCache.prototype, {
+
+ // Internal method to load the template asynchronously.
+ load: function(){
+ var that = this;
+
+ // Guard clause to prevent loading this template more than once
+ if (this.compiledTemplate){
+ return this.compiledTemplate;
+ }
+
+ // Load the template and compile it
+ var template = this.loadTemplate(this.templateId);
+ this.compiledTemplate = this.compileTemplate(template);
+
+ return this.compiledTemplate;
+ },
+
+ // Load a template from the DOM, by default. Override
+ // this method to provide your own template retrieval,
+ // such as asynchronous loading from a server.
+ loadTemplate: function(templateId){
+ var template = $(templateId).html();
+
+ if (!template || template.length === 0){
+ var msg = "Could not find template: '" + templateId + "'";
+ var err = new Error(msg);
+ err.name = "NoTemplateError";
+ throw err;
+ }
+
+ return template;
+ },
+
+ // Pre-compile the template before caching it. Override
+ // this method if you do not need to pre-compile a template
+ // (JST / RequireJS for example) or if you want to change
+ // the template engine used (Handebars, etc).
+ compileTemplate: function(rawTemplate){
+ return _.template(rawTemplate);
+ }
+});
+
+
+// Renderer
+// --------
+
+// Render a template with data by passing in the template
+// selector and the data to render.
+Marionette.Renderer = {
+
+ // Render a template with data. The `template` parameter is
+ // passed to the `TemplateCache` object to retrieve the
+ // template function. Override this method to provide your own
+ // custom rendering and template handling for all of Marionette.
+ render: function(template, data){
+ var templateFunc = typeof template === 'function' ? template : Marionette.TemplateCache.get(template);
+ var html = templateFunc(data);
+ return html;
+ }
+};
+
+
+// Callbacks
+// ---------
+
+// A simple way of managing a collection of callbacks
+// and executing them at a later point in time, using jQuery's
+// `Deferred` object.
+Marionette.Callbacks = function(){
+ this._deferred = $.Deferred();
+ this._callbacks = [];
+};
+
+_.extend(Marionette.Callbacks.prototype, {
+
+ // Add a callback to be executed. Callbacks added here are
+ // guaranteed to execute, even if they are added after the
+ // `run` method is called.
+ add: function(callback, contextOverride){
+ this._callbacks.push({cb: callback, ctx: contextOverride});
+
+ this._deferred.done(function(context, options){
+ if (contextOverride){ context = contextOverride; }
+ callback.call(context, options);
+ });
+ },
+
+ // Run all registered callbacks with the context specified.
+ // Additional callbacks can be added after this has been run
+ // and they will still be executed.
+ run: function(options, context){
+ this._deferred.resolve(context, options);
+ },
+
+ // Resets the list of callbacks to be run, allowing the same list
+ // to be run multiple times - whenever the `run` method is called.
+ reset: function(){
+ var that = this;
+ var callbacks = this._callbacks;
+ this._deferred = $.Deferred();
+ this._callbacks = [];
+ _.each(callbacks, function(cb){
+ that.add(cb.cb, cb.ctx);
+ });
+ }
+});
+
+
+// Event Aggregator
+// ----------------
+// A pub-sub object that can be used to decouple various parts
+// of an application through event-driven architecture.
+//
+// https://github.com/marionettejs/backbone.wreqr
+Marionette.EventAggregator = Backbone.Wreqr.EventAggregator;
+
+
+ return Marionette;
+})(Backbone, _, $ || window.jQuery || window.Zepto || window.ender);
View
13 lib/bundles/marionette.core.min.js
@@ -0,0 +1,13 @@
+/*!
+ * Backbone.Marionette, v1.0.0-beta1
+ * Copyright (c)2012 Derick Bailey, Muted Solutions, LLC.
+ * Distributed under MIT license
+ * http://github.com/marionettejs/backbone.marionette
+*/
+/*!
+ * Includes Wreqr
+ * https://github.com/marionettejs/backbone.wreqr/
+ * Includes EventBinder
+ * https://github.com/marionettejs/backbone.eventbinder
+ */
+Backbone.EventBinder=function(e,t){var n=function(){this._eventBindings=[]};return n.extend=e.View.extend,t.extend(n.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)})}}),n}(Backbone,_),Backbone.Wreqr=function(e,t,n){"option strict";var r={};return r.Handlers=function(e,t){var n=function(){"use strict";this._handlers={}};return n.extend=e.Model.extend,t.extend(n.prototype,{addHandler:function(e,t,n){var r={callback:t,context:n};this._handlers[e]=r},getHandler:function(e){var t=this._handlers[e];if(!t)throw new Error("Handler not found for '"+e+"'");return function(){return t.callback.apply(t.context,arguments)}},removeHandler:function(e){delete this._handlers[e]},removeAllHandlers:function(){this._handlers={}}}),n}(e,n),r.Commands=function(e){return e.Handlers.extend({execute:function(e,t){this.getHandler(e)(t)}})}(r),r.RequestResponse=function(e){return e.Handlers.extend({request:function(e,t){return this.getHandler(e)(t)}})}(r),r.EventAggregator=function(e,t){var n=function(){};return n.extend=e.Model.extend,t.extend(n.prototype,e.Events),n}(e,n),r}(Backbone,Backbone.Marionette,_),Backbone.Marionette=Marionette=function(e,t,n){var r={},i=Array.prototype.slice;return r.extend=e.Model.extend,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),t.isFunction(this[o])&&(e.shift(),this[o].apply(this,e))},r.EventBinder=e.EventBinder,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.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(){var e;return this.options&&this.options.template?e=this.options.template:e=this.template,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(){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=this.mixinTemplateHelpers(e),e},render:function(){this.isClosed=!1,this.triggerMethod("before:render",this),this.triggerMethod("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.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(){this.initChildViewStorage(),r.View.prototype.constructor.apply(this,arguments),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=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.triggerMethod("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.triggerMethod.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.triggerMethod("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(){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&&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},serializeData:function(){var e={};return this.model&&(e=this.model.toJSON()),e=this.mixinTemplateHelpers(e),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.triggerMethod("render"),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();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.Region=function(e){this.options=e||{};var t=this.options.el;delete this.options.el,r.addEventBinder(this),t&&(this.el=t);if(!this.el){var n=new Error("An 'el' must be specified for a region.");throw n.name="NoElError",n}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),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||e.isClosed)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=r.extend,r.Layout=r.ItemView.extend({regionType:r.Region,constructor:function(){this.initializeRegions(),e.Marionette.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.Marionette.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.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)},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.trigger("initialize:before",e),this.initCallbacks.run(e,this),this.trigger("initialize:after",e),this.trigger("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.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,t){this.moduleName=e,this.submodules={},this._setupInitializersAndFinalizers(),this.config={},this.config.app=t,r.addEventBinder(this)},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,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=s._getModuleDefinition(o,t,e);f.config.options=s._getModuleOptions(o,r),i&&s._configureAutoStart(e,f),i&&f.config.options.hasDefinition&&f.addDefinition(f.config.options.definition,u),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){var i=e[t];return i||(i=new r.Module(t,n),e[t]=i,e.submodules[t]=i),i},_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,r=this._callbacks;this._deferred=n.Deferred(),this._callbacks=[],t.each(r,function(t){e.add(t.cb,t.ctx)})}}),r.EventAggregator=e.Wreqr.EventAggregator,r}(Backbone,_,$||window.jQuery||window.Zepto||window.ender);
Please sign in to comment.
Something went wrong with that request. Please try again.