Commit f83a3caa authored by Stephen Sawchuk's avatar Stephen Sawchuk

DUEL bug fixed, code style.

parent b852875e
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<%-- could have embedded in 'tasks' for-loop, but this allows us to add single tasks --%> <%-- could have embedded in 'tasks' for-loop, but this allows us to add single tasks --%>
<li class="<%= data.completed ? 'complete' : '' %>"> <li class="<%= data.completed ? 'completed' : '' %>">
<div class="view"> <div class="view">
<input class="toggle" type="checkbox" checked="<%= data.completed %>" <input class="toggle" type="checkbox" checked="<%= data.completed %>"
......
/*global window */
/*jshint camelcase:false */
var todos = todos || {}; var todos = todos || {};
(function( todos, document ) { (function (todos, document) {
'use strict';
/*-- private members -------------------------------*/ /*-- private members -------------------------------*/
var ENTER_KEY = 13, var ENTER_KEY = 13;
STATS_ID = 'footer', var STATS_ID = 'footer';
TODOAPP_ID = 'todoapp', var TODOAPP_ID = 'todoapp';
TASKS_ID = 'main', var TASKS_ID = 'main';
LIST_ID = 'todo-list', var LIST_ID = 'todo-list';
EDITING_CSS = 'editing'; var EDITING_CSS = 'editing';
function getById( id ) { function getById(id) {
return document.getElementById( id ); return document.getElementById(id);
} }
function refreshStats( stats ) { function refreshStats(stats) {
// get the data // get the data
var data = stats || todos.model.stats(); var data = stats || todos.model.stats();
// build the view // build the view
var view = todos.views.Stats( data ).toDOM(); var view = todos.views.Stats(data).toDOM();
// replace old stats // replace old stats
var old = getById( STATS_ID ); var old = getById(STATS_ID);
if ( old ) { if (old) {
old.parentNode.replaceChild( view, old ); old.parentNode.replaceChild(view, old);
} else { } else {
getById( TODOAPP_ID ).appendChild( view ); getById(TODOAPP_ID).appendChild(view);
} }
} }
...@@ -39,47 +43,47 @@ var todos = todos || {}; ...@@ -39,47 +43,47 @@ var todos = todos || {};
}; };
// build the view // build the view
var view = todos.views.Tasks( data ).toDOM(); var view = todos.views.Tasks(data).toDOM();
// replace old task list // replace old task list
var old = getById( TASKS_ID ); var old = getById(TASKS_ID);
if ( old ) { if (old) {
old.parentNode.replaceChild( view, old ); old.parentNode.replaceChild(view, old);
} else { } else {
getById( TODOAPP_ID ).appendChild( view ); getById(TODOAPP_ID).appendChild(view);
} }
refreshStats( data.stats ); refreshStats(data.stats);
} }
function add( input ) { function add(input) {
var title = (input.value || '').trim(); var title = (input.value || '').trim();
input.value = ''; input.value = '';
if ( !title ) { if (!title) {
return; return;
} }
var task = todos.model.add( title ); var task = todos.model.add(title);
var list = getById( LIST_ID ); var list = getById(LIST_ID);
if ( list ) { if (list) {
// add new at the top // add new at the top
list.appendChild( todos.views.Task( task ).toDOM() ); list.appendChild(todos.views.Task(task).toDOM());
refreshStats(); refreshStats();
} else { } else {
refreshAll(); refreshAll();
} }
} }
function edit( input, id ) { function edit(input, id) {
var title = (input.value || '').trim(); var title = (input.value || '').trim();
input.value = title; input.value = title;
if ( title ) { if (title) {
todos.model.edit( id, title ); todos.model.edit(id, title);
} else { } else {
todos.model.remove( id ); todos.model.remove(id);
} }
refreshAll(); refreshAll();
} }
...@@ -88,74 +92,84 @@ var todos = todos || {}; ...@@ -88,74 +92,84 @@ var todos = todos || {};
// event handlers // event handlers
todos.actions = { todos.actions = {
add_blur: function( e ) { addBlur: function () {
add( this ); add(this);
}, },
add_keypress: function( e ) { add_keypress: function (e) {
if ( e.keyCode === ENTER_KEY ) { if (e.keyCode === ENTER_KEY) {
add( this ); add(this);
} }
}, },
edit_blur: function( id ) { edit_blur: function (id) {
// create a closure around the ID // create a closure around the ID
return function( e ) { return function () {
edit( this, id ); edit(this, id);
}; };
}, },
edit_keypress: function( id ) { edit_keypress: function () {
// create a closure around the ID // create a closure around the ID
return function(e) { return function (e) {
if ( e.keyCode === ENTER_KEY ) { if (e.keyCode === ENTER_KEY) {
// just blur so doesn't get triggered twice // just blur so doesn't get triggered twice
this.blur(); this.blur();
} }
}; };
}, },
remove_click: function( id ) { remove_click: function (id) {
// create a closure around the ID // create a closure around the ID
return function( e ) { return function () {
todos.model.remove( id ); todos.model.remove(id);
refreshAll(); refreshAll();
}; };
}, },
clear_click: function() { clear_click: function () {
todos.model.expunge(); todos.model.expunge();
refreshAll(); refreshAll();
}, },
content_dblclick: function( id ) { content_dblclick: function () {
// create a closure around the ID // create a closure around the ID
return function( e ) { var toggleEditingMode = function (li) {
var li = this; if (li.tagName !== 'LI') {
return toggleEditingMode(li.parentNode);
}
li.className = EDITING_CSS; li.className = EDITING_CSS;
li.getElementsByTagName( 'input' )[1].focus();
var input = li.getElementsByTagName('input')[1];
input.focus();
input.value = input.value;
};
return function () {
toggleEditingMode(this);
}; };
}, },
completed_change: function( id ) { completed_change: function (id) {
// create a closure around the ID // create a closure around the ID
return function( e ) { return function () {
var checkbox = this; var checkbox = this;
todos.model.toggle( id, checkbox.checked ); todos.model.toggle(id, checkbox.checked);
refreshAll(); refreshAll();
}; };
}, },
toggle_change: function( e ) { toggle_change: function () {
var checkbox = this; var checkbox = this;
todos.model.toggleAll( checkbox.checked ); todos.model.toggleAll(checkbox.checked);
refreshAll(); refreshAll();
} }
}; };
/*-- init task list -------------------------------*/ /*-- init task list -------------------------------*/
(function( body ) { (function (body) {
// build out task list // build out task list
var view = todos.views.TodoApp({ var view = todos.views.TodoApp({
tasks: todos.model.tasks(), tasks: todos.model.tasks(),
...@@ -163,7 +177,7 @@ var todos = todos || {}; ...@@ -163,7 +177,7 @@ var todos = todos || {};
}).toDOM(); }).toDOM();
// insert at top // insert at top
body.insertBefore( view, body.firstChild ); body.insertBefore(view, body.firstChild);
})( document.body ); })(document.body);
})( todos, document ); })(todos, window.document);
/*global window */
var todos = todos || {}; var todos = todos || {};
(function( todos, localStorage, KEY ) { (function (todos, localStorage, KEY) {
'use strict';
/*-- private members -------------------------------*/ /*-- private members -------------------------------*/
...@@ -8,22 +11,22 @@ var todos = todos || {}; ...@@ -8,22 +11,22 @@ var todos = todos || {};
// model uses localStorage as the underlying data store // model uses localStorage as the underlying data store
// this creates a poor man's localStorage polyfill // this creates a poor man's localStorage polyfill
localStorage = localStorage || (function() { localStorage = localStorage || (function () {
var storage = {}; var storage = {};
return { return {
getItem: function( key ) { getItem: function (key) {
return storage[ key ]; return storage[key];
}, },
setItem: function( key, value ) { setItem: function (key, value) {
storage[ key ] = value; storage[key] = value;
} }
}; };
})(); })();
function create( title, completed ) { function create(title, completed) {
return { return {
// fast, compact, non-repeating, unique ID: e.g., 'c2wwu0vz.pz4zpvi' // fast, compact, non-repeating, unique ID: e.g., 'c2wwu0vz.pz4zpvi'
id: (new Date().getTime() + Math.random()).toString( 36 ), id: (new Date().getTime() + Math.random()).toString(36),
title: title, title: title,
completed: !!completed completed: !!completed
}; };
...@@ -31,16 +34,15 @@ var todos = todos || {}; ...@@ -31,16 +34,15 @@ var todos = todos || {};
function save() { function save() {
// if doesn't support JSON then will be directly stored in polyfill // if doesn't support JSON then will be directly stored in polyfill
var value = typeof JSON !== 'undefined' ? JSON.stringify( tasks ) : tasks; var value = typeof JSON !== 'undefined' ? JSON.stringify(tasks) : tasks;
localStorage.setItem( KEY, value ); localStorage.setItem(KEY, value);
} }
// initialize storage // initialize storage
var value = localStorage.getItem( KEY ); var value = localStorage.getItem(KEY);
if ( value ) { if (value) {
// if doesn't support JSON then will be directly stored in polyfill // if doesn't support JSON then will be directly stored in polyfill
tasks = typeof JSON !== 'undefined' ? JSON.parse( value ) : value; tasks = typeof JSON !== 'undefined' ? JSON.parse(value) : value;
} else { } else {
tasks = []; tasks = [];
} }
...@@ -48,90 +50,77 @@ var todos = todos || {}; ...@@ -48,90 +50,77 @@ var todos = todos || {};
/*-- export public interface -------------------------------*/ /*-- export public interface -------------------------------*/
todos.model = { todos.model = {
tasks: function () {
tasks: function() {
return tasks; return tasks;
}, },
stats: function() { stats: function () {
var stats = { var stats = {};
total: tasks.length,
active: tasks.length,
completed: 0
};
var i = tasks.length; stats.total = tasks.length;
while ( i-- ) {
if ( tasks[i].completed ) { stats.completed = tasks.filter(function (task) {
stats.completed++; return task.completed;
} }).length;
}
stats.active -= stats.completed; stats.active = stats.total - stats.completed;
return stats; return stats;
}, },
add: function( title ) { add: function (title) {
var task = create( title, false ); var task = create(title, false);
tasks.push( task ); tasks.push(task);
save(); save();
return task; return task;
}, },
edit: function( id, title ) { edit: function (id, title) {
var i = tasks.length; tasks.filter(function (task) {
while ( i-- ) { return task.id === id;
if ( tasks[i].id === id ) { })[0].title = title;
tasks[i].title = title;
save(); save();
return;
}
}
}, },
// toggle completion of task // toggle completion of task
toggle: function( id, completed ) { toggle: function (id, completed) {
var i = tasks.length; tasks.filter(function (task) {
while ( i-- ) { return task.id === id;
if ( tasks[i].id === id ) { })[0].completed = completed;
tasks[i].completed = completed;
save(); save();
return;
}
}
}, },
// toggle completion of all tasks // toggle completion of all tasks
toggleAll: function( completed ) { toggleAll: function (completed) {
var i = tasks.length; tasks.forEach(function (task) {
while ( i-- ) { task.completed = completed;
tasks[i].completed = completed; });
}
save(); save();
}, },
remove: function( id ) { remove: function (id) {
var i = tasks.length; tasks.forEach(function (task, index) {
while ( i-- ) { if (task.id === id) {
if ( tasks[i].id === id ) { tasks.splice(index, 1);
tasks.splice( i, 1 );
save();
return;
}
} }
});
save();
}, },
expunge: function() { expunge: function () {
var i = tasks.length; tasks.forEach(function (task, index) {
while ( i-- ) { if (task.completed) {
if ( tasks[i].completed ) { tasks.splice(index, 1);
tasks.splice( i, 1 );
}
} }
});
save(); save();
} }
}; };
})(todos, window.localStorage, 'todos-duel');
})( todos, window.localStorage, 'todos-duel' );
(function(){function g(){var a=["labs","architecture-examples","dependency-examples"].filter(function(a){return location.href.match(RegExp(a))})[0];return location.href.substr(0,location.href.indexOf(a))}function e(a,c){if(!(this instanceof e))return new e(a,c);var b,d;if("object"!==typeof a)try{a=JSON.parse(a)}catch(h){return}if(c)b=c.template,d=c.framework;if(!b&&a.templates)b=a.templates.todomvc;!d&&document.querySelector("[data-framework]")&&(d=document.querySelector("[data-framework]").getAttribute("data-framework")); (function(){function j(){var a;[/labs/,/\w*-examples/].forEach(function(b){b=location.href.match(b);!a&&b&&(a=location.href.indexOf(b))});return location.href.substr(0,a)}function i(a,b){if(!(this instanceof i))return new i(a,b);var c,e;if("object"!==typeof a)try{a=JSON.parse(a)}catch(n){return}if(b)c=b.template,e=b.framework;if(!c&&a.templates)c=a.templates.todomvc;!e&&document.querySelector("[data-framework]")&&(e=document.querySelector("[data-framework]").getAttribute("data-framework"));if(c&&
if(b&&a[d])this.frameworkJSON=a[d],this.template=b,this.append()}if("todomvc.com"===location.hostname)window._gaq=[["_setAccount","UA-31081062-1"],["_trackPageview"]],function(a,c){var b=a.createElement(c),d=a.getElementsByTagName(c)[0];b.src="//www.google-analytics.com/ga.js";d.parentNode.insertBefore(b,d)}(document,"script");e.prototype._prepareTemplate=function(){var a=document.createElement("aside"),c=a.cloneNode(a);c.innerHTML=this.template;var b=c.cloneNode(a);b.removeChild(b.querySelector("ul")); a[e])this.frameworkJSON=a[e],this.template=c,this.append()}var m=function(a){a.defaults=function(a){if(!a)return a;for(var b=1,c=arguments.length;b<c;b++){var e=arguments[b];if(e)for(var h in e)null==a[h]&&(a[h]=e[h])}return a};a.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var b=/(.)^/,c={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},e=/\\|'|\r|\n|\t|\u2028|\u2029/g;a.template=function(i,g,f){var k,f=a.defaults({},
b.removeChild(b.querySelectorAll("footer")[1]);return{header:b,links:c.cloneNode(a).querySelector("ul a"),footer:c.cloneNode(a).querySelectorAll("footer")[1]}};e.prototype._parseTemplate=function(){if(this.template){var a=this.frameworkJSON,c=this._prepareTemplate(),b=document.createElement("aside"),d=c.links.outerHTML,e=/\{\{([^}]*)\}\}/g,f;f=c.header.innerHTML.replace(e,function(b,c){return a[c]});b.innerHTML=f;if(a.examples)f=a.examples.map(function(a){return"<h5>"+a.name+'</h5><p> <a href="https://github.com/tastejs/todomvc/tree/gh-pages/'+ f,a.templateSettings),h=RegExp([(f.escape||b).source,(f.interpolate||b).source,(f.evaluate||b).source].join("|")+"|$","g"),j=0,d="__p+='";i.replace(h,function(a,b,f,g,h){d+=i.slice(j,h).replace(e,function(a){return"\\"+c[a]});b&&(d+="'+\n((__t=("+b+"))==null?'':_.escape(__t))+\n'");f&&(d+="'+\n((__t=("+f+"))==null?'':__t)+\n'");g&&(d+="';\n"+g+"\n__p+='");j=h+a.length;return a});d+="';\n";f.variable||(d="with(obj||{}){\n"+d+"}\n");d="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+
(a.source_url||a.url)+'">Source</a></p>'}).join(""),b.querySelector(".source-links").innerHTML=f;a.link_groups&&(f=a.link_groups.map(function(a){return"<h4>"+a.heading+"</h4><ul>"+a.links.map(function(a){return"<li>"+d.replace(e,function(b,c){return a[c]})+"</li>"}).join("")+"</ul>"}).join(""),b.innerHTML+=f,b.innerHTML+=c.footer.outerHTML);return b}};e.prototype.append=function(){var a=this._parseTemplate();a.className="learn";document.body.className=(document.body.className+" learn-bar").trim(); d+"return __p;\n";try{k=new Function(f.variable||"obj","_",d)}catch(l){throw l.source=d,l;}if(g)return k(g,a);g=function(b){return k.call(this,b,a)};g.source="function("+(f.variable||"obj")+"){\n"+d+"}";return g};return a}({});if("todomvc.com"===location.hostname)window._gaq=[["_setAccount","UA-31081062-1"],["_trackPageview"]],function(a,b){var c=a.createElement(b),e=a.getElementsByTagName(b)[0];c.src="//www.google-analytics.com/ga.js";e.parentNode.insertBefore(c,e)}(document,"script");i.prototype.append=
document.body.insertAdjacentElement("afterBegin",a)};(function(){var a=document.createElement("a"),c=document.createElement("p"),b=document.getElementById("info");if(b)a.href="https://github.com/tastejs/todomvc/tree/gh-pages"+(0<location.hostname.indexOf("github.io")?location.pathname.replace(/todomvc\//,""):location.pathname),a.appendChild(document.createTextNode("Check out the source")),c.appendChild(a),b.appendChild(c)})();if("tastejs.github.io"===location.hostname)location.href=location.href.replace("tastejs.github.io/todomvc", function(){var a=document.createElement("aside");a.innerHTML=m.template(this.template,this.frameworkJSON);a.className="learn";var b=a.querySelectorAll(".demo-link");Array.prototype.forEach.call(b,function(a){a.setAttribute("href",j()+a.getAttribute("href"))});document.body.className=(document.body.className+" learn-bar").trim();document.body.insertAdjacentHTML("afterBegin",a.outerHTML)};if("tastejs.github.io"===location.hostname)location.href=location.href.replace("tastejs.github.io/todomvc","todomvc.com");
"todomvc.com");(function(a,c){var b=new XMLHttpRequest;b.open("GET",g()+a,!0);b.send();b.onload=function(){200===b.status&&c&&c(b.responseText)}})("learn.json",e)})();/* (function(a,b){if(!location.host)return console.info("Miss the info bar? Run TodoMVC from a server to avoid a cross-origin error.");var c=new XMLHttpRequest;c.open("GET",j()+a,!0);c.send();c.onload=function(){200===c.status&&b&&b(c.responseText)}})("learn.json",i)})();/*
DUEL v0.8.2 http://duelengine.org DUEL v0.8.2 http://duelengine.org
Copyright (c)2006-2012 Stephen M. McKamey. Copyright (c)2006-2012 Stephen M. McKamey.
Licensed under The MIT License. Licensed under The MIT License.
...@@ -24,10 +24,10 @@ k(e.index,b,c,f,d):c;i=e.hasOwnProperty("count")?k(e.count,b,c,f,d):f;b=e.hasOwn ...@@ -24,10 +24,10 @@ k(e.index,b,c,f,d):c;i=e.hasOwnProperty("count")?k(e.count,b,c,f,d):f;b=e.hasOwn
u=function(a){return n(a)&&n(a.getView)?a:J(a)};u.raw=function(a){return new x(a)};var M={area:!0,base:!0,basefont:!0,br:!0,col:!0,frame:!0,hr:!0,img:!0,input:!0,isindex:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,wbr:!0},C={async:1,checked:1,defer:1,disabled:1,hidden:1,novalidate:1,formnovalidate:1};q.prototype.toString=function(){var a;var b=this.value;try{var c=new o;B(c,b);a=c.toString()}catch(f){a="["+f+"]"}return a};q.prototype.write=function(a){(a||m).write(""+this)};var P={rowspan:"rowSpan", u=function(a){return n(a)&&n(a.getView)?a:J(a)};u.raw=function(a){return new x(a)};var M={area:!0,base:!0,basefont:!0,br:!0,col:!0,frame:!0,hr:!0,img:!0,input:!0,isindex:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,wbr:!0},C={async:1,checked:1,defer:1,disabled:1,hidden:1,novalidate:1,formnovalidate:1};q.prototype.toString=function(){var a;var b=this.value;try{var c=new o;B(c,b);a=c.toString()}catch(f){a="["+f+"]"}return a};q.prototype.write=function(a){(a||m).write(""+this)};var P={rowspan:"rowSpan",
colspan:"colSpan",cellpadding:"cellPadding",cellspacing:"cellSpacing",tabindex:"tabIndex",accesskey:"accessKey",hidefocus:"hideFocus",usemap:"useMap",maxlength:"maxLength",readonly:"readOnly",contenteditable:"contentEditable"},p={enctype:"encoding",onscroll:"DOMMouseScroll",checked:"defaultChecked"},N=/^[\r\n]+/,O=/[\r\n]+$/;q.prototype.toDOM=function(a,b){4===l(a)&&(a=m.getElementById(a));var c;try{b&&(c=a,a=null),c=I(c||t(this.value[0]),this.value)}catch(f){c=m.createTextNode("["+f+"]")}a&&a.parentNode&& colspan:"colSpan",cellpadding:"cellPadding",cellspacing:"cellSpacing",tabindex:"tabIndex",accesskey:"accessKey",hidefocus:"hideFocus",usemap:"useMap",maxlength:"maxLength",readonly:"readOnly",contenteditable:"contentEditable"},p={enctype:"encoding",onscroll:"DOMMouseScroll",checked:"defaultChecked"},N=/^[\r\n]+/,O=/[\r\n]+$/;q.prototype.toDOM=function(a,b){4===l(a)&&(a=m.getElementById(a));var c;try{b&&(c=a,a=null),c=I(c||t(this.value[0]),this.value)}catch(f){c=m.createTextNode("["+f+"]")}a&&a.parentNode&&
a.parentNode.replaceChild(c,a);return c};q.prototype.reload=function(){var a=m;try{var b=this.toDOM();a.replaceChild(b,a.documentElement);if(a.createStyleSheet){for(var c=b.firstChild;c&&"HEAD"!==(c.tagName||"");)c=c.nextSibling;for(var f=c&&c.firstChild;f;){if("LINK"===(f.tagName||""))f.href=f.href;f=f.nextSibling}}}catch(d){a=a.open("text/html"),a.write(this.toString()),a.close()}};return u}(document,window.ScriptEngineMajorVersion);var todos=todos||{}; a.parentNode.replaceChild(c,a);return c};q.prototype.reload=function(){var a=m;try{var b=this.toDOM();a.replaceChild(b,a.documentElement);if(a.createStyleSheet){for(var c=b.firstChild;c&&"HEAD"!==(c.tagName||"");)c=c.nextSibling;for(var f=c&&c.firstChild;f;){if("LINK"===(f.tagName||""))f.href=f.href;f=f.nextSibling}}}catch(d){a=a.open("text/html"),a.write(this.toString()),a.close()}};return u}(document,window.ScriptEngineMajorVersion);var todos=todos||{};
(function(i,f,h){function e(){var b="undefined"!==typeof JSON?JSON.stringify(a):a;f.setItem(h,b)}var a,f=f||function(){var b={};return{getItem:function(a){return b[a]},setItem:function(a,d){b[a]=d}}}(),g=f.getItem(h);a=g?"undefined"!==typeof JSON?JSON.parse(g):g:[];i.model={tasks:function(){return a},stats:function(){for(var b={total:a.length,active:a.length,completed:0},c=a.length;c--;)a[c].completed&&b.completed++;b.active-=b.completed;return b},add:function(b){b={id:((new Date).getTime()+Math.random()).toString(36), (function(h,e,g){function d(){var a="undefined"!==typeof JSON?JSON.stringify(b):b;e.setItem(g,a)}var b,e=e||function(){var a={};return{getItem:function(c){return a[c]},setItem:function(c,b){a[c]=b}}}(),f=e.getItem(g);b=f?"undefined"!==typeof JSON?JSON.parse(f):f:[];h.model={tasks:function(){return b},stats:function(){var a={};a.total=b.length;a.completed=b.filter(function(a){return a.completed}).length;a.active=a.total-a.completed;return a},add:function(a){a={id:((new Date).getTime()+Math.random()).toString(36),
title:b,completed:!1};a.push(b);e();return b},edit:function(b,c){for(var d=a.length;d--;)if(a[d].id===b){a[d].title=c;e();break}},toggle:function(b,c){for(var d=a.length;d--;)if(a[d].id===b){a[d].completed=c;e();break}},toggleAll:function(b){for(var c=a.length;c--;)a[c].completed=b;e()},remove:function(b){for(var c=a.length;c--;)if(a[c].id===b){a.splice(c,1);e();break}},expunge:function(){for(var b=a.length;b--;)a[b].completed&&a.splice(b,1);e()}}})(todos,window.localStorage,"todos-duel");var todos=todos||{};todos.views=todos.views||{};todos.views.Stats=duel([""," ",["$if",{test:function(a){return a.total}},["footer",{id:"footer"}," ",["span",{id:"todo-count"},["strong",function(a){return a.active}]," ",function(a){return 1===a.active?"item":"items"}," left"]," "," ",["$if",{test:function(a){return a.completed}},["button",{id:"clear-completed",onclick:function(){return todos.actions.clear_click}},"Clear completed (",function(a){return a.completed},")"]]]]]);var todos=todos||{};todos.views=todos.views||{}; title:a,completed:!1};b.push(a);d();return a},edit:function(a,c){b.filter(function(b){return b.id===a})[0].title=c;d()},toggle:function(a,c){b.filter(function(b){return b.id===a})[0].completed=c;d()},toggleAll:function(a){b.forEach(function(b){b.completed=a});d()},remove:function(a){b.forEach(function(c,d){c.id===a&&b.splice(d,1)});d()},expunge:function(){b.forEach(function(a,c){a.completed&&b.splice(c,1)});d()}}})(todos,window.localStorage,"todos-duel");var todos=todos||{};todos.views=todos.views||{};todos.views.Stats=duel([""," ",["$if",{test:function(a){return a.total}},["footer",{id:"footer"}," ",["span",{id:"todo-count"},["strong",function(a){return a.active}]," ",function(a){return 1===a.active?"item":"items"}," left"]," "," ",["$if",{test:function(a){return a.completed}},["button",{id:"clear-completed",onclick:function(){return todos.actions.clear_click}},"Clear completed (",function(a){return a.completed},")"]]]]]);var todos=todos||{};todos.views=todos.views||{};
todos.views.Task=duel([""," ",["li",{"class":function(a){return a.completed?"complete":""}}," ",["div",{"class":"view"}," ",["input",{"class":"toggle",type:"checkbox",checked:function(a){return a.completed},onchange:function(a){return todos.actions.completed_change(a.id)}}]," ",["label",{ondblclick:function(a){return todos.actions.content_dblclick(a.id)}},function(a){return a.title}]," ",["button",{"class":"destroy",onclick:function(a){return todos.actions.remove_click(a.id)}}]," "]," ",["input", todos.views.Task=duel([""," ",["li",{"class":function(a){return a.completed?"completed":""}}," ",["div",{"class":"view"}," ",["input",{"class":"toggle",type:"checkbox",checked:function(a){return a.completed},onchange:function(a){return todos.actions.completed_change(a.id)}}]," ",["label",{ondblclick:function(a){return todos.actions.content_dblclick(a.id)}},function(a){return a.title}]," ",["button",{"class":"destroy",onclick:function(a){return todos.actions.remove_click(a.id)}}]," "]," ",["input",
{"class":"edit",type:"text",value:function(a){return a.title},onblur:function(a){return todos.actions.edit_blur(a.id)},onkeypress:function(a){return todos.actions.edit_keypress(a.id)}}]]]);var todos=todos||{};todos.views=todos.views||{};todos.views.Tasks=duel([""," ",["$if",{test:function(a){return a.tasks.length}},["section",{id:"main"}," ",["input",{id:"toggle-all",type:"checkbox",checked:function(a){return!a.stats.active},onchange:function(){return todos.actions.toggle_change}}]," ",["label",{"for":"toggle-all"},"Mark all as complete"]," ",["ul",{id:"todo-list"}," ",["$for",{each:function(a){return a.tasks}}," ",["$call",{view:function(){return todos.views.Task}}]]," "]]]]);var todos=todos||{};todos.views=todos.views||{};todos.views.TodoApp=duel(["section",{id:"todoapp"}," ",["header",{id:"header"}," ",["h1","todos"]," ",["input",{id:"new-todo",placeholder:"What needs to be done?",autofocus:null,onblur:function(){return todos.actions.add_blur},onkeypress:function(){return todos.actions.add_keypress}}]," "]," ",["$call",{view:function(){return todos.views.Tasks},data:function(a){return a}}]," ",["$call",{view:function(){return todos.views.Stats},data:function(a){return a.stats}}]]);var todos=todos||{}; {"class":"edit",type:"text",value:function(a){return a.title},onblur:function(a){return todos.actions.edit_blur(a.id)},onkeypress:function(a){return todos.actions.edit_keypress(a.id)}}]]]);var todos=todos||{};todos.views=todos.views||{};todos.views.Tasks=duel([""," ",["$if",{test:function(a){return a.tasks.length}},["section",{id:"main"}," ",["input",{id:"toggle-all",type:"checkbox",checked:function(a){return!a.stats.active},onchange:function(){return todos.actions.toggle_change}}]," ",["label",{"for":"toggle-all"},"Mark all as complete"]," ",["ul",{id:"todo-list"}," ",["$for",{each:function(a){return a.tasks}}," ",["$call",{view:function(){return todos.views.Task}}]]," "]]]]);var todos=todos||{};todos.views=todos.views||{};todos.views.TodoApp=duel(["section",{id:"todoapp"}," ",["header",{id:"header"}," ",["h1","todos"]," ",["input",{id:"new-todo",placeholder:"What needs to be done?",autofocus:null,onblur:function(){return todos.actions.add_blur},onkeypress:function(){return todos.actions.add_keypress}}]," "]," ",["$call",{view:function(){return todos.views.Tasks},data:function(a){return a}}]," ",["$call",{view:function(){return todos.views.Stats},data:function(a){return a.stats}}]]);var todos=todos||{};
(function(b,e){function f(a){var a=a||b.model.stats(),a=b.views.Stats(a).toDOM(),c=e.getElementById(i);c?c.parentNode.replaceChild(a,c):e.getElementById(g).appendChild(a)}function d(){var a={tasks:b.model.tasks(),stats:b.model.stats()},c=b.views.Tasks(a).toDOM(),d=e.getElementById(j);d?d.parentNode.replaceChild(c,d):e.getElementById(g).appendChild(c);f(a.stats)}function h(a){var c=(a.value||"").trim();a.value="";c&&(a=b.model.add(c),(c=e.getElementById(k))?(c.appendChild(b.views.Task(a).toDOM()),f()): (function(c,e){function f(a){var a=a||c.model.stats(),a=c.views.Stats(a).toDOM(),b=e.getElementById(i);b?b.parentNode.replaceChild(a,b):e.getElementById(g).appendChild(a)}function d(){var a={tasks:c.model.tasks(),stats:c.model.stats()},b=c.views.Tasks(a).toDOM(),d=e.getElementById(j);d?d.parentNode.replaceChild(b,d):e.getElementById(g).appendChild(b);f(a.stats)}function h(a){var b=(a.value||"").trim();a.value="";b&&(a=c.model.add(b),(b=e.getElementById(k))?(b.appendChild(c.views.Task(a).toDOM()),f()):
d())}var i="footer",g="todoapp",j="main",k="todo-list";b.actions={add_blur:function(){h(this)},add_keypress:function(a){13===a.keyCode&&h(this)},edit_blur:function(a){return function(){var c=(this.value||"").trim();(this.value=c)?b.model.edit(a,c):b.model.remove(a);d()}},edit_keypress:function(){return function(a){13===a.keyCode&&this.blur()}},remove_click:function(a){return function(){b.model.remove(a);d()}},clear_click:function(){b.model.expunge();d()},content_dblclick:function(){return function(){this.className= d())}var i="footer",g="todoapp",j="main",k="todo-list";c.actions={addBlur:function(){h(this)},add_keypress:function(a){13===a.keyCode&&h(this)},edit_blur:function(a){return function(){var b=(this.value||"").trim();(this.value=b)?c.model.edit(a,b):c.model.remove(a);d()}},edit_keypress:function(){return function(a){13===a.keyCode&&this.blur()}},remove_click:function(a){return function(){c.model.remove(a);d()}},clear_click:function(){c.model.expunge();d()},content_dblclick:function(){var a=function(b){if("LI"!==
"editing";this.getElementsByTagName("input")[1].focus()}},completed_change:function(a){return function(){b.model.toggle(a,this.checked);d()}},toggle_change:function(){b.model.toggleAll(this.checked);d()}};(function(a){var c=b.views.TodoApp({tasks:b.model.tasks(),stats:b.model.stats()}).toDOM();a.insertBefore(c,a.firstChild)})(e.body)})(todos,document); b.tagName)return a(b.parentNode);b.className="editing";b=b.getElementsByTagName("input")[1];b.focus();b.value=b.value};return function(){a(this)}},completed_change:function(a){return function(){c.model.toggle(a,this.checked);d()}},toggle_change:function(){c.model.toggleAll(this.checked);d()}};(function(a){var b=c.views.TodoApp({tasks:c.model.tasks(),stats:c.model.stats()}).toDOM();a.insertBefore(b,a.firstChild)})(e.body)})(todos,window.document);
\ No newline at end of file \ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<p>Ported to <a href="http://duelengine.org">DUEL</a> by <a href="http://mck.me">Stephen McKamey</a></p> <p>Ported to <a href="http://duelengine.org">DUEL</a> by <a href="http://mck.me">Stephen McKamey</a></p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p> <p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer> </footer>
<script src="./cdn/cb86ce6c04dc2c3e1a7111b0000b1252c883d20c.js"></script> <script src="./cdn/4340176df828f72a94b201a48c223860b95908dc.js"></script>
</body> </body>
</html> </html>
\ 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