forked from yyx990803/HTML5-Clear-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
124 lines (92 loc) · 3.17 KB
/
main.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var C = {
debug: window.location.hash.replace('#','') === 'debug',
// dom elements
$wrapper: $('#wrapper'),
$log: $('#log'),
// view states
states: {
LIST_COLLECTION_VIEW: 'lists',
TODO_COLLECTION_VIEW: 'todos'
},
isEditing: false,
ITEM_HEIGHT: 62,
init: function () {
C.start = Date.now();
// init some components
C.client.init();
C.db.init(C.debug);
C.touch.init();
C.listCollection.init();
// restore state
var data = C.db.data,
state = data.state,
lists = data.items,
i = lists.length;
switch (state.view) {
case C.states.LIST_COLLECTION_VIEW:
C.log('App: init at ListCollection.');
C.currentCollection = C.listCollection;
break;
case C.states.TODO_COLLECTION_VIEW:
C.log('App: init at TodoCollection with order: ' + state.order);
while (i--) {
if (lists[i].order === state.order) {
C.currentCollection = new C.TodoCollection(lists[i]);
break;
}
}
break;
default:
C.log('App: init at ListCollection.');
C.currentCollection = C.listCollection;
break;
}
C.currentCollection.load(0, true); // passing in (position:0) and (noAnimation:true)
if (!C.listCollection.initiated) {
// If we started with a TodoCollection, load ListCollection and position it for pulldown
C.listCollection.positionForPulldown();
C.listCollection.load();
} else {
// otherwise, load the last used todoCollection
C.lastTodoCollection = new C.TodoCollection(lists[state.lastTodoCollection || 0]);
C.lastTodoCollection.load(C.client.height + C.ITEM_HEIGHT, true);
C.lastTodoCollection.positionForPullUp();
}
},
setCurrentCollection: function (col) {
var msg = 'Current collection set to: '
C.log(msg + (col.data.title ? 'TodoCollection <' + col.data.title + '>' : 'ListCollection'));
C.currentCollection = col;
var state = C.db.data.state;
state.view = col.stateType;
state.order = col.data.order;
C.db.save();
},
setLastTodoCollection: function (col) {
C.lastTodoCollection = col;
C.db.data.state.lastTodoCollection = col.data.order;
C.db.save();
},
log: function (msg) {
if (!this.debug) return;
//$('#log').text(msg);
var time = Date.now() - C.start;
if (time < 1000) {
time = '[' + time + 'ms] ';
} else {
time = '[' + (time / 1000).toFixed(2) + 's] ';
}
msg = time + msg;
console.log(msg);
},
raf: window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function (callback) {
window.setTimeout(callback, 16);
}
};
// boot up on page load
$(function () {
C.init();
});