2
2
( function ( window ) {
3
3
'use strict' ;
4
4
5
- // represents a single todo item
6
- var Todo = o_O . model . extend ( {
7
- title : '' ,
8
- completed : false
9
- } ,
10
- {
11
- initialize : function ( ) {
12
- this . editing = o_O ( false ) ;
13
- } ,
14
-
15
- startEditing : function ( ) {
16
- this . editing ( true ) ;
17
- var self = this ;
18
- setTimeout ( function ( ) {
19
- $ ( self . el ) . parent ( ) . find ( 'input.edit' ) . select ( ) ;
20
- } , 0 ) ;
5
+ // represents a single todo item
6
+ var Todo = o_O . model . extend ( {
7
+ title : '' ,
8
+ completed : false
21
9
} ,
10
+ {
11
+ initialize : function ( ) {
12
+ this . editing = o_O ( false ) ;
13
+ } ,
14
+
15
+ startEditing : function ( ) {
16
+ this . editing ( true ) ;
17
+ var self = this ;
18
+ setTimeout ( function ( ) {
19
+ $ ( self . el ) . parent ( ) . find ( 'input.edit' ) . select ( ) ;
20
+ } , 0 ) ;
21
+ } ,
22
+
23
+ stopEditing : function ( ) {
24
+ var text = $ . trim ( this . title ( ) ) ;
25
+
26
+ if ( text ) {
27
+ this . title ( text ) ;
28
+ } else {
29
+ this . remove ( ) ;
30
+ }
22
31
23
- stopEditing : function ( ) {
24
- var text = $ . trim ( this . title ( ) ) ;
25
-
26
- if ( text ) {
27
- this . title ( text ) ;
28
- } else {
29
- this . remove ( ) ;
30
- }
31
-
32
- this . editing ( false ) ;
33
- } ,
32
+ this . editing ( false ) ;
33
+ } ,
34
34
35
- remove : function ( ) {
36
- todoapp . todos . remove ( this ) ;
37
- } ,
35
+ remove : function ( ) {
36
+ todoapp . todos . remove ( this ) ;
37
+ } ,
38
38
39
- visible : function ( ) {
40
- var filter = todoapp . filter ( ) ,
41
- completed = this . completed ( ) ;
39
+ visible : function ( ) {
40
+ var filter = todoapp . filter ( ) ,
41
+ completed = this . completed ( ) ;
42
42
43
- return filter === '' ||
44
- ( filter === 'completed' && completed ) ||
45
- ( filter === 'active' && ! completed ) ;
46
- } ,
43
+ return filter === '' ||
44
+ ( filter === 'completed' && completed ) ||
45
+ ( filter === 'active' && ! completed ) ;
46
+ } ,
47
47
48
- klass : function ( ) {
49
- if ( this . editing ( ) ) {
50
- return 'editing' ;
51
- }
52
- if ( this . completed ( ) ) {
53
- return 'completed' ;
54
- } else {
55
- return '' ;
48
+ klass : function ( ) {
49
+ if ( this . editing ( ) ) {
50
+ return 'editing' ;
51
+ }
52
+ if ( this . completed ( ) ) {
53
+ return 'completed' ;
54
+ } else {
55
+ return '' ;
56
+ }
56
57
}
57
58
}
58
- }
59
- ) ;
60
-
61
- // main application
62
- var TodoApp = o_O . model . extend ( {
63
- current : '' ,
64
- completedCount : 0 ,
65
- filter : ''
66
- } , {
59
+ ) ;
60
+
61
+ // main application
62
+ var TodoApp = o_O . model . extend ( {
63
+ current : '' ,
64
+ completedCount : 0 ,
65
+ filter : ''
66
+ } , {
67
67
initialize : function ( ) {
68
68
var self = this ;
69
69
@@ -123,59 +123,58 @@ var TodoApp = o_O.model.extend({
123
123
pluralize : function ( word , count ) {
124
124
return word + ( count === 1 ? '' : 's' ) ;
125
125
}
126
- }
127
- ) ;
126
+ } ) ;
128
127
129
- function main ( ) {
130
- // load todos
131
- var i , l ,
132
- todos = [ ] ;
128
+ function main ( ) {
129
+ // load todos
130
+ var i , l ,
131
+ todos = [ ] ;
133
132
134
- try {
135
- todos = JSON . parse ( localStorage [ 'todos-o_O' ] ) ;
136
- } catch ( e ) { }
133
+ try {
134
+ todos = JSON . parse ( localStorage [ 'todos-o_O' ] ) ;
135
+ } catch ( e ) { }
137
136
138
- // create models
139
- for ( i = 0 , l = todos . length ; i < l ; i ++ ) {
140
- todos [ i ] = Todo . create ( todos [ i ] ) ;
137
+ // create models
138
+ for ( i = 0 , l = todos . length ; i < l ; i ++ ) {
139
+ todos [ i ] = Todo . create ( todos [ i ] ) ;
140
+ }
141
+
142
+ // create app
143
+ window . todoapp = TodoApp ( {
144
+ todos : todos
145
+ } ) ;
146
+
147
+ // bind to DOM element
148
+ todoapp . bind ( '#todoapp' ) ;
149
+
150
+ // setup Routing
151
+ o_O . router ( )
152
+ . add ( '*filter' , function ( filter ) {
153
+ todoapp . filter ( filter ) ;
154
+
155
+ $ ( '#filters a' )
156
+ . removeClass ( 'selected' )
157
+ . filter ( '[href="#/' + filter + '"]' )
158
+ . addClass ( 'selected' ) ;
159
+ } )
160
+ . start ( ) ;
141
161
}
142
162
143
- // create app
144
- window . todoapp = TodoApp ( {
145
- todos : todos
146
- } ) ;
163
+ // a custom binding to handle the enter key
164
+ o_O . bindings . enterKey = function ( func , $el ) {
165
+ var ENTER_KEY = 13 ,
166
+ context = this ;
147
167
148
- // bind to DOM element
149
- todoapp . bind ( '#todoapp' ) ;
150
-
151
- // setup Routing
152
- o_O . router ( )
153
- . add ( '*filter' , function ( filter ) {
154
- todoapp . filter ( filter ) ;
155
-
156
- $ ( '#filters a' )
157
- . removeClass ( 'selected' )
158
- . filter ( '[href="#/' + filter + '"]' )
159
- . addClass ( 'selected' ) ;
160
- } )
161
- . start ( ) ;
162
- }
163
-
164
- // a custom binding to handle the enter key
165
- o_O . bindings . enterKey = function ( func , $el ) {
166
- var ENTER_KEY = 13 ,
167
- context = this ;
168
-
169
- $el . keyup ( function ( e ) {
170
- if ( e . which === ENTER_KEY ) {
171
- func . call ( context ) ;
172
- }
173
- } ) ;
174
- } ;
168
+ $el . keyup ( function ( e ) {
169
+ if ( e . which === ENTER_KEY ) {
170
+ func . call ( context ) ;
171
+ }
172
+ } ) ;
173
+ } ;
175
174
176
- o_O . bindingTypes . enterKey = 'outbound' ;
175
+ o_O . bindingTypes . enterKey = 'outbound' ;
177
176
178
- // kick it off
179
- main ( ) ;
177
+ // kick it off
178
+ main ( ) ;
180
179
181
180
} ) ( window ) ;
0 commit comments