/* knockback-full-stack.js 0.19.1 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),n(15),n(16),n(17),n(18),n(19),e.exports=n(14)},function(e,t,n){var r,i,o,a,s,l,u,c,d=function(e,t){return function(){return e.apply(t,arguments)}},p=[].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),u=c._,l=c.ko,o=0,r=-1,i=1,a=["destroy","shareOptions","filters","comparator","sortAttribute","viewModelByModel","hasViewModels"],s.compare=function(e,t){return u.isString(e)?e.localeCompare(""+t):u.isString(t)?t.localeCompare(""+e):e===t?o:t>e?r:i},s.CollectionObservable=function(){function e(e,t){return this._onCollectionChange=d(this._onCollectionChange,this),s.ignore(function(n){return function(){var r,i,o;return!u.isUndefined(t)||e instanceof s.Collection?u.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,l.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=l.observable(t.sort_attribute?n._attributeComparator(t.sort_attribute):t.comparator),n._filters=l.observableArray(t.filters?u.isArray(t.filters)?t.filters:t.filters?[t.filters]:void 0:[]),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=l.observable(e),i.collection=n.collection=l.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=l.computed(function(){var e,t,r,o,a,c,d,p;if(e=n._comparator(),o=n._filters())for(d=0,p=o.length;p>d;d++)r=o[d],l.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=u.filter(a,function(e){return!o.length||n._selectModel(e)}),c=e?u.map(a,function(e){return n._createViewModel(e)}).sort(e):n.models_only?o.length?a:a.slice():u.map(a,function(e){return n._createViewModel(e)})):c=[],n.in_edit++,i(c),n.in_edit--)}),i.subscribe(u.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 this._filters(e?u.isArray(e)?e:[e]:[])},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",u.find(s.peek(s.utils.wrappedObservable(this)),function(n){var r;return(null!=n&&null!=(r=n.__kb)?r.object: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,l,c,d,p;if(!t.in_edit&&(t.models_only&&(!e.length||s.utils.hasModelSignature(e[0]))||!t.models_only&&(!e.length||u.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=u.filter(e,function(e){return!r||t._selectModel(e)});else for(!r||(c=[]),o=[],d=0,p=e.length;p>d;d++){if(l=e[d],i=s.utils.wrappedObject(l),r){if(!t._selectModel(i))continue;c.push(l)}t.create_options.store.findOrReplace(i,t.create_options.creator,l),o.push(i)}t.in_edit++,e.length===c.length||a(c),u.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=l.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),u.isFunction(t)){if(!t(e))return!1}else if(u.isArray(t)){if(o=e.id,p.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,l,u;u=i=n(6),l=u._,a=u.ko,r={"default":null,"backbone-orm":null,"backbone-associations":n(23),"backbone-relational":n(24),supermodel:n(25)},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(l.isString(s)){if(!r.hasOwnProperty(s)){console.log("Knockback configure: could not find orm: "+s+". Available: "+l.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,l,u,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,l=function(n){return function(a){var l,u;return(l=n.__kb.callbacks[a])||(l=n.__kb.callbacks[a]={model:null,list:[],fn:function(e){var t,n,o,s;for(s=l.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}}),l.list.push(u=o.defaults({obj:e},t)),s?n._onModelLoaded(s):void 0}}(this),u=0,c=a.length;c>u;u++)n=a[u],n&&l(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,l,u;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)),l=t.list,o=0,a=l.length;a>o;o++)i=l[o],i.unbind_fn||(i.unbind_fn=null!=(u=r.orm)?u.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,l,u;a=null!=a?a:e,u=r=n(6),s=u._,i=u.ko,t=u.$,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 l;return l=function(e){var l,u,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(l in e)c=e[l],"view_model"!==l&&("create"===l?c(t,n,i,o):s.isObject(c)&&!s.isFunction(c)?(u=a||c&&c.create?{}:t,t[l]=r.Inject.inject(c,u,n,i,o,!0)):t[l]=c)}return t},a?l(e):r.ignore(function(){return l(e)})},e.injectViewModels=function(e){var t,n,i,o,l,u,c,d,p,f;for(d=[],u=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,d.push({el:e,view_model:{},binding:t.value})),o=e.childNodes,r=0,i=o.length;i>r;r++)n=o[r],u(n)},!e&&(null!=a?a.document:void 0)&&(e=a.document),u(e),p=0,f=d.length;f>p;p++)n=d[p],(l=n.binding)&&(l.search(/[:]/)<0||(l="{"+l+"}"),o=new Function("","return ( "+l+" )")(),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 d},e}(),l=i.applyBindings,i.applyBindings=function(e,t){var n;return n=r.RECUSIVE_AUTO_INJECT?r.injectViewModels(t):[],n.length?void 0:l.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,l;s=null!=s?s:t,a=n(28),i=function(e,t){var n,r;for(n in t)r=t[n],e[n]=r;return e};var u=function(){},c=function(e,t,n){var r;return r=t&&t.hasOwnProperty("constructor")?t.constructor:function(){e.apply(this,arguments)},i(r,e),u.prototype=e.prototype,r.prototype=new u,t&&i(r.prototype,t),n&&i(r,n),r.prototype.constructor=r,r.__super__=e.prototype,r},d=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.18.6",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||t instanceof e.Model||t instanceof e.Collection)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(l.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)&&l.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 void("function"==typeof t.dispose&&t.dispose())}"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,l;return null==r&&(r={}),(i=null!=s?s.document:void 0)?(o=i.createElement("div"),l=a.renderTemplate(t,n,r,o,"replaceChildren"),1===o.children.length&&(o=o.children[0]),e.releaseOnNodeRemove(n,o),l.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 l.isFunction(t[n])&&(null!=(i=e.orm)?i.useFunction(t,n):void 0)?t[n]():r?t.get.apply(t,l.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 l.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=d,e._throwMissing=function(e,t){throw""+(l.isString(e)?e:e.constructor.name)+": "+t+" is missing"},e._throwUnexpected=function(e,t){throw""+(l.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}(),s.Parse?(r=o.Parse=s.Parse,l=o._=s.Parse._):(r=o.Backbone=n(26),l=o._=n(27)),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(20))}catch(p){}}).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)&&(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,l,u;u=a=n(6),l=u._,s=u.ko,o=n(11),i=["value","valueType","destroy"],r=["args","read","write"],a.Observable=function(){function e(e,t,n,u){return this._vm=null!=u?u:{},a.ignore(function(u){return function(){var c,d,p,f,h,v;for(t||a._throwMissing(u,"key_or_info"),u.key=t.key||t,h=0,v=r.length;v>h;h++)p=r[h],t[p]&&(u[p]=t[p]);return c=a.utils.collapseOptions(n),d=c.event_watcher,delete c.event_watcher,u._value=new o(c),u._model=s.observable(),f=a.utils.wrappedObservable(u,s.computed({read:function(){var e,t,n,r,i,o,c;for(i=u._model(),o=t=[u.key].concat(u.args||[]),n=0,r=o.length;r>n;n++)e=o[n],s.utils.unwrapObservable(e);return null!=(c=a.utils.wrappedEventWatcher(u))&&c.emitter(i||null),u.read?u.update(u.read.apply(u._vm,t)):l.isUndefined(i)||a.ignore(function(){return u.update(a.getValue(i,a.peek(u.key),u.args))}),u._value.value()},write:function(e){return a.ignore(function(){var t,n;return t=a.utils.unwrapModels(e),n=a.peek(u._model),u.write?(u.write.call(u._vm,t),e=a.getValue(n,a.peek(u.key),u.args)):n&&a.setValue(n,a.peek(u.key),t),u.update(e)})},owner:u._vm})),f.__kb_is_o=!0,c.store=a.utils.wrappedStore(f,c.store),c.path=a.utils.pathJoin(c.path,u.key),c.factories&&("function"==typeof c.factories||c.factories.create)?(c.factory=a.utils.wrappedFactory(f,new a.Factory(c.factory)),c.factory.addPathMapping(c.path,c.factories)):c.factory=a.Factory.useOptionsOrCreate(c,f,c.path),delete c.factories,a.publishMethods(f,u,i),f.model=u.model=s.computed({read:function(){return s.utils.unwrapObservable(u._model)},write:function(e){return a.ignore(function(){var t;if(!u.__kb_released&&a.peek(u._model)!==e)return t=a.getValue(e,a.peek(u.key),u.args),u._model(e),e?l.isUndefined(t)?void 0:u.update(t):u.update(null)})}}),a.EventWatcher.useOptionsOrCreate({event_watcher:d},e||null,u,{emitter:u.model,update:function(){return a.ignore(function(){return u.update()})},key:u.key,path:c.path}),u._value.rawValue()||u._value.update(),a.LocalizedObservable&&t.localizer&&(f=new t.localizer(f)),a.DefaultObservable&&t.hasOwnProperty("default")&&(f=a.defaultObservable(f,t["default"])),f}}(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,l,u;for(o={count:0},n=e._events||e._callbacks||{},u=t?[t]:i.keys(n),s=0,l=u.length;l>s;s++)if(t=u[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||e instanceof r.Model){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&&e instanceof r.Model&&(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))&&a.isFunction(n.collection))return void(i.peek(n.collection)!==e&&n.collection(e));break;case i.TYPE_MODEL:if(t===i.TYPE_MODEL||a.isNull(e))return void(a.isFunction(n.model)?i.peek(n.model)!==e&&n.model(e):i.utils.wrappedObject(n)!==e&&this._updateValueObservable(e))}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,l,u,c,d;c=r=n(6),o=c._,i=c.ko,d=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},l=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},u=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 d.apply(this,a(arguments,"observable"))},e.wrappedObject=function(){return d.apply(this,a(arguments,"object"))},e.wrappedModel=function(e,t){return 1===arguments.length?(t=d(e,"object"),o.isUndefined(t)?e:t):d(e,"object",t)},e.wrappedStore=function(){return d.apply(this,a(arguments,"store"))},e.wrappedStoreIsOwned=function(){return d.apply(this,a(arguments,"store_is_owned"))},e.wrappedFactory=function(){return d.apply(this,a(arguments,"factory"))},e.wrappedEventWatcher=function(){return d.apply(this,a(arguments,"event_watcher"))},e.wrappedEventWatcherIsOwned=function(){return d.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 e instanceof r.Model?r.viewModel(e,t):e instanceof r.Collection?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":l(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])),u(n,t,r)):l(n,t,r);break;case"factories":o.isFunction(r)?n[t]=r:u(n,t,r);break;case"static_defaults":u(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,l,u,c,d;d=l=n(6),c=d._,u=d.ko,a=function(){return function(e){return{store:l.utils.wrappedStore(e),factory:l.utils.wrappedFactory(e),path:e.__kb.path,event_watcher:l.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]=l.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"],l.ViewModel=function(){function e(e,t,n){return null==t&&(t={}),l.ignore(function(i){return function(){var o,d,p,f,h,v;for(!e||e instanceof l.Model||"function"==typeof e.get&&"function"==typeof e.bind||l._throwUnexpected(i,"not a model"),t=c.isArray(t)?{keys:t}:l.utils.collapseOptions(t),i.__kb||(i.__kb={}),i.__kb.view_model=n||i,f=0,h=r.length;h>f;f++)p=r[f],t.hasOwnProperty(p)&&(i.__kb[p]=t[p]);return l.Store.useOptionsOrCreate(t,e,i),i.__kb.path=t.path,l.Factory.useOptionsOrCreate(t,i,t.path),v=l._wrappedKey(i,"_model",u.observable()),i.model=u.computed({read:function(){return u.utils.unwrapObservable(v)},write:function(e){return l.ignore(function(){return l.utils.wrappedObject(i)!==e&&!l.wasReleased(i)&&d?i.__kb_null?void(!e||l._throwUnexpected(i,"model set on shared null")):(d.emitter(e),l.utils.wrappedObject(i,d.ee),v(d.ee),!d.ee||i.createObservables(d.ee)):void 0})}}),d=l.utils.wrappedEventWatcher(i,new l.EventWatcher(e,i,{emitter:i._model,update:function(){return l.ignore(function(){return!(null!=d?d.ee:void 0)||i.createObservables(null!=d?d.ee:void 0)})}})),l.utils.wrappedObject(i,e=d.ee),v(d.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),!l.statistics||l.statistics.register("ViewModel",i),i}}(this))}return e.extend=l.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,l.releaseKeys(this),l.utils.wrappedDestroy(this),!l.statistics||l.statistics.unregister("ViewModel",this)},e.prototype.shareOptions=function(){return{store:l.utils.wrappedStore(this),factory:l.utils.wrappedFactory(this)}},e.prototype.createObservables=function(e,t,n){var r,s,u,d,p,f,h,v,b;if(n||(n=a(this)),t)if(c.isArray(t))for(f=0,v=t.length;v>f;f++)r=t[f],o(this,e,r,n);else for(r in t)s=t[r],(d=i(this,r))&&(c.isString(s)||s.key||(s.key=d),this[d]=this.__kb.view_model[d]=l.observable(e,s,n,this));else{if(this.__kb.keys||!e)return;for(r in e.attributes)o(this,e,r,n);if(u=null!=(b=l.orm)&&"function"==typeof b.keys?b.keys(e):void 0)for(p=0,h=u.length;h>p;p++)r=u[p],o(this,e,r,n)}},e}(),l.viewModel=function(e,t,n){return new l.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(e,t,n){var r,i,o,a,s;s=i=n(6),a=s._,o=s.ko,n(21),r=["destroy","setToDefault"],e.exports=i.DefaultObservable=function(){function e(e,t){var n;return this.dv=t,n=i.utils.wrappedObservable(this,o.computed({read:function(t){return function(){var n;return n=o.utils.unwrapObservable(e()),a.isNull(n)||a.isUndefined(n)?o.utils.unwrapObservable(t.dv):n}}(this),write:function(t){return e(t)}})),i.publishMethods(n,this,r),n}return e.prototype.destroy=function(){return i.utils.wrappedDestroy(this)},e.prototype.setToDefault=function(){return i.utils.wrappedObservable(this)(this.dv)},e}(),i.defaultObservable=function(e,t){return new i.DefaultObservable(e,t)}},function(e,t,n){var r,i,o,a,s;s=i=n(6),a=s._,o=s.ko,r=Array.prototype.slice,i.toFormattedString=function(e){var t,n,i,s,l,u;l=e.slice(),n=r.call(arguments,1);for(i in n)for(t=n[i],u=o.utils.unwrapObservable(t),(a.isUndefined(u)||a.isNull(u))&&(u=""),s=e.indexOf("{"+i+"}");s>=0;)l=l.replace("{"+i+"}",u),s=e.indexOf("{"+i+"}",s+1);return l},i.parseFormattedString=function(e,t){var n,r,i,o,s,l,u,c,d,p,f,h,v;for(p=t.slice(),i=0,l=0,c={};p.search("\\{"+i+"\\}")>=0;){for(u=t.indexOf("{"+i+"}");u>=0;)p=p.replace("{"+i+"}","(.*)"),c[u]=i,l++,u=t.indexOf("{"+i+"}",u+1);i++}if(n=i,d=new RegExp(p),s=d.exec(e),s&&s.shift(),!s||s.length!==l){for(f=[];n-->0;)f.push("");return f}v=a.sortBy(a.keys(c),function(e){return parseInt(e,10)}),r={};for(o in v)u=v[o],i=c[u],r.hasOwnProperty(i)||(r[i]=o);for(h=[],i=0;n>i;)h.push(s[r[i]]),i++;return h},e.exports=i.FormattedObservable=function(){function e(e,t){var n,s;return a.isArray(t)?(e=e,s=t):s=r.call(arguments,1),n=i.utils.wrappedObservable(this,o.computed({read:function(){var n,r,a;for(t=[o.utils.unwrapObservable(e)],r=0,a=s.length;a>r;r++)n=s[r],t.push(o.utils.unwrapObservable(n));return i.toFormattedString.apply(null,t)},write:function(t){var n,r,a;for(r=i.parseFormattedString(t,o.utils.unwrapObservable(e)),a=Math.min(s.length,r.length),n=0;a>n;)s[n](r[n]),n++}}))}return e.prototype.destroy=function(){return i.utils.wrappedDestroy(this)},e}(),i.formattedObservable=function(e){return new i.FormattedObservable(e,r.call(arguments,1))}},function(e,t,n){var r,i,o,a,s;s=i=n(6),a=s._,o=s.ko,r=["destroy","observedValue","resetToCurrent"],i.locale_manager||(i.locale_manager=void 0),e.exports=i.LocalizedObservable=function(){function e(e,t,n){var s;return this.value=e,this.vm=n,t||(t={}),this.vm||(this.vm={}),this.read||i._throwMissing(this,"read"),i.locale_manager||i._throwMissing(this,"kb.locale_manager"),this.__kb||(this.__kb={}),this.__kb._onLocaleChange=a.bind(this._onLocaleChange,this),this.__kb._onChange=t.onChange,this.value&&(e=o.utils.unwrapObservable(this.value)),this.vo=o.observable(e?this.read(e,null):null),s=i.utils.wrappedObservable(this,o.computed({read:function(e){return function(){return e.value&&o.utils.unwrapObservable(e.value),e.vo(),e.read(o.utils.unwrapObservable(e.value))}}(this),write:function(e){return function(t){return e.write||i._throwUnexpected(e,"writing to read-only"),e.write(t,o.utils.unwrapObservable(e.value)),e.vo(t),e.__kb._onChange?e.__kb._onChange(t):void 0}}(this),owner:this.vm})),i.publishMethods(s,this,r),i.locale_manager.bind("change",this.__kb._onLocaleChange),t.hasOwnProperty("default")&&(s=i.DefaultObservable&&o.defaultObservable(s,t["default"])),s}return e.extend=i.extend,e.prototype.destroy=function(){return i.locale_manager.unbind("change",this.__kb._onLocaleChange),this.vm=null,i.utils.wrappedDestroy(this)},e.prototype.resetToCurrent=function(){var e,t;return t=i.utils.wrappedObservable(this),e=this.value?this.read(o.utils.unwrapObservable(this.value)):null,t()!==e?t(e):void 0},e.prototype.observedValue=function(e){return 0===arguments.length?this.value:(this.value=e,void this._onLocaleChange())},e.prototype._onLocaleChange=function(){var e;return e=this.read(o.utils.unwrapObservable(this.value)),this.vo(e),this.__kb._onChange?this.__kb._onChange(e):void 0},e}(),i.localizedObservable=function(e,t,n){return new i.LocalizedObservable(e,t,n)}},function(e,t,n){var r,i,o,a,s;s=i=n(6),a=s._,o=s.ko,r=["destroy"],e.exports=i.TriggeredObservable=function(){function e(e,t){var n;return this.event_selector=t,e||i._throwMissing(this,"emitter"),this.event_selector||i._throwMissing(this,"event_selector"),this.vo=o.observable(),n=i.utils.wrappedObservable(this,o.computed(function(e){return function(){return e.vo()}}(this))),i.publishMethods(n,this,r),i.utils.wrappedEventWatcher(this,new i.EventWatcher(e,this,{emitter:a.bind(this.emitter,this),update:a.bind(this.update,this),event_selector:this.event_selector})),n}return e.prototype.destroy=function(){return i.utils.wrappedDestroy(this)},e.prototype.emitter=function(e){return 0===arguments.length||this.ee===e?this.ee:(this.ee=e)?this.update():void 0},e.prototype.update=function(){return this.ee?this.vo()!==this.ee?this.vo(this.ee):this.vo.valueHasMutated():void 0},e}(),i.triggeredObservable=function(e,t){return new i.TriggeredObservable(e,t)}},function(e,t,n){var r,i,o,a,s,l;l=o=n(6),s=l._,a=l.ko,r=l.$,n(22),i=function(e){return e=a.utils.unwrapObservable(e),"function"==typeof e?e.apply(null,Array.prototype.slice.call(arguments,1)):e},e.exports=o.Validation=function(){function e(){}return e}(),o.valueValidator=function(e,t,n){return null==n&&(n={}),n&&!("function"==typeof n)||(n={}),a.computed(function(){var r,o,l,u,c,d,p,f;p={$error_count:0},o=a.utils.unwrapObservable(e),!("disable"in n)||(l=i(n.disable)),!("enable"in n)||(l=!i(n.enable)),d=n.priorities||[],s.isArray(d)||(d=[d]),r=d.length+1;for(u in t)f=t[u],p[u]=!l&&i(f,o),p[u]&&(p.$error_count++,(c=s.indexOf(d,u)>=0)||(c=d.length),p.$active_error&&r>c?(p.$active_error=u,r=c):p.$active_error||(p.$active_error=u,r=c));return p.$enabled=!l,p.$disable=!!l,p.$valid=0===p.$error_count,p})},o.inputValidator=function(e,t,n){var i,a,l,u,c,d,p,f,h,v;if(null==n&&(n={}),n&&!("function"==typeof n)||(n={}),h=o.valid,i=r(t),(u=i.attr("name"))&&!s.isString(u)&&(u=null),!(a=i.attr("data-bind")))return null;if(c=new Function("sc","with(sc[0]) { return { "+a+" } }")([e]),!c||!c.value)return null;if(!c.validation_options||(s.defaults(c.validation_options,n),n=c.validation_options),a={},!h[p=i.attr("type")]||(a[p]=h[p]),!i.attr("required")||(a.required=h.required),c.validations){v=c.validations;for(l in v)f=v[l],a[l]=f}return d=o.valueValidator(c.value,a,n),!u&&!n.no_attach||(e["$"+u]=d),d},o.formValidator=function(e,t){var n,i,l,u,c,d,p,f,h,v,b,m,g;for(p={},v=[],n=r(t),(l=n.attr("name"))&&!s.isString(l)&&(l=null),(i=n.attr("data-bind"))&&(d=new Function("sc","with(sc[0]) { return { "+i+" } }")([e]),f=d.validation_options),f||(f={}),f.no_attach=!!l,g=n.find("input"),b=0,m=g.length;m>b;b++)u=g[b],(c=r(u).attr("name"))&&(h=o.inputValidator(e,u,f),!h||v.push(p[c]=h));return p.$error_count=a.computed(function(){var e,t,n;for(e=0,t=0,n=v.length;n>t;t++)h=v[t],e+=h().$error_count;return e}),p.$valid=a.computed(function(){return 0===p.$error_count()}),p.$enabled=a.computed(function(){var e,t,n;for(e=!0,t=0,n=v.length;n>t;t++)h=v[t],e&=h().$enabled;return e}),p.$disabled=a.computed(function(){return!p.$enabled()}),l&&(e["$"+l]=p),p}},function(t){t.exports=e},function(e,t,n){var r,i,o,a;a=r=n(6),o=a._,i=a.ko,r.Observable.prototype.setToDefault=function(){var e;null!=(e=this.__kb_value)&&"function"==typeof e.setToDefault&&e.setToDefault()},r.ViewModel.prototype.setToDefault=function(){var e,t;for(e in this.__kb.vm_keys)null!=(t=this[e])&&"function"==typeof t.setToDefault&&t.setToDefault()},r.utils.setToDefault=function(e){var t,n;if(e){if(i.isObservable(e))"function"==typeof e.setToDefault&&e.setToDefault();else if(o.isObject(e))for(t in e)n=e[t],!n||!i.isObservable(n)&&"function"==typeof n||"_"===t[0]&&!t.search("__kb")||this.setToDefault(n);return e}}},function(e,t,n){var r,i,o,a,s,l,u,c;c=s=n(6),u=c._,l=c.ko,r=c.$,a=/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/,i=/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/,o=/^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/,s.valid={required:function(e){return!e},url:function(e){return!a.test(e)},email:function(e){return!i.test(e)},number:function(e){return!o.test(e)}},s.hasChangedFn=function(e){var t,n;return n=null,t=null,function(){var r;return n!==(r=l.utils.unwrapObservable(e))?(n=r,t=n?n.toJSON():null,!1):n&&t?!u.isEqual(n.toJSON(),t):!1}},s.minLengthFn=function(e){return function(t){return!t||t.lengthu;u++)i=o[u],e.bind(""+i+":"+t,s);else e.bind(""+o[0]+":"+t,s);return function(){var n,r;if(l===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},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(27),n(20),t],i=function(e,t,n){o.Backbone=a(o,n,e,t)}.apply(null,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(!u(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(!u(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,l,c,d,p;if(!this._events||!u(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),l=0,c=s.length;c>l;l++)if(e=s[l],a=this._events[e]){if(this._events[e]=i=[],t||r)for(d=0,p=a.length;p>d;d++)o=a[d],(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(!u(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}},l=/\s+/,u=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(l.test(n)){for(var o=n.split(l),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(;++rp;p++)this.trigger("change:"+s[p],this,d[s[p]],r)}if(u)return this;if(!l)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),void t.trigger("sync",t,n,e)):!1},I(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 l=this,u=r.success;return r.success=function(e){l.attributes=s;var t=l.parse(e,r);return r.wait&&(t=n.extend(i||{},t)),n.isObject(t)&&!l.set(t,r)?!1:(u&&u(l,e,r),void l.trigger("sync",l,e,r))},I(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;I(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")||F();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 f=["keys","values","pairs","invert","pick","omit"];n.each(f,function(e){p.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))},v={add:!0,remove:!0,merge:!0},b={add:!0,remove:!1};n.extend(h.prototype,s,{model:p,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,b))},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,v),t.parse&&(e=this.parse(e,t));var r=!n.isArray(e);e=r?e?[e]:[]:n.clone(e);var i,o,a,s,l,u,c,d=t.at,f=this.model,h=this.comparator&&null==d&&t.sort!==!1,b=n.isString(this.comparator)?this.comparator:null,m=[],g=[],y={},_=t.add,w=t.merge,x=t.remove,k=!h&&_&&x?[]:!1;for(i=0,o=e.length;o>i;i++){if(l=e[i]||{},a=l instanceof p?s=l:l[f.prototype.idAttribute||"id"],u=this.get(a))x&&(y[u.cid]=!0),w&&(l=l===s?s.attributes:l,t.parse&&(l=u.parse(l,t)),u.set(l,t),h&&!c&&u.hasChanged(b)&&(c=!0)),e[i]=u;else if(_){if(s=e[i]=this._prepareModel(l,t),!s)continue;m.push(s),this._addReference(s,t)}s=u||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(m.length||k&&k.length)if(h&&(c=!0),this.length+=m.length,null!=d)for(i=0,o=m.length;o>i;i++)this.models.splice(d+i,0,m[i]);else{k&&(this.models.length=0);var E=k||m;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=m.length;o>i;i++)(s=m[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)},I(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 p)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 m=["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(m,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")||F()),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 l=i.xhr=t.ajax(n.extend(a,i));return r.trigger("request",r,l,i),l};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)},O=/\((.*?)\)/g,S=/(\(\?)?:\w+/g,T=/\*\w+/g,C=/[\-{}\[\]+?.,\\\^$|#\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(C,"\\$&").replace(O,"(?:$1)?").replace(S,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,M=/^\/+|\/+$/g,A=/msie [\w.]+/,P=/\/$/,R=/#.*$/;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(P,"");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=A.exec(navigator.userAgent.toLowerCase())&&(!i||7>=i);if(this.root=("/"+this.root+"/").replace(M,"/"),o&&this._wantsHashChange){var a=t.$('