// Backbone.BabySitter, v0.0.3.1 // Primary Copyright (c)2012 Derick Bailey, Muted Solutions, LLC. // Distributed under MIT license // http://github.com/marionettejs/backbone.babysitter // Custom version by Jeremy McLeod, Isochronous.org // http://github.com/isochronous/backbone.babysitter (function(e,t){if(typeof exports=="object"){var n=require("underscore"),r=require("backbone");module.exports=t(n,r)}else typeof define=="function"&&define.amd&&define(["underscore","backbone"],t)})(this,function(e,t){"option strict";return t.ChildViewContainer=function(e,t){var n=function(e){this.options=e||(e={}),this._views={},this._indexByModel={},this._indexByCollection={},this._indexByCustom={},this._updateLength();var n=e.initialize||this.initialize||null;t.isFunction(n)&&n.apply(this,arguments)};n.extend=e.Model.extend,t.extend(n.prototype,e.Events,{add:function(e,t){var n=e.cid;this._views[n]=e,e.model&&(this._indexByModel[e.model.cid]=n),e.collection&&(this._indexByCollection[e.collection.cid]=n),t&&(this._indexByCustom[t]=n),this._updateLength()},findByModel:function(e){var t=this._indexByModel[e.cid];return this.findByCid(t)},findByCollection:function(e){var t=this._indexByCollection[e.cid];return this.findByCid(t)},findByCustom:function(e){var t=this._indexByCustom[e];return this.findByCid(t)},findByIndex:function(e){return t.values(this._views)[e]},findByCid:function(e){return this._views[e]},remove:function(e){var t=e.cid;e.model&&delete this._indexByModel[e.model.cid],e.collection&&delete this._indexByCollection[e.collection.cid];var n;for(var r in this._indexByCustom)if(this._indexByCustom.hasOwnProperty(r)&&this._indexByCustom[r]===t){n=r;break}n&&delete this._indexByCustom[n],delete this._views[t],this._updateLength()},call:function(e,t){t=Array.prototype.slice.call(arguments,1),this.apply(e,t)},apply:function(e,n){var r;t.each(this._views,function(r,i){t.isFunction(r[e])&&r[e].apply(r,n)})},_updateLength:function(){this.length=t.size(this._views)}});var r=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck"];return t.each(r,function(e){n.prototype[e]=function(){var n=t.values(this._views),r=[n].concat(t.toArray(arguments));return t[e].apply(t,r)}}),n}(t,e),t.ChildViewContainer});