-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
97 lines (60 loc) · 2.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var Utils = require('common/utils');
var autosize = require('autosize');
module.exports = {
path: 'viewTodos',
subPageOf: false,
previousPage: false,
backSafe: true,
template: require("./template.jade"),
extend: {
fullscreen: false,
},
domEvents : {
// remove a todo item if the remove button is touched
'touch .todo-item-remove-button' : function(e, target) {
var todo_id = target.parentNode.getAttribute("data-id");
App.emit("alert:error", todo_id + " destroyed");
// remove the autosize listener on this items textarea
autosize.destroy(target.parentNode.querySelector("textarea"));
App.Collections.Todos.remove(todo_id);
this.resetState();
},
// remove focus from any textarea if the user touches off of it
'touch #viewTodos-page': function(e) {
console.log("touched the page");
if (e.target.id === "viewTodos-page") {
document.activeElement.blur();
}
},
// store the new array of todos if any todo item's value is updated
'input .todo-item-text': function(e) {
var todo_id = e.target.parentNode.getAttribute("data-id");
var todo_text = e.target.value;
App.Collections.Todos.update(todo_id, todo_text);
this.resetState();
}
},
appEvents : {},
// must synchronously return an object that will set the initial state of the component. this object will be passed to the templating engine
setInitialState : function() {
var state = {
todos: App.Collections.Todos.getAll()
};
return state;
},
// this function runs before the Page is rendered
beforeRender : function(callback) {
App.Data.Header.title = "Your ToDo List";
callback();
},
// this function runs after the Page is rendered
afterRender : function(callback) {
autosize(this.element.querySelectorAll("textarea"));
callback();
},
// this function runs right before the Page is destroyed
beforeRemove : function(callback) {
autosize.destroy(this.element.querySelectorAll("textarea"));
callback();
}
};