Commit 2a30629f authored by Kevin Malakoff's avatar Kevin Malakoff Committed by Sindre Sorhus

Close GH-291: Updated to Latest Knockback and simplified the implementation (take 2).

parent 1bb1340f
......@@ -4,7 +4,9 @@
task 'build', 'Build js/ from src/', ->
coffee = spawn 'coffee', ['-c', '-o', 'js', 'src']
coffee.stderr.on 'data', (data) ->
process.stderr.write data.toString()
message = data.toString()
if message.search('is now called') < 0
process.stderr.write message
coffee.stdout.on 'data', (data) ->
print data.toString()
coffee.on 'exit', (code) ->
......@@ -15,4 +17,4 @@ task 'watch', 'Watch src/ for changes', ->
coffee.stderr.on 'data', (data) ->
process.stderr.write data.toString()
coffee.stdout.on 'data', (data) ->
print data.toString()
print data.toString()
\ No newline at end of file
......@@ -10,68 +10,61 @@
<![endif]-->
</head>
<body>
<section id="todoapp">
<section id="todoapp" kb-inject="AppViewModel">
<header id="header">
<h1>todos</h1>
<input id="new-todo" type="text" data-bind="value: header.title, valueUpdate: 'afterkeydown', event: {keyup: header.onAddTodo}" placeholder="What needs to be done?" autofocus>
<input id="new-todo" type="text" data-bind="value: title, valueUpdate: 'afterkeydown', event: {keyup: onAddTodo}" placeholder="What needs to be done?" autofocus>
</header>
<section id="main" data-bind="block: todos.tasks_exist">
<input id="toggle-all" type="checkbox" data-bind="checked: todos.all_completed">
<section id="main" data-bind="block: tasks_exist">
<input id="toggle-all" type="checkbox" data-bind="checked: all_completed">
<label for="toggle-all">Mark all as complete</label>
<ul id="todo-list" data-bind="foreach: todos.todos">
<li data-bind="css: {completed: completed, editing: editing}, visible: visible">
<div class="view">
<ul id="todo-list" data-bind="foreach: todos">
<li data-bind="css: {completed: completed, editing: editing}">
<div class="view" data-bind="event: {dblclick: onCheckEditBegin}">
<input class="toggle" type="checkbox" data-bind="checked: completed" checked>
<label data-bind="text: title, event: {dblclick: onCheckEditBegin}"></label>
<label data-bind="text: title"></label>
<button class="destroy" data-bind="click: onDestroyTodo"></button>
</div>
<input class="edit" type="text" data-bind="value: title, selectAndFocus: editing, event: {blur: onCheckEditEnd, keyup: onCheckEditEnd}">
</li>
</ul>
</section>
<footer id="footer" data-bind="block: todos.tasks_exist">
<span id="todo-count" data-bind="html: footer.remaining_text"></span>
<footer id="footer" data-bind="block: tasks_exist">
<span id="todo-count" data-bind="html: loc.remaining_message"></span>
<ul id="filters">
<li>
<a href="#/" data-bind="css: {selected: settings.list_filter_mode()==''}">All</a>
<a href="#/" data-bind="css: {selected: list_filter_mode()==''}">All</a>
</li>
<li>
<a href="#/active" data-bind="css: {selected: settings.list_filter_mode()=='active'}">Active</a>
<a href="#/active" data-bind="css: {selected: list_filter_mode()=='active'}">Active</a>
</li>
<li>
<a href="#/completed" data-bind="css: {selected: settings.list_filter_mode()=='completed'}">Completed</a>
<a href="#/completed" data-bind="css: {selected: list_filter_mode()=='completed'}">Completed</a>
</li>
</ul>
<button id="clear-completed" data-bind="text: footer.clear_text, block: footer.clear_text, click: footer.onDestroyCompleted"></button>
<button id="clear-completed" data-bind="text: loc.clear_message, block: loc.clear_message, click: onDestroyCompleted"></button>
</footer>
</section>
<footer id="info">
<p>Double-click to edit a todo</p>
<p>Created by <a href="https://github.com/kmalakoff">Kevin Malakoff</a>. <br/>
Please try out the <a href="http://kmalakoff.github.com/knockback-todos/">enhanced version</a> <br/>
Please try out the <a href="http://kmalakoff.github.com/knockback-todos-app/">enhanced version</a> <br/>
with localization, priority colors, and lazy loading <br/>
to see just how dynamic <a href="https://github.com/kmalakoff/knockback">Knockback.js</a> can be!</p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer>
<!-- Demo Dependencies -->
<!-- App Dependencies -->
<script src="../../assets/base.js"></script>
<script src="../../assets/jquery.min.js"></script>
<!-- Knockback Dependencies -->
<script src="../../assets/lodash.min.js"></script>
<script src="js/lib/backbone-min.js"></script>
<script src="js/lib/knockout-2.1.0.js"></script>
<script src="js/lib/knockback.min.js"></script>
<!-- More Demo Dependencies -->
<script src="js/lib/knockback-full-stack-0.16.7.min.js"></script>
<script src="js/lib/backbone.localStorage-min.js"></script>
<!-- Demo Components -->
<!-- App and Components -->
<script src="js/lib/knockout-extended-bindings.js"></script>
<script src="js/models/todo.js"></script>
<script src="js/models/todo_collection.js"></script>
<script src="js/viewmodels/settings.js"></script>
<script src="js/viewmodels/header.js"></script>
<script src="js/viewmodels/todos.js"></script>
<script src="js/viewmodels/footer.js"></script>
<script src="js/routers/app.js"></script>
<!-- The Demo -->
<script src="js/app.js"></script>
<script src="js/viewmodels/todo.js"></script>
<script src="js/viewmodels/app.js"></script>
</body>
</html>
</html>
\ No newline at end of file
// Generated by CoffeeScript 1.3.3
(function() {
$(function() {
var todos;
ko.bindingHandlers.dblclick = {
init: function(element, value_accessor) {
return $(element).dblclick(ko.utils.unwrapObservable(value_accessor()));
}
};
ko.bindingHandlers.block = {
update: function(element, value_accessor) {
return element.style.display = ko.utils.unwrapObservable(value_accessor()) ? 'block' : 'none';
}
};
ko.bindingHandlers.selectAndFocus = {
init: function(element, value_accessor, all_bindings_accessor) {
ko.bindingHandlers.hasfocus.init(element, value_accessor, all_bindings_accessor);
return ko.utils.registerEventHandler(element, 'focus', function() {
return element.focus();
});
},
update: function(element, value_accessor) {
var _this = this;
ko.utils.unwrapObservable(value_accessor());
return _.defer(function() {
return ko.bindingHandlers.hasfocus.update(element, value_accessor);
});
}
};
window.app = {
viewmodels: {}
};
app.viewmodels.settings = new SettingsViewModel();
todos = new TodoCollection();
app.viewmodels.header = new HeaderViewModel(todos);
app.viewmodels.todos = new TodosViewModel(todos);
app.viewmodels.footer = new FooterViewModel(todos);
ko.applyBindings(app.viewmodels, $('#todoapp')[0]);
new AppRouter();
Backbone.history.start();
return todos.fetch();
});
}).call(this);
// Backbone.js 0.9.2
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org
(function(){var l=this,y=l.Backbone,z=Array.prototype.slice,A=Array.prototype.splice,g;g="undefined"!==typeof exports?exports:l.Backbone={};g.VERSION="0.9.2";var f=l._;!f&&"undefined"!==typeof require&&(f=require("underscore"));var i=l.jQuery||l.Zepto||l.ender;g.setDomLibrary=function(a){i=a};g.noConflict=function(){l.Backbone=y;return this};g.emulateHTTP=!1;g.emulateJSON=!1;var p=/\s+/,k=g.Events={on:function(a,b,c){var d,e,f,g,j;if(!b)return this;a=a.split(p);for(d=this._callbacks||(this._callbacks=
{});e=a.shift();)f=(j=d[e])?j.tail:{},f.next=g={},f.context=c,f.callback=b,d[e]={tail:g,next:j?j.next:f};return this},off:function(a,b,c){var d,e,h,g,j,q;if(e=this._callbacks){if(!a&&!b&&!c)return delete this._callbacks,this;for(a=a?a.split(p):f.keys(e);d=a.shift();)if(h=e[d],delete e[d],h&&(b||c))for(g=h.tail;(h=h.next)!==g;)if(j=h.callback,q=h.context,b&&j!==b||c&&q!==c)this.on(d,j,q);return this}},trigger:function(a){var b,c,d,e,f,g;if(!(d=this._callbacks))return this;f=d.all;a=a.split(p);for(g=
z.call(arguments,1);b=a.shift();){if(c=d[b])for(e=c.tail;(c=c.next)!==e;)c.callback.apply(c.context||this,g);if(c=f){e=c.tail;for(b=[b].concat(g);(c=c.next)!==e;)c.callback.apply(c.context||this,b)}}return this}};k.bind=k.on;k.unbind=k.off;var o=g.Model=function(a,b){var c;a||(a={});b&&b.parse&&(a=this.parse(a));if(c=n(this,"defaults"))a=f.extend({},c,a);b&&b.collection&&(this.collection=b.collection);this.attributes={};this._escapedAttributes={};this.cid=f.uniqueId("c");this.changed={};this._silent=
{};this._pending={};this.set(a,{silent:!0});this.changed={};this._silent={};this._pending={};this._previousAttributes=f.clone(this.attributes);this.initialize.apply(this,arguments)};f.extend(o.prototype,k,{changed:null,_silent:null,_pending:null,idAttribute:"id",initialize:function(){},toJSON:function(){return f.clone(this.attributes)},get:function(a){return this.attributes[a]},escape:function(a){var b;if(b=this._escapedAttributes[a])return b;b=this.get(a);return this._escapedAttributes[a]=f.escape(null==
b?"":""+b)},has:function(a){return null!=this.get(a)},set:function(a,b,c){var d,e;f.isObject(a)||null==a?(d=a,c=b):(d={},d[a]=b);c||(c={});if(!d)return this;d instanceof o&&(d=d.attributes);if(c.unset)for(e in d)d[e]=void 0;if(!this._validate(d,c))return!1;this.idAttribute in d&&(this.id=d[this.idAttribute]);var b=c.changes={},h=this.attributes,g=this._escapedAttributes,j=this._previousAttributes||{};for(e in d){a=d[e];if(!f.isEqual(h[e],a)||c.unset&&f.has(h,e))delete g[e],(c.silent?this._silent:
b)[e]=!0;c.unset?delete h[e]:h[e]=a;!f.isEqual(j[e],a)||f.has(h,e)!=f.has(j,e)?(this.changed[e]=a,c.silent||(this._pending[e]=!0)):(delete this.changed[e],delete this._pending[e])}c.silent||this.change(c);return this},unset:function(a,b){(b||(b={})).unset=!0;return this.set(a,null,b)},clear:function(a){(a||(a={})).unset=!0;return this.set(f.clone(this.attributes),a)},fetch:function(a){var a=a?f.clone(a):{},b=this,c=a.success;a.success=function(d,e,f){if(!b.set(b.parse(d,f),a))return!1;c&&c(b,d)};
a.error=g.wrapError(a.error,b,a);return(this.sync||g.sync).call(this,"read",this,a)},save:function(a,b,c){var d,e;f.isObject(a)||null==a?(d=a,c=b):(d={},d[a]=b);c=c?f.clone(c):{};if(c.wait){if(!this._validate(d,c))return!1;e=f.clone(this.attributes)}a=f.extend({},c,{silent:!0});if(d&&!this.set(d,c.wait?a:c))return!1;var h=this,i=c.success;c.success=function(a,b,e){b=h.parse(a,e);if(c.wait){delete c.wait;b=f.extend(d||{},b)}if(!h.set(b,c))return false;i?i(h,a):h.trigger("sync",h,a,c)};c.error=g.wrapError(c.error,
h,c);b=this.isNew()?"create":"update";b=(this.sync||g.sync).call(this,b,this,c);c.wait&&this.set(e,a);return b},destroy:function(a){var a=a?f.clone(a):{},b=this,c=a.success,d=function(){b.trigger("destroy",b,b.collection,a)};if(this.isNew())return d(),!1;a.success=function(e){a.wait&&d();c?c(b,e):b.trigger("sync",b,e,a)};a.error=g.wrapError(a.error,b,a);var e=(this.sync||g.sync).call(this,"delete",this,a);a.wait||d();return e},url:function(){var a=n(this,"urlRoot")||n(this.collection,"url")||t();
return this.isNew()?a:a+("/"==a.charAt(a.length-1)?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return null==this.id},change:function(a){a||(a={});var b=this._changing;this._changing=!0;for(var c in this._silent)this._pending[c]=!0;var d=f.extend({},a.changes,this._silent);this._silent={};for(c in d)this.trigger("change:"+c,this,this.get(c),a);if(b)return this;for(;!f.isEmpty(this._pending);){this._pending=
{};this.trigger("change",this,a);for(c in this.changed)!this._pending[c]&&!this._silent[c]&&delete this.changed[c];this._previousAttributes=f.clone(this.attributes)}this._changing=!1;return this},hasChanged:function(a){return!arguments.length?!f.isEmpty(this.changed):f.has(this.changed,a)},changedAttributes:function(a){if(!a)return this.hasChanged()?f.clone(this.changed):!1;var b,c=!1,d=this._previousAttributes,e;for(e in a)if(!f.isEqual(d[e],b=a[e]))(c||(c={}))[e]=b;return c},previous:function(a){return!arguments.length||
!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){return f.clone(this._previousAttributes)},isValid:function(){return!this.validate(this.attributes)},_validate:function(a,b){if(b.silent||!this.validate)return!0;var a=f.extend({},this.attributes,a),c=this.validate(a,b);if(!c)return!0;b&&b.error?b.error(this,c,b):this.trigger("error",this,c,b);return!1}});var r=g.Collection=function(a,b){b||(b={});b.model&&(this.model=b.model);b.comparator&&(this.comparator=b.comparator);
this._reset();this.initialize.apply(this,arguments);a&&this.reset(a,{silent:!0,parse:b.parse})};f.extend(r.prototype,k,{model:o,initialize:function(){},toJSON:function(a){return this.map(function(b){return b.toJSON(a)})},add:function(a,b){var c,d,e,g,i,j={},k={},l=[];b||(b={});a=f.isArray(a)?a.slice():[a];c=0;for(d=a.length;c<d;c++){if(!(e=a[c]=this._prepareModel(a[c],b)))throw Error("Can't add an invalid model to a collection");g=e.cid;i=e.id;j[g]||this._byCid[g]||null!=i&&(k[i]||this._byId[i])?
l.push(c):j[g]=k[i]=e}for(c=l.length;c--;)a.splice(l[c],1);c=0;for(d=a.length;c<d;c++)(e=a[c]).on("all",this._onModelEvent,this),this._byCid[e.cid]=e,null!=e.id&&(this._byId[e.id]=e);this.length+=d;A.apply(this.models,[null!=b.at?b.at:this.models.length,0].concat(a));this.comparator&&this.sort({silent:!0});if(b.silent)return this;c=0;for(d=this.models.length;c<d;c++)if(j[(e=this.models[c]).cid])b.index=c,e.trigger("add",e,this,b);return this},remove:function(a,b){var c,d,e,g;b||(b={});a=f.isArray(a)?
a.slice():[a];c=0;for(d=a.length;c<d;c++)if(g=this.getByCid(a[c])||this.get(a[c]))delete this._byId[g.id],delete this._byCid[g.cid],e=this.indexOf(g),this.models.splice(e,1),this.length--,b.silent||(b.index=e,g.trigger("remove",g,this,b)),this._removeReference(g);return this},push:function(a,b){a=this._prepareModel(a,b);this.add(a,b);return a},pop:function(a){var b=this.at(this.length-1);this.remove(b,a);return b},unshift:function(a,b){a=this._prepareModel(a,b);this.add(a,f.extend({at:0},b));return a},
shift:function(a){var b=this.at(0);this.remove(b,a);return b},get:function(a){return null==a?void 0:this._byId[null!=a.id?a.id:a]},getByCid:function(a){return a&&this._byCid[a.cid||a]},at:function(a){return this.models[a]},where:function(a){return f.isEmpty(a)?[]:this.filter(function(b){for(var c in a)if(a[c]!==b.get(c))return!1;return!0})},sort:function(a){a||(a={});if(!this.comparator)throw Error("Cannot sort a set without a comparator");var b=f.bind(this.comparator,this);1==this.comparator.length?
this.models=this.sortBy(b):this.models.sort(b);a.silent||this.trigger("reset",this,a);return this},pluck:function(a){return f.map(this.models,function(b){return b.get(a)})},reset:function(a,b){a||(a=[]);b||(b={});for(var c=0,d=this.models.length;c<d;c++)this._removeReference(this.models[c]);this._reset();this.add(a,f.extend({silent:!0},b));b.silent||this.trigger("reset",this,b);return this},fetch:function(a){a=a?f.clone(a):{};void 0===a.parse&&(a.parse=!0);var b=this,c=a.success;a.success=function(d,
e,f){b[a.add?"add":"reset"](b.parse(d,f),a);c&&c(b,d)};a.error=g.wrapError(a.error,b,a);return(this.sync||g.sync).call(this,"read",this,a)},create:function(a,b){var c=this,b=b?f.clone(b):{},a=this._prepareModel(a,b);if(!a)return!1;b.wait||c.add(a,b);var d=b.success;b.success=function(e,f){b.wait&&c.add(e,b);d?d(e,f):e.trigger("sync",a,f,b)};a.save(null,b);return a},parse:function(a){return a},chain:function(){return f(this.models).chain()},_reset:function(){this.length=0;this.models=[];this._byId=
{};this._byCid={}},_prepareModel:function(a,b){b||(b={});a instanceof o?a.collection||(a.collection=this):(b.collection=this,a=new this.model(a,b),a._validate(a.attributes,b)||(a=!1));return a},_removeReference:function(a){this==a.collection&&delete a.collection;a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,b,c,d){("add"==a||"remove"==a)&&c!=this||("destroy"==a&&this.remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],this._byId[b.id]=b),this.trigger.apply(this,
arguments))}});f.each("forEach,each,map,reduce,reduceRight,find,detect,filter,select,reject,every,all,some,any,include,contains,invoke,max,min,sortBy,sortedIndex,toArray,size,first,initial,rest,last,without,indexOf,shuffle,lastIndexOf,isEmpty,groupBy".split(","),function(a){r.prototype[a]=function(){return f[a].apply(f,[this.models].concat(f.toArray(arguments)))}});var u=g.Router=function(a){a||(a={});a.routes&&(this.routes=a.routes);this._bindRoutes();this.initialize.apply(this,arguments)},B=/:\w+/g,
C=/\*\w+/g,D=/[-[\]{}()+?.,\\^$|#\s]/g;f.extend(u.prototype,k,{initialize:function(){},route:function(a,b,c){g.history||(g.history=new m);f.isRegExp(a)||(a=this._routeToRegExp(a));c||(c=this[b]);g.history.route(a,f.bind(function(d){d=this._extractParameters(a,d);c&&c.apply(this,d);this.trigger.apply(this,["route:"+b].concat(d));g.history.trigger("route",this,b,d)},this));return this},navigate:function(a,b){g.history.navigate(a,b)},_bindRoutes:function(){if(this.routes){var a=[],b;for(b in this.routes)a.unshift([b,
this.routes[b]]);b=0;for(var c=a.length;b<c;b++)this.route(a[b][0],a[b][1],this[a[b][1]])}},_routeToRegExp:function(a){a=a.replace(D,"\\$&").replace(B,"([^/]+)").replace(C,"(.*?)");return RegExp("^"+a+"$")},_extractParameters:function(a,b){return a.exec(b).slice(1)}});var m=g.History=function(){this.handlers=[];f.bindAll(this,"checkUrl")},s=/^[#\/]/,E=/msie [\w.]+/;m.started=!1;f.extend(m.prototype,k,{interval:50,getHash:function(a){return(a=(a?a.location:window.location).href.match(/#(.*)$/))?a[1]:
""},getFragment:function(a,b){if(null==a)if(this._hasPushState||b){var a=window.location.pathname,c=window.location.search;c&&(a+=c)}else a=this.getHash();a.indexOf(this.options.root)||(a=a.substr(this.options.root.length));return a.replace(s,"")},start:function(a){if(m.started)throw Error("Backbone.history has already been started");m.started=!0;this.options=f.extend({},{root:"/"},this.options,a);this._wantsHashChange=!1!==this.options.hashChange;this._wantsPushState=!!this.options.pushState;this._hasPushState=
!(!this.options.pushState||!window.history||!window.history.pushState);var a=this.getFragment(),b=document.documentMode;if(b=E.exec(navigator.userAgent.toLowerCase())&&(!b||7>=b))this.iframe=i('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(a);this._hasPushState?i(window).bind("popstate",this.checkUrl):this._wantsHashChange&&"onhashchange"in window&&!b?i(window).bind("hashchange",this.checkUrl):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,
this.interval));this.fragment=a;a=window.location;b=a.pathname==this.options.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!b)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;this._wantsPushState&&this._hasPushState&&b&&a.hash&&(this.fragment=this.getHash().replace(s,""),window.history.replaceState({},document.title,a.protocol+"//"+a.host+this.options.root+this.fragment));if(!this.options.silent)return this.loadUrl()},
stop:function(){i(window).unbind("popstate",this.checkUrl).unbind("hashchange",this.checkUrl);clearInterval(this._checkUrlInterval);m.started=!1},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a==this.fragment&&this.iframe&&(a=this.getFragment(this.getHash(this.iframe)));if(a==this.fragment)return!1;this.iframe&&this.navigate(a);this.loadUrl()||this.loadUrl(this.getHash())},loadUrl:function(a){var b=this.fragment=this.getFragment(a);return f.any(this.handlers,
function(a){if(a.route.test(b))return a.callback(b),!0})},navigate:function(a,b){if(!m.started)return!1;if(!b||!0===b)b={trigger:b};var c=(a||"").replace(s,"");this.fragment!=c&&(this._hasPushState?(0!=c.indexOf(this.options.root)&&(c=this.options.root+c),this.fragment=c,window.history[b.replace?"replaceState":"pushState"]({},document.title,c)):this._wantsHashChange?(this.fragment=c,this._updateHash(window.location,c,b.replace),this.iframe&&c!=this.getFragment(this.getHash(this.iframe))&&(b.replace||
this.iframe.document.open().close(),this._updateHash(this.iframe.location,c,b.replace))):window.location.assign(this.options.root+a),b.trigger&&this.loadUrl(a))},_updateHash:function(a,b,c){c?a.replace(a.toString().replace(/(javascript:|#).*$/,"")+"#"+b):a.hash=b}});var v=g.View=function(a){this.cid=f.uniqueId("view");this._configure(a||{});this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()},F=/^(\S+)\s*(.*)$/,w="model,collection,el,id,attributes,className,tagName".split(",");
f.extend(v.prototype,k,{tagName:"div",$:function(a){return this.$el.find(a)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();return this},make:function(a,b,c){a=document.createElement(a);b&&i(a).attr(b);c&&i(a).html(c);return a},setElement:function(a,b){this.$el&&this.undelegateEvents();this.$el=a instanceof i?a:i(a);this.el=this.$el[0];!1!==b&&this.delegateEvents();return this},delegateEvents:function(a){if(a||(a=n(this,"events"))){this.undelegateEvents();
for(var b in a){var c=a[b];f.isFunction(c)||(c=this[a[b]]);if(!c)throw Error('Method "'+a[b]+'" does not exist');var d=b.match(F),e=d[1],d=d[2],c=f.bind(c,this),e=e+(".delegateEvents"+this.cid);""===d?this.$el.bind(e,c):this.$el.delegate(d,e,c)}}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(var b=0,c=w.length;b<c;b++){var d=w[b];a[d]&&(this[d]=a[d])}this.options=a},_ensureElement:function(){if(this.el)this.setElement(this.el,
!1);else{var a=n(this,"attributes")||{};this.id&&(a.id=this.id);this.className&&(a["class"]=this.className);this.setElement(this.make(this.tagName,a),!1)}}});o.extend=r.extend=u.extend=v.extend=function(a,b){var c=G(this,a,b);c.extend=this.extend;return c};var H={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};g.sync=function(a,b,c){var d=H[a];c||(c={});var e={type:d,dataType:"json"};c.url||(e.url=n(b,"url")||t());if(!c.data&&b&&("create"==a||"update"==a))e.contentType="application/json",
e.data=JSON.stringify(b.toJSON());g.emulateJSON&&(e.contentType="application/x-www-form-urlencoded",e.data=e.data?{model:e.data}:{});if(g.emulateHTTP&&("PUT"===d||"DELETE"===d))g.emulateJSON&&(e.data._method=d),e.type="POST",e.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",d)};"GET"!==e.type&&!g.emulateJSON&&(e.processData=!1);return i.ajax(f.extend(e,c))};g.wrapError=function(a,b,c){return function(d,e){e=d===b?e:d;a?a(b,e,c):b.trigger("error",b,e,c)}};var x=function(){},G=function(a,
b,c){var d;d=b&&b.hasOwnProperty("constructor")?b.constructor:function(){a.apply(this,arguments)};f.extend(d,a);x.prototype=a.prototype;d.prototype=new x;b&&f.extend(d.prototype,b);c&&f.extend(d,c);d.prototype.constructor=d;d.__super__=a.prototype;return d},n=function(a,b){return!a||!a[b]?null:f.isFunction(a[b])?a[b]():a[b]},t=function(){throw Error('A "url" property or function must be specified');}}).call(this);
/**
* Backbone localStorage Adapter
* https://github.com/jeromegn/Backbone.localStorage
*/(function(){function a(){return((1+Math.random())*65536|0).toString(16).substring(1)}function b(){return a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()}Backbone.LocalStorage=window.Store=function(a){this.name=a;var b=this.localStorage().getItem(this.name);this.records=b&&b.split(",")||[]},_.extend(Backbone.LocalStorage.prototype,{save:function(){this.localStorage().setItem(this.name,this.records.join(","))},create:function(a){return a.id||(a.id=b(),a.set(a.idAttribute,a.id)),this.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),this.records.push(a.id.toString()),this.save(),a},update:function(a){return this.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),_.include(this.records,a.id.toString())||this.records.push(a.id.toString()),this.save(),a},find:function(a){return JSON.parse(this.localStorage().getItem(this.name+"-"+a.id))},findAll:function(){return _(this.records).chain().map(function(a){return JSON.parse(this.localStorage().getItem(this.name+"-"+a))},this).compact().value()},destroy:function(a){return this.localStorage().removeItem(this.name+"-"+a.id),this.records=_.reject(this.records,function(b){return b==a.id.toString()}),this.save(),a},localStorage:function(){return localStorage}}),Backbone.LocalStorage.sync=window.Store.sync=Backbone.localSync=function(a,b,c,d){var e=b.localStorage||b.collection.localStorage;typeof c=="function"&&(c={success:c,error:d});var f;switch(a){case"read":f=b.id!=undefined?e.find(b):e.findAll();break;case"create":f=e.create(b);break;case"update":f=e.update(b);break;case"delete":f=e.destroy(b)}f?c.success(f):c.error("Record not found")},Backbone.ajaxSync=Backbone.sync,Backbone.getSyncMethod=function(a){return a.localStorage||a.collection&&a.collection.localStorage?Backbone.localSync:Backbone.ajaxSync},Backbone.sync=function(a,b,c,d){return Backbone.getSyncMethod(b).apply(this,[a,b,c,d])}})();
*/(function(){function a(){return((1+Math.random())*65536|0).toString(16).substring(1)}function b(){return a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()}Backbone.LocalStorage=window.Store=function(a){this.name=a;var b=this.localStorage().getItem(this.name);this.records=b&&b.split(",")||[]},_.extend(Backbone.LocalStorage.prototype,{save:function(){this.localStorage().setItem(this.name,this.records.join(","))},create:function(a){return a.id||(a.id=b(),a.set(a.idAttribute,a.id)),this.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),this.records.push(a.id.toString()),this.save(),a},update:function(a){return this.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),_.include(this.records,a.id.toString())||this.records.push(a.id.toString()),this.save(),a},find:function(a){return JSON.parse(this.localStorage().getItem(this.name+"-"+a.id))},findAll:function(){return _(this.records).chain().map(function(a){return JSON.parse(this.localStorage().getItem(this.name+"-"+a))},this).compact().value()},destroy:function(a){return this.localStorage().removeItem(this.name+"-"+a.id),this.records=_.reject(this.records,function(b){return b==a.id.toString()}),this.save(),a},localStorage:function(){return localStorage}}),Backbone.LocalStorage.sync=window.Store.sync=Backbone.localSync=function(a,b,c,d){var e=b.localStorage||b.collection.localStorage;typeof c=="function"&&(c={success:c,error:d});var f;switch(a){case"read":f=b.id!=undefined?e.find(b):e.findAll();break;case"create":f=e.create(b);break;case"update":f=e.update(b);break;case"delete":f=e.destroy(b)}f?c.success(f):c.error("Record not found")},Backbone.ajaxSync=Backbone.sync,Backbone.getSyncMethod=function(a){return a.localStorage||a.collection&&a.collection.localStorage?Backbone.localSync:Backbone.ajaxSync},Backbone.sync=function(a,b,c,d){return Backbone.getSyncMethod(b).apply(this,[a,b,c,d])}})();
\ No newline at end of file
/*
knockback-full-stack.js 0.16.7
(c) 2011, 2012 Kevin Malakoff - http://kmalakoff.github.com/knockback/
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
*/
// Underscore.js 1.3.3
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore is freely distributable under the MIT license.
// Portions of Underscore are inspired or borrowed from Prototype,
// Oliver Steele's Functional, and John Resig's Micro-Templating.
// For all details and documentation:
// http://documentcloud.github.com/underscore
(function(){function r(a,c,d){if(a===c)return 0!==a||1/a==1/c;if(null==a||null==c)return a===c;a._chain&&(a=a._wrapped);c._chain&&(c=c._wrapped);if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return!1;switch(e){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:0==a?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==
c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if("object"!=typeof a||"object"!=typeof c)return!1;for(var f=d.length;f--;)if(d[f]==a)return!0;d.push(a);var f=0,g=!0;if("[object Array]"==e){if(f=a.length,g=f==c.length)for(;f--&&(g=f in a==f in c&&r(a[f],c[f],d)););}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return!1;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&r(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c,h)&&!f--)break;
g=!f}}d.pop();return g}var s=this,I=s._,o={},k=Array.prototype,p=Object.prototype,i=k.slice,J=k.unshift,l=p.toString,K=p.hasOwnProperty,y=k.forEach,z=k.map,A=k.reduce,B=k.reduceRight,C=k.filter,D=k.every,E=k.some,q=k.indexOf,F=k.lastIndexOf,p=Array.isArray,L=Object.keys,t=Function.prototype.bind,b=function(a){return new m(a)};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._=b):s._=b;b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,
c,d){if(a!=null)if(y&&a.forEach===y)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e<f;e++){if(e in a&&c.call(d,a[e],e,a)===o)break}else for(e in a)if(b.has(a,e)&&c.call(d,a[e],e,a)===o)break};b.map=b.collect=function(a,c,b){var e=[];if(a==null)return e;if(z&&a.map===z)return a.map(c,b);j(a,function(a,g,h){e[e.length]=c.call(b,a,g,h)});if(a.length===+a.length)e.length=a.length;return e};b.reduce=b.foldl=b.inject=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(A&&
a.reduce===A){e&&(c=b.bind(c,e));return f?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,i){if(f)d=c.call(e,d,a,b,i);else{d=a;f=true}});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));return f?a.reduceRight(c,d):a.reduceRight(c)}var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect=function(a,
c,b){var e;G(a,function(a,g,h){if(c.call(b,a,g,h)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(C&&a.filter===C)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(D&&a.every===D)return a.every(c,b);j(a,function(a,g,h){if(!(e=e&&c.call(b,
a,g,h)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck=
function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0])return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0])return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b<e.computed&&
(e={value:a,computed:b})});return e.value};b.shuffle=function(a){var b=[],d;j(a,function(a,f){d=Math.floor(Math.random()*(f+1));b[f]=b[d];b[d]=a});return b};b.sortBy=function(a,c,d){var e=b.isFunction(c)?c:function(a){return a[c]};return b.pluck(b.map(a,function(a,b,c){return{value:a,criteria:e.call(d,a,b,c)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;return c===void 0?1:d===void 0?-1:c<d?-1:c>d?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};
j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var e=0,f=a.length;e<f;){var g=e+f>>1;d(a[g])<d(c)?e=g+1:f=g}return e};b.toArray=function(a){return!a?[]:b.isArray(a)||b.isArguments(a)?i.call(a):a.toArray&&b.isFunction(a.toArray)?a.toArray():b.values(a)};b.size=function(a){return b.isArray(a)?a.length:b.keys(a).length};b.first=b.head=b.take=function(a,b,d){return b!=null&&!d?i.call(a,0,b):a[0]};b.initial=function(a,b,d){return i.call(a,
0,a.length-(b==null||d?1:b))};b.last=function(a,b,d){return b!=null&&!d?i.call(a,Math.max(a.length-b,0)):a[a.length-1]};b.rest=b.tail=function(a,b,d){return i.call(a,b==null||d?1:b)};b.compact=function(a){return b.filter(a,function(a){return!!a})};b.flatten=function(a,c){return b.reduce(a,function(a,e){if(b.isArray(e))return a.concat(c?e:b.flatten(e));a[a.length]=e;return a},[])};b.without=function(a){return b.difference(a,i.call(arguments,1))};b.uniq=b.unique=function(a,c,d){var d=d?b.map(a,d):a,
e=[];a.length<3&&(c=true);b.reduce(d,function(d,g,h){if(c?b.last(d)!==g||!d.length:!b.include(d,g)){d.push(g);e.push(a[h])}return d},[]);return e};b.union=function(){return b.uniq(b.flatten(arguments,true))};b.intersection=b.intersect=function(a){var c=i.call(arguments,1);return b.filter(b.uniq(a),function(a){return b.every(c,function(c){return b.indexOf(c,a)>=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1),true);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=
i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e<c;e++)d[e]=b.pluck(a,""+e);return d};b.indexOf=function(a,c,d){if(a==null)return-1;var e;if(d){d=b.sortedIndex(a,c);return a[d]===c?d:-1}if(q&&a.indexOf===q)return a.indexOf(c);d=0;for(e=a.length;d<e;d++)if(d in a&&a[d]===c)return d;return-1};b.lastIndexOf=function(a,b){if(a==null)return-1;if(F&&a.lastIndexOf===F)return a.lastIndexOf(b);for(var d=a.length;d--;)if(d in a&&a[d]===b)return d;return-1};b.range=function(a,b,d){if(arguments.length<=
1){b=a||0;a=0}for(var d=arguments[2]||1,e=Math.max(Math.ceil((b-a)/d),0),f=0,g=Array(e);f<e;){g[f++]=a;a=a+d}return g};var H=function(){};b.bind=function(a,c){var d,e;if(a.bind===t&&t)return t.apply(a,i.call(arguments,1));if(!b.isFunction(a))throw new TypeError;e=i.call(arguments,2);return d=function(){if(!(this instanceof d))return a.apply(c,e.concat(i.call(arguments)));H.prototype=a.prototype;var b=new H,g=a.apply(b,e.concat(i.call(arguments)));return Object(g)===g?g:b}};b.bindAll=function(a){var c=
i.call(arguments,1);c.length==0&&(c=b.functions(a));j(c,function(c){a[c]=b.bind(a[c],a)});return a};b.memoize=function(a,c){var d={};c||(c=b.identity);return function(){var e=c.apply(this,arguments);return b.has(d,e)?d[e]:d[e]=a.apply(this,arguments)}};b.delay=function(a,b){var d=i.call(arguments,2);return setTimeout(function(){return a.apply(null,d)},b)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(i.call(arguments,1)))};b.throttle=function(a,c){var d,e,f,g,h,i,j=b.debounce(function(){h=
g=false},c);return function(){d=this;e=arguments;f||(f=setTimeout(function(){f=null;h&&a.apply(d,e);j()},c));g?h=true:i=a.apply(d,e);j();g=true;return i}};b.debounce=function(a,b,d){var e;return function(){var f=this,g=arguments;d&&!e&&a.apply(f,g);clearTimeout(e);e=setTimeout(function(){e=null;d||a.apply(f,g)},b)}};b.once=function(a){var b=false,d;return function(){if(b)return d;b=true;return d=a.apply(this,arguments)}};b.wrap=function(a,b){return function(){var d=[a].concat(i.call(arguments,0));
return b.apply(this,d)}};b.compose=function(){var a=arguments;return function(){for(var b=arguments,d=a.length-1;d>=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=L||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&
c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var c={};j(b.flatten(i.call(arguments,1)),function(b){b in a&&(c[b]=a[b])});return c};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return r(a,b,[])};b.isEmpty=
function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};b.isArguments=function(a){return l.call(a)=="[object Arguments]"};b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFunction=function(a){return l.call(a)=="[object Function]"};
b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"};b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,
b){return K.call(a,b)};b.noConflict=function(){s._=I;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e<a;e++)b.call(d,e)};b.escape=function(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;")};b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){M(c,b[c]=a[c])})};var N=0;b.uniqueId=
function(a){var b=N++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var u=/.^/,n={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},v;for(v in n)n[n[v]]=v;var O=/\\|'|\r|\n|\t|\u2028|\u2029/g,P=/\\(\\|'|r|n|t|u2028|u2029)/g,w=function(a){return a.replace(P,function(a,b){return n[b]})};b.template=function(a,c,d){d=b.defaults(d||{},b.templateSettings);a="__p+='"+a.replace(O,function(a){return"\\"+n[a]}).replace(d.escape||
u,function(a,b){return"'+\n_.escape("+w(b)+")+\n'"}).replace(d.interpolate||u,function(a,b){return"'+\n("+w(b)+")+\n'"}).replace(d.evaluate||u,function(a,b){return"';\n"+w(b)+"\n;__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+a+"}\n");var a="var __p='';var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n"+a+"return __p;\n",e=new Function(d.variable||"obj","_",a);if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c};
b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var x=function(a,c){return c?b(a).chain():a},M=function(a,c){m.prototype[a]=function(){var a=i.call(arguments);J.call(a,this._wrapped);return x(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return x(d,
this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return x(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain=true;return this};m.prototype.value=function(){return this._wrapped}}).call(this);
// Backbone.js 0.9.2
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org
(function(){var l=this,y=l.Backbone,z=Array.prototype.slice,A=Array.prototype.splice,g;g="undefined"!==typeof exports?exports:l.Backbone={};g.VERSION="0.9.2";var f=l._;!f&&"undefined"!==typeof require&&(f=require("underscore"));var i=l.jQuery||l.Zepto||l.ender;g.setDomLibrary=function(a){i=a};g.noConflict=function(){l.Backbone=y;return this};g.emulateHTTP=!1;g.emulateJSON=!1;var p=/\s+/,k=g.Events={on:function(a,b,c){var d,e,f,g,j;if(!b)return this;a=a.split(p);for(d=this._callbacks||(this._callbacks=
{});e=a.shift();)f=(j=d[e])?j.tail:{},f.next=g={},f.context=c,f.callback=b,d[e]={tail:g,next:j?j.next:f};return this},off:function(a,b,c){var d,e,h,g,j,q;if(e=this._callbacks){if(!a&&!b&&!c)return delete this._callbacks,this;for(a=a?a.split(p):f.keys(e);d=a.shift();)if(h=e[d],delete e[d],h&&(b||c))for(g=h.tail;(h=h.next)!==g;)if(j=h.callback,q=h.context,b&&j!==b||c&&q!==c)this.on(d,j,q);return this}},trigger:function(a){var b,c,d,e,f,g;if(!(d=this._callbacks))return this;f=d.all;a=a.split(p);for(g=
z.call(arguments,1);b=a.shift();){if(c=d[b])for(e=c.tail;(c=c.next)!==e;)c.callback.apply(c.context||this,g);if(c=f){e=c.tail;for(b=[b].concat(g);(c=c.next)!==e;)c.callback.apply(c.context||this,b)}}return this}};k.bind=k.on;k.unbind=k.off;var o=g.Model=function(a,b){var c;a||(a={});b&&b.parse&&(a=this.parse(a));if(c=n(this,"defaults"))a=f.extend({},c,a);b&&b.collection&&(this.collection=b.collection);this.attributes={};this._escapedAttributes={};this.cid=f.uniqueId("c");this.changed={};this._silent=
{};this._pending={};this.set(a,{silent:!0});this.changed={};this._silent={};this._pending={};this._previousAttributes=f.clone(this.attributes);this.initialize.apply(this,arguments)};f.extend(o.prototype,k,{changed:null,_silent:null,_pending:null,idAttribute:"id",initialize:function(){},toJSON:function(){return f.clone(this.attributes)},get:function(a){return this.attributes[a]},escape:function(a){var b;if(b=this._escapedAttributes[a])return b;b=this.get(a);return this._escapedAttributes[a]=f.escape(null==
b?"":""+b)},has:function(a){return null!=this.get(a)},set:function(a,b,c){var d,e;f.isObject(a)||null==a?(d=a,c=b):(d={},d[a]=b);c||(c={});if(!d)return this;d instanceof o&&(d=d.attributes);if(c.unset)for(e in d)d[e]=void 0;if(!this._validate(d,c))return!1;this.idAttribute in d&&(this.id=d[this.idAttribute]);var b=c.changes={},h=this.attributes,g=this._escapedAttributes,j=this._previousAttributes||{};for(e in d){a=d[e];if(!f.isEqual(h[e],a)||c.unset&&f.has(h,e))delete g[e],(c.silent?this._silent:
b)[e]=!0;c.unset?delete h[e]:h[e]=a;!f.isEqual(j[e],a)||f.has(h,e)!=f.has(j,e)?(this.changed[e]=a,c.silent||(this._pending[e]=!0)):(delete this.changed[e],delete this._pending[e])}c.silent||this.change(c);return this},unset:function(a,b){(b||(b={})).unset=!0;return this.set(a,null,b)},clear:function(a){(a||(a={})).unset=!0;return this.set(f.clone(this.attributes),a)},fetch:function(a){var a=a?f.clone(a):{},b=this,c=a.success;a.success=function(d,e,f){if(!b.set(b.parse(d,f),a))return!1;c&&c(b,d)};
a.error=g.wrapError(a.error,b,a);return(this.sync||g.sync).call(this,"read",this,a)},save:function(a,b,c){var d,e;f.isObject(a)||null==a?(d=a,c=b):(d={},d[a]=b);c=c?f.clone(c):{};if(c.wait){if(!this._validate(d,c))return!1;e=f.clone(this.attributes)}a=f.extend({},c,{silent:!0});if(d&&!this.set(d,c.wait?a:c))return!1;var h=this,i=c.success;c.success=function(a,b,e){b=h.parse(a,e);if(c.wait){delete c.wait;b=f.extend(d||{},b)}if(!h.set(b,c))return false;i?i(h,a):h.trigger("sync",h,a,c)};c.error=g.wrapError(c.error,
h,c);b=this.isNew()?"create":"update";b=(this.sync||g.sync).call(this,b,this,c);c.wait&&this.set(e,a);return b},destroy:function(a){var a=a?f.clone(a):{},b=this,c=a.success,d=function(){b.trigger("destroy",b,b.collection,a)};if(this.isNew())return d(),!1;a.success=function(e){a.wait&&d();c?c(b,e):b.trigger("sync",b,e,a)};a.error=g.wrapError(a.error,b,a);var e=(this.sync||g.sync).call(this,"delete",this,a);a.wait||d();return e},url:function(){var a=n(this,"urlRoot")||n(this.collection,"url")||t();
return this.isNew()?a:a+("/"==a.charAt(a.length-1)?"":"/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return null==this.id},change:function(a){a||(a={});var b=this._changing;this._changing=!0;for(var c in this._silent)this._pending[c]=!0;var d=f.extend({},a.changes,this._silent);this._silent={};for(c in d)this.trigger("change:"+c,this,this.get(c),a);if(b)return this;for(;!f.isEmpty(this._pending);){this._pending=
{};this.trigger("change",this,a);for(c in this.changed)!this._pending[c]&&!this._silent[c]&&delete this.changed[c];this._previousAttributes=f.clone(this.attributes)}this._changing=!1;return this},hasChanged:function(a){return!arguments.length?!f.isEmpty(this.changed):f.has(this.changed,a)},changedAttributes:function(a){if(!a)return this.hasChanged()?f.clone(this.changed):!1;var b,c=!1,d=this._previousAttributes,e;for(e in a)if(!f.isEqual(d[e],b=a[e]))(c||(c={}))[e]=b;return c},previous:function(a){return!arguments.length||
!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){return f.clone(this._previousAttributes)},isValid:function(){return!this.validate(this.attributes)},_validate:function(a,b){if(b.silent||!this.validate)return!0;var a=f.extend({},this.attributes,a),c=this.validate(a,b);if(!c)return!0;b&&b.error?b.error(this,c,b):this.trigger("error",this,c,b);return!1}});var r=g.Collection=function(a,b){b||(b={});b.model&&(this.model=b.model);b.comparator&&(this.comparator=b.comparator);
this._reset();this.initialize.apply(this,arguments);a&&this.reset(a,{silent:!0,parse:b.parse})};f.extend(r.prototype,k,{model:o,initialize:function(){},toJSON:function(a){return this.map(function(b){return b.toJSON(a)})},add:function(a,b){var c,d,e,g,i,j={},k={},l=[];b||(b={});a=f.isArray(a)?a.slice():[a];c=0;for(d=a.length;c<d;c++){if(!(e=a[c]=this._prepareModel(a[c],b)))throw Error("Can't add an invalid model to a collection");g=e.cid;i=e.id;j[g]||this._byCid[g]||null!=i&&(k[i]||this._byId[i])?
l.push(c):j[g]=k[i]=e}for(c=l.length;c--;)a.splice(l[c],1);c=0;for(d=a.length;c<d;c++)(e=a[c]).on("all",this._onModelEvent,this),this._byCid[e.cid]=e,null!=e.id&&(this._byId[e.id]=e);this.length+=d;A.apply(this.models,[null!=b.at?b.at:this.models.length,0].concat(a));this.comparator&&this.sort({silent:!0});if(b.silent)return this;c=0;for(d=this.models.length;c<d;c++)if(j[(e=this.models[c]).cid])b.index=c,e.trigger("add",e,this,b);return this},remove:function(a,b){var c,d,e,g;b||(b={});a=f.isArray(a)?
a.slice():[a];c=0;for(d=a.length;c<d;c++)if(g=this.getByCid(a[c])||this.get(a[c]))delete this._byId[g.id],delete this._byCid[g.cid],e=this.indexOf(g),this.models.splice(e,1),this.length--,b.silent||(b.index=e,g.trigger("remove",g,this,b)),this._removeReference(g);return this},push:function(a,b){a=this._prepareModel(a,b);this.add(a,b);return a},pop:function(a){var b=this.at(this.length-1);this.remove(b,a);return b},unshift:function(a,b){a=this._prepareModel(a,b);this.add(a,f.extend({at:0},b));return a},
shift:function(a){var b=this.at(0);this.remove(b,a);return b},get:function(a){return null==a?void 0:this._byId[null!=a.id?a.id:a]},getByCid:function(a){return a&&this._byCid[a.cid||a]},at:function(a){return this.models[a]},where:function(a){return f.isEmpty(a)?[]:this.filter(function(b){for(var c in a)if(a[c]!==b.get(c))return!1;return!0})},sort:function(a){a||(a={});if(!this.comparator)throw Error("Cannot sort a set without a comparator");var b=f.bind(this.comparator,this);1==this.comparator.length?
this.models=this.sortBy(b):this.models.sort(b);a.silent||this.trigger("reset",this,a);return this},pluck:function(a){return f.map(this.models,function(b){return b.get(a)})},reset:function(a,b){a||(a=[]);b||(b={});for(var c=0,d=this.models.length;c<d;c++)this._removeReference(this.models[c]);this._reset();this.add(a,f.extend({silent:!0},b));b.silent||this.trigger("reset",this,b);return this},fetch:function(a){a=a?f.clone(a):{};void 0===a.parse&&(a.parse=!0);var b=this,c=a.success;a.success=function(d,
e,f){b[a.add?"add":"reset"](b.parse(d,f),a);c&&c(b,d)};a.error=g.wrapError(a.error,b,a);return(this.sync||g.sync).call(this,"read",this,a)},create:function(a,b){var c=this,b=b?f.clone(b):{},a=this._prepareModel(a,b);if(!a)return!1;b.wait||c.add(a,b);var d=b.success;b.success=function(e,f){b.wait&&c.add(e,b);d?d(e,f):e.trigger("sync",a,f,b)};a.save(null,b);return a},parse:function(a){return a},chain:function(){return f(this.models).chain()},_reset:function(){this.length=0;this.models=[];this._byId=
{};this._byCid={}},_prepareModel:function(a,b){b||(b={});a instanceof o?a.collection||(a.collection=this):(b.collection=this,a=new this.model(a,b),a._validate(a.attributes,b)||(a=!1));return a},_removeReference:function(a){this==a.collection&&delete a.collection;a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,b,c,d){("add"==a||"remove"==a)&&c!=this||("destroy"==a&&this.remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],this._byId[b.id]=b),this.trigger.apply(this,
arguments))}});f.each("forEach,each,map,reduce,reduceRight,find,detect,filter,select,reject,every,all,some,any,include,contains,invoke,max,min,sortBy,sortedIndex,toArray,size,first,initial,rest,last,without,indexOf,shuffle,lastIndexOf,isEmpty,groupBy".split(","),function(a){r.prototype[a]=function(){return f[a].apply(f,[this.models].concat(f.toArray(arguments)))}});var u=g.Router=function(a){a||(a={});a.routes&&(this.routes=a.routes);this._bindRoutes();this.initialize.apply(this,arguments)},B=/:\w+/g,
C=/\*\w+/g,D=/[-[\]{}()+?.,\\^$|#\s]/g;f.extend(u.prototype,k,{initialize:function(){},route:function(a,b,c){g.history||(g.history=new m);f.isRegExp(a)||(a=this._routeToRegExp(a));c||(c=this[b]);g.history.route(a,f.bind(function(d){d=this._extractParameters(a,d);c&&c.apply(this,d);this.trigger.apply(this,["route:"+b].concat(d));g.history.trigger("route",this,b,d)},this));return this},navigate:function(a,b){g.history.navigate(a,b)},_bindRoutes:function(){if(this.routes){var a=[],b;for(b in this.routes)a.unshift([b,
this.routes[b]]);b=0;for(var c=a.length;b<c;b++)this.route(a[b][0],a[b][1],this[a[b][1]])}},_routeToRegExp:function(a){a=a.replace(D,"\\$&").replace(B,"([^/]+)").replace(C,"(.*?)");return RegExp("^"+a+"$")},_extractParameters:function(a,b){return a.exec(b).slice(1)}});var m=g.History=function(){this.handlers=[];f.bindAll(this,"checkUrl")},s=/^[#\/]/,E=/msie [\w.]+/;m.started=!1;f.extend(m.prototype,k,{interval:50,getHash:function(a){return(a=(a?a.location:window.location).href.match(/#(.*)$/))?a[1]:
""},getFragment:function(a,b){if(null==a)if(this._hasPushState||b){var a=window.location.pathname,c=window.location.search;c&&(a+=c)}else a=this.getHash();a.indexOf(this.options.root)||(a=a.substr(this.options.root.length));return a.replace(s,"")},start:function(a){if(m.started)throw Error("Backbone.history has already been started");m.started=!0;this.options=f.extend({},{root:"/"},this.options,a);this._wantsHashChange=!1!==this.options.hashChange;this._wantsPushState=!!this.options.pushState;this._hasPushState=
!(!this.options.pushState||!window.history||!window.history.pushState);var a=this.getFragment(),b=document.documentMode;if(b=E.exec(navigator.userAgent.toLowerCase())&&(!b||7>=b))this.iframe=i('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(a);this._hasPushState?i(window).bind("popstate",this.checkUrl):this._wantsHashChange&&"onhashchange"in window&&!b?i(window).bind("hashchange",this.checkUrl):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,
this.interval));this.fragment=a;a=window.location;b=a.pathname==this.options.root;if(this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!b)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;this._wantsPushState&&this._hasPushState&&b&&a.hash&&(this.fragment=this.getHash().replace(s,""),window.history.replaceState({},document.title,a.protocol+"//"+a.host+this.options.root+this.fragment));if(!this.options.silent)return this.loadUrl()},
stop:function(){i(window).unbind("popstate",this.checkUrl).unbind("hashchange",this.checkUrl);clearInterval(this._checkUrlInterval);m.started=!1},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(){var a=this.getFragment();a==this.fragment&&this.iframe&&(a=this.getFragment(this.getHash(this.iframe)));if(a==this.fragment)return!1;this.iframe&&this.navigate(a);this.loadUrl()||this.loadUrl(this.getHash())},loadUrl:function(a){var b=this.fragment=this.getFragment(a);return f.any(this.handlers,
function(a){if(a.route.test(b))return a.callback(b),!0})},navigate:function(a,b){if(!m.started)return!1;if(!b||!0===b)b={trigger:b};var c=(a||"").replace(s,"");this.fragment!=c&&(this._hasPushState?(0!=c.indexOf(this.options.root)&&(c=this.options.root+c),this.fragment=c,window.history[b.replace?"replaceState":"pushState"]({},document.title,c)):this._wantsHashChange?(this.fragment=c,this._updateHash(window.location,c,b.replace),this.iframe&&c!=this.getFragment(this.getHash(this.iframe))&&(b.replace||
this.iframe.document.open().close(),this._updateHash(this.iframe.location,c,b.replace))):window.location.assign(this.options.root+a),b.trigger&&this.loadUrl(a))},_updateHash:function(a,b,c){c?a.replace(a.toString().replace(/(javascript:|#).*$/,"")+"#"+b):a.hash=b}});var v=g.View=function(a){this.cid=f.uniqueId("view");this._configure(a||{});this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()},F=/^(\S+)\s*(.*)$/,w="model,collection,el,id,attributes,className,tagName".split(",");
f.extend(v.prototype,k,{tagName:"div",$:function(a){return this.$el.find(a)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();return this},make:function(a,b,c){a=document.createElement(a);b&&i(a).attr(b);c&&i(a).html(c);return a},setElement:function(a,b){this.$el&&this.undelegateEvents();this.$el=a instanceof i?a:i(a);this.el=this.$el[0];!1!==b&&this.delegateEvents();return this},delegateEvents:function(a){if(a||(a=n(this,"events"))){this.undelegateEvents();
for(var b in a){var c=a[b];f.isFunction(c)||(c=this[a[b]]);if(!c)throw Error('Method "'+a[b]+'" does not exist');var d=b.match(F),e=d[1],d=d[2],c=f.bind(c,this),e=e+(".delegateEvents"+this.cid);""===d?this.$el.bind(e,c):this.$el.delegate(d,e,c)}}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(var b=0,c=w.length;b<c;b++){var d=w[b];a[d]&&(this[d]=a[d])}this.options=a},_ensureElement:function(){if(this.el)this.setElement(this.el,
!1);else{var a=n(this,"attributes")||{};this.id&&(a.id=this.id);this.className&&(a["class"]=this.className);this.setElement(this.make(this.tagName,a),!1)}}});o.extend=r.extend=u.extend=v.extend=function(a,b){var c=G(this,a,b);c.extend=this.extend;return c};var H={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};g.sync=function(a,b,c){var d=H[a];c||(c={});var e={type:d,dataType:"json"};c.url||(e.url=n(b,"url")||t());if(!c.data&&b&&("create"==a||"update"==a))e.contentType="application/json",
e.data=JSON.stringify(b.toJSON());g.emulateJSON&&(e.contentType="application/x-www-form-urlencoded",e.data=e.data?{model:e.data}:{});if(g.emulateHTTP&&("PUT"===d||"DELETE"===d))g.emulateJSON&&(e.data._method=d),e.type="POST",e.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",d)};"GET"!==e.type&&!g.emulateJSON&&(e.processData=!1);return i.ajax(f.extend(e,c))};g.wrapError=function(a,b,c){return function(d,e){e=d===b?e:d;a?a(b,e,c):b.trigger("error",b,e,c)}};var x=function(){},G=function(a,
b,c){var d;d=b&&b.hasOwnProperty("constructor")?b.constructor:function(){a.apply(this,arguments)};f.extend(d,a);x.prototype=a.prototype;d.prototype=new x;b&&f.extend(d.prototype,b);c&&f.extend(d,c);d.prototype.constructor=d;d.__super__=a.prototype;return d},n=function(a,b){return!a||!a[b]?null:f.isFunction(a[b])?a[b]():a[b]},t=function(){throw Error('A "url" property or function must be specified');}}).call(this);
// Knockout JavaScript library v2.1.0
// (c) Steven Sanderson - http://knockoutjs.com/
// License: MIT (http://www.opensource.org/licenses/mit-license.php)
......@@ -84,3 +160,10 @@ if(c)return a.a.L(c.cloneNode(p).childNodes);b=b.text();return a.a.pa(b)};a.q.K=
e||(e=b.text()||"",e=jQuery.template(s,"{{ko_with $item.koBindingContext}}"+e+"{{/ko_with}}"),b.data("precompiled",e));b=[f.$data];f=jQuery.extend({koBindingContext:f},g.templateOptions);f=jQuery.tmpl(e,b,f);f.appendTo(document.createElement("div"));jQuery.fragments={};return f};this.createJavaScriptEvaluatorBlock=function(a){return"{{ko_code ((function() { return "+a+" })()) }}"};this.addTemplate=function(a,b){document.write("<script type='text/html' id='"+a+"'>"+b+"<\/script>")};0<a&&(jQuery.tmpl.tag.ko_code=
{open:"__.push($1 || '');"},jQuery.tmpl.tag.ko_with={open:"with($1) {",close:"} "})};a.ma.prototype=new a.t;var b=new a.ma;0<b.vb&&a.ra(b);a.b("jqueryTmplTemplateEngine",a.ma)})()}"function"===typeof require&&"object"===typeof exports&&"object"===typeof module?E(module.exports||exports):"function"===typeof define&&define.amd?define(["exports"],E):E(window.ko={});p;
})(window,document,navigator);
/*
knockback.js 0.16.7 (full version)
(c) 2011, 2012 Kevin Malakoff - http://kmalakoff.github.com/knockback/
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
*/(function(){return function(e){return typeof define=="function"&&define.amd?define("knockback",["underscore","backbone","knockout"],e):e.call(this)}(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L=function(e,t){return function(){return e.apply(t,arguments)}};m=function(){function t(){}return t.VERSION="0.16.7",t.TYPE_UNKNOWN=0,t.TYPE_SIMPLE=1,t.TYPE_ARRAY=2,t.TYPE_MODEL=3,t.TYPE_COLLECTION=4,t.release=function(n,r){var i,s,u,a,f,l,c,h;if(!n||n!==Object(n)||typeof n=="function"&&!g.isObservable(n)||n.__kb_destroyed||n instanceof e.Model||n instanceof e.Collection)return this;if(b.isArray(n)){i=n.splice(0,n.length);for(f=0,c=i.length;f<c;f++)s=i[f],t.release(s);return this}n.__kb_destroyed=!0,!r||r();if(g.isObservable(n)||typeof n.dispose=="function"||typeof n.destroy=="function"||typeof n.release=="function")if(g.isObservable(n)&&b.isArray(i=n())){if(n.__kb_is_co||n.__kb_is_o&&n.valueType()===o)n.destroy?n.destroy():n.dispose&&n.dispose();else if(i.length){a=i.slice(0),i.splice(0,i.length);for(l=0,h=a.length;l<h;l++)u=a[l],t.release(u)}}else n.release?n.release():n.destroy?n.destroy():n.dispose&&n.dispose();else this.releaseKeys(n);return this},t.releaseKeys=function(e){var n,r;for(n in e)r=e[n],n==="__kb"||t.release(r,function(){return e[n]=null});return this},t.releaseOnNodeRemove=function(e,n){return e||T(this,"missing view model"),n||T(this,"missing node"),g.utils.domNodeDisposal.addDisposeCallback(n,function(){return t.release(e)})},t.renderTemplate=function(e,n,r){var i,s;return r==null&&(r={}),i=document.createElement("div"),s=g.renderTemplate(e,n,r,i,"replaceChildren"),i.children.length===1&&(i=i.children[0]),t.releaseOnNodeRemove(n,i),s.dispose(),i},t.renderAutoReleasedTemplate=function(e,t,n){return n==null&&(n={}),S("kb.renderAutoReleasedTemplate","0.16.3","Please use kb.renderTemplate instead"),this.renderTemplate(e,t,n={})},t.applyBindings=function(e,n){return g.applyBindings(e,n),t.releaseOnNodeRemove(e,n)},t}(),this.Knockback=this.kb=m,typeof exports!="undefined"&&(module.exports=m);if(!this._&&typeof require!="undefined")try{b=require("lodash")}catch(A){b=require("underscore")}else b=this._;return m._=b=b.hasOwnProperty("_")?b._:b,m.Backbone=e=!this.Backbone&&typeof require!="undefined"?require("backbone"):this.Backbone,m.ko=g=!this.ko&&typeof require!="undefined"?require("knockout"):this.ko,x=function(e,t){throw""+(b.isString(e)?e:e.constructor.name)+": "+t+" is missing"},T=function(e,t){throw""+(b.isString(e)?e:e.constructor.name)+": "+t+" is unexpected"},S=function(e,t,n){var r;return this._legacy_warnings||(this._legacy_warnings={}),(r=this._legacy_warnings)[e]||(r[e]=0),this._legacy_warnings[e]++,console.warn("warning: '"+e+"' has been deprecated (will be removed in Knockback after "+t+"). "+n+".")},E=Array.prototype.splice,C=g.utils.unwrapObservable,v=function(e){var t;t=b.clone(e);while(e.options)b.defaults(t,e.options),e=e.options;return delete t.options,t},f=m.TYPE_UNKNOWN,a=m.TYPE_SIMPLE,s=m.TYPE_ARRAY,u=m.TYPE_MODEL,o=m.TYPE_COLLECTION,k=function(e,t,n){return arguments.length===2?e&&e.__kb&&e.__kb.hasOwnProperty(t)?e.__kb[t]:void 0:(e||T(this,"no obj for wrapping "+t),e.__kb||(e.__kb={}),e.__kb[t]=n,n)},w=function(e,t){return E.call(e,1,0,t),e},N=function(e){var t,n,r;if(!e)return e;if(e.__kb)return"object"in e.__kb?e.__kb.object:e;if(b.isArray(e))return b.map(e,function(e){return N(e)});if(b.isObject(e)&&e.constructor==={}.constructor){n={};for(t in e)r=e[t],n[t]=N(r);return n}return e},m.utils=function(){function t(){}return t.wrappedObservable=function(e,t){return k.apply(this,w(arguments,"observable"))},t.wrappedObject=function(e,t){return k.apply(this,w(arguments,"object"))},t.wrappedModel=function(e,t){return arguments.length===1?(t=k(e,"object"),b.isUndefined(t)?e:t):k(e,"object",t)},t.wrappedStore=function(e,t){return k.apply(this,w(arguments,"store"))},t.wrappedStoreIsOwned=function(e,t){return k.apply(this,w(arguments,"store_is_owned"))},t.wrappedFactory=function(e,t){return k.apply(this,w(arguments,"factory"))},t.wrappedEventWatcher=function(e,t){return k.apply(this,w(arguments,"event_watcher"))},t.wrappedEventWatcherIsOwned=function(e,t){return k.apply(this,w(arguments,"event_watcher_is_owned"))},t.wrappedDestroy=function(e){var t;if(!e.__kb)return;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},t.valueType=function(t){return t?t.__kb_is_o?t.valueType():t.__kb_is_co||t instanceof e.Collection?o:t instanceof m.ViewModel||t instanceof e.Model?u:b.isArray(t)?s:a:f},t.pathJoin=function(e,t){return(e?e[e.length-1]!=="."?""+e+".":e:"")+t},t.optionsPathJoin=function(e,t){return b.defaults({path:this.pathJoin(e.path,t)},e)},t.inferCreator=function(t,n,r,i,s){var o,u;n&&(o=n.creatorForPath(t,r));if(o)return o;if(i&&e.RelationalModel&&i instanceof e.RelationalModel){s=C(s),u=b.find(i.getRelations(),function(e){return e.key===s});if(u)return u.collectionType||b.isArray(u.keyContents)?m.CollectionObservable:m.ViewModel}return t?t instanceof e.Model?m.ViewModel:t instanceof e.Collection?m.CollectionObservable:null:null},t.createFromDefaultCreator=function(t,n){return t instanceof e.Model?m.viewModel(t,n):t instanceof e.Collection?m.collectionObservable(t,n):b.isArray(t)?g.observableArray(t):g.observable(t)},t.hasModelSignature=function(e){return e&&e.attributes&&!e.models&&typeof e.get=="function"&&typeof e.trigger=="function"},t.hasCollectionSignature=function(e){return e&&e.models&&typeof e.get=="function"&&typeof e.trigger=="function"},t.release=function(e){return S("kb.utils.release","0.16.0","Please use kb.release instead"),m.release(e)},t}(),m.Factory=function(){function e(e){this.parent_factory=e,this.paths={}}return e.useOptionsOrCreate=function(e,t,n){var r;return e.factory&&(!e.factories||e.factories&&e.factory.hasPathMappings(e.factories,n))?m.utils.wrappedFactory(t,e.factory):(r=m.utils.wrappedFactory(t,new m.Factory(e.factory)),e.factories&&r.addPathMappings(e.factories,n),r)},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,r;for(r in e)n=e[r],this.paths[m.utils.pathJoin(t,r)]=n},e.prototype.hasPathMappings=function(e,t){var n,r,i,s;n=!0;for(s in e)r=e[s],n&=(i=this.creatorForPath(null,m.utils.pathJoin(t,s)))&&r===i;return n},e.prototype.creatorForPath=function(e,t){var n;if(n=this.paths[t])return n.view_model?n.view_model:n;if(this.parent_factory)if(n=this.parent_factory.creatorForPath(e,t))return n;return null},e}(),m.Store=function(){function t(){this.observable_records=[],this.replaced_observables=[]}return t.useOptionsOrCreate=function(e,t,n){return e.store?(e.store.register(t,n,e),m.utils.wrappedStore(n,e.store)):(m.utils.wrappedStoreIsOwned(n,!0),m.utils.wrappedStore(n,new m.Store))},t.prototype.destroy=function(){return this.clear()},t.prototype.clear=function(){var e,t,n,r;r=this.observable_records.splice(0,this.observable_records.length);for(t=0,n=r.length;t<n;t++)e=r[t],m.release(e.observable);m.release(this.replaced_observables)},t.prototype.register=function(e,t,n){var r;if(!t)return;if(g.isObservable(t)||t.__kb_is_co)return;return m.utils.wrappedObject(t,e),e||(t.__kb_null=!0),r=n.creator?n.creator:n.path&&n.factory?n.factory.creatorForPath(e,n.path):null,r||(r=t.constructor),this.observable_records.push({obj:e,observable:t,creator:r}),t},t.prototype.findIndex=function(t,n){var r,i,s;if(!t||t instanceof e.Model){s=this.observable_records;for(r in s){i=s[r];if(!i.observable)continue;if(i.observable.__kb_destroyed){i.obj=null,i.observable=null;continue}if(!t&&!i.observable.__kb_null||t&&(i.observable.__kb_null||i.obj!==t))continue;if(i.creator===n||i.creator.create&&i.creator.create===n.create)return r}}return-1},t.prototype.find=function(e,t){var n;return(n=this.findIndex(e,t))<0?null:this.observable_records[n].observable},t.prototype.isRegistered=function(e){var t,n,r,i;i=this.observable_records;for(n=0,r=i.length;n<r;n++){t=i[n];if(t.observable===e)return!0}return!1},t.prototype.findOrCreate=function(t,n){var r,i;return n.store=this,n.creator||(n.creator=m.utils.inferCreator(t,n.factory,n.path)),!n.creator&&t instanceof e.Model&&(n.creator=kv.ViewModel),r=n.creator,r?r.models_only?t:(r&&(i=this.find(t,r)),i?i:(r.create?i=r.create(t,n):i=new r(t,n),i||(i=g.observable(null)),g.isObservable(i)||this.isRegistered(i)||this.register(t,i,n),i)):m.utils.createFromDefaultCreator(t,n)},t.prototype.findOrReplace=function(e,t,n){var r,i;return e||raiseUnexpected("obj missing"),(r=this.findIndex(e,t))<0?this.register(e,n,{creator:t}):(i=this.observable_records[r],m.utils.wrappedObject(i.observable)===e||T(this,"different object"),i.observable!==n&&(i.observable.constructor===n.constructor||T(this,"replacing different type"),this.replaced_observables.push(i.observable),i.observable=n),n)},t}(),h=function(e,t,n){return!m.statistics||m.statistics.addModelEvent({name:t,emitter:e,key:n.key,path:n.path})},m.EventWatcher=function(){function t(e,t,n){this._onModelUnloaded=L(this._onModelUnloaded,this),this._onModelLoaded=L(this._onModelLoaded,this),this.__kb||(this.__kb={}),this.__kb.callbacks={},this.__kb._onModelLoaded=b.bind(this._onModelLoaded,this),this.__kb._onModelUnloaded=b.bind(this._onModelUnloaded,this),n&&this.registerCallbacks(t,n),e?this.emitter(e):this.ee=null}return t.useOptionsOrCreate=function(e,t,n,r){return e.event_watcher?(e.event_watcher.emitter()!==t&&e.event_watcher.model_ref!==t&&T(this,"emitter not matching"),m.utils.wrappedEventWatcher(n,e.event_watcher).registerCallbacks(n,r)):(m.utils.wrappedEventWatcherIsOwned(n,!0),m.utils.wrappedEventWatcher(n,new m.EventWatcher(t)).registerCallbacks(n,r))},t.prototype.destroy=function(){return this.emitter(null),this.__kb.callbacks=null,m.utils.wrappedDestroy(this)},t.prototype.emitter=function(t){var n,r,i,s,o,u,a,f;if(arguments.length===0||this.ee===t)return this.ee;this.model_ref&&(this.model_ref.unbind("loaded",this.__kb._onModelLoaded),this.model_ref.unbind("unloaded",this.__kb._onModelUnloaded),this.model_ref.release(),this.model_ref=null),e.ModelRef&&t instanceof e.ModelRef?(this.model_ref=t,this.model_ref.retain(),this.model_ref.bind("loaded",this.__kb._onModelLoaded),this.model_ref.bind("unloaded",this.__kb._onModelUnloaded),t=this.model_ref.model()):delete this.model_ref,o=this.ee,this.ee=t,f=this.__kb.callbacks;for(r in f){n=f[r],o&&o.unbind(r,n.fn),t&&this.ee.bind(r,n.fn),s=n.list;for(u=0,a=s.length;u<a;u++)i=s[u],i.emitter&&i.emitter(this.ee)}return t},t.prototype.registerCallbacks=function(t,n){var r,i,s,o,u,a,f,l,c=this;t||x(this,"obj"),n||x(this,"info"),o=n.event_selector?n.event_selector:"change",s=o.split(" ");for(f=0,l=s.length;f<l;f++){i=s[f];if(!i)continue;r=this.__kb.callbacks[i],r||(a=[],r={list:a,fn:function(e){var t,n,r;for(n=0,r=a.length;n<r;n++){t=a[n];if(t.update&&!t.rel_fn){if(e&&t.key&&e.hasChanged&&!e.hasChanged(C(t.key)))continue;!m.statistics||h(e,i,t),t.update()}}return null}},this.__kb.callbacks[i]=r,this.ee&&this.ee.bind(i,r.fn)),u=b.defaults({obj:t},n),r.list.push(u)}this.ee&&(e.RelationalModel&&this.ee instanceof e.RelationalModel&&b.contains(s,"change")&&this._modelBindRelatationalInfo("change",u),u.emitter(this.ee)&&u.emitter)},t.prototype.releaseCallbacks=function(e){var t,n,r,i,s,o;if(!this.__kb.callbacks)return;s=this.__kb.callbacks;for(n in s){t=s[n],o=t.list;for(r in o){i=o[r];if(i.obj!==e)continue;t.list.splice(r,1),i.rel_fn&&this._modelUnbindRelatationalInfo(n,i),i.emitter&&i.emitter(null);return}}},t.prototype._onModelLoaded=function(t){var n,r,i,s,o,u,a,f;s=e.RelationalModel&&t instanceof e.RelationalModel,this.ee=t,f=this.__kb.callbacks;for(r in f){n=f[r],this.ee.bind(r,n.fn),o=n.list;for(u=0,a=o.length;u<a;u++)i=o[u],s&&this._modelBindRelatationalInfo(r,i),i.emitter&&i.emitter(this.ee)}},t.prototype._onModelUnloaded=function(e){var t,n,r,i,s,o,u;this.ee=null,u=this.__kb.callbacks;for(n in u){t=u[n],e.unbind(n,t.fn),i=t.list;for(s=0,o=i.length;s<o;s++)r=i[s],r.rel_fn&&this._modelUnbindRelatationalInfo(n,r),r.emitter&&r.emitter(null)}},t.prototype._modelBindRelatationalInfo=function(e,t){var n,r;if(e==="change"&&t.key&&t.update){n=C(t.key),r=b.find(this.ee.getRelations(),function(e){return e.key===n});if(!r)return;t.rel_fn=function(n){return!m.statistics||h(n,""+e+" (relational)",t),t.update()},r.collectionType||b.isArray(r.keyContents)?(t.is_collection=!0,this.ee.bind("add:"+t.key,t.rel_fn),this.ee.bind("remove:"+t.key,t.rel_fn)):this.ee.bind("update:"+t.key,t.rel_fn)}},t.prototype._modelUnbindRelatationalInfo=function(e,t){if(!t.rel_fn)return;t.is_collection?(this.ee.unbind("add:"+t.key,t.rel_fn),this.ee.unbind("remove:"+t.key,t.rel_fn)):this.ee.unbind("update:"+t.key,t.rel_fn),t.rel_fn=null},t}(),m.emitterObservable=function(e,t){return new m.EventWatcher(e,t)},m.Observable=function(){function e(e,t,n){var r,i,s,o=this;return this.vm=n,t||x(this,"options"),this.vm||(this.vm={}),b.isString(t)||g.isObservable(t)?r=this.create_options={key:t}:r=this.create_options=v(t),this.key=r.key,delete r.key,this.key||x(this,"key"),!r.args||(this.args=r.args,delete r.args),!r.read||(this.read=r.read,delete r.read),!r.write||(this.write=r.write,delete r.write),i=r.event_watcher,delete r.event_watcher,this.vo=g.observable(null),this._model=g.observable(),s=m.utils.wrappedObservable(this,g.dependentObservable({read:function(){var e,t,n,r,i,s;t=[C(o.key)];if(o.args)if(b.isArray(o.args)){s=o.args;for(r=0,i=s.length;r<i;r++)e=s[r],t.push(C(e))}else t.push(C(o.args));return o._mdl===o._model()&&o._mdl&&(n=o.read?o.read.apply(o.vm,t):o._mdl.get.apply(o._mdl,t),o.update(n)),C(o.vo())},write:function(e){var t,n,r,i,s,u,a;i=N(e),r={},r[C(o.key)]=i,n=o.write?[i]:[r];if(o.args)if(b.isArray(o.args)){a=o.args;for(s=0,u=a.length;s<u;s++)t=a[s],n.push(C(t))}else n.push(C(o.args));return o._mdl&&(o.write?o.write.apply(o.vm,n):o._mdl.set.apply(o._mdl,n)),o.update(e)},owner:this.vm})),s.__kb_is_o=!0,r.store=m.utils.wrappedStore(s,r.store),r.path=m.utils.pathJoin(r.path,this.key),r.factories&&(typeof r.factories=="function"||r.factories.create)?(r.factory=m.utils.wrappedFactory(s,new m.Factory(r.factory)),r.factory.addPathMapping(r.path,r.factories)):r.factory=m.Factory.useOptionsOrCreate(r,s,r.path),delete r.factories,s.value=b.bind(this.value,this),s.valueType=b.bind(this.valueType,this),s.destroy=b.bind(this.destroy,this),s.model=this.model=g.dependentObservable({read:function(){return o._model(),o._mdl},write:function(e){if(o.__kb_destroyed||o._mdl===e)return;return o._mdl=e,o.update(null),o._model(e)}}),m.EventWatcher.useOptionsOrCreate({event_watcher:i},e,this,{emitter:this.model,update:b.bind(this.update,this),key:this.key,path:r.path}),this.__kb_value||this.update(),m.LocalizedObservable&&r.localizer&&(s=new r.localizer(s),delete r.localizer),m.DefaultObservable&&r.hasOwnProperty("default")&&(s=m.defaultObservable(s,r["default"]),delete r["default"]),s}return e.prototype.destroy=function(){var e;return e=m.utils.wrappedObservable(this),this.__kb_destroyed=!0,m.release(this.__kb_value),this.__kb_value=null,this.model.dispose(),this._mdl=this.model=e.model=null,m.utils.wrappedDestroy(this)},e.prototype.value=function(){return this.__kb_value},e.prototype.valueType=function(){var e;return e=this._mdl?this._mdl.get(this.key):null,this.value_type||this._updateValueObservable(e),this.value_type},e.prototype.update=function(e){var t,n;if(this.__kb_destroyed)return;this._mdl&&!arguments.length&&(e=this._mdl.get(C(this.key))),e!==void 0||(e=null),t=m.utils.valueType(e);if(!this.__kb_value||this.__kb_value.__kb_destroyed||this.__kb_value.__kb_null&&e)this.__kb_value=void 0,this.value_type=void 0;n=this.__kb_value;if(b.isUndefined(this.value_type)||this.value_type!==t&&t!==f)return this.value_type===o&&t===s?n(e):this._updateValueObservable(e);if(this.value_type===u){if(typeof n.model=="function"){if(n.model()!==e)return n.model(e)}else if(m.utils.wrappedObject(n)!==e)return this._updateValueObservable(e)}else if(this.value_type===o){if(n.collection()!==e)return n.collection(e)}else if(n()!==e)return n(e)},e.prototype._updateValueObservable=function(e){var t,n,r,i;return t=this.create_options,t.creator=m.utils.inferCreator(e,t.factory,t.path,this._mdl,this.key),this.value_type=f,n=t.creator,r=this.__kb_value,this.__kb_value=void 0,r&&m.release(r),n?t.store?i=t.store.findOrCreate(e,t):n.models_only?(i=e,this.value_type=a):n.create?i=n.create(e,t):i=new n(e,t):b.isArray(e)?(this.value_type=s,i=g.observableArray(e)):(this.value_type=a,i=g.observable(e)),this.value_type===f&&(g.isObservable(i)?i.__kb_is_co?this.value_type=o:this.value_type=a:(this.value_type=u,typeof i.model!="function"&&m.utils.wrappedObject(i,e))),this.__kb_value=i,this.vo(i)},e}(),m.observable=function(e,t,n){return new m.Observable(e,t,n)},m.ViewModel=function(){function t(t,n,r){var i,s,o,u,a,f,l,c,h,p=this;!t||t instanceof e.Model||typeof t.get=="function"&&typeof t.bind=="function"||T(this,"not a model"),n||(n={}),r||(r={}),b.isArray(n)?n={keys:n}:n=v(n),this.__kb||(this.__kb={}),this.__kb.vm_keys={},this.__kb.model_keys={},this.__kb.view_model=b.isUndefined(r)?this:r,!n.internals||(this.__kb.internals=n.internals),!n.excludes||(this.__kb.excludes=n.excludes),m.Store.useOptionsOrCreate(n,t,this),this.__kb.path=n.path,m.Factory.useOptionsOrCreate(n,this,n.path),c=k(this,"_mdl",g.observable()),this.model=g.dependentObservable({read:function(){return c(),m.utils.wrappedObject(p)},write:function(e){var t,n;if(m.utils.wrappedObject(p)===e)return;if(p.__kb_null){!e||T(p,"model set on shared null");return}m.utils.wrappedObject(p,e),t=m.utils.wrappedEventWatcher(p);if(!t){c(e);return}t.emitter(e),p.__kb.keys||!e||!e.attributes||(n=b.difference(b.keys(e.attributes),b.keys(p.__kb.model_keys)),n&&p._createObservables(e,n)),c(e)}}),o=m.utils.wrappedEventWatcher(this,new m.EventWatcher(t,this,{emitter:this.model})),n.requires&&b.isArray(n.requires)&&(u=b.clone(n.requires)),this.__kb.internals&&(u=u?b.union(u,this.__kb.internals):b.clone(this.__kb.internals));if(n.keys)if(b.isArray(n.keys))this.__kb.keys=n.keys,u=u?b.union(u,n.keys):b.clone(n.keys);else{a={},h=n.keys;for(l in h)f=h[l],a[b.isString(f)?f:f.key?f.key:l]=!0;this.__kb.keys=b.keys(a)}else s=o.emitter(),s&&s.attributes&&(i=b.keys(s.attributes),u=u?b.union(u,i):i);u&&this.__kb.excludes&&(u=b.difference(u,this.__kb.excludes)),b.isObject(n.keys)&&!b.isArray(n.keys)&&this._mapObservables(t,n.keys),b.isObject(n.requires)&&!b.isArray(n.requires)&&this._mapObservables(t,n.requires),!n.mappings||this._mapObservables(t,n.mappings),!u||this._createObservables(t,u),!m.statistics||m.statistics.register("ViewModel",this)}return t.extend=e.Model.extend,t.prototype.destroy=function(){var e;if(this.__kb.view_model!==this)for(e in this.__kb.vm_keys)this.__kb.view_model[e]=null;return this.__kb.view_model=null,m.releaseKeys(this),m.utils.wrappedDestroy(this),!m.statistics||m.statistics.unregister("ViewModel",this)},t.prototype.shareOptions=function(){return{store:m.utils.wrappedStore(this),factory:m.utils.wrappedFactory(this)}},t.prototype._createObservables=function(e,t){var n,r,i,s,o;n={store:m.utils.wrappedStore(this),factory:m.utils.wrappedFactory(this),path:this.__kb.path,event_watcher:m.utils.wrappedEventWatcher(this)};for(s=0,o=t.length;s<o;s++){r=t[s],i=this.__kb.internals&&b.contains(this.__kb.internals,r)?"_"+r:r;if(this[i])continue;this.__kb.vm_keys[i]=!0,this.__kb.model_keys[r]=!0,n.key=r,this[i]=this.__kb.view_model[i]=m.observable(e,n,this)}},t.prototype._mapObservables=function(e,t){var n,r,i;n={store:m.utils.wrappedStore(this),factory:m.utils.wrappedFactory(this),path:this.__kb.path,event_watcher:m.utils.wrappedEventWatcher(this)};for(i in t){r=t[i];if(this[i])continue;r=b.isString(r)?{key:r}:b.clone(r),r.key||(r.key=i),this.__kb.vm_keys[i]=!0,this.__kb.model_keys[r.key]=!0,this[i]=this.__kb.view_model[i]=m.observable(e,b.defaults(r,n),this)}},t}(),m.viewModel=function(e,t,n){return new m.ViewModel(e,t,n)},m.observables=function(e,t,n){return S("kb.observables","0.16.0","Please use kb.viewModel instead"),new m.ViewModel(e,t,n)},r=0,t=-1,n=1,m.compare=function(e,i){return b.isString(e)?e.localeCompare(i):b.isString(i)?i.localeCompare(e):typeof e!="object"?e===i?r:e<i?t:n:e===i?r:e<i?t:n},m.CollectionObservable=function(){function t(t,n){var r,i,s=this;return!t||t instanceof e.Collection||T(this,"not a collection"),n||(n={}),i=m.utils.wrappedObservable(this,g.observableArray([])),i.__kb_is_co=!0,this.in_edit=0,this.__kb||(this.__kb={}),this.__kb._onCollectionChange=b.bind(this._onCollectionChange,this),n=v(n),n.sort_attribute?this._comparator=g.observable(this._attributeComparator(n.sort_attribute)):(n.sorted_index&&S("sortedIndex no longer supported","0.16.7","please use comparator instead"),this._comparator=g.observable(n.comparator)),n.filters?this._filters=g.observableArray(b.isArray(n.filters)?n.filters:n.filters?[n.filters]:void 0):this._filters=g.observableArray([]),r=this.create_options={store:m.Store.useOptionsOrCreate(n,t,i)},this.path=n.path,r.factory=m.utils.wrappedFactory(i,this._shareOrCreateFactory(n)),r.path=m.utils.pathJoin(n.path,"models"),r.creator=r.factory.creatorForPath(null,r.path),r.creator&&(this.models_only=r.creator.models_only),i.destroy=b.bind(this.destroy,this),i.shareOptions=b.bind(this.shareOptions,this),i.filters=b.bind(this.filters,this),i.comparator=b.bind(this.comparator,this),i.sortAttribute=b.bind(this.sortAttribute,this),i.viewModelByModel=b.bind(this.viewModelByModel,this),i.hasViewModels=b.bind(this.hasViewModels,this),this._collection=g.observable(t),i.collection=this.collection=g.dependentObservable({read:function(){return s._collection()},write:function(e){var t;if((t=s._collection())===e)return;return t&&t.unbind("all",s.__kb._onCollectionChange),e&&e.bind("all",s.__kb._onCollectionChange),s._collection(e)}}),t&&t.bind("all",this.__kb._onCollectionChange),this._mapper=g.dependentObservable(function(){var e,t,n,r,o;e=s._comparator(),n=s._filters(),t=s._collection();if(s.in_edit)return;return i=m.utils.wrappedObservable(s),t&&(r=t.models),!r||t.models.length===0?o=[]:(n.length&&(r=b.filter(r,function(e){return!s._modelIsFiltered(e)})),e?o=b.map(r,function(e){return s._createViewModel(e)}).sort(e):s.models_only?o=n.length?r:r.slice():o=b.map(r,function(e){return s._createViewModel(e)})),s.in_edit++,i(o),s.in_edit--}),i.subscribe(b.bind(this._onObservableArrayChange,this)),!m.statistics||m.statistics.register("CollectionObservable",this),i}return t.extend=e.Model.extend,t.prototype.destroy=function(){var e,t,n;return n=m.utils.wrappedObservable(this),t=this._collection(),t&&(t.unbind("all",this.__kb._onCollectionChange),e=n(),e.splice(0,e.length)),this._mapper.dispose(),this._mapper=null,m.release(this._filters),this._comparator(null),this.collection.dispose(),n.collection=this.collection=null,n.collection=null,m.utils.wrappedDestroy(this),!m.statistics||m.statistics.unregister("CollectionObservable",this)},t.prototype.shareOptions=function(){var e;return e=m.utils.wrappedObservable(this),{store:m.utils.wrappedStore(e),factory:m.utils.wrappedFactory(e)}},t.prototype.filters=function(e){return e?this._filters(b.isArray(e)?e:[e]):this._filters([])},t.prototype.comparator=function(e){return this._comparator(e)},t.prototype.sortedIndex=function(){return S("sortedIndex no longer supported","0.16.7","please use comparator instead")},t.prototype.sortAttribute=function(e){return this._comparator(e?this._attributeComparator(e):null)},t.prototype.viewModelByModel=function(e){var t;return this.models_only?null:(t=e.hasOwnProperty(e.idAttribute)?e.idAttribute:"cid",b.find(m.utils.wrappedObservable(this)(),function(n){return n.__kb.object[t]===e[t]}))},t.prototype.hasViewModels=function(){return!this.models_only},t.prototype._shareOrCreateFactory=function(e){var t,n,r,i;t=m.utils.pathJoin(e.path,"models"),r=e.factories;if(i=e.factory)if((n=i.creatorForPath(null,t))&&(!r||r.models===n)){if(!r)return i;if(i.hasPathMappings(r,e.path))return i}return i=new m.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,m.ViewModel):e.view_model?i.addPathMapping(t,e.view_model):e.create?i.addPathMapping(t,{create:e.create}):i.addPathMapping(t,m.ViewModel)),i},t.prototype._onCollectionChange=function(e,t){var n,r,i,s;if(this.in_edit)return;switch(e){case"reset":case"resort":this._collection.notifySubscribers(this._collection());break;case"new":case"add":if(this._modelIsFiltered(t))return;i=m.utils.wrappedObservable(this),n=this._collection();if(s=this.viewModelByModel(t))return;s=this._createViewModel(t),this.in_edit++,(r=this._comparator())?(i().push(s),i.sort(r)):i.splice(n.indexOf(t),0,s),this.in_edit--;break;case"remove":case"destroy":this._onModelRemove(t);break;case"change":if(this._modelIsFiltered(t))this._onModelRemove(t);else{s=this.viewModelByModel(t);if(s){if(r=this._comparator())i=m.utils.wrappedObservable(this),this.in_edit++,i.sort(r),this.in_edit--}else this._onCollectionChange("add",t)}}},t.prototype._onModelRemove=function(e){var t,n;n=this.models_only?e:this.viewModelByModel(e);if(!n)return;return t=m.utils.wrappedObservable(this),this.in_edit++,t.remove(n),this.in_edit--},t.prototype._onObservableArrayChange=function(e){var t,n,r,i,s,o,u,a,f,l=this;if(this.in_edit)return;this.models_only&&(!e.length||m.utils.hasModelSignature(e[0]))||!this.models_only&&(!e.length||b.isObject(e[0])&&!m.utils.hasModelSignature(e[0]))||T(this,"incorrect type passed"),s=m.utils.wrappedObservable(this),t=this._collection(),n=this._filters().length;if(!t)return;u=e;if(this.models_only)n&&(i=b.filter(e,function(e){return!l._modelIsFiltered(e)}));else{!n||(u=[]),i=[];for(a=0,f=e.length;a<f;a++){o=e[a],r=m.utils.wrappedObject(o);if(n){if(this._modelIsFiltered(r))continue;u.push(o)}this.create_options.store.findOrReplace(r,this.create_options.creator,o),i.push(r)}}this.in_edit++,e.length===u.length||s(u),b.isEqual(t.models,i)||t.reset(i),this.in_edit--},t.prototype._attributeComparator=function(e){var t;return t=function(t,n){var r;return r=C(e),m.compare(t.get(r),n.get(r))},this.models_only?t:function(e,n){return t(m.utils.wrappedModel(e),m.utils.wrappedModel(n))}},t.prototype._createViewModel=function(e){return this.models_only?e:this.create_options.store.findOrCreate(e,this.create_options)},t.prototype._modelIsFiltered=function(e){var t,n,r,i;n=this._filters();for(r=0,i=n.length;r<i;r++){t=n[r],t=C(t);if(typeof t=="function"&&t(e)||e&&e.id===t)return!0}return!1},t}(),m.collectionObservable=function(e,t){return new m.CollectionObservable(e,t)},g.bindingHandlers.inject={init:function(e,t,n,r){return m.Inject.inject(C(t()),r,e,t,n)}},m.Inject=function(){function e(){}return e.inject=function(e,t,n,r,i,s){var o,u,a;return o=function(e){var o,u,a;if(b.isFunction(e))t=new e(t,n,r,i),m.releaseOnNodeRemove(t,n);else{e.view_model&&(t=new e.view_model(t,n,r,i),m.releaseOnNodeRemove(t,n));for(o in e){a=e[o];if(o==="view_model")continue;o==="create"?a(t,n,r,i):b.isObject(a)&&!b.isFunction(a)?(u=s||a&&a.create?{}:t,t[o]=m.Inject.inject(a,u,n,r,i,!0)):t[o]=a}}return t},s?o(e):(u=(a=g.dependentObservable(function(){return o(e)}))(),a.dispose(),u)},e.injectViewModels=function(e){var t,n,r,i,s,o,u,a,f,l;a=[],o=function(e){var t,n,r,i,s;e.__kb_injected||e.attributes&&(t=b.find(e.attributes,function(e){return e.name==="kb-inject"}))&&(e.__kb_injected=!0,a.push({el:e,view_model:{},binding:t.value})),s=e.childNodes;for(r=0,i=s.length;r<i;r++)n=s[r],o(n)},o(e||document);for(f=0,l=a.length;f<l;f++){n=a[f];if(s=n.binding)s.search(/[:]/)<0||(s="{"+s+"}"),i=(new Function("","return ( "+s+" )"))(),i||(i={}),!i.options||(u=i.options,delete i.options),u||(u={}),n.view_model=m.Inject.inject(i,n.view_model,n.el,null,null,!0),t=n.view_model.afterBinding||u.afterBinding,r=n.view_model.beforeBinding||u.beforeBinding;r&&r(n.view_model,n.el,u),m.applyBindings(n.view_model,n.el,u),t&&t(n.view_model,n.el,u)}return a},e}(),m.injectViewModels=m.Inject.injectViewModels,this.$?this.$(function(){return m.injectViewModels()}):(y=function(){return document.readyState!=="complete"?setTimeout(y,0):m.injectViewModels()})(),m.DefaultObservable=function(){function e(e,t){var n,r=this;return this.dv=t,n=m.utils.wrappedObservable(this,g.dependentObservable({read:function(){var t;return(t=C(e()))?t:C(r.dv)},write:function(t){return e(t)}})),n.destroy=b.bind(this.destroy,this),n.setToDefault=b.bind(this.setToDefault,this),n}return e.prototype.destroy=function(){return m.utils.wrappedDestroy(this)},e.prototype.setToDefault=function(){return m.utils.wrappedObservable(this)(this.dv)},e}(),m.defaultObservable=function(e,t){return new m.DefaultObservable(e,t)},m.defaultWrapper=function(e,t){return S("ko.defaultWrapper","0.16.3","Please use kb.defaultObservable instead"),new m.DefaultObservable(e,t)},m.Observable.prototype.setToDefault=function(){var e;(e=this.__kb_value)!=null&&typeof e.setToDefault=="function"&&e.setToDefault()},m.ViewModel.prototype.setToDefault=function(){var e,t;for(e in this.__kb.vm_keys)(t=this[e])!=null&&typeof t.setToDefault=="function"&&t.setToDefault()},m.utils.setToDefault=function(e){var t,n;if(!e)return;if(g.isObservable(e))typeof e.setToDefault=="function"&&e.setToDefault();else if(b.isObject(e))for(t in e)n=e[t],n&&(g.isObservable(n)||typeof n!="function")&&(t[0]!=="_"||t.search("__kb"))&&this.setToDefault(n);return e},p=Array.prototype.slice,m.toFormattedString=function(e){var t,n,r,i,s,o;s=e.slice(),n=p.call(arguments,1);for(r in n){t=n[r],o=C(t),o||(o=""),i=e.indexOf("{"+r+"}");while(i>=0)s=s.replace("{"+r+"}",o),i=e.indexOf("{"+r+"}",i+1)}return s},m.parseFormattedString=function(e,t){var n,r,i,s,o,u,a,f,l,c,h,p,d;c=t.slice(),i=0,u=0,f={};while(c.search("\\{"+i+"\\}")>=0){a=t.indexOf("{"+i+"}");while(a>=0)c=c.replace("{"+i+"}","(.*)"),f[a]=i,u++,a=t.indexOf("{"+i+"}",a+1);i++}n=i,l=new RegExp(c),o=l.exec(e),o&&o.shift();if(!o||o.length!==u){h=[];while(n-->0)h.push("");return h}d=b.sortBy(b.keys(f),function(e,t){return parseInt(e,10)}),r={};for(s in d){a=d[s],i=f[a];if(r.hasOwnProperty(i))continue;r[i]=s}p=[],i=0;while(i<n)p.push(o[r[i]]),i++;return p},m.FormattedObservable=function(){function e(e,t){var n,r;return b.isArray(t)?(e=e,r=t):r=p.call(arguments,1),n=m.utils.wrappedObservable(this,g.dependentObservable({read:function(){var n,i,s;t=[C(e)];for(i=0,s=r.length;i<s;i++)n=r[i],t.push(C(n));return m.toFormattedString.apply(null,t)},write:function(t){var n,i,s;i=m.parseFormattedString(t,C(e)),s=Math.min(r.length,i.length),n=0;while(n<s)r[n](i[n]),n++}})),n}return e.prototype.destroy=function(){return m.utils.wrappedDestroy(this)},e}(),m.formattedObservable=function(e,t){return new m.FormattedObservable(e,p.call(arguments,1))},m.LocalizedObservable=function(){function t(e,t,n){var r,i=this;return this.value=e,this.vm=n,t||(t={}),this.vm||(this.vm={}),this.read||x(this,"read"),m.locale_manager||x(this,"kb.locale_manager"),this.__kb||(this.__kb={}),this.__kb._onLocaleChange=b.bind(this._onLocaleChange,this),this.__kb._onChange=t.onChange,this.value&&(e=C(this.value)),this.vo=g.observable(e?this.read(e,null):null),r=m.utils.wrappedObservable(this,g.dependentObservable({read:function(){return i.value&&C(i.value),i.vo(),i.read(C(i.value))},write:function(e){i.write||T(i,"writing to read-only"),i.write(e,C(i.value)),i.vo(e);if(i.__kb._onChange)return i.__kb._onChange(e)},owner:this.vm})),r.destroy=b.bind(this.destroy,this),r.observedValue=b.bind(this.observedValue,this),r.resetToCurrent=b.bind(this.resetToCurrent,this),m.locale_manager.bind("change",this.__kb._onLocaleChange),t.hasOwnProperty("default")&&(r=m.DefaultObservable&&g.defaultObservable(r,t["default"])),r}return t.extend=e.Model.extend,t.prototype.destroy=function(){return m.locale_manager.unbind("change",this.__kb._onLocaleChange),this.vm=null,m.utils.wrappedDestroy(this)},t.prototype.resetToCurrent=function(){var e,t;t=m.utils.wrappedObservable(this),e=this.value?this.read(C(this.value)):null;if(t()===e)return;return t(e)},t.prototype.observedValue=function(e){if(arguments.length===0)return this.value;this
.value=e,this._onLocaleChange()},t.prototype._onLocaleChange=function(){var e;e=this.read(C(this.value)),this.vo(e);if(this.__kb._onChange)return this.__kb._onChange(e)},t}(),m.localizedObservable=function(e,t,n){return new m.LocalizedObservable(e,t,n)},m.locale_manager=void 0,m.TriggeredObservable=function(){function e(e,t){var n,r=this;return this.event_selector=t,e||x(this,"emitter"),this.event_selector||x(this,"event_selector"),this.vo=g.observable(),n=m.utils.wrappedObservable(this,g.dependentObservable(function(){return r.vo()})),n.destroy=b.bind(this.destroy,this),m.utils.wrappedEventWatcher(this,new m.EventWatcher(e,this,{emitter:b.bind(this.emitter,this),update:b.bind(this.update,this),event_selector:this.event_selector})),n}return e.prototype.destroy=function(){return m.utils.wrappedDestroy(this)},e.prototype.emitter=function(e){if(arguments.length===0||this.ee===e)return this.ee;if(this.ee=e)return this.update()},e.prototype.update=function(){if(!this.ee)return;return this.vo()!==this.ee?this.vo(this.ee):this.vo.valueHasMutated()},e}(),m.triggeredObservable=function(e,t){return new m.TriggeredObservable(e,t)},d=function(e){return e=C(e),typeof e=="function"?e.apply(null,Array.prototype.slice.call(arguments,1)):e},m.Validation=function(){function e(){}return e}(),m.valueValidator=function(e,t,n){return n==null&&(n={}),n&&typeof n!="function"||(n={}),g.dependentObservable(function(){var r,i,s,o,u,a,f,l;f={$error_count:0},i=C(e),!("disable"in n)||(s=d(n.disable)),!("enable"in n)||(s=!d(n.enable)),a=n.priorities||[],b.isArray(a)||(a=[a]),r=a.length+1;for(o in t)l=t[o],f[o]=!s&&d(l,i),f[o]&&(f.$error_count++,(u=b.indexOf(a,o)>=0)||(u=a.length),f.$active_error&&u<r?(f.$active_error=o,r=u):f.$active_error||(f.$active_error=o,r=u));return f.$enabled=!s,f.$disable=!!s,f.$valid=f.$error_count===0,f})},m.inputValidator=function(e,t,n){var r,i,s,o,u,a,f,l,c;return n==null&&(n={}),n&&typeof n!="function"||(n={}),c=m.valid,r=$(t),(o=r.attr("name"))&&!b.isString(o)&&(o=null),(i=r.attr("data-bind"))?(u=(new Function("sc","with(sc[0]) { return { "+i+" } }"))([e]),!u||!u.value?null:(!u.validation_options||(b.defaults(u.validation_options,n),n=u.validation_options),i={},!c[f=r.attr("type")]||(i[f]=c[f]),!r.attr("required")||(i.required=c.required),!u.validations||function(){var e,t;e=u.validations,t=[];for(s in e)l=e[s],t.push(i[s]=l);return t}(),a=m.valueValidator(u.value,i,n),!o&&!n.no_attach||(e["$"+o]=a),a)):null},m.formValidator=function(e,t){var n,r,i,s,o,u,a,f,l,c,h,p,d;a={},c=[],n=$(t),(i=n.attr("name"))&&!b.isString(i)&&(i=null);if(r=n.attr("data-bind"))u=(new Function("sc","with(sc[0]) { return { "+r+" } }"))([e]),f=u.validation_options;f||(f={}),f.no_attach=!!i,d=n.find("input");for(h=0,p=d.length;h<p;h++){s=d[h];if(!(o=$(s).attr("name")))continue;l=m.inputValidator(e,s,f),!l||c.push(a[o]=l)}return a.$error_count=g.dependentObservable(function(){var e,t,n;e=0;for(t=0,n=c.length;t<n;t++)l=c[t],e+=l().$error_count;return e}),a.$valid=g.dependentObservable(function(){return a.$error_count()===0}),a.$enabled=g.dependentObservable(function(){var e,t,n;e=!0;for(t=0,n=c.length;t<n;t++)l=c[t],e&=l().$enabled;return e}),a.$disabled=g.dependentObservable(function(){return!a.$enabled()}),i&&(e["$"+i]=a),a},c=/^(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}$/,l=/^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/,m.valid={required:function(e){return!e},url:function(e){return!c.test(e)},email:function(e){return!i.test(e)},number:function(e){return!l.test(e)}},m.hasChangedFn=function(e){var t,n;return n=null,t=null,function(){var r;return n!==(r=C(e))?(n=r,t=n?n.toJSON():null,!1):!n||!t?!1:!b.isEqual(n.toJSON(),t)}},m.minLengthFn=function(e){return function(t){return!t||t.length<e}},m.uniqueValueFn=function(e,t,n){return function(r){var i,s,o,u=this;return o=C(e),s=C(t),i=C(n),o&&s&&i?!!b.find(i.models,function(e){return e!==o&&e.get(s)===r}):!1}},m.untilTrueFn=function(e,t,n){var r;return r=!1,n&&g.isObservable(n)&&n.subscribe(function(){return r=!1}),function(n){var i,s;return(i=C(t))?(r|=!!(s=i(C(n))),r?s:C(e)):C(e)}},m.untilFalseFn=function(e,t,n){var r;return r=!1,n&&g.isObservable(n)&&n.subscribe(function(){return r=!1}),function(n){var i,s;return(i=C(t))?(r|=!(s=i(C(n))),r?s:C(e)):C(e)}},m})}).call(this);
\ No newline at end of file
// Generated by CoffeeScript 1.3.1
/*
knockback.js 0.15.1
(c) 2011 Kevin Malakoff.
Knockback.js is freely distributable under the MIT license.
See the following for full license details:
https://github.com/kmalakoff/knockback/blob/master/LICENSE
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
Optional dependency: Backbone.ModelRef.js.
*/
var Backbone,Knockback,kb,ko,_;if(typeof exports!=="undefined"){Knockback=kb=exports}else{this.Knockback=this.kb={}}Knockback.VERSION="0.15.1";_=!this._&&(typeof require!=="undefined")?require("underscore"):this._;Backbone=!this.Backbone&&(typeof require!=="undefined")?require("backbone"):this.Backbone;ko=!this.ko&&(typeof require!=="undefined")?require("knockout"):this.ko;Knockback.locale_manager;Knockback.stats={collection_observables:0,view_models:0};Knockback.stats_on=false;Knockback.utils={};Knockback.utils.legacyWarning=function(a,d,c){var b;kb._legacy_warnings||(kb._legacy_warnings={});(b=kb._legacy_warnings)[a]||(b[a]=0);kb._legacy_warnings[a]++;return console.warn("Legacy warning! '"+a+"' has been deprecated (will be removed in Knockback "+d+"). "+c+".")};Knockback.utils.wrappedObservable=function(a,b){if(arguments.length===1){if(!(a&&a.__kb&&a.__kb.observable)){throw new Error("Knockback: instance is not wrapping an observable")}return a.__kb.observable}if(!a){throw new Error("Knockback: no instance for wrapping a observable")}a.__kb||(a.__kb={});if(a.__kb.observable&&a.__kb.observable.__kb){a.__kb.observable.__kb.instance=null}a.__kb.observable=b;if(b){b.__kb||(b.__kb={});b.__kb.instance=a}return b};Knockback.wrappedObservable=function(a){kb.utils.legacyWarning("kb.wrappedObservable","0.16.0","Please use kb.utils.wrappedObservable instead");return kb.utils.wrappedObservable(a)};Knockback.utils.observableInstanceOf=function(b,a){if(!b){return false}if(!(b.__kb&&b.__kb.instance)){return false}return b.__kb.instance instanceof a};Knockback.utils.wrappedModel=function(a,b){if(arguments.length===1){if(a&&a.__kb&&a.__kb.hasOwnProperty("model")){return a.__kb.model}else{return a}}if(!a){throw new Error("Knockback: no view_model for wrapping a model")}a.__kb||(a.__kb={});a.__kb.model=b;return b};Knockback.viewModelGetModel=Knockback.vmModel=function(a){kb.utils.legacyWarning("kb.vmModel","0.16.0","Please use kb.utils.wrappedModel instead");return kb.utils.wrappedModel(a)};Knockback.utils.setToDefault=function(d){var b,c,a;if(!d){return}if(ko.isObservable(d)){return typeof d.setToDefault==="function"?d.setToDefault():void 0}else{if(_.isObject(d)){a=[];for(b in d){c=d[b];a.push(c&&(b!=="__kb")?kb.utils.setToDefault(c):void 0)}return a}}};Knockback.vmSetToDefault=function(a){kb.utils.legacyWarning("kb.vmSetToDefault","0.16.0","Please use kb.utils.release instead");return kb.utils.setToDefault(a)};Knockback.utils.release=function(c){var a,b;if(!c){return false}if(ko.isObservable(c)||(c instanceof kb.Observables)||(typeof c.release==="function")||(typeof c.destroy==="function")){if(c.release){c.release()}else{if(c.destroy){c.destroy()}else{if(c.dispose){c.dispose()}}}return true}else{if(_.isObject(c)&&!(typeof c==="function")){for(a in c){b=c[a];if(!b||(a==="__kb")){continue}if(kb.utils.release(b)){c[a]=null}}return true}}return false};Knockback.vmRelease=function(a){kb.utils.legacyWarning("kb.vmRelease","0.16.0","Please use kb.utils.release instead");return kb.utils.release(a)};Knockback.vmReleaseObservable=function(a){kb.utils.legacyWarning("kb.vmReleaseObservable","0.16.0","Please use kb.utils.release instead");return kb.utils.release(a)};kb.utils.optionsCreateClear=function(a){delete a.create;delete a.children;delete a.view_model;return delete a.view_model_create};kb.utils.optionsCreateOverride=function(a,b){kb.utils.optionsCreateClear(a);return _.extend(a,b)};Knockback.RefCountable=(function(){a.name="RefCountable";a.extend=Backbone.Model.extend;function a(){this.__kb||(this.__kb={});this.__kb.ref_count=1}a.prototype.__destroy=function(){};a.prototype.retain=function(){if(this.__kb.ref_count<=0){throw new Error("RefCountable: ref_count is corrupt: "+this.__kb.ref_count)}this.__kb.ref_count++;return this};a.prototype.release=function(){if(this.__kb.ref_count<=0){throw new Error("RefCountable: ref_count is corrupt: "+this.__kb.ref_count)}this.__kb.ref_count--;if(!this.__kb.ref_count){this.__destroy()}return this};a.prototype.refCount=function(){return this.__kb.ref_count};return a})();Knockback.Store=(function(){a.name="Store";function a(){this.keys=[];this.values=[]}a.prototype.destroy=function(){var c,e,d,b;this.keys=null;d=this.values;for(c in d){e=d[c];if(!kb.utils.observableInstanceOf(e,kb.CollectionObservable)){continue}this.values[c]=null;while(e.refCount()>0){e.release()}}b=this.values;for(c in b){e=b[c];if(!e){continue}this.values[c]=null;if(e instanceof kb.RefCountable){while(e.refCount()>0){e.release()}}else{kb.utils.release(e)}}return this.values=null};a.prototype.registerValue=function(c,d){var b;if(d instanceof kb.RefCountable){d.retain()}b=_.indexOf(this.keys,c);if(b>=0){this.values[b]=d}else{this.keys.push(c);this.values.push(d)}return d};a.prototype.resolveValue=function(d,f,c){var b,e;b=_.indexOf(this.keys,d);if(b>=0){if(this.values[b]){if((this.values[b] instanceof kb.RefCountable)&&(this.values[b].refCount()<=0)){this.values[b]=null}else{if(this.values[b] instanceof kb.RefCountable){return this.values[b].retain()}else{return this.values[b]}}}}else{b=this.keys.length;this.keys.push(d);this.values.push(void 0)}e=f.apply(null,Array.prototype.slice.call(arguments,2));if(this.keys[b]!==d){this.registerValue(d,e)}else{if(!this.values[b]){if(e instanceof kb.RefCountable){e.retain()}this.values[b]=e}}return e};a.prototype.releaseValue=function(c){var b;if(!(c instanceof kb.RefCountable)){return}c.release();if(c.refCount()>0){return}b=_.indexOf(this.values,c);if(!(b>=0)){return}return this.values[b]=0};a.prototype.addResolverToOptions=function(b,c){return _.extend(b,{store:this,store_key:c})};a.resolveFromOptions=function(b,c){if(!(b.store&&b.store_key)){return}return b.store.registerValue(b.store_key,c)};return a})();var __hasProp={}.hasOwnProperty,__extends=function(d,b){for(var a in b){if(__hasProp.call(b,a)){d[a]=b[a]}}function c(){this.constructor=d}c.prototype=b.prototype;d.prototype=new c;d.__super__=b.prototype;return d};Knockback.CollectionObservable=(function(b){__extends(a,b);a.name="CollectionObservable";function a(f,c){var e,d,g=this;if(c==null){c={}}if(!f){throw new Error("CollectionObservable: collection is missing")}a.__super__.constructor.apply(this,arguments);if(Knockback.stats_on){kb.stats.collection_observables++}if(ko.isObservable(c)&&c.hasOwnProperty("indexOf")){kb.utils.legacyWarning("kb.collectionObservable with an external ko.observableArray","0.16.0","Please use the kb.collectionObservable directly instead of passing a ko.observableArray");d=kb.utils.wrappedObservable(this,c);c=arguments[2]||{};e=true}else{d=kb.utils.wrappedObservable(this,ko.observableArray([]))}if(!c.store_skip_resolve){kb.Store.resolveFromOptions(c,kb.utils.wrappedObservable(this))}if(c.store){this.__kb.store=c.store}else{this.__kb.store=new kb.Store();this.__kb.store_is_owned=true}if(c.hasOwnProperty("view_model")){if(!c.view_model){throw new Error("Knockback.CollectionObservable: options.view_model is empty")}this.view_model_create_fn=c.view_model;this.view_model_create_with_new=true}else{if(c.hasOwnProperty("view_model_constructor")){if(!c.view_model_constructor){throw new Error("Knockback.CollectionObservable: options.view_model_constructor is empty")}kb.utils.legacyWarning("kb.collectionObservable option view_model_constructor","0.16.0","Please use view_model option instead");this.view_model_create_fn=c.view_model_constructor;this.view_model_create_with_new=true}else{if(c.hasOwnProperty("view_model_create")){if(!c.view_model_create){throw new Error("Knockback.CollectionObservable: options.view_model_create is empty")}this.view_model_create_fn=c.view_model_create}else{if(c.hasOwnProperty("create")){if(!c.create){throw new Error("Knockback.CollectionObservable: options.create is empty")}this.view_model_create_fn=c.create}}}}this.sort_attribute=c.sort_attribute;this.sorted_index=c.sorted_index;this.__kb._onCollectionReset=_.bind(this._onCollectionReset,this);this.__kb._onCollectionResort=_.bind(this._onCollectionResort,this);this.__kb._onModelAdd=_.bind(this._onModelAdd,this);this.__kb._onModelRemove=_.bind(this._onModelRemove,this);this.__kb._onModelChange=_.bind(this._onModelChange,this);if(e&&f){f.bind("change",function(){return kb.utils.wrappedObservable(g).valueHasMutated()})}d.retain=_.bind(this.retain,this);d.refCount=_.bind(this.refCount,this);d.release=_.bind(this.release,this);d.collection=_.bind(this.collection,this);d.viewModelByModel=_.bind(this.viewModelByModel,this);d.sortedIndex=_.bind(this.sortedIndex,this);d.sortAttribute=_.bind(this.sortAttribute,this);d.hasViewModels=_.bind(this.hasViewModels,this);d.bind=_.bind(this.bind,this);d.unbind=_.bind(this.unbind,this);d.trigger=_.bind(this.trigger,this);this.collection(f,{silent:true,defer:c.defer});return d}a.prototype.__destroy=function(){this.collection(null);if(this.hasViewModels()&&this.__kb.store_is_owned){this.__kb.store.destroy();this.__kb.store=null}this.view_model_create_fn=null;this.__kb.collection=null;kb.utils.wrappedObservable(this,null);a.__super__.__destroy.apply(this,arguments);if(Knockback.stats_on){return kb.stats.collection_observables--}};a.prototype.retain=function(){a.__super__.retain.apply(this,arguments);return kb.utils.wrappedObservable(this)};a.prototype.release=function(){var c;c=kb.utils.wrappedObservable(this);a.__super__.release.apply(this,arguments);return c};a.prototype.collection=function(g,c){var f,d,e;f=kb.utils.wrappedObservable(this);if(arguments.length===0){f();return this.__kb.collection}if(g===this.__kb.collection){return}if(this.__kb.collection){this._clear();this._collectionUnbind(this.__kb.collection);if(typeof(d=this.__kb.collection).release==="function"){d.release()}this.__kb.collection=null}this.__kb.collection=g;if(this.__kb.collection){if(typeof(e=this.__kb.collection).retain==="function"){e.retain()}this._collectionBind(this.__kb.collection);return this.sortedIndex(this.sorted_index,this.sort_attribute,c)}};a.prototype.sortedIndex=function(g,c,d){var e,f=this;if(d==null){d={}}if(g){this.sorted_index=g;this.sort_attribute=c}else{if(c){this.sort_attribute=c;this.sorted_index=this._sortAttributeFn(c)}else{this.sort_attribute=null;this.sorted_index=null}}e=function(){var h;h=kb.utils.wrappedObservable(f);if((f.__kb.collection.models.length===0)&&(h().length===0)){return}f._collectionResync(true);if(!d.silent){return f.trigger("resort",h())}};if(d.defer){_.defer(e)}else{e()}return this};a.prototype.sortAttribute=function(d,e,c){return this.sortedIndex(e,d,c)};a.prototype.viewModelByModel=function(d){var c,e;if(!this.hasViewModels()){return null}e=kb.utils.wrappedObservable(this);c=d.hasOwnProperty(d.idAttribute)?d.idAttribute:"cid";return _.find(e(),function(f){return f.__kb.model[c]===d[c]})};a.prototype.hasViewModels=function(){return !!this.view_model_create_fn};a.prototype._collectionBind=function(j){var g,i,f,e,d,h,c;if(!j){return}j.bind("reset",this.__kb._onCollectionReset);if(!this.sorted_index){j.bind("resort",this.__kb._onCollectionResort)}h=["new","add"];for(i=0,e=h.length;i<e;i++){g=h[i];j.bind(g,this.__kb._onModelAdd)}c=["remove","destroy"];for(f=0,d=c.length;f<d;f++){g=c[f];j.bind(g,this.__kb._onModelRemove)}return j.bind("change",this.__kb._onModelChange)};a.prototype._collectionUnbind=function(j){var g,i,f,e,d,h,c;if(!j){return}j.unbind("reset",this.__kb._onCollectionReset);if(!this.sorted_index){j.unbind("resort",this.__kb._onCollectionResort)}h=["new","add"];for(i=0,e=h.length;i<e;i++){g=h[i];j.unbind(g,this.__kb._onModelAdd)}c=["remove","destroy"];for(f=0,d=c.length;f<d;f++){g=c[f];j.unbind(g,this.__kb._onModelRemove)}return j.unbind("change",this.__kb._onModelChange)};a.prototype._onCollectionReset=function(){return this._collectionResync()};a.prototype._onCollectionResort=function(d){var c;if(this.sorted_index){throw new Error("CollectionObservable: collection sorted_index unexpected")}if(_.isArray(d)){c=kb.utils.wrappedObservable(this);return this.trigger("resort",c())}else{return this._onModelResort(d)}};a.prototype._onModelAdd=function(d){var c,f,e;e=this.hasViewModels()?this._createTarget(d):d;f=kb.utils.wrappedObservable(this);if(this.sorted_index){c=this.sorted_index(f(),e)}else{c=this.__kb.collection.indexOf(d)}f.splice(c,0,e);return this.trigger("add",e,f())};a.prototype._onModelRemove=function(c){var e,d;d=this.hasViewModels()?this.viewModelByModel(c):c;if(!d){return}e=kb.utils.wrappedObservable(this);e.remove(d);this.trigger("remove",d,e);if(this.hasViewModels()){return this.__kb.store.releaseValue(d)}};a.prototype._onModelChange=function(c){if(this.sorted_index&&(!this.sort_attribute||c.hasChanged(this.sort_attribute))){return this._onModelResort(c)}};a.prototype._onModelResort=function(d){var c,g,f,h,e;g=kb.utils.wrappedObservable(this);e=this.hasViewModels()?this.viewModelByModel(d):d;f=g.indexOf(e);if(this.sorted_index){h=_.clone(g());h.splice(f,1);c=this.sorted_index(h,e)}else{c=this.__kb.collection.indexOf(d)}if(f===c){return}g.splice(f,1);g.splice(c,0,e);return this.trigger("resort",e,g(),c)};a.prototype._clear=function(f){var i,h,e,g,d,c;i=kb.utils.wrappedObservable(this);if(!f){this.trigger("remove",i())}e=i.removeAll();if(this.hasViewModels()){c=[];for(g=0,d=e.length;g<d;g++){h=e[g];c.push(this.__kb.store.releaseValue(h))}return c}};a.prototype._collectionResync=function(k){var d,g,c,j,i,e,l,f,h=this;this._clear(k);c=kb.utils.wrappedObservable(this);if(this.sorted_index){i=[];f=this.__kb.collection.models;for(e=0,l=f.length;e<l;e++){g=f[e];j=this._createTarget(g);d=this.sorted_index(i,j);i.splice(d,0,j)}}else{i=this.hasViewModels()?_.map(this.__kb.collection.models,function(m){return h._createTarget(m)}):_.clone(this.__kb.collection.models)}c(i);if(!k){return this.trigger("add",c())}};a.prototype._sortAttributeFn=function(c){if(this.hasViewModels()){return function(e,d){return _.sortedIndex(e,d,function(f){return kb.utils.wrappedModel(f).get(c)})}}else{return function(e,d){return _.sortedIndex(e,d,function(f){return f.get(c)})}}};a.prototype._createTarget=function(c){var e,d=this;e=function(){var h,g,f;g=d.__kb.store.addResolverToOptions({},c);h=kb.utils.wrappedObservable(d);f=d.view_model_create_with_new?new d.view_model_create_fn(c,g,h):d.view_model_create_fn(c,g,h);kb.utils.wrappedModel(f,c);return f};if(this.hasViewModels()){return this.__kb.store.resolveValue(c,e)}else{return c}};return a})(kb.RefCountable);__extends(Knockback.CollectionObservable.prototype,Backbone.Events);Knockback.collectionObservable=function(c,b,a){return new Knockback.CollectionObservable(c,b,a)};Knockback.sortedIndexWrapAttr=Knockback.siwa=function(a,b){return function(d,c){return _.sortedIndex(d,c,function(e){return new b(kb.utils.wrappedModel(e).get(a))})}};if(!this.Knockback){throw new Error("Knockback: Dependency alert! knockback_core.js must be included before this file")}Knockback.DefaultWrapper=(function(){a.name="DefaultWrapper";function a(b,e){var c,d=this;this.default_value_observable=e;this.__kb={};c=kb.utils.wrappedObservable(this,ko.dependentObservable({read:function(){var g,f;f=ko.utils.unwrapObservable(b());g=ko.utils.unwrapObservable(d.default_value_observable);if(!f){return g}else{return f}},write:function(f){return b(f)}}));c.destroy=_.bind(this.destroy,this);c.setToDefault=_.bind(this.setToDefault,this);return c}a.prototype.destroy=function(){kb.utils.wrappedObservable(this,null);return this.default_value=null};a.prototype.setToDefault=function(){var b;b=kb.utils.wrappedObservable(this);return b(this.default_value_observable)};return a})();Knockback.defaultWrapper=function(b,a){return new Knockback.DefaultWrapper(b,a)};Knockback.toFormattedString=function(g){var b,e,d,c,a,f;a=g.slice();e=Array.prototype.slice.call(arguments,1);for(d in e){b=e[d];f=ko.utils.unwrapObservable(b);if(!f){f=""}c=g.indexOf("{"+d+"}");while(c>=0){a=a.replace("{"+d+"}",f);c=g.indexOf("{"+d+"}",c+1)}}return a};Knockback.parseFormattedString=function(h,m){var i,a,j,k,g,p,o,f,l,b,e,n,d,c;b=m.slice();j=0;p=0;f={};while(b.search("\\{"+j+"\\}")>=0){o=m.indexOf("{"+j+"}");while(o>=0){b=b.replace("{"+j+"}","(.*)");f[o]=j;p++;o=m.indexOf("{"+j+"}",o+1)}j++}i=j;l=new RegExp(b);g=l.exec(h);if(g){g.shift()}if(!g||(g.length!==p)){return _.map((function(){c=[];for(var q=1;1<=i?q<=i:q>=i;1<=i?q++:q--){c.push(q)}return c}).apply(this),function(){return""})}n=_.sortBy(_.keys(f),function(q,r){return parseInt(q,10)});a={};for(k in n){o=n[k];j=f[o];if(a.hasOwnProperty(j)){continue}a[j]=k}e=[];j=0;while(j<i){e.push(g[a[j]]);j++}return e};Knockback.FormattedObservable=(function(){a.name="FormattedObservable";function a(e,c){var d,b;this.__kb={};if(_.isArray(c)){e=e;b=c}else{b=Array.prototype.slice.call(arguments,1)}d=kb.utils.wrappedObservable(this,ko.dependentObservable({read:function(){var f,h,g;c=[ko.utils.unwrapObservable(e)];for(h=0,g=b.length;h<g;h++){f=b[h];c.push(ko.utils.unwrapObservable(f))}return kb.toFormattedString.apply(null,c)},write:function(i){var g,h,j,f;h=kb.parseFormattedString(i,ko.utils.unwrapObservable(e));j=Math.min(b.length,h.length);g=0;f=[];while(g<j){b[g](h[g]);f.push(g++)}return f}}));return d}a.prototype.destroy=function(){return kb.utils.wrappedObservable(this,null)};return a})();Knockback.formattedObservable=function(b,a){return new Knockback.FormattedObservable(b,Array.prototype.slice.call(arguments,1))};Knockback.LocalizedObservable=(function(){a.name="LocalizedObservable";a.extend=Backbone.Model.extend;function a(d,c,b){var e;this.value=d;this.options=c!=null?c:{};this.view_model=b!=null?b:{};if(!(this.options.read||this.read)){throw new Error("LocalizedObservable: options.read is missing")}if(this.options.read&&this.read){throw new Error("LocalizedObservable: options.read and read class function exist. You need to choose one.")}if(this.options.write&&this.write){throw new Error("LocalizedObservable: options.write and write class function exist. You need to choose one.")}if(!kb.locale_manager){throw new Error("LocalizedObservable: Knockback.locale_manager is not defined")}this.__kb={};this.__kb._onLocaleChange=_.bind(this._onLocaleChange,this);if(this.value){d=ko.utils.unwrapObservable(this.value)}this.__kb.value_observable=ko.observable(!d?this._getDefaultValue():this.read.call(this,d,null));if(this.write&&!(typeof this.write==="function")){throw new Error("LocalizedObservable: options.write is not a function for read_write model attribute")}e=kb.utils.wrappedObservable(this,ko.dependentObservable({read:_.bind(this._onGetValue,this),write:this.write?_.bind(this._onSetValue,this):(function(){throw new Error("Knockback.LocalizedObservable: value is read only")}),owner:this.view_model}));e.destroy=_.bind(this.destroy,this);e.observedValue=_.bind(this.observedValue,this);e.setToDefault=_.bind(this.setToDefault,this);e.resetToCurrent=_.bind(this.resetToCurrent,this);kb.locale_manager.bind("change",this.__kb._onLocaleChange);return e}a.prototype.destroy=function(){kb.locale_manager.unbind("change",this.__kb._onLocaleChange);this.__kb.value_observable=null;kb.utils.wrappedObservable(this).dispose();kb.utils.wrappedObservable(this,null);this.options={};this.view_model=null;return this.__kb=null};a.prototype.setToDefault=function(){var c,b;if(!this["default"]){return}b=this._getDefaultValue();c=this.__kb.value_observable();if(c!==b){return this._onSetValue(b)}else{return this.__kb.value_observable.valueHasMutated()}};a.prototype.resetToCurrent=function(){this.__kb.value_observable(null);return this._onSetValue(this._getCurrentValue())};a.prototype.observedValue=function(b){if(arguments.length===0){return this.value}this.value=b;this._onLocaleChange();return this};a.prototype._getDefaultValue=function(){if(!this["default"]){return""}if(typeof this["default"]==="function"){return this["default"]()}else{return this["default"]}};a.prototype._getCurrentValue=function(){var b;b=kb.utils.wrappedObservable(this);if(!(this.value&&b)){return this._getDefaultValue()}return this.read.call(this,ko.utils.unwrapObservable(this.value))};a.prototype._onGetValue=function(){if(this.value){ko.utils.unwrapObservable(this.value)}return this.__kb.value_observable()};a.prototype._onSetValue=function(b){this.write.call(this,b,ko.utils.unwrapObservable(this.value));b=this.read.call(this,ko.utils.unwrapObservable(this.value));this.__kb.value_observable(b);if(this.options.onChange){return this.options.onChange(b)}};a.prototype._onLocaleChange=function(){var b;b=this.read.call(this,ko.utils.unwrapObservable(this.value));this.__kb.value_observable(b);if(this.options.onChange){return this.options.onChange(b)}};return a})();Knockback.localizedObservable=function(c,b,a){return new Knockback.LocalizedObservable(c,b,a)};Knockback.Observable=(function(){a.name="Observable";function a(c,d,b){var e,f=this;this.model=c;this.mapping_info=d;this.view_model=b!=null?b:{};if(!this.model){throw new Error("Observable: model is missing")}if(!this.mapping_info){throw new Error("Observable: mapping_info is missing")}if(_.isString(this.mapping_info)||ko.isObservable(this.mapping_info)){this.mapping_info={key:this.mapping_info}}if(!this.mapping_info.key){throw new Error("Observable: mapping_info.key is missing")}this.__kb={};this.__kb._onModelChange=_.bind(this._onModelChange,this);this.__kb._onModelLoaded=_.bind(this._onModelLoaded,this);this.__kb._onModelUnloaded=_.bind(this._onModelUnloaded,this);if(this.mapping_info.hasOwnProperty("write")&&_.isBoolean(this.mapping_info.write)){this.mapping_info=_.clone(this.mapping_info);this.mapping_info.read_only=!this.mapping_info.write}if(Backbone.ModelRef&&(this.model instanceof Backbone.ModelRef)){this.model_ref=this.model;this.model_ref.retain();this.model_ref.bind("loaded",this.__kb._onModelLoaded);this.model_ref.bind("unloaded",this.__kb._onModelUnloaded);this.model=this.model_ref.getModel()}this.__kb.value_observable=ko.observable();if(this.mapping_info.localizer){this.__kb.localizer=new this.mapping_info.localizer(this._getCurrentValue())}e=kb.utils.wrappedObservable(this,ko.dependentObservable({read:_.bind(this._onGetValue,this),write:this.mapping_info.read_only?(function(){throw new Error("Knockback.Observable: "+f.mapping_info.key+" is read only")}):_.bind(this._onSetValue,this),owner:this.view_model}));e.destroy=_.bind(this.destroy,this);e.setToDefault=_.bind(this.setToDefault,this);if(!this.model_ref||this.model_ref.isLoaded()){this.model.bind("change",this.__kb._onModelChange)}return e}a.prototype.destroy=function(){this.__kb.value_observable=null;kb.utils.wrappedObservable(this).dispose();kb.utils.wrappedObservable(this,null);if(this.model){this.__kb._onModelUnloaded(this.model)}if(this.model_ref){this.model_ref.unbind("loaded",this.__kb._onModelLoaded);this.model_ref.unbind("unloaded",this.__kb._onModelUnloaded);this.model_ref.release();this.model_ref=null}this.mapping_info=null;this.view_model=null;return this.__kb=null};a.prototype.setToDefault=function(){var b;b=this._getDefaultValue();if(this.__kb.localizer){this.__kb.localizer.observedValue(b);b=this.__kb.localizer()}return this.__kb.value_observable(b)};a.prototype._getDefaultValue=function(){if(!this.mapping_info.hasOwnProperty("default")){return""}if(typeof this.mapping_info["default"]==="function"){return this.mapping_info["default"]()}else{return this.mapping_info["default"]}};a.prototype._getCurrentValue=function(){var b,d,e,g,c,f;if(!this.model){return this._getDefaultValue()}e=ko.utils.unwrapObservable(this.mapping_info.key);d=[e];if(!_.isUndefined(this.mapping_info.args)){if(_.isArray(this.mapping_info.args)){f=this.mapping_info.args;for(g=0,c=f.length;g<c;g++){b=f[g];d.push(ko.utils.unwrapObservable(b))}}else{d.push(ko.utils.unwrapObservable(this.mapping_info.args))}}if(this.mapping_info.read){return this.mapping_info.read.apply(this.view_model,d)}else{return this.model.get.apply(this.model,d)}};a.prototype._onGetValue=function(){var b,f,e,c,d;this.__kb.value_observable();ko.utils.unwrapObservable(this.mapping_info.key);if(!_.isUndefined(this.mapping_info.args)){if(_.isArray(this.mapping_info.args)){d=this.mapping_info.args;for(e=0,c=d.length;e<c;e++){b=d[e];ko.utils.unwrapObservable(b)}}else{ko.utils.unwrapObservable(this.mapping_info.args)}}f=this._getCurrentValue();if(this.__kb.localizer){this.__kb.localizer.observedValue(f);f=this.__kb.localizer()}return f};a.prototype._onSetValue=function(h){var b,e,d,g,c,f;if(this.__kb.localizer){this.__kb.localizer(h);h=this.__kb.localizer.observedValue()}if(this.model){d={};d[ko.utils.unwrapObservable(this.mapping_info.key)]=h;e=typeof this.mapping_info.write==="function"?[h]:[d];if(!_.isUndefined(this.mapping_info.args)){if(_.isArray(this.mapping_info.args)){f=this.mapping_info.args;for(g=0,c=f.length;g<c;g++){b=f[g];e.push(ko.utils.unwrapObservable(b))}}else{e.push(ko.utils.unwrapObservable(this.mapping_info.args))}}if(typeof this.mapping_info.write==="function"){this.mapping_info.write.apply(this.view_model,e)}else{this.model.set.apply(this.model,e)}}if(this.__kb.localizer){return this.__kb.value_observable(this.__kb.localizer())}else{return this.__kb.value_observable(h)}};a.prototype._modelBind=function(b){if(!b){return}b.bind("change",this.__kb._onModelChange);if(Backbone.RelationalModel&&(b instanceof Backbone.RelationalModel)){b.bind("add",this.__kb._onModelChange);b.bind("remove",this.__kb._onModelChange);return b.bind("update",this.__kb._onModelChange)}};a.prototype._modelUnbind=function(b){if(!b){return}b.unbind("change",this.__kb._onModelChange);if(Backbone.RelationalModel&&(b instanceof Backbone.RelationalModel)){b.unbind("add",this.__kb._onModelChange);b.unbind("remove",this.__kb._onModelChange);return b.unbind("update",this.__kb._onModelChange)}};a.prototype._onModelLoaded=function(b){this.model=b;this._modelBind(b);return this._updateValue()};a.prototype._onModelUnloaded=function(b){if(this.__kb.localizer&&this.__kb.localizer.destroy){this.__kb.localizer.destroy();this.__kb.localizer=null}this._modelUnbind(b);return this.model=null};a.prototype._onModelChange=function(){if((this.model&&this.model.hasChanged)&&!this.model.hasChanged(ko.utils.unwrapObservable(this.mapping_info.key))){return}return this._updateValue()};a.prototype._updateValue=function(){var b;b=this._getCurrentValue();if(this.__kb.localizer){this.__kb.localizer.observedValue(b);b=this.__kb.localizer()}return this.__kb.value_observable(b)};return a})();Knockback.observable=function(b,c,a){return new Knockback.Observable(b,c,a)};Knockback.Observables=(function(){a.name="Observables";function a(e,g,k,j){var h,i,f,c,d,b;if(!e){throw new Error("Observables: model is missing")}if(!g||!_.isObject(g)){throw new Error("Observables: mappings_info is missing")}this.__kb||(this.__kb={});this.__kb.model=e;this.__kb.mappings_info=g;this.__kb.view_model=_.isUndefined(k)?this:k;if(!_.isUndefined(j)&&j.hasOwnProperty("write")){kb.utils.legacyWarning("Knockback.Observables option.write","0.16.0","Now default is writable so only supply read_only as required");j.read_only=!j.write;delete j.write}if(!_.isUndefined(j)){c=_.isBoolean(j)?j:j.read_only;d=this.__kb.mappings_info;for(f in d){i=d[f];h=_.isString(i);if(h){i=!_.isUndefined(c)?{key:i,read_only:c}:{key:i}}else{if(!_.isUndefined(c)&&!(i.hasOwnProperty("read_only")||i.hasOwnProperty("write"))){i.read_only=c}}if(!i.hasOwnProperty("key")){i.key=f}this[f]=this.__kb.view_model[f]=kb.observable(this.__kb.model,i,this.__kb.view_model)}}else{b=this.__kb.mappings_info;for(f in b){i=b[f];if(i.hasOwnProperty("write")){kb.utils.legacyWarning("Knockback.Observables option.write","0.16.0","Now default is writable so only supply read_only as required")}if(!i.hasOwnProperty("key")){i.key=f}this[f]=this.__kb.view_model[f]=kb.observable(this.__kb.model,i,this.__kb.view_model)}}}a.prototype.destroy=function(){var c,b,d;d=this.__kb.mappings_info;for(b in d){c=d[b];if(this.__kb.view_model[b]){this.__kb.view_model[b].destroy()}this.__kb.view_model[b]=null;this[b]=null}this.__kb.view_model=null;this.__kb.mappings_info=null;return this.__kb.model=null};a.prototype.setToDefault=function(){var d,b,e,c;e=this.__kb.mappings_info;c=[];for(b in e){d=e[b];c.push(this.__kb.view_model[b].setToDefault())}return c};return a})();Knockback.observables=function(c,d,a,b){return new Knockback.Observables(c,d,a,b)};Knockback.TriggeredObservable=(function(){a.name="TriggeredObservable";function a(b,d){var c;this.model=b;this.event_name=d;if(!this.model){throw new Error("Observable: model is missing")}if(!this.event_name){throw new Error("Observable: event_name is missing")}this.__kb={};this.__kb._onValueChange=_.bind(this._onValueChange,this);this.__kb._onModelLoaded=_.bind(this._onModelLoaded,this);this.__kb._onModelUnloaded=_.bind(this._onModelUnloaded,this);if(Backbone.ModelRef&&(this.model instanceof Backbone.ModelRef)){this.model_ref=this.model;this.model_ref.retain();this.model_ref.bind("loaded",this.__kb._onModelLoaded);this.model_ref.bind("unloaded",this.__kb._onModelUnloaded);this.model=this.model_ref.getModel()}this.__kb.value_observable=ko.observable();c=kb.utils.wrappedObservable(this,ko.dependentObservable(_.bind(this._onGetValue,this)));c.destroy=_.bind(this.destroy,this);if(!this.model_ref||this.model_ref.isLoaded()){this._onModelLoaded(this.model)}return c}a.prototype.destroy=function(){kb.utils.wrappedObservable(this).dispose();kb.utils.wrappedObservable(this,null);this.__kb.value_observable=null;if(this.model){this._onModelUnloaded(this.model)}if(this.model_ref){this.model_ref.unbind("loaded",this.__kb._onModelLoaded);this.model_ref.unbind("unloaded",this.__kb._onModelUnloaded);this.model_ref.release();this.model_ref=null}this.options=null;this.view_model=null;return this.__kb=null};a.prototype._onGetValue=function(){return this.__kb.value_observable()};a.prototype._onModelLoaded=function(b){this.model=b;this.model.bind(this.event_name,this.__kb._onValueChange);return this._onValueChange()};a.prototype._onModelUnloaded=function(){if(this.__kb.localizer&&this.__kb.localizer.destroy){this.__kb.localizer.destroy();this.__kb.localizer=null}this.model.unbind(this.event_name,this.__kb._onValueChange);return this.model=null};a.prototype._onValueChange=function(){var b;b=this.__kb.value_observable();if(b!==this.model){return this.__kb.value_observable(this.model)}else{return this.__kb.value_observable.valueHasMutated()}};return a})();Knockback.triggeredObservable=function(a,b){return new Knockback.TriggeredObservable(a,b)};var __hasProp={}.hasOwnProperty,__extends=function(d,b){for(var a in b){if(__hasProp.call(b,a)){d[a]=b[a]}}function c(){this.constructor=d}c.prototype=b.prototype;d.prototype=new c;d.__super__=b.prototype;return d};Knockback.AttributeConnector=(function(){a.name="AttributeConnector";function a(c,d,b){var e;this.key=d;this.options=b!=null?b:{};kb.utils.wrappedModel(this,c);this.options=_.clone(this.options);this.__kb.value_observable=ko.observable();e=kb.utils.wrappedObservable(this,ko.dependentObservable({read:_.bind(this.read,this),write:_.bind(this.write,this)}));e.destroy=_.bind(this.destroy,this);e.model=_.bind(this.model,this);e.update=_.bind(this.update,this);this.__kb.initializing=true;this.update();this.__kb.initializing=false;return e}a.prototype.destroy=function(){this.__kb.value_observable=null;kb.utils.wrappedObservable(this).dispose();return kb.utils.wrappedObservable(this,null)};a.prototype.read=function(){return this.__kb.value_observable()};a.prototype.write=function(d){var c,b;c=kb.utils.wrappedModel(this);if(!c){return}if(this.options.read_only){if(!this.__kb.initializing){throw"Cannot write a value to a dependentObservable unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters."}}else{b={};b[this.key]=d;return c.set(b)}};a.prototype.model=function(b){var c;c=kb.utils.wrappedModel(this);if(arguments.length===0){return c}if(c===b){return}kb.utils.wrappedModel(this,b);return this.update()};a.inferType=function(b,c){var d,e;e=b.get(c);if(!e){if(!(Backbone.RelationalModel&&(b instanceof Backbone.RelationalModel))){return"simple"}d=_.find(b.getRelations(),function(f){return f.key===c});if(!d){return"simple"}if(d.collectionKey){return"collection"}else{return"model"}}if(e instanceof Backbone.Collection){return"collection"}if((e instanceof Backbone.Model)||(Backbone.ModelRef&&(e instanceof Backbone.ModelRef))){return"model"}return"simple"};a.createByType=function(e,c,d,b){var f;switch(e){case"collection":f=b?_.clone(b):{};if(!(b.view_model||b.view_model_create||b.children||b.create)){f.view_model=kb.ViewModel}if(b.store){b.store.addResolverToOptions(f,c.get(d))}return kb.collectionAttributeConnector(c,d,f);case"model":f=b?_.clone(b):{};if(!f.options){f.options={}}if(!(b.view_model||b.view_model_create||b.children||b.create)){f.view_model=kb.ViewModel}if(b.store){b.store.addResolverToOptions(f.options,c.get(d))}return kb.viewModelAttributeConnector(c,d,f);default:return kb.simpleAttributeConnector(c,d,b)}};a.createOrUpdate=function(f,c,d,b){var g,e;if(f){if(kb.utils.observableInstanceOf(f,kb.AttributeConnector)){if(f.model()!==c){f.model(c)}else{f.update()}}return f}if(!c){return kb.simpleAttributeConnector(c,d,b)}if(b.hasOwnProperty("create")){if(!b.create){throw new Error("Knockback.AttributeConnector: options.create is empty")}return b.create(c,d,b.options||{})}e=c.get(d);if(b.hasOwnProperty("view_model")){if(!b.view_model){throw new Error("Knockback.AttributeConnector: options.view_model is empty")}return new b.view_model(e,b.options||{})}else{if(b.hasOwnProperty("view_model_create")){if(!b.view_model_create){throw new Error("Knockback.AttributeConnector: options.view_model_create is empty")}return b.view_model_create(e,b.options||{})}else{if(b.hasOwnProperty("children")){if(!b.children){throw new Error("Knockback.AttributeConnector: options.children is empty")}if(typeof b.children==="function"){g={view_model:b.children}}else{g=b.children||{}}return kb.collectionAttributeConnector(c,d,g)}}}return this.createByType(this.inferType(c,d),c,d,b)};return a})();Knockback.SimpleAttributeConnector=(function(b){__extends(a,b);a.name="SimpleAttributeConnector";function a(){a.__super__.constructor.apply(this,arguments);return kb.utils.wrappedObservable(this)}a.prototype.destroy=function(){this.current_value=null;return a.__super__.destroy.apply(this,arguments)};a.prototype.update=function(){var d,c,e;c=kb.utils.wrappedModel(this);if(!c){return}e=c.get(this.key);d=this.__kb.value_observable();if(!_.isEqual(d,e)){return this.__kb.value_observable(e)}};a.prototype.write=function(d){var c;c=kb.utils.wrappedModel(this);if(!c){this.__kb.value_observable(d);return}return a.__super__.write.apply(this,arguments)};return a})(Knockback.AttributeConnector);Knockback.simpleAttributeConnector=function(b,c,a){return new Knockback.SimpleAttributeConnector(b,c,a)};Knockback.CollectionAttributeConnector=(function(a){__extends(b,a);b.name="CollectionAttributeConnector";function b(){b.__super__.constructor.apply(this,arguments);return kb.utils.wrappedObservable(this)}b.prototype.destroy=function(){var c;c=this.__kb.value_observable();if(c&&(typeof c.refCount==="function")&&(c.refCount()>0)){c.release()}return b.__super__.destroy.apply(this,arguments)};b.prototype.update=function(){var d,c,e,f=this;c=kb.utils.wrappedModel(this);if(!c){return}e=c.get(this.key);d=this.__kb.value_observable();if(!d){if(this.options.store){return this.__kb.value_observable(this.options.store.resolveValue(e,function(){return kb.collectionObservable(e,f.options)}))}else{return this.__kb.value_observable(kb.collectionObservable(e,this.options))}}else{if(d.collection()!==e){d.collection(e);return this.__kb.value_observable.valueHasMutated()}}};b.prototype.read=function(){var c;c=this.__kb.value_observable();if(c){return c()}else{return}};return b})(Knockback.AttributeConnector);Knockback.collectionAttributeConnector=function(b,c,a){return new Knockback.CollectionAttributeConnector(b,c,a)};Knockback.ViewModelAttributeConnector=(function(b){__extends(a,b);a.name="ViewModelAttributeConnector";function a(){a.__super__.constructor.apply(this,arguments);return kb.utils.wrappedObservable(this)}a.prototype.destroy=function(){var c;c=this.__kb.value_observable();if(c&&(typeof c.refCount==="function")&&(c.refCount()>0)){c.release()}return a.__super__.destroy.apply(this,arguments)};a.prototype.update=function(){var d,c,e,f,g=this;c=kb.utils.wrappedModel(this);if(!c){return}e=c.get(this.key);d=this.__kb.value_observable();if(!d){f=this.options.options?_.clone(this.options.options):{};if(f.store){return this.__kb.value_observable(f.store.resolveValue(e,function(){if(g.options.view_model){return new g.options.view_model(e,f)}else{return g.options.view_model_create(e,f)}}))}else{return this.__kb.value_observable(this.options.view_model?new this.options.view_model(e,f):this.options.view_model_create(e,f))}}else{if(!(d.model&&(typeof d.model==="function"))){throw new Error("Knockback.viewModelAttributeConnector: unknown how to model a view model")}if(d.model()!==e){d.model(e);return this.__kb.value_observable.valueHasMutated()}}};return a})(Knockback.AttributeConnector);Knockback.viewModelAttributeConnector=function(b,c,a){return new Knockback.ViewModelAttributeConnector(b,c,a)};var __hasProp={}.hasOwnProperty,__extends=function(d,b){for(var a in b){if(__hasProp.call(b,a)){d[a]=b[a]}}function c(){this.constructor=d}c.prototype=b.prototype;d.prototype=new c;d.__super__=b.prototype;return d};Knockback.ViewModel_RCBase=(function(b){__extends(a,b);a.name="ViewModel_RCBase";function a(){return a.__super__.constructor.apply(this,arguments)}a.prototype.__destroy=function(){var d,e,c;c=[];for(d in this){e=this[d];if(!e||(d==="__kb")){continue}if(kb.utils.release(e)){c.push(this[d]=null)}else{c.push(void 0)}}return c};return a})(Knockback.RefCountable);Knockback.ViewModel=(function(b){__extends(a,b);a.name="ViewModel";function a(e,d){var g,f,h,c;if(d==null){d={}}a.__super__.constructor.apply(this,arguments);if(Knockback.stats_on){kb.stats.view_models++}if(!d.store_skip_resolve){kb.Store.resolveFromOptions(d,this)}if(d.store){this.__kb.store=d.store}else{this.__kb.store=new kb.Store();this.__kb.store_is_owned=true}this.__kb._onModelChange=_.bind(this._onModelChange,this);this.__kb._onModelLoaded=_.bind(this._onModelLoaded,this);this.__kb._onModelUnloaded=_.bind(this._onModelUnloaded,this);this.__kb.internals=d.internals;this.__kb.requires=d.requires;this.__kb.children=d.children;this.__kb.create=d.create;this.__kb.read_only=d.read_only;kb.utils.wrappedModel(this,e);if(Backbone.ModelRef&&(e instanceof Backbone.ModelRef)){this.__kb.model_ref=e;this.__kb.model_ref.retain();kb.utils.wrappedModel(this,this.__kb.model_ref.getModel());this.__kb.model_ref.bind("loaded",this.__kb._onModelLoaded);this.__kb.model_ref.bind("unloaded",this.__kb._onModelUnloaded)}if(this.__kb.model){this._onModelLoaded(this.__kb.model)}if(!this.__kb.internals&&!this.__kb.requires){return this}f=_.union((this.__kb.internals?this.__kb.internals:[]),(this.__kb.requires?this.__kb.requires:[]));if(!this.__kb.model_ref||this.__kb.model_ref.isLoaded()){f=_.difference(f,_.keys(this.__kb.model.attributes))}for(h=0,c=f.length;h<c;h++){g=f[h];this._updateAttributeConnector(this.__kb.model,g)}}a.prototype.__destroy=function(){var c;c=this.__kb.model;kb.utils.wrappedModel(this,null);this._modelUnbind(c);if(this.__kb.store_is_owned){this.__kb.store.destroy()}this.__kb.store=null;a.__super__.__destroy.apply(this,arguments);if(Knockback.stats_on){return kb.stats.view_models--}};a.prototype.model=function(c){var d;d=kb.utils.wrappedModel(this);if(arguments.length===0){return d}if(c===d){return}if(d){this._onModelUnloaded(d)}if(c){return this._onModelLoaded(c)}};a.prototype._modelBind=function(c){if(!c){return}c.bind("change",this.__kb._onModelChange);if(Backbone.RelationalModel&&(c instanceof Backbone.RelationalModel)){c.bind("add",this.__kb._onModelChange);c.bind("remove",this.__kb._onModelChange);return c.bind("update",this.__kb._onModelChange)}};a.prototype._modelUnbind=function(c){if(!c){return}c.unbind("change",this.__kb._onModelChange);if(Backbone.RelationalModel&&(c instanceof Backbone.RelationalModel)){c.unbind("add",this.__kb._onModelChange);c.unbind("remove",this.__kb._onModelChange);return c.unbind("update",this.__kb._onModelChange)}};a.prototype._onModelLoaded=function(d){var e,c;kb.utils.wrappedModel(this,d);this._modelBind(d);c=[];for(e in this.__kb.model.attributes){c.push(this._updateAttributeConnector(this.__kb.model,e))}return c};a.prototype._onModelUnloaded=function(d){var e,c;this._modelUnbind(d);kb.utils.wrappedModel(this,null);c=[];for(e in d.attributes){c.push(this._updateAttributeConnector(null,e))}return c};a.prototype._onModelChange=function(){var e,c,d;if(this.__kb.model._changed){c=[];for(e in this.__kb.model.attributes){c.push(this.__kb.model.hasChanged(e)?this._updateAttributeConnector(this.__kb.model,e):void 0)}return c}else{if(this.__kb.model.changed){d=[];for(e in this.__kb.model.changed){d.push(this._updateAttributeConnector(this.__kb.model,e))}return d}}};a.prototype._updateAttributeConnector=function(c,e){var d;d=this.__kb.internals&&_.contains(this.__kb.internals,e)?"_"+e:e;return this[d]=kb.AttributeConnector.createOrUpdate(this[d],c,e,this._createOptions(e))};a.prototype._createOptions=function(d){var c;if(this.__kb.children){if(this.__kb.children.hasOwnProperty(d)){c=this.__kb.children[d];if(typeof c==="function"){c={view_model:c}}c.options={read_only:this.__kb.read_only,store:this.__kb.store};return c}else{if(this.__kb.children.hasOwnProperty("create")){return{create:this.__kb.children.create,options:{read_only:this.__kb.read_only,store:this.__kb.store}}}}}else{if(this.__kb.create){return{create:this.__kb.create,options:{read_only:this.__kb.read_only,store:this.__kb.store}}}}return{read_only:this.__kb.read_only,store:this.__kb.store}};return a})(Knockback.ViewModel_RCBase);Knockback.viewModel=function(b,a){return new Knockback.ViewModel(b,a)};
// Generated by CoffeeScript 1.3.3
(function() {
ko.bindingHandlers.dblclick = {
init: function(element, value_accessor) {
return $(element).dblclick(ko.utils.unwrapObservable(value_accessor()));
}
};
ko.bindingHandlers.block = {
update: function(element, value_accessor) {
return element.style.display = ko.utils.unwrapObservable(value_accessor()) ? 'block' : 'none';
}
};
ko.bindingHandlers.selectAndFocus = {
init: function(element, value_accessor, all_bindings_accessor) {
ko.bindingHandlers.hasfocus.init(element, value_accessor, all_bindings_accessor);
return ko.utils.registerEventHandler(element, 'focus', function() {
return element.select();
});
},
update: function(element, value_accessor) {
ko.utils.unwrapObservable(value_accessor());
return _.defer(function() {
return ko.bindingHandlers.hasfocus.update(element, value_accessor);
});
}
};
}).call(this);
......@@ -32,16 +32,14 @@
};
TodoCollection.prototype.destroyCompleted = function() {
var completed_tasks, model, _i, _len, _results;
var completed_tasks, model, _i, _len;
completed_tasks = this.filter(function(todo) {
return todo.completed();
});
_results = [];
for (_i = 0, _len = completed_tasks.length; _i < _len; _i++) {
model = completed_tasks[_i];
_results.push(model.destroy());
model.destroy();
}
return _results;
};
return TodoCollection;
......
// Generated by CoffeeScript 1.3.3
(function() {
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.AppRouter = (function(_super) {
__extends(AppRouter, _super);
function AppRouter() {
return AppRouter.__super__.constructor.apply(this, arguments);
}
AppRouter.prototype.routes = {
"": "all",
"active": "active",
"completed": "completed"
};
AppRouter.prototype.all = function() {
return app.viewmodels.settings.list_filter_mode('');
};
AppRouter.prototype.active = function() {
return app.viewmodels.settings.list_filter_mode('active');
};
AppRouter.prototype.completed = function() {
return app.viewmodels.settings.list_filter_mode('completed');
};
return AppRouter;
})(Backbone.Router);
}).call(this);
// Generated by CoffeeScript 1.3.3
(function() {
var ENTER_KEY;
ENTER_KEY = 13;
window.AppViewModel = function() {
var filter_fn, router,
_this = this;
this.collections = {
todos: new TodoCollection()
};
this.collections.todos.fetch();
this.list_filter_mode = ko.observable('');
filter_fn = ko.computed(function() {
switch (_this.list_filter_mode()) {
case 'active':
return function(model) {
return model.completed();
};
case 'completed':
return function(model) {
return !model.completed();
};
default:
return function() {
return false;
};
}
});
this.todos = kb.collectionObservable(this.collections.todos, {
view_model: TodoViewModel,
filters: filter_fn
});
this.todos_changed = kb.triggeredObservable(this.collections.todos, 'change add remove');
this.tasks_exist = ko.computed(function() {
_this.todos_changed();
return !!_this.collections.todos.length;
});
this.title = ko.observable('');
this.onAddTodo = function(view_model, event) {
if (!$.trim(_this.title()) || (event.keyCode !== ENTER_KEY)) {
return true;
}
_this.collections.todos.create({
title: $.trim(_this.title())
});
return _this.title('');
};
this.remaining_count = ko.computed(function() {
_this.todos_changed();
return _this.collections.todos.remainingCount();
});
this.completed_count = ko.computed(function() {
_this.todos_changed();
return _this.collections.todos.completedCount();
});
this.all_completed = ko.computed({
read: function() {
return !_this.remaining_count();
},
write: function(completed) {
return _this.collections.todos.completeAll(completed);
}
});
this.onDestroyCompleted = function() {
return _this.collections.todos.destroyCompleted();
};
this.loc = {
remaining_message: ko.computed(function() {
return "<strong>" + (_this.remaining_count()) + "</strong> " + (_this.remaining_count() === 1 ? 'item' : 'items') + " left";
}),
clear_message: ko.computed(function() {
var count;
if ((count = _this.completed_count())) {
return "Clear completed (" + count + ")";
} else {
return '';
}
})
};
router = new Backbone.Router;
router.route('', null, function() {
return _this.list_filter_mode('');
});
router.route('active', null, function() {
return _this.list_filter_mode('active');
});
router.route('completed', null, function() {
return _this.list_filter_mode('completed');
});
Backbone.history.start();
};
}).call(this);
// Generated by CoffeeScript 1.3.3
(function() {
window.FooterViewModel = function(todos) {
var _this = this;
this.todos = kb.collectionObservable(todos);
this.todos.collection().bind('change', function() {
return _this.todos.valueHasMutated();
});
this.remaining_text = ko.computed(function() {
return "<strong>" + (_this.todos.collection().remainingCount()) + "</strong> " + (_this.todos.collection().remainingCount() === 1 ? 'item' : 'items') + " left";
});
this.clear_text = ko.computed(function() {
var count;
count = _this.todos.collection().completedCount();
if (count) {
return "Clear completed (" + count + ")";
} else {
return '';
}
});
this.onDestroyCompleted = function() {
return todos.destroyCompleted();
};
return this;
};
}).call(this);
// Generated by CoffeeScript 1.3.3
(function() {
var ENTER_KEY;
ENTER_KEY = 13;
window.HeaderViewModel = function(todos) {
var _this = this;
this.title = ko.observable('');
this.onAddTodo = function(view_model, event) {
if (!$.trim(_this.title()) || (event.keyCode !== ENTER_KEY)) {
return true;
}
todos.create({
title: $.trim(_this.title())
});
return _this.title('');
};
return this;
};
}).call(this);
// Generated by CoffeeScript 1.3.3
(function() {
window.SettingsViewModel = function() {
this.list_filter_mode = ko.observable('');
return this;
};
}).call(this);
// Generated by CoffeeScript 1.3.3
(function() {
var TodoViewModel;
TodoViewModel = function(model) {
window.TodoViewModel = function(model) {
var _this = this;
this.editing = ko.observable(false);
this.completed = kb.observable(model, {
......@@ -14,16 +13,6 @@
return model.completed(completed);
})
}, this);
this.visible = ko.computed(function() {
switch (app.viewmodels.settings.list_filter_mode()) {
case 'active':
return !_this.completed();
case 'completed':
return _this.completed();
default:
return true;
}
});
this.title = kb.observable(model, {
key: 'title',
write: (function(title) {
......@@ -44,7 +33,8 @@
};
this.onCheckEditBegin = function() {
if (!_this.editing() && !_this.completed()) {
return _this.editing(true);
_this.editing(true);
return $('.todo-input').focus();
}
};
this.onCheckEditEnd = function(view_model, event) {
......@@ -53,29 +43,6 @@
return _this.editing(false);
}
};
return this;
};
window.TodosViewModel = function(todos) {
var _this = this;
this.todos = kb.collectionObservable(todos, {
view_model: TodoViewModel
});
this.todos.collection().bind('change', function() {
return _this.todos.valueHasMutated();
});
this.tasks_exist = ko.computed(function() {
return _this.todos().length;
});
this.all_completed = ko.computed({
read: function() {
return !_this.todos.collection().remainingCount();
},
write: function(completed) {
return _this.todos.collection().completeAll(completed);
}
});
return this;
};
}).call(this);
# Knockback.js • [TodoMVC](http://todomvc.com)
Forked from https://github.com/kmalakoff/knockback-todos
## Getting started
[CoffeeScript](http://coffeescript.org) is required to compile this application if you make changes to the files in the `src` folder.
You need [CoffeScript](http://coffeescript.org) to compile if you make changes to the files in the `src` folder.
## Compile
......@@ -14,4 +11,4 @@ Open Terminal in this folder.
- `cake build` to compile once
- `cake watch` to compile on save
- `cake watch` to compile on save
\ No newline at end of file
$ ->
# Add custom handlers to Knockout.js - adapted from Knockout.js Todos app: https://github.com/ashish01/knockoutjs-todos
ko.bindingHandlers.dblclick =
init: (element, value_accessor) -> $(element).dblclick(ko.utils.unwrapObservable(value_accessor()))
ko.bindingHandlers.block =
update: (element, value_accessor) -> element.style.display = if ko.utils.unwrapObservable(value_accessor()) then 'block' else 'none'
ko.bindingHandlers.selectAndFocus =
init: (element, value_accessor, all_bindings_accessor) ->
ko.bindingHandlers.hasfocus.init(element, value_accessor, all_bindings_accessor)
ko.utils.registerEventHandler(element, 'focus', -> element.focus())
update: (element, value_accessor) ->
ko.utils.unwrapObservable(value_accessor()) # create dependency
_.defer(=>ko.bindingHandlers.hasfocus.update(element, value_accessor))
# Create and bind the app viewmodels
window.app = {viewmodels: {}}
app.viewmodels.settings = new SettingsViewModel()
todos = new TodoCollection()
app.viewmodels.header = new HeaderViewModel(todos)
app.viewmodels.todos = new TodosViewModel(todos)
app.viewmodels.footer = new FooterViewModel(todos)
ko.applyBindings(app.viewmodels, $('#todoapp')[0])
# Start the app routing
new AppRouter()
Backbone.history.start()
# Load the todos
todos.fetch()
# kb.vmRelease(app.viewmodels) # Destroy when finished with the view model
# Add custom handlers to Knockout.js - adapted from Knockout.js Todos app: https://github.com/ashish01/knockoutjs-todos
ko.bindingHandlers.dblclick =
init: (element, value_accessor) -> $(element).dblclick(ko.utils.unwrapObservable(value_accessor()))
ko.bindingHandlers.block =
update: (element, value_accessor) -> element.style.display = if ko.utils.unwrapObservable(value_accessor()) then 'block' else 'none'
ko.bindingHandlers.selectAndFocus =
init: (element, value_accessor, all_bindings_accessor) ->
ko.bindingHandlers.hasfocus.init(element, value_accessor, all_bindings_accessor)
ko.utils.registerEventHandler(element, 'focus', -> element.select())
update: (element, value_accessor) ->
ko.utils.unwrapObservable(value_accessor()) # create dependency
_.defer(->ko.bindingHandlers.hasfocus.update(element, value_accessor))
\ No newline at end of file
class window.Todo extends Backbone.Model
completed: (completed) ->
return !!@get('completed') if arguments.length == 0
@save({completed: if completed then new Date() else null})
return !!@get('completed') if arguments.length is 0 # getter
@save({completed: if completed then new Date() else null}) # setter
\ No newline at end of file
class window.TodoCollection extends Backbone.Collection
localStorage: new Store('todos-knockback') # Save all of the todos under the `"todos-knockback"` namespace.
localStorage: new Store('todos-knockback') # Save all of the todos under the "todos-knockback" namespace.
model: Todo
completedCount: -> @models.reduce(((prev,cur)-> return prev + if cur.completed() then 1 else 0), 0)
......@@ -10,3 +10,4 @@ class window.TodoCollection extends Backbone.Collection
destroyCompleted: ->
completed_tasks = @filter((todo) -> return todo.completed())
model.destroy() for model in completed_tasks
return
\ No newline at end of file
class window.AppRouter extends Backbone.Router
routes:
"": "all"
"active": "active"
"completed": "completed"
all: -> app.viewmodels.settings.list_filter_mode('')
active: -> app.viewmodels.settings.list_filter_mode('active')
completed: -> app.viewmodels.settings.list_filter_mode('completed')
ENTER_KEY = 13
window.AppViewModel = ->
#############################
# Shared
#############################
# collections
@collections =
todos: new TodoCollection()
@collections.todos.fetch()
# shared observables
@list_filter_mode = ko.observable('')
filter_fn = ko.computed(=>
switch @list_filter_mode()
when 'active' then return (model) -> return model.completed()
when 'completed' then return (model) -> return not model.completed()
else return -> return false
)
@todos = kb.collectionObservable(@collections.todos, {view_model: TodoViewModel, filters: filter_fn})
@todos_changed = kb.triggeredObservable(@collections.todos, 'change add remove')
@tasks_exist = ko.computed(=> @todos_changed(); return !!@collections.todos.length)
#############################
# Header Section
#############################
@title = ko.observable('')
@onAddTodo = (view_model, event) =>
return true if not $.trim(@title()) or (event.keyCode != ENTER_KEY)
# Create task and reset UI
@collections.todos.create({title: $.trim(@title())})
@title('')
#############################
# Main Section
#############################
@remaining_count = ko.computed(=> @todos_changed(); return @collections.todos.remainingCount())
@completed_count = ko.computed(=> @todos_changed(); return @collections.todos.completedCount())
@all_completed = ko.computed(
read: => return not @remaining_count()
write: (completed) => @collections.todos.completeAll(completed)
)
#############################
# Footer Section
#############################
@onDestroyCompleted = =>
@collections.todos.destroyCompleted()
#############################
# Localization
#############################
@loc =
remaining_message: ko.computed(=> return "<strong>#{@remaining_count()}</strong> #{if @remaining_count() == 1 then 'item' else 'items'} left")
clear_message: ko.computed(=> return if (count = @completed_count()) then "Clear completed (#{count})" else '')
#############################
# Routing
#############################
router = new Backbone.Router
router.route('', null, => @list_filter_mode(''))
router.route('active', null, => @list_filter_mode('active'))
router.route('completed', null, => @list_filter_mode('completed'))
Backbone.history.start()
return
\ No newline at end of file
window.FooterViewModel = (todos) ->
@todos = kb.collectionObservable(todos)
@todos.collection().bind('change', => @todos.valueHasMutated()) # get notified of changes to any models
@remaining_text = ko.computed(=> return "<strong>#{@todos.collection().remainingCount()}</strong> #{if @todos.collection().remainingCount() == 1 then 'item' else 'items'} left")
@clear_text = ko.computed(=>
count = @todos.collection().completedCount()
return if count then "Clear completed (#{count})" else ''
)
@onDestroyCompleted = => todos.destroyCompleted()
@
ENTER_KEY = 13
window.HeaderViewModel = (todos) ->
@title = ko.observable('')
@onAddTodo = (view_model, event) =>
return true if not $.trim(@title()) or (event.keyCode != ENTER_KEY)
# Create task and reset UI
todos.create({title: $.trim(@title())})
@title('')
@
window.SettingsViewModel = ->
@list_filter_mode = ko.observable('')
@
TodoViewModel = (model) ->
# Task UI state
window.TodoViewModel = (model) ->
@editing = ko.observable(false)
@completed = kb.observable(model, {key: 'completed', read: (-> return model.completed()), write: ((completed) -> model.completed(completed)) }, @)
@visible = ko.computed(=>
switch app.viewmodels.settings.list_filter_mode()
when 'active' then return not @completed()
when 'completed' then return @completed()
else return true
)
@title = kb.observable(model, {
key: 'title'
......@@ -19,18 +12,14 @@ TodoViewModel = (model) ->
@onDestroyTodo = => model.destroy()
@onCheckEditBegin = => @editing(true) if not @editing() and not @completed()
@onCheckEditEnd = (view_model, event) => ($('.todo-input').blur(); @editing(false)) if (event.keyCode == 13) or (event.type == 'blur')
@
@onCheckEditBegin = =>
if not @editing() and not @completed()
@editing(true)
$('.todo-input').focus()
window.TodosViewModel = (todos) ->
@todos = kb.collectionObservable(todos, {view_model: TodoViewModel})
@todos.collection().bind('change', => @todos.valueHasMutated()) # get notified of changes to any models
@tasks_exist = ko.computed(=> @todos().length)
@onCheckEditEnd = (view_model, event) =>
if (event.keyCode == 13) or (event.type == 'blur')
$('.todo-input').blur()
@editing(false)
@all_completed = ko.computed(
read: => return not @todos.collection().remainingCount()
write: (completed) => @todos.collection().completeAll(completed)
)
@
return
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment