Skip to content

Commit b81aff4

Browse files
committed
Merge pull request totaljs#10 from josephpconley/master
knockout.js example for total.js
2 parents 7e4b900 + e75f026 commit b81aff4

File tree

12 files changed

+139
-0
lines changed

12 files changed

+139
-0
lines changed

knockoutjs-todo/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pid
2+
tmp

knockoutjs-todo/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
##knockout.js/total.js
2+
3+
The obligatory TODO app featuring Knockout.js and total.js
4+
5+
npm install total.js

knockoutjs-todo/config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Both configuration (debug/release)
2+
3+
allow-compile-js: false
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
exports.install = function(framework) {
2+
framework.route('/', view_homepage);
3+
};
4+
5+
function view_homepage() {
6+
var self = this;
7+
self.view('index');
8+
}

knockoutjs-todo/debug.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

knockoutjs-todo/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var framework = require('total.js');
2+
var http = require('http');
3+
var debug = true;
4+
5+
framework.run(http, debug);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.completed{
2+
text-decoration: line-through;
3+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function Todo(description){
2+
var self = this;
3+
self.description = ko.observable(description);
4+
self.completed = ko.observable(false);
5+
}
6+
7+
function TodoApp(){
8+
var self = this;
9+
self.todos = ko.observableArray([]);
10+
self.newTodo = ko.observable("");
11+
self.saveTodo = function (data, event) {
12+
//if enter was pressed then save
13+
if (event.keyCode == 13) {
14+
self.todos.push(new Todo(self.newTodo()));
15+
self.newTodo("");
16+
}
17+
return true;
18+
}
19+
self.clearCompleted = function(){
20+
self.todos.remove(function(todo) { return todo.completed() })
21+
}
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.completed{text-decoration:line-through;}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function Todo(description){
2+
var self = this;
3+
self.description = ko.observable(description);
4+
self.completed = ko.observable(false);
5+
}
6+
7+
function TodoApp(){
8+
var self = this;
9+
self.todos = ko.observableArray([]);
10+
self.newTodo = ko.observable("");
11+
self.saveTodo = function (data, event) {
12+
//if enter was pressed then save
13+
if (event.keyCode == 13) {
14+
self.todos.push(new Todo(self.newTodo()));
15+
self.newTodo("");
16+
}
17+
return true;
18+
}
19+
self.clearCompleted = function(){
20+
self.todos.remove(function(todo) { return todo.completed() })
21+
}
22+
}

0 commit comments

Comments
 (0)