/* knockback-core-stack.js 0.19.4 Copyright (c) 2011-2014 Kevin Malakoff. License: MIT (http://www.opensource.org/licenses/mit-license.php) Source: https://github.com/kmalakoff/knockback Dependencies: Knockout.js, Backbone.js, and Underscore.js (or LoDash.js). Optional dependencies: Backbone.ModelRef.js and BackboneORM. */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?exports.kb=t(require("jquery")):e.kb=t(e.jQuery)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return e[r].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){n(1),n(2),n(3),n(4),n(5),n(6),n(7),n(8),n(9),n(10),n(11),n(12),n(13),e.exports=n(14)},function(e,t,n){var r,i,o,a,s,u,l,c,f=function(e,t){return function(){return e.apply(t,arguments)}},d=[].indexOf||function(e){for(var t=0,n=this.length;n>t;t++)if(t in this&&this[t]===e)return t;return-1};c=s=n(6),l=c._,u=c.ko,o=0,r=-1,i=1,a=["destroy","shareOptions","filters","comparator","sortAttribute","viewModelByModel","hasViewModels"],s.compare=function(e,t){return l.isString(e)?e.localeCompare(""+t):l.isString(t)?t.localeCompare(""+e):e===t?o:t>e?r:i},s.CollectionObservable=function(){function e(e,t){return this._onCollectionChange=f(this._onCollectionChange,this),s.ignore(function(n){return function(){var r,i,o;return!l.isUndefined(t)||e instanceof s.Collection?l.isArray(e)&&(e=new s.Collection(e)):(o=[new s.Collection,e],e=o[0],t=o[1]),t||(t={}),i=s.utils.wrappedObservable(n,u.observableArray([])),i.__kb_is_co=!0,n.in_edit=0,n.__kb||(n.__kb={}),t=s.utils.collapseOptions(t),t.auto_compact&&(n.auto_compact=!0),n._comparator=t.sort_attribute?u.observable(n._attributeComparator(t.sort_attribute)):u.observable(t.comparator),n._filters=t.filters?u.observableArray(l.isArray(t.filters)?t.filters:t.filters?[t.filters]:void 0):u.observableArray([]),r=n.create_options={store:s.Store.useOptionsOrCreate(t,e,i)},n.path=t.path,r.factory=s.utils.wrappedFactory(i,n._shareOrCreateFactory(t)),r.path=s.utils.pathJoin(t.path,"models"),r.creator=r.factory.creatorForPath(null,r.path),r.creator&&(n.models_only=r.creator.models_only),s.publishMethods(i,n,a),n._collection=u.observable(e),i.collection=n.collection=u.computed({read:function(){return n._collection()},write:function(e){return s.ignore(function(){var t;if((t=n._collection())!==e)return t&&t.unbind("all",n._onCollectionChange),e&&e.bind("all",n._onCollectionChange),n._collection(e)})}}),e&&e.bind("all",n._onCollectionChange),n._mapper=u.computed(function(){var e,t,r,o,a,c,f,d;if(e=n._comparator(),o=n._filters())for(f=0,d=o.length;d>f;f++)r=o[f],u.utils.unwrapObservable(r);return t=n._collection(),n.in_edit?void 0:(i=s.utils.wrappedObservable(n),t&&(a=t.models),a&&0!==t.models.length?(a=l.filter(a,function(e){return!o.length||n._selectModel(e)}),c=e?l.map(a,function(e){return n._createViewModel(e)}).sort(e):n.models_only?o.length?a:a.slice():l.map(a,function(e){return n._createViewModel(e)})):c=[],n.in_edit++,i(c),n.in_edit--)}),i.subscribe(l.bind(n._onObservableArrayChange,n)),!s.statistics||s.statistics.register("CollectionObservable",n),i}}(this))}return e.extend=s.extend,e.prototype.destroy=function(){var e,t,n;return this.__kb_released=!0,n=s.utils.wrappedObservable(this),t=s.peek(this._collection),t&&(t.unbind("all",this._onCollectionChange),e=s.peek(n),e.splice(0,e.length)),this.collection.dispose(),this._collection=n.collection=this.collection=null,this._mapper.dispose(),this._mapper=null,s.release(this._filters),this._filters=null,this._comparator(null),this._comparator=null,this.create_options=null,n.collection=null,s.utils.wrappedDestroy(this),!s.statistics||s.statistics.unregister("CollectionObservable",this)},e.prototype.shareOptions=function(){var e;return e=s.utils.wrappedObservable(this),{store:s.utils.wrappedStore(e),factory:s.utils.wrappedFactory(e)}},e.prototype.filters=function(e){return e?this._filters(l.isArray(e)?e:[e]):this._filters([])},e.prototype.comparator=function(e){return this._comparator(e)},e.prototype.sortAttribute=function(e){return this._comparator(e?this._attributeComparator(e):null)},e.prototype.viewModelByModel=function(e){var t;return this.models_only?null:(t=e.hasOwnProperty(e.idAttribute)?e.idAttribute:"cid",l.find(s.peek(s.utils.wrappedObservable(this)),function(n){var r;return(null!=n?null!=(r=n.__kb)?r.object:void 0:void 0)?n.__kb.object[t]===e[t]:!1}))},e.prototype.hasViewModels=function(){return!this.models_only},e.prototype.compact=function(){return s.ignore(function(e){return function(){var t;return t=s.utils.wrappedObservable(e),s.utils.wrappedStoreIsOwned(t)?(s.utils.wrappedStore(t).clear(),e._collection.notifySubscribers(e._collection())):void 0}}(this))},e.prototype._shareOrCreateFactory=function(e){var t,n,r,i;if(t=s.utils.pathJoin(e.path,"models"),r=e.factories,(i=e.factory)&&(n=i.creatorForPath(null,t))&&(!r||r.models===n)){if(!r)return i;if(i.hasPathMappings(r,e.path))return i}return i=new s.Factory(e.factory),r&&i.addPathMappings(r,e.path),i.creatorForPath(null,t)||(e.hasOwnProperty("models_only")?e.models_only?i.addPathMapping(t,{models_only:!0}):i.addPathMapping(t,s.ViewModel):e.view_model?i.addPathMapping(t,e.view_model):e.create?i.addPathMapping(t,{create:e.create}):i.addPathMapping(t,s.ViewModel)),i},e.prototype._onCollectionChange=function(e,t){return s.ignore(function(n){return function(){var r,i,o,a;if(!n.in_edit)switch(e){case"reset":n.auto_compact?n.compact():n._collection.notifySubscribers(n._collection());break;case"sort":case"resort":n._collection.notifySubscribers(n._collection());break;case"new":case"add":if(!n._selectModel(t))return;if(o=s.utils.wrappedObservable(n),r=n._collection(),-1===r.indexOf(t))return;if(a=n.viewModelByModel(t))return;n.in_edit++,(i=n._comparator())?(o().push(n._createViewModel(t)),o.sort(i)):o.splice(r.indexOf(t),0,n._createViewModel(t)),n.in_edit--;break;case"remove":case"destroy":n._onModelRemove(t);break;case"change":n._selectModel(t)?(a=n.models_only?t:n.viewModelByModel(t),a?(i=n._comparator())&&(o=s.utils.wrappedObservable(n),n.in_edit++,o.sort(i),n.in_edit--):n._onCollectionChange("add",t)):n._onModelRemove(t)}}}(this))},e.prototype._onModelRemove=function(e){var t,n;return(n=this.models_only?e:this.viewModelByModel(e))?(t=s.utils.wrappedObservable(this),this.in_edit++,t.remove(n),this.in_edit--):void 0},e.prototype._onObservableArrayChange=function(e){return s.ignore(function(t){return function(){var n,r,i,o,a,u,c,f,d;if(!t.in_edit&&(t.models_only&&(!e.length||s.utils.hasModelSignature(e[0]))||!t.models_only&&(!e.length||l.isObject(e[0])&&!s.utils.hasModelSignature(e[0]))||s._throwUnexpected(t,"incorrect type passed"),a=s.utils.wrappedObservable(t),n=s.peek(t._collection),r=s.peek(t._filters).length,n)){if(c=e,t.models_only)o=l.filter(e,function(e){return!r||t._selectModel(e)});else for(!r||(c=[]),o=[],f=0,d=e.length;d>f;f++){if(u=e[f],i=s.utils.wrappedObject(u),r){if(!t._selectModel(i))continue;c.push(u)}t.create_options.store.findOrReplace(i,t.create_options.creator,u),o.push(i)}t.in_edit++,e.length===c.length||a(c),l.isEqual(n.models,o)||n.reset(o),t.in_edit--}}}(this))},e.prototype._attributeComparator=function(e){var t;return t=function(t,n){var r;return r=u.utils.unwrapObservable(e),s.compare(t.get(r),n.get(r))},this.models_only?t:function(e,n){return t(s.utils.wrappedModel(e),s.utils.wrappedModel(n))}},e.prototype._createViewModel=function(e){return this.models_only?e:this.create_options.store.findOrCreate(e,this.create_options)},e.prototype._selectModel=function(e){var t,n,r,i,o;for(n=s.peek(this._filters),r=0,i=n.length;i>r;r++)if(t=n[r],t=s.peek(t),l.isFunction(t)){if(!t(e))return!1}else if(l.isArray(t)){if(o=e.id,d.call(t,o)<0)return!1}else if(e.id!==t)return!1;return!0},e}(),s.collectionObservable=function(e,t){return new s.CollectionObservable(e,t)}},function(e,t,n){var r,i,o,a,s,u,l;l=i=n(6),u=l._,a=l.ko,r={"default":null,"backbone-orm":null,"backbone-associations":n(16),"backbone-relational":n(17),supermodel:n(18)},i.orm=r["default"];for(o in r)if(s=r[o],s&&s.isAvailable()){i.orm=s;break}e.exports=function(e){var t;null==e&&(e={});for(o in e)switch(s=e[o],o){case"orm":if(u.isString(s)){if(!r.hasOwnProperty(s)){console.log("Knockback configure: could not find orm: "+s+". Available: "+u.keys(r).join(", "));continue}if((t=r[s])&&!t.isAvailable()){console.log("Knockback configure: could not enable orm "+s+". Make sure it is included before Knockback");continue}i.orm=t;continue}i.orm=s;break;default:i[o]=s}}},function(e,t,n){var r,i,o,a,s=function(e,t){return function(){return e.apply(t,arguments)}};a=r=n(6),o=a._,i=a.ko,r.EventWatcher=function(){function e(e,t,n){this._unbindCallbacks=s(this._unbindCallbacks,this),this._onModelUnloaded=s(this._onModelUnloaded,this),this._onModelLoaded=s(this._onModelLoaded,this),this.__kb||(this.__kb={}),this.__kb.callbacks={},this.ee=null,n&&this.registerCallbacks(t,n),e&&this.emitter(e)}return e.useOptionsOrCreate=function(e,t,n,i){return e.event_watcher?(e.event_watcher.emitter()!==t&&e.event_watcher.model_ref!==t&&r._throwUnexpected(this,"emitter not matching"),r.utils.wrappedEventWatcher(n,e.event_watcher).registerCallbacks(n,i)):(r.utils.wrappedEventWatcherIsOwned(n,!0),r.utils.wrappedEventWatcher(n,new r.EventWatcher(t)).registerCallbacks(n,i))},e.prototype.destroy=function(){return this.emitter(null),this.__kb.callbacks=null,r.utils.wrappedDestroy(this)},e.prototype.emitter=function(e){return 0===arguments.length||this.ee===e?this.ee:(this.model_ref&&(this.model_ref.unbind("loaded",this._onModelLoaded),this.model_ref.unbind("unloaded",this._onModelUnloaded),this.model_ref.release(),this.model_ref=null),r.Backbone&&r.Backbone.ModelRef&&e instanceof r.Backbone.ModelRef?(this.model_ref=e,this.model_ref.retain(),this.model_ref.bind("loaded",this._onModelLoaded),this.model_ref.bind("unloaded",this._onModelUnloaded),e=this.model_ref.model()||null):delete this.model_ref,this.ee!==e&&(e?this._onModelLoaded(e):this._onModelUnloaded(this.ee)),e)},e.prototype.registerCallbacks=function(e,t){var n,a,s,u,l,c;for(e||r._throwMissing(this,"obj"),t||r._throwMissing(this,"callback_info"),a=t.event_selector?t.event_selector.split(" "):["change"],s=this.ee,u=function(n){return function(a){var u,l;return(u=n.__kb.callbacks[a])||(u=n.__kb.callbacks[a]={model:null,list:[],fn:function(e){var t,n,o,s;for(s=u.list,n=0,o=s.length;o>n;n++)t=s[n],t.update&&(e&&t.key&&e.hasChanged&&!e.hasChanged(i.utils.unwrapObservable(t.key))||(!r.statistics||r.statistics.addModelEvent({name:a,model:e,key:t.key,path:t.path}),t.update()));return null}}),u.list.push(l=o.defaults({obj:e},t)),s?n._onModelLoaded(s):void 0}}(this),l=0,c=a.length;c>l;l++)n=a[l],n&&u(n);return this},e.prototype.releaseCallbacks=function(e){var t,n,i;this.ee=null,i=this.__kb.callbacks;for(n in i)t=i[n],this._unbindCallbacks(n,t,r.wasReleased(e));return delete this.__kb.callbacks},e.prototype._onModelLoaded=function(e){var t,n,i,o,a,s,u,l;this.ee=e,s=this.__kb.callbacks;for(n in s)for(t=s[n],t.model&&t.model!==e&&this._unbindCallbacks(n,t,!0),t.model||(t.model=e,e.bind(n,t.fn)),u=t.list,o=0,a=u.length;a>o;o++)i=u[o],i.unbind_fn||(i.unbind_fn=null!=(l=r.orm)?l.bind(e,i.key,i.update,i.path):void 0),i.emitter&&i.emitter(e)},e.prototype._onModelUnloaded=function(e){var t,n,r;if(this.ee===e){this.ee=null,r=this.__kb.callbacks;for(n in r)t=r[n],this._unbindCallbacks(n,t)}},e.prototype._unbindCallbacks=function(e,t,n){var i,o,a,s;for(t.model&&(t.model.unbind(e,t.fn),t.model=null),s=t.list,o=0,a=s.length;a>o;o++)i=s[o],i.unbind_fn&&(i.unbind_fn(),i.unbind_fn=null),!i.emitter||n||r.wasReleased(i.obj)||i.emitter(null)},e}(),r.emitterObservable=function(e,t){return new r.EventWatcher(e,t)}},function(e,t,n){var r,i;i=(r=n(6))._,r.Factory=function(){function e(e){this.parent_factory=e,this.paths={}}return e.useOptionsOrCreate=function(e,t,n){var i;return e.factory&&(!e.factories||e.factories&&e.factory.hasPathMappings(e.factories,n))?r.utils.wrappedFactory(t,e.factory):(i=r.utils.wrappedFactory(t,new r.Factory(e.factory)),e.factories&&i.addPathMappings(e.factories,n),i)},e.prototype.hasPath=function(e){return this.paths.hasOwnProperty(e)||this.parent_factory&&this.parent_factory.hasPath(e)},e.prototype.addPathMapping=function(e,t){return this.paths[e]=t},e.prototype.addPathMappings=function(e,t){var n,i;for(i in e)n=e[i],this.paths[r.utils.pathJoin(t,i)]=n},e.prototype.hasPathMappings=function(e,t){var n,i,o,a;n=!0;for(a in e)i=e[a],n&=(o=this.creatorForPath(null,r.utils.pathJoin(t,a)))&&i===o;return n},e.prototype.creatorForPath=function(e,t){var n;return(n=this.paths[t])?n.view_model?n.view_model:n:this.parent_factory&&(n=this.parent_factory.creatorForPath(e,t))?n:null},e}()},function(e,t,n){(function(e){var t,r,i,o,a,s,u,l;a=null!=a?a:e,l=r=n(6),s=l._,i=l.ko,t=l.$,r.RECUSIVE_AUTO_INJECT=!0,i.bindingHandlers.inject={init:function(e,t,n,o){return r.Inject.inject(i.utils.unwrapObservable(t()),o,e,t,n)}},r.Inject=function(){function e(){}return e.inject=function(e,t,n,i,o,a){var u;return u=function(e){var u,l,c;if(s.isFunction(e))t=new e(t,n,i,o),r.releaseOnNodeRemove(t,n);else{e.view_model&&(t=new e.view_model(t,n,i,o),r.releaseOnNodeRemove(t,n));for(u in e)c=e[u],"view_model"!==u&&("create"===u?c(t,n,i,o):s.isObject(c)&&!s.isFunction(c)?(l=a||c&&c.create?{}:t,t[u]=r.Inject.inject(c,l,n,i,o,!0)):t[u]=c)}return t},a?u(e):r.ignore(function(){return u(e)})},e.injectViewModels=function(e){var t,n,i,o,u,l,c,f,d,p;for(f=[],l=function(e){var t,n,r,i,o;for(e.__kb_injected||e.attributes&&(t=s.find(e.attributes,function(e){return"kb-inject"===e.name}))&&(e.__kb_injected=!0,f.push({el:e,view_model:{},binding:t.value})),o=e.childNodes,r=0,i=o.length;i>r;r++)n=o[r],l(n)},!e&&(null!=a?a.document:void 0)&&(e=a.document),l(e),d=0,p=f.length;p>d;d++)n=f[d],(u=n.binding)&&(u.search(/[:]/)<0||(u="{"+u+"}"),o=new Function("","return ( "+u+" )")(),o||(o={}),!o.options||(c=o.options,delete o.options),c||(c={}),n.view_model=r.Inject.inject(o,n.view_model,n.el,null,null,!0),t=n.view_model.afterBinding||c.afterBinding,i=n.view_model.beforeBinding||c.beforeBinding),i&&i(n.view_model,n.el,c),r.applyBindings(n.view_model,n.el,c),t&&t(n.view_model,n.el,c);return f},e}(),u=i.applyBindings,i.applyBindings=function(e,t){var n;return n=r.RECUSIVE_AUTO_INJECT?r.injectViewModels(t):[],n.length?void 0:u.apply(this,arguments)},r.injectViewModels=r.Inject.injectViewModels,"undefined"!=typeof document&&null!==document&&(t?t(function(){return r.injectViewModels()}):(o=function(){return"complete"!==document.readyState?setTimeout(o,0):r.injectViewModels()})())}).call(t,function(){return this}())},function(e,t,n){(function(t){var r,i,o,a,s,u;s=null!=s?s:t,a=n(21),i=function(e,t){var n,r;for(n in t)r=t[n],e[n]=r;return e};var l=function(){},c=function(e,t,n){var r;return r=t&&t.hasOwnProperty("constructor")?t.constructor:function(){e.apply(this,arguments)},i(r,e),l.prototype=e.prototype,r.prototype=new l,t&&i(r.prototype,t),n&&i(r,n),r.prototype.constructor=r,r.__super__=e.prototype,r},f=function(e,t){var n=c(this,e,t);return n.extend=this.extend,n};e.exports=o=function(){function e(){}var t;return e.VERSION="0.19.4",e.TYPE_UNKNOWN=0,e.TYPE_SIMPLE=1,e.TYPE_ARRAY=2,e.TYPE_MODEL=3,e.TYPE_COLLECTION=4,e.wasReleased=function(e){return!e||e.__kb_released},e.isReleaseable=function(t,n){var r,i;if(null==n&&(n=0),!t||t!==Object(t)||t.__kb_released)return!1;if(a.isObservable(t)||t instanceof e.ViewModel)return!0;if("function"==typeof t||e.isModel(t)||e.isCollection(t))return!1;if("function"==typeof t.dispose||"function"==typeof t.destroy||"function"==typeof t.release)return!0;if(1>n)for(r in t)if(i=t[r],"__kb"!==r&&e.isReleaseable(i,n+1))return!0;return!1},e.release=function(t){var n,r,i;if(e.isReleaseable(t))if(u.isArray(t))for(r in t)i=t[r],e.isReleaseable(i)&&(t[r]=null,e.release(i));else{if(t.__kb_released=!0,a.isObservable(t)&&u.isArray(n=e.peek(t))){if(t.__kb_is_co||t.__kb_is_o&&t.valueType()===e.TYPE_COLLECTION)return t.destroy();for(r in n)i=n[r],e.isReleaseable(i)&&(n[r]=null,e.release(i));return"function"==typeof t.dispose&&t.dispose(),void 0}"function"==typeof t.release?t.release():"function"==typeof t.destroy?t.destroy():"function"==typeof t.dispose?t.dispose():a.isObservable(t)||this.releaseKeys(t)}},e.releaseKeys=function(t){var n,r;for(n in t)r=t[n],"__kb"!==n&&e.isReleaseable(r)&&(t[n]=null,e.release(r))},e.releaseOnNodeRemove=function(t,n){return t||e._throwUnexpected(this,"missing view model"),n||e._throwUnexpected(this,"missing node"),a.utils.domNodeDisposal.addDisposeCallback(n,function(){return e.release(t)})},e.renderTemplate=function(t,n,r){var i,o,u;return null==r&&(r={}),(i=null!=s?s.document:void 0)?(o=i.createElement("div"),u=a.renderTemplate(t,n,r,o,"replaceChildren"),1===o.childNodes.length&&(o=o.childNodes[0]),e.releaseOnNodeRemove(n,o),u.dispose(),n.afterRender&&!r.afterRender&&n.afterRender(o),o):"undefined"!=typeof console&&null!==console?console.log("renderTemplate: document is undefined"):void 0},e.applyBindings=function(t,n){return a.applyBindings(t,n),e.releaseOnNodeRemove(t,n)},e.getValue=function(t,n,r){var i;if(t)return u.isFunction(t[n])&&(null!=(i=e.orm)?i.useFunction(t,n):void 0)?t[n]():r?t.get.apply(t,u.map([n].concat(r),function(t){return e.peek(t)})):t.get(n)},e.setValue=function(t,n,r){var i,o;if(t)return u.isFunction(t[n])&&(null!=(o=e.orm)?o.useFunction(t,n):void 0)?t[n](r):((i={})[n]=r,t.set(i))},e.ignore=(null!=(t=a.dependencyDetection)?t.ignore:void 0)||function(e,t,n){var r;return r=null,a.computed(function(){return r=e.apply(t,n||[])}).dispose(),r},e.extend=f,e._throwMissing=function(e,t){throw""+(u.isString(e)?e:e.constructor.name)+": "+t+" is missing"},e._throwUnexpected=function(e,t){throw""+(u.isString(e)?e:e.constructor.name)+": "+t+" is unexpected"},e.publishMethods=function(t,n,r){var i,o,a;for(o=0,a=r.length;a>o;o++)i=r[o],t[i]=e._.bind(n[i],n)},e.peek=function(t){return a.isObservable(t)?t.peek?t.peek():e.ignore(function(){return t()}):t},e.isModel=function(t){return t&&(t instanceof e.Model||"function"==typeof t.get&&"function"==typeof t.bind)},e.isCollection=function(t){return t&&t instanceof e.Collection},e}(),s.Parse?(r=o.Parse=s.Parse,u=o._=s.Parse._):(r=o.Backbone=n(19),u=o._=n(20)),o.ko=a,o.Collection=r.Collection,o.Model=r.Object||r.Model,o.Events=r.Events,o.$=s.jQuery||s.$;try{o.$||(o.$=n(15))}catch(d){}}).call(t,function(){return this}())},function(e,t,n){var r,i,o,a,s;i=(r=n(6)).ko,(null!=(a=i.subscribable)?null!=(s=a.fn)?s.extend:void 0:void 0)&&(o=i.subscribable.fn.extend,i.subscribable.fn.extend=function(){var e,t;return e=o.apply(this,arguments),e!==this&&r.isReleaseable(this)&&(t=e.dispose,e.dispose=function(n){return function(){return null!=t&&t.apply(e,arguments),r.release(n)}}(this)),e})},function(e,t,n){var r,i,o,a,s,u,l;l=a=n(6),u=l._,s=l.ko,o=n(11),i=["value","valueType","destroy"],r=["args","read","write"],a.Observable=function(){function e(e,t,n,l){return this._vm=null!=l?l:{},a.ignore(function(l){return function(){var c,f,d,p,h,m;for(t||a._throwMissing(l,"key_or_info"),l.key=t.key||t,h=0,m=r.length;m>h;h++)d=r[h],t[d]&&(l[d]=t[d]);return c=a.utils.collapseOptions(n),f=c.event_watcher,delete c.event_watcher,l._value=new o(c),l._model=s.observable(),p=a.utils.wrappedObservable(l,s.computed({read:function(){var e,t,n,r,i,o,c;for(i=l._model(),o=t=[l.key].concat(l.args||[]),n=0,r=o.length;r>n;n++)e=o[n],s.utils.unwrapObservable(e);return null!=(c=a.utils.wrappedEventWatcher(l))&&c.emitter(i||null),l.read?l.update(l.read.apply(l._vm,t)):u.isUndefined(i)||a.ignore(function(){return l.update(a.getValue(i,a.peek(l.key),l.args))}),l._value.value()},write:function(e){return a.ignore(function(){var t,n;return t=a.utils.unwrapModels(e),n=a.peek(l._model),l.write?(l.write.call(l._vm,t),e=a.getValue(n,a.peek(l.key),l.args)):n&&a.setValue(n,a.peek(l.key),t),l.update(e)})},owner:l._vm})),p.__kb_is_o=!0,c.store=a.utils.wrappedStore(p,c.store),c.path=a.utils.pathJoin(c.path,l.key),c.factories&&("function"==typeof c.factories||c.factories.create)?(c.factory=a.utils.wrappedFactory(p,new a.Factory(c.factory)),c.factory.addPathMapping(c.path,c.factories)):c.factory=a.Factory.useOptionsOrCreate(c,p,c.path),delete c.factories,a.publishMethods(p,l,i),p.model=l.model=s.computed({read:function(){return s.utils.unwrapObservable(l._model)},write:function(e){return a.ignore(function(){var t;if(!l.__kb_released&&a.peek(l._model)!==e)return t=a.getValue(e,a.peek(l.key),l.args),l._model(e),e?u.isUndefined(t)?void 0:l.update(t):l.update(null)})}}),a.EventWatcher.useOptionsOrCreate({event_watcher:f},e||null,l,{emitter:l.model,update:function(){return a.ignore(function(){return l.update()})},key:l.key,path:c.path}),l._value.rawValue()||l._value.update(),a.LocalizedObservable&&t.localizer&&(p=new t.localizer(p)),a.DefaultObservable&&t.hasOwnProperty("default")&&(p=a.defaultObservable(p,t["default"])),p}}(this))}return e.prototype.destroy=function(){var e;return e=a.utils.wrappedObservable(this),this.__kb_released=!0,this._value.destroy(),this._value=null,this.model.dispose(),this.model=e.model=null,a.utils.wrappedDestroy(this)},e.prototype.value=function(){return this._value.rawValue()},e.prototype.valueType=function(){return this._value.valueType(a.peek(this._model),a.peek(this.key))},e.prototype.update=function(e){return this.__kb_released?void 0:(arguments.length||(e=a.getValue(a.peek(this._model),a.peek(this.key))),this._value.update(e))},e}(),a.observable=function(e,t,n,r){return new a.Observable(e,t,n,r)}},function(e,t,n){var r,i;i=(r=n(6))._,e.exports=r.Statistics=function(){function e(){this.model_events_tracker=[],this.registered_tracker={}}return e.prototype.clear=function(){return this.model_events_tracker=[]},e.prototype.addModelEvent=function(e){return this.model_events_tracker.push(e)},e.prototype.modelEventsStatsString=function(){var e,t,n,r;n="",n+="Total Count: "+this.model_events_tracker.length,e=i.groupBy(this.model_events_tracker,function(e){return"event name: '"+e.name+"', attribute name: '"+e.key+"'"});for(t in e)r=e[t],n+="\n "+t+", count: "+r.length;return n},e.prototype.register=function(e,t){return this.registeredTracker(e).push(t)},e.prototype.unregister=function(e,t){var n,r;return r=this.registeredTracker(e),n=i.indexOf(r,t),0>n&&"undefined"!=typeof console&&null!==console&&console.log("kb.Statistics: failed to unregister type: "+e),r.splice(n,1)},e.prototype.registeredCount=function(e){var t,n,r;if(e)return this.registeredTracker(e).length;t=0,r=this.registered_tracker[e];for(e in r)n=r[e],t+=n.length;return t},e.prototype.registeredStatsString=function(e){var t,n,r,i,o;t="",o=this.registered_tracker;for(n in o)r=o[n],r.length&&(i&&(t+="\n "),t+=""+(n?n:"No Name")+": "+r.length,i=!0);return t?t:e},e.prototype.registeredTracker=function(e){var t;return this.registered_tracker.hasOwnProperty(e)?this.registered_tracker[e]:(t=[],this.registered_tracker[e]=t,t)},e.eventsStats=function(e,t){var n,r,o,a,s,u,l;for(o={count:0},n=e._events||e._callbacks||{},l=t?[t]:i.keys(n),s=0,u=l.length;u>s;s++)if(t=l[s],r=n[t]){if(i.isArray(r))o[t]=i.compact(r).length;else for(o[t]=0,a=r.tail;(r=r.next)!==a;)o[t]++;o.count+=o[t]}return o},e}()},function(e,t,n){var r,i,o,a;a=r=n(6),o=a._,i=a.ko,e.exports=r.Store=function(){function e(){this.observable_records=[],this.replaced_observables=[]}return e.useOptionsOrCreate=function(e,t,n){return e.store?(e.store.register(t,n,e),r.utils.wrappedStore(n,e.store)):(r.utils.wrappedStoreIsOwned(n,!0),r.utils.wrappedStore(n,new r.Store))},e.prototype.destroy=function(){return this.clear()},e.prototype.clear=function(){var e,t,n,i,o,a,s;for(a=[this.observable_records,[]],e=a[0],this.observable_records=a[1],i=0,o=e.length;o>i;i++)t=e[i],r.release(t.observable);s=[this.replaced_observables,[]],n=s[0],this.replaced_observables=s[1],r.release(n)},e.prototype.compact=function(){var e,t,n,r,i,a;for(t=[],i=this.observable_records,n=0,r=i.length;r>n;n++)e=i[n],(null!=(a=e.observable)?a.__kb_released:void 0)&&t.push(e);t.length&&(this.observable_records=o.difference(this.observable_records,t))},e.prototype.register=function(e,t,n){var o;if(t&&!i.isObservable(t)&&!t.__kb_is_co)return r.utils.wrappedObject(t,e),e||(t.__kb_null=!0),o=n.creator?n.creator:n.path&&n.factory?n.factory.creatorForPath(e,n.path):null,o||(o=t.constructor),this.observable_records.push({obj:e,observable:t,creator:o}),t},e.prototype.findIndex=function(e,t){var n,i,a,s;if(a=[],!e||r.isModel(e)){s=this.observable_records;for(n in s)if(i=s[n],i.observable)if(i.observable.__kb_released)a.push(i);else if((e||i.observable.__kb_null)&&(!e||!i.observable.__kb_null&&i.obj===e)&&(i.creator===t||i.creator.create&&i.creator.create===t.create))return a.length?(this.observable_records=o.difference(this.observable_records,a),o.indexOf(this.observable_records,i)):n}return a.length&&(this.observable_records=o.difference(this.observable_records,a)),-1},e.prototype.find=function(e,t){var n;return(n=this.findIndex(e,t))<0?null:this.observable_records[n].observable},e.prototype.isRegistered=function(e){var t,n,r,i;for(i=this.observable_records,n=0,r=i.length;r>n;n++)if(t=i[n],t.observable===e)return!0;return!1},e.prototype.findOrCreate=function(e,t){var n,o;return t.store=this,t.creator||(t.creator=r.utils.inferCreator(e,t.factory,t.path)),!t.creator&&r.isModel(e)&&(t.creator=r.ViewModel),(n=t.creator)?n.models_only?e:(n&&(o=this.find(e,n)),o?o:(o=r.ignore(function(){return function(){return o=n.create?n.create(e,t):new n(e,t),o||i.observable(null)}}(this)),i.isObservable(o)||this.isRegistered(o)||this.register(e,o,t),o)):r.utils.createFromDefaultCreator(e,t)},e.prototype.findOrReplace=function(e,t,n){var i,o;return e||r._throwUnexpected(this,"obj missing"),(i=this.findIndex(e,t))<0?this.register(e,n,{creator:t}):(o=this.observable_records[i],r.utils.wrappedObject(o.observable)===e||r._throwUnexpected(this,"different object"),o.observable!==n&&(o.observable.constructor===n.constructor||r._throwUnexpected(this,"replacing different type"),this.replaced_observables.push(o.observable),o.observable=n),n)},e}()},function(e,t,n){var r,i,o,a,s;s=i=n(6),a=s._,o=s.ko,e.exports=r=function(){function e(e){this.create_options=e,this._vo=o.observable(null)}return e.prototype.destroy=function(){return this.__kb_released=!0,i.release(this.__kb_value),this.__kb_value=null},e.prototype.value=function(){return o.utils.unwrapObservable(this._vo())},e.prototype.rawValue=function(){return this.__kb_value},e.prototype.valueType=function(e,t){var n;return n=i.getValue(e,t),this.value_type||this._updateValueObservable(n),this.value_type},e.prototype.update=function(e){var t,n;if(!this.__kb_released){switch(void 0!==e||(e=null),t=i.utils.valueType(e),(!this.__kb_value||this.__kb_value.__kb_released||this.__kb_value.__kb_null&&e)&&(this.__kb_value=void 0,this.value_type=void 0),n=this.__kb_value,this.value_type){case i.TYPE_COLLECTION:if(this.value_type===i.TYPE_COLLECTION&&t===i.TYPE_ARRAY)return n(e);if((t===i.TYPE_COLLECTION||a.isNull(e))&&(e&&!i.isCollection(e)&&a.isFunction(e.collection)&&(e=i.peek(e.collection)),a.isFunction(n.collection)))return i.peek(n.collection)!==e&&n.collection(e),void 0;break;case i.TYPE_MODEL:if(t===i.TYPE_MODEL||a.isNull(e))return e&&!i.isModel(e)&&(e=a.isFunction(e.model)?i.peek(e.model):i.utils.wrappedObject(e)),a.isFunction(n.model)?i.peek(n.model)!==e&&n.model(e):i.utils.wrappedObject(n)!==e&&this._updateValueObservable(e),void 0}if(this.value_type!==t||a.isUndefined(this.value_type)){if(i.peek(n)!==e)return this._updateValueObservable(e)}else if(i.peek(n)!==e)return n(e)}},e.prototype._updateValueObservable=function(e){var t,n,r,s;return t=this.create_options,n=t.creator=i.utils.inferCreator(e,t.factory,t.path),this.value_type=i.TYPE_UNKNOWN,r=this.__kb_value,this.__kb_value=void 0,r&&i.release(r),n?t.store?s=t.store.findOrCreate(e,t):n.models_only?(s=e,this.value_type=i.TYPE_SIMPLE):s=n.create?n.create(e,t):new n(e,t):a.isArray(e)?(this.value_type=i.TYPE_ARRAY,s=o.observableArray(e)):(this.value_type=i.TYPE_SIMPLE,s=o.observable(e)),this.value_type===i.TYPE_UNKNOWN&&(o.isObservable(s)?this.value_type=s.__kb_is_co?i.TYPE_COLLECTION:i.TYPE_SIMPLE:(this.value_type=i.TYPE_MODEL,"function"!=typeof s.model&&i.utils.wrappedObject(s,e))),this.__kb_value=s,this._vo(s)},e}()},function(e,t,n){var r,i,o,a,s,u,l,c,f;c=r=n(6),o=c._,i=c.ko,f=r._wrappedKey=function(e,t,n){return 2===arguments.length?e&&e.__kb&&e.__kb.hasOwnProperty(t)?e.__kb[t]:void 0:(e||r._throwUnexpected(this,"no obj for wrapping "+t),e.__kb||(e.__kb={}),e.__kb[t]=n,n)},a=function(e,t){return Array.prototype.splice.call(e,1,0,t),e},u=function(e,t,n){return e[t]||(e[t]=[]),o.isArray(n)||(n=[n]),e[t]=e[t].length?o.union(e[t],n):n,e},l=function(e,t,n){return e[t]||(e[t]={}),o.extend(e[t],n)},s=function(e){var t,n,r,i;for(n={},r=0,i=e.length;i>r;r++)t=e[r],n[t]={key:t};return n},r.utils=function(){function e(){}return e.wrappedObservable=function(){return f.apply(this,a(arguments,"observable"))},e.wrappedObject=function(){return f.apply(this,a(arguments,"object"))},e.wrappedModel=function(e,t){return 1===arguments.length?(t=f(e,"object"),o.isUndefined(t)?e:t):f(e,"object",t)},e.wrappedStore=function(){return f.apply(this,a(arguments,"store"))},e.wrappedStoreIsOwned=function(){return f.apply(this,a(arguments,"store_is_owned"))},e.wrappedFactory=function(){return f.apply(this,a(arguments,"factory"))},e.wrappedEventWatcher=function(){return f.apply(this,a(arguments,"event_watcher"))},e.wrappedEventWatcherIsOwned=function(){return f.apply(this,a(arguments,"event_watcher_is_owned"))},e.wrappedDestroy=function(e){var t;if(e.__kb)return e.__kb.event_watcher&&e.__kb.event_watcher.releaseCallbacks(e),t=e.__kb,e.__kb=null,t.observable&&(t.observable.destroy=t.observable.release=null,this.wrappedDestroy(t.observable),t.observable=null),t.factory=null,t.event_watcher_is_owned&&t.event_watcher.destroy(),t.event_watcher=null,t.store_is_owned&&t.store.destroy(),t.store=null},e.valueType=function(e){return e?e.__kb_is_o?e.valueType():e.__kb_is_co||e instanceof r.Collection?r.TYPE_COLLECTION:e instanceof r.ViewModel||e instanceof r.Model?r.TYPE_MODEL:o.isArray(e)?r.TYPE_ARRAY:r.TYPE_SIMPLE:r.TYPE_UNKNOWN},e.pathJoin=function(e,t){return(e?"."!==e[e.length-1]?""+e+".":e:"")+t},e.optionsPathJoin=function(e,t){return o.defaults({path:this.pathJoin(e.path,t)},e)},e.inferCreator=function(e,t,n){var i;return t&&(i=t.creatorForPath(e,n))?i:e?e instanceof r.Model?r.ViewModel:e instanceof r.Collection?r.CollectionObservable:null:null},e.createFromDefaultCreator=function(e,t){return r.isModel(e)?r.viewModel(e,t):r.isCollection(e)?r.collectionObservable(e,t):o.isArray(e)?i.observableArray(e):i.observable(e)},e.hasModelSignature=function(e){return e&&e.attributes&&!e.models&&"function"==typeof e.get&&"function"==typeof e.trigger},e.hasCollectionSignature=function(e){return e&&e.models&&"function"==typeof e.get&&"function"==typeof e.trigger},e.collapseOptions=function(e){var t,n,r,i;for(n={},e={options:e};e.options;){i=e.options;for(t in i)switch(r=i[t],t){case"internals":case"requires":case"excludes":case"statics":u(n,t,r);break;case"keys":o.isObject(r)&&!o.isArray(r)||o.isObject(n[t])&&!o.isArray(n[t])?(o.isObject(r)||(r=[r]),o.isArray(r)&&(r=s(r)),o.isArray(n[t])&&(n[t]=s(n[t])),l(n,t,r)):u(n,t,r);break;case"factories":o.isFunction(r)?n[t]=r:l(n,t,r);break;case"static_defaults":l(n,t,r);break;case"options":break;default:n[t]=r}e=e.options}return n},e.unwrapModels=function(e){var t,n,i;if(!e)return e;if(e.__kb)return"object"in e.__kb?e.__kb.object:e;if(o.isArray(e))return o.map(e,function(e){return r.utils.unwrapModels(e)});if(o.isObject(e)&&e.constructor==={}.constructor){n={};for(t in e)i=e[t],n[t]=r.utils.unwrapModels(i);return n}return e},e}()},function(e,t,n){var r,i,o,a,s,u,l,c,f;f=u=n(6),c=f._,l=f.ko,a=function(){return function(e){return{store:u.utils.wrappedStore(e),factory:u.utils.wrappedFactory(e),path:e.__kb.path,event_watcher:u.utils.wrappedEventWatcher(e)}}}(this),i=function(e,t){var n;return n=e.__kb.internals&&c.contains(e.__kb.internals,t)?"_"+t:t,e.__kb.view_model.hasOwnProperty(n)?void 0:(e.__kb.view_model[n]=null,n) },o=function(e,t,n,r){var o;if(!(e.__kb.excludes&&c.contains(e.__kb.excludes,n)||e.__kb.statics&&c.contains(e.__kb.statics,n)||!(o=i(e,n))))return e[o]=e.__kb.view_model[o]=u.observable(t,n,r,e)},s=function(e,t){var n,r,o,a,s;for(s=e.__kb.statics,o=0,a=s.length;a>o;o++)n=s[o],(r=i(e,n))&&(t.has(r)?e[r]=e.__kb.view_model[r]=t.get(r):e.__kb.static_defaults&&r in e.__kb.static_defaults?e[r]=e.__kb.view_model[r]=e.__kb.static_defaults[r]:delete e.__kb.view_model[r])},r=["keys","internals","excludes","statics","static_defaults"],u.ViewModel=function(){function e(e,t,n){return null==t&&(t={}),u.ignore(function(i){return function(){var o,f,d,p,h,m;for(!e||e instanceof u.Model||"function"==typeof e.get&&"function"==typeof e.bind||u._throwUnexpected(i,"not a model"),t=c.isArray(t)?{keys:t}:u.utils.collapseOptions(t),i.__kb||(i.__kb={}),i.__kb.view_model=n||i,p=0,h=r.length;h>p;p++)d=r[p],t.hasOwnProperty(d)&&(i.__kb[d]=t[d]);return u.Store.useOptionsOrCreate(t,e,i),i.__kb.path=t.path,u.Factory.useOptionsOrCreate(t,i,t.path),m=u._wrappedKey(i,"_model",l.observable()),i.model=l.computed({read:function(){return l.utils.unwrapObservable(m)},write:function(e){return u.ignore(function(){return u.utils.wrappedObject(i)!==e&&!u.wasReleased(i)&&f?i.__kb_null?(!e||u._throwUnexpected(i,"model set on shared null"),void 0):(f.emitter(e),u.utils.wrappedObject(i,f.ee),m(f.ee),!f.ee||i.createObservables(f.ee)):void 0})}}),f=u.utils.wrappedEventWatcher(i,new u.EventWatcher(e,i,{emitter:i._model,update:function(){return u.ignore(function(){return!(null!=f?f.ee:void 0)||i.createObservables(null!=f?f.ee:void 0)})}})),u.utils.wrappedObject(i,e=f.ee),m(f.ee),o=a(i),!t.requires||i.createObservables(e,t.requires,o),!i.__kb.internals||i.createObservables(e,i.__kb.internals,o),!t.mappings||i.createObservables(e,t.mappings,o),!i.__kb.statics||s(i,e),i.createObservables(e,i.__kb.keys,o),!u.statistics||u.statistics.register("ViewModel",i),i}}(this))}return e.extend=u.extend,e.prototype.destroy=function(){var e;if(this.__kb_released=!0,this.__kb.view_model!==this)for(e in this.__kb.vm_keys)this.__kb.view_model[e]=null;return this.__kb.view_model=null,u.releaseKeys(this),u.utils.wrappedDestroy(this),!u.statistics||u.statistics.unregister("ViewModel",this)},e.prototype.shareOptions=function(){return{store:u.utils.wrappedStore(this),factory:u.utils.wrappedFactory(this)}},e.prototype.createObservables=function(e,t,n){var r,s,l,f,d,p,h,m,v;if(n||(n=a(this)),t)if(c.isArray(t))for(p=0,m=t.length;m>p;p++)r=t[p],o(this,e,r,n);else for(r in t)s=t[r],(f=i(this,r))&&(c.isString(s)||s.key||(s.key=f),this[f]=this.__kb.view_model[f]=u.observable(e,s,n,this));else{if(this.__kb.keys||!e)return;for(r in e.attributes)o(this,e,r,n);if(l=null!=(v=u.orm)?"function"==typeof v.keys?v.keys(e):void 0:void 0)for(d=0,h=l.length;h>d;d++)r=l[d],o(this,e,r,n)}},e}(),u.viewModel=function(e,t,n){return new u.ViewModel(e,t,n)}},function(e,t,n){var r,i,o,a,s;if(e.exports=r=n(6),r.configure=n(2),r.modules={underscore:r._,backbone:r.Parse||r.Backbone,knockout:r.ko},"undefined"!=typeof window&&null!==window)for(s=["_","Backbone","Parse","ko","$"],o=0,a=s.length;a>o;o++)i=s[o],r[i]&&!window.hasOwnProperty(i)&&(window[i]=r[i])},function(t){t.exports=e},function(e,t,n){var r,i,o,a,s,u;u=a=n(6),s=u._,i=u.Backbone,r=null,e.exports=o=function(){function e(){}return e.isAvailable=function(){return!!(r=null!=i?i.AssociatedModel:void 0)},e.keys=function(e){return e instanceof r?s.map(e.relations,function(e){return e.key}):null},e.relationType=function(e,t){var n;return e instanceof r?(n=s.find(e.relations,function(e){return e.key===t}))?"Many"===n.type?a.TYPE_COLLECTION:a.TYPE_MODEL:null:null},e}()},function(e,t,n){var r,i,o,a,s,u;u=a=n(6),s=u._,r=u.Backbone,o=null,e.exports=i=function(){function e(){}return e.isAvailable=function(){return!!(o=null!=r?r.RelationalModel:void 0)},e.relationType=function(e,t){var n;return e instanceof o?(n=s.find(e.getRelations(),function(e){return e.key===t}))?n.collectionType||s.isArray(n.keyContents)?a.TYPE_COLLECTION:a.TYPE_MODEL:null:null},e.bind=function(e,t,n,r){var i,o,s,u,l,c;if(!(u=this.relationType(e,t)))return null;if(s=function(e){return!a.statistics||a.statistics.addModelEvent({name:"update (relational)",model:e,key:t,path:r}),n()},o=a.Backbone.Relation.prototype.sanitizeOptions?["update","add","remove"]:["change","add","remove"],u===a.TYPE_COLLECTION)for(l=0,c=o.length;c>l;l++)i=o[l],e.bind(""+i+":"+t,s);else e.bind(""+o[0]+":"+t,s);return function(){var n,r;if(u===a.TYPE_COLLECTION)for(n=0,r=o.length;r>n;n++)i=o[n],e.unbind(""+i+":"+t,s);else e.unbind(""+o[0]+":"+t,s)}},e}()},function(e,t,n){(function(t){var r,i,o,a;o="undefined"!=typeof window&&null!==window?window:t,a=(i=n(6))._,r=null,e.exports=r=function(){function e(){}return e.isAvailable=function(){return!!(e=o.Supermodel)},e.keys=function(t){return t instanceof e.Model?a.keys(t.constructor.associations()):null},e.relationType=function(t,n){var r;return t instanceof e.Model?(r=t.constructor.associations()[n])?r.add?i.TYPE_COLLECTION:i.TYPE_MODEL:null:null},e.bind=function(e,t,n,r){var o,a;return(a=this.relationType(e,t))?(o=function(e,o){var a,s;return!i.statistics||i.statistics.addModelEvent({name:"update (supermodel)",model:e,key:t,path:r}),s=e.constructor.associations()[t],a=e[s.store],e[s.store]=o,n(o),e[s.store]=a},a===i.TYPE_MODEL?(e.bind("associate:"+t,o),function(){return e.unbind("associate:"+t,o)}):void 0):null},e.useFunction=function(e,t){return!!this.relationType(e,t)},e}()}).call(t,function(){return this}())},function(e,t,n){var r,i;!function(o,a){r=[n(20),n(15),t],i=function(e,t,n){o.Backbone=a(o,n,e,t)}.apply(t,r),!(void 0!==i&&(e.exports=i))}(this,function(e,t,n,r){{var i=e.Backbone,o=[],a=(o.push,o.slice);o.splice}t.VERSION="1.1.2",t.$=r,t.noConflict=function(){return e.Backbone=i,this},t.emulateHTTP=!1,t.emulateJSON=!1;var s=t.Events={on:function(e,t,n){if(!l(this,"on",e,[t,n])||!t)return this;this._events||(this._events={});var r=this._events[e]||(this._events[e]=[]);return r.push({callback:t,context:n,ctx:n||this}),this},once:function(e,t,r){if(!l(this,"once",e,[t,r])||!t)return this;var i=this,o=n.once(function(){i.off(e,o),t.apply(this,arguments)});return o._callback=t,this.on(e,o,r)},off:function(e,t,r){var i,o,a,s,u,c,f,d;if(!this._events||!l(this,"off",e,[t,r]))return this;if(!e&&!t&&!r)return this._events=void 0,this;for(s=e?[e]:n.keys(this._events),u=0,c=s.length;c>u;u++)if(e=s[u],a=this._events[e]){if(this._events[e]=i=[],t||r)for(f=0,d=a.length;d>f;f++)o=a[f],(t&&t!==o.callback&&t!==o.callback._callback||r&&r!==o.context)&&i.push(o);i.length||delete this._events[e]}return this},trigger:function(e){if(!this._events)return this;var t=a.call(arguments,1);if(!l(this,"trigger",e,t))return this;var n=this._events[e],r=this._events.all;return n&&c(n,t),r&&c(r,arguments),this},stopListening:function(e,t,r){var i=this._listeningTo;if(!i)return this;var o=!t&&!r;r||"object"!=typeof t||(r=this),e&&((i={})[e._listenId]=e);for(var a in i)e=i[a],e.off(t,r,this),(o||n.isEmpty(e._events))&&delete this._listeningTo[a];return this}},u=/\s+/,l=function(e,t,n,r){if(!n)return!0;if("object"==typeof n){for(var i in n)e[t].apply(e,[i,n[i]].concat(r));return!1}if(u.test(n)){for(var o=n.split(u),a=0,s=o.length;s>a;a++)e[t].apply(e,[o[a]].concat(r));return!1}return!0},c=function(e,t){var n,r=-1,i=e.length,o=t[0],a=t[1],s=t[2];switch(t.length){case 0:for(;++rd;d++)this.trigger("change:"+s[d],this,f[s[d]],r)}if(l)return this;if(!u)for(;this._pending;)r=this._pending,this._pending=!1,this.trigger("change",this,r);return this._pending=!1,this._changing=!1,this},unset:function(e,t){return this.set(e,void 0,n.extend({},t,{unset:!0}))},clear:function(e){var t={};for(var r in this.attributes)t[r]=void 0;return this.set(t,n.extend({},e,{unset:!0}))},hasChanged:function(e){return null==e?!n.isEmpty(this.changed):n.has(this.changed,e)},changedAttributes:function(e){if(!e)return this.hasChanged()?n.clone(this.changed):!1;var t,r=!1,i=this._changing?this._previousAttributes:this.attributes;for(var o in e)n.isEqual(i[o],t=e[o])||((r||(r={}))[o]=t);return r},previous:function(e){return null!=e&&this._previousAttributes?this._previousAttributes[e]:null},previousAttributes:function(){return n.clone(this._previousAttributes)},fetch:function(e){e=e?n.clone(e):{},void 0===e.parse&&(e.parse=!0);var t=this,r=e.success;return e.success=function(n){return t.set(t.parse(n,e),e)?(r&&r(t,n,e),t.trigger("sync",t,n,e),void 0):!1},F(this,e),this.sync("read",this,e)},save:function(e,t,r){var i,o,a,s=this.attributes;if(null==e||"object"==typeof e?(i=e,r=t):(i={})[e]=t,r=n.extend({validate:!0},r),i&&!r.wait){if(!this.set(i,r))return!1}else if(!this._validate(i,r))return!1;i&&r.wait&&(this.attributes=n.extend({},s,i)),void 0===r.parse&&(r.parse=!0);var u=this,l=r.success;return r.success=function(e){u.attributes=s;var t=u.parse(e,r);return r.wait&&(t=n.extend(i||{},t)),n.isObject(t)&&!u.set(t,r)?!1:(l&&l(u,e,r),u.trigger("sync",u,e,r),void 0)},F(this,r),o=this.isNew()?"create":r.patch?"patch":"update","patch"===o&&(r.attrs=i),a=this.sync(o,this,r),i&&r.wait&&(this.attributes=s),a},destroy:function(e){e=e?n.clone(e):{};var t=this,r=e.success,i=function(){t.trigger("destroy",t,t.collection,e)};if(e.success=function(n){(e.wait||t.isNew())&&i(),r&&r(t,n,e),t.isNew()||t.trigger("sync",t,n,e)},this.isNew())return e.success(),!1;F(this,e);var o=this.sync("delete",this,e);return e.wait||i(),o},url:function(){var e=n.result(this,"urlRoot")||n.result(this.collection,"url")||P();return this.isNew()?e:e.replace(/([^\/])$/,"$1/")+encodeURIComponent(this.id)},parse:function(e){return e},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return!this.has(this.idAttribute)},isValid:function(e){return this._validate({},n.extend(e||{},{validate:!0}))},_validate:function(e,t){if(!t.validate||!this.validate)return!0;e=n.extend({},this.attributes,e);var r=this.validationError=this.validate(e,t)||null;return r?(this.trigger("invalid",this,r,n.extend(t,{validationError:r})),!1):!0}});var p=["keys","values","pairs","invert","pick","omit"];n.each(p,function(e){d.prototype[e]=function(){var t=a.call(arguments);return t.unshift(this.attributes),n[e].apply(n,t)}});var h=t.Collection=function(e,t){t||(t={}),t.model&&(this.model=t.model),void 0!==t.comparator&&(this.comparator=t.comparator),this._reset(),this.initialize.apply(this,arguments),e&&this.reset(e,n.extend({silent:!0},t))},m={add:!0,remove:!0,merge:!0},v={add:!0,remove:!1};n.extend(h.prototype,s,{model:d,initialize:function(){},toJSON:function(e){return this.map(function(t){return t.toJSON(e)})},sync:function(){return t.sync.apply(this,arguments)},add:function(e,t){return this.set(e,n.extend({merge:!1},t,v))},remove:function(e,t){var r=!n.isArray(e);e=r?[e]:n.clone(e),t||(t={});var i,o,a,s;for(i=0,o=e.length;o>i;i++)s=e[i]=this.get(e[i]),s&&(delete this._byId[s.id],delete this._byId[s.cid],a=this.indexOf(s),this.models.splice(a,1),this.length--,t.silent||(t.index=a,s.trigger("remove",s,this,t)),this._removeReference(s,t));return r?e[0]:e},set:function(e,t){t=n.defaults({},t,m),t.parse&&(e=this.parse(e,t));var r=!n.isArray(e);e=r?e?[e]:[]:n.clone(e);var i,o,a,s,u,l,c,f=t.at,p=this.model,h=this.comparator&&null==f&&t.sort!==!1,v=n.isString(this.comparator)?this.comparator:null,b=[],g=[],y={},_=t.add,w=t.merge,x=t.remove,k=!h&&_&&x?[]:!1;for(i=0,o=e.length;o>i;i++){if(u=e[i]||{},a=u instanceof d?s=u:u[p.prototype.idAttribute||"id"],l=this.get(a))x&&(y[l.cid]=!0),w&&(u=u===s?s.attributes:u,t.parse&&(u=l.parse(u,t)),l.set(u,t),h&&!c&&l.hasChanged(v)&&(c=!0)),e[i]=l;else if(_){if(s=e[i]=this._prepareModel(u,t),!s)continue;b.push(s),this._addReference(s,t)}s=l||s,!k||!s.isNew()&&y[s.id]||k.push(s),y[s.id]=!0}if(x){for(i=0,o=this.length;o>i;++i)y[(s=this.models[i]).cid]||g.push(s);g.length&&this.remove(g,t)}if(b.length||k&&k.length)if(h&&(c=!0),this.length+=b.length,null!=f)for(i=0,o=b.length;o>i;i++)this.models.splice(f+i,0,b[i]);else{k&&(this.models.length=0);var E=k||b;for(i=0,o=E.length;o>i;i++)this.models.push(E[i])}if(c&&this.sort({silent:!0}),!t.silent){for(i=0,o=b.length;o>i;i++)(s=b[i]).trigger("add",s,this,t);(c||k&&k.length)&&this.trigger("sort",this,t)}return r?e[0]:e},reset:function(e,t){t||(t={});for(var r=0,i=this.models.length;i>r;r++)this._removeReference(this.models[r],t);return t.previousModels=this.models,this._reset(),e=this.add(e,n.extend({silent:!0},t)),t.silent||this.trigger("reset",this,t),e},push:function(e,t){return this.add(e,n.extend({at:this.length},t))},pop:function(e){var t=this.at(this.length-1);return this.remove(t,e),t},unshift:function(e,t){return this.add(e,n.extend({at:0},t))},shift:function(e){var t=this.at(0);return this.remove(t,e),t},slice:function(){return a.apply(this.models,arguments)},get:function(e){return null==e?void 0:this._byId[e]||this._byId[e.id]||this._byId[e.cid]},at:function(e){return this.models[e]},where:function(e,t){return n.isEmpty(e)?t?void 0:[]:this[t?"find":"filter"](function(t){for(var n in e)if(e[n]!==t.get(n))return!1;return!0})},findWhere:function(e){return this.where(e,!0)},sort:function(e){if(!this.comparator)throw new Error("Cannot sort a set without a comparator");return e||(e={}),n.isString(this.comparator)||1===this.comparator.length?this.models=this.sortBy(this.comparator,this):this.models.sort(n.bind(this.comparator,this)),e.silent||this.trigger("sort",this,e),this},pluck:function(e){return n.invoke(this.models,"get",e)},fetch:function(e){e=e?n.clone(e):{},void 0===e.parse&&(e.parse=!0);var t=e.success,r=this;return e.success=function(n){var i=e.reset?"reset":"set";r[i](n,e),t&&t(r,n,e),r.trigger("sync",r,n,e)},F(this,e),this.sync("read",this,e)},create:function(e,t){if(t=t?n.clone(t):{},!(e=this._prepareModel(e,t)))return!1;t.wait||this.add(e,t);var r=this,i=t.success;return t.success=function(e,n){t.wait&&r.add(e,t),i&&i(e,n,t)},e.save(null,t),e},parse:function(e){return e},clone:function(){return new this.constructor(this.models)},_reset:function(){this.length=0,this.models=[],this._byId={}},_prepareModel:function(e,t){if(e instanceof d)return e;t=t?n.clone(t):{},t.collection=this;var r=new this.model(e,t);return r.validationError?(this.trigger("invalid",this,r.validationError,t),!1):r},_addReference:function(e){this._byId[e.cid]=e,null!=e.id&&(this._byId[e.id]=e),e.collection||(e.collection=this),e.on("all",this._onModelEvent,this)},_removeReference:function(e){this===e.collection&&delete e.collection,e.off("all",this._onModelEvent,this)},_onModelEvent:function(e,t,n,r){("add"!==e&&"remove"!==e||n===this)&&("destroy"===e&&this.remove(t,r),t&&e==="change:"+t.idAttribute&&(delete this._byId[t.previous(t.idAttribute)],null!=t.id&&(this._byId[t.id]=t)),this.trigger.apply(this,arguments))}});var b=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","difference","indexOf","shuffle","lastIndexOf","isEmpty","chain","sample"];n.each(b,function(e){h.prototype[e]=function(){var t=a.call(arguments);return t.unshift(this.models),n[e].apply(n,t)}});var g=["groupBy","countBy","sortBy","indexBy"];n.each(g,function(e){h.prototype[e]=function(t,r){var i=n.isFunction(t)?t:function(e){return e.get(t)};return n[e](this.models,i,r)}});var y=t.View=function(e){this.cid=n.uniqueId("view"),e||(e={}),n.extend(this,n.pick(e,w)),this._ensureElement(),this.initialize.apply(this,arguments),this.delegateEvents()},_=/^(\S+)\s*(.*)$/,w=["model","collection","el","id","attributes","className","tagName","events"];n.extend(y.prototype,s,{tagName:"div",$:function(e){return this.$el.find(e)},initialize:function(){},render:function(){return this},remove:function(){return this.$el.remove(),this.stopListening(),this},setElement:function(e,n){return this.$el&&this.undelegateEvents(),this.$el=e instanceof t.$?e:t.$(e),this.el=this.$el[0],n!==!1&&this.delegateEvents(),this},delegateEvents:function(e){if(!e&&!(e=n.result(this,"events")))return this;this.undelegateEvents();for(var t in e){var r=e[t];if(n.isFunction(r)||(r=this[e[t]]),r){var i=t.match(_),o=i[1],a=i[2];r=n.bind(r,this),o+=".delegateEvents"+this.cid,""===a?this.$el.on(o,r):this.$el.on(o,a,r)}}return this},undelegateEvents:function(){return this.$el.off(".delegateEvents"+this.cid),this},_ensureElement:function(){if(this.el)this.setElement(n.result(this,"el"),!1);else{var e=n.extend({},n.result(this,"attributes"));this.id&&(e.id=n.result(this,"id")),this.className&&(e["class"]=n.result(this,"className"));var r=t.$("<"+n.result(this,"tagName")+">").attr(e);this.setElement(r,!1)}}}),t.sync=function(e,r,i){var o=k[e];n.defaults(i||(i={}),{emulateHTTP:t.emulateHTTP,emulateJSON:t.emulateJSON});var a={type:o,dataType:"json"};if(i.url||(a.url=n.result(r,"url")||P()),null!=i.data||!r||"create"!==e&&"update"!==e&&"patch"!==e||(a.contentType="application/json",a.data=JSON.stringify(i.attrs||r.toJSON(i))),i.emulateJSON&&(a.contentType="application/x-www-form-urlencoded",a.data=a.data?{model:a.data}:{}),i.emulateHTTP&&("PUT"===o||"DELETE"===o||"PATCH"===o)){a.type="POST",i.emulateJSON&&(a.data._method=o);var s=i.beforeSend;i.beforeSend=function(e){return e.setRequestHeader("X-HTTP-Method-Override",o),s?s.apply(this,arguments):void 0}}"GET"===a.type||i.emulateJSON||(a.processData=!1),"PATCH"===a.type&&x&&(a.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")});var u=i.xhr=t.ajax(n.extend(a,i));return r.trigger("request",r,u,i),u};var x=!("undefined"==typeof window||!window.ActiveXObject||window.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent),k={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};t.ajax=function(){return t.$.ajax.apply(t.$,arguments)};var E=t.Router=function(e){e||(e={}),e.routes&&(this.routes=e.routes),this._bindRoutes(),this.initialize.apply(this,arguments)},C=/\((.*?)\)/g,O=/(\(\?)?:\w+/g,T=/\*\w+/g,S=/[\-{}\[\]+?.,\\\^$|#\s]/g;n.extend(E.prototype,s,{initialize:function(){},route:function(e,r,i){n.isRegExp(e)||(e=this._routeToRegExp(e)),n.isFunction(r)&&(i=r,r=""),i||(i=this[r]);var o=this;return t.history.route(e,function(n){var a=o._extractParameters(e,n);o.execute(i,a),o.trigger.apply(o,["route:"+r].concat(a)),o.trigger("route",r,a),t.history.trigger("route",o,r,a)}),this},execute:function(e,t){e&&e.apply(this,t)},navigate:function(e,n){return t.history.navigate(e,n),this},_bindRoutes:function(){if(this.routes){this.routes=n.result(this,"routes");for(var e,t=n.keys(this.routes);null!=(e=t.pop());)this.route(e,this.routes[e])}},_routeToRegExp:function(e){return e=e.replace(S,"\\$&").replace(C,"(?:$1)?").replace(O,function(e,t){return t?e:"([^/?]+)"}).replace(T,"([^?]*?)"),new RegExp("^"+e+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(e,t){var r=e.exec(t).slice(1);return n.map(r,function(e,t){return t===r.length-1?e||null:e?decodeURIComponent(e):null})}});var N=t.History=function(){this.handlers=[],n.bindAll(this,"checkUrl"),"undefined"!=typeof window&&(this.location=window.location,this.history=window.history)},D=/^[#\/]|\s+$/g,A=/^\/+|\/+$/g,M=/msie [\w.]+/,R=/\/$/,B=/#.*$/;N.started=!1,n.extend(N.prototype,s,{interval:50,atRoot:function(){return this.location.pathname.replace(/[^\/]$/,"$&/")===this.root},getHash:function(e){var t=(e||this).location.href.match(/#(.*)$/);return t?t[1]:""},getFragment:function(e,t){if(null==e)if(this._hasPushState||!this._wantsHashChange||t){e=decodeURI(this.location.pathname+this.location.search);var n=this.root.replace(R,"");e.indexOf(n)||(e=e.slice(n.length))}else e=this.getHash();return e.replace(D,"")},start:function(e){if(N.started)throw new Error("Backbone.history has already been started");N.started=!0,this.options=n.extend({root:"/"},this.options,e),this.root=this.options.root,this._wantsHashChange=this.options.hashChange!==!1,this._wantsPushState=!!this.options.pushState,this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var r=this.getFragment(),i=document.documentMode,o=M.exec(navigator.userAgent.toLowerCase())&&(!i||7>=i);if(this.root=("/"+this.root+"/").replace(A,"/"),o&&this._wantsHashChange){var a=t.$('