Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Franck
todomvc
Commits
9005b8d2
Commit
9005b8d2
authored
Feb 23, 2013
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
o_O: jshint style
parent
ae0d41a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
80 deletions
+82
-80
labs/architecture-examples/o_O/js/app.js
labs/architecture-examples/o_O/js/app.js
+82
-80
No files found.
labs/architecture-examples/o_O/js/app.js
View file @
9005b8d2
/*global $, o_O, todoapp */
(
function
(
window
)
{
/*jshint camelcase:false newcap:false*/
/*global $ o_O todoapp */
(
function
(
window
)
{
'
use strict
'
;
// represents a single todo item
...
...
@@ -8,48 +10,48 @@
completed
:
false
},
{
initialize
:
function
()
{
this
.
editing
=
o_O
(
false
);
initialize
:
function
()
{
this
.
editing
=
o_O
(
false
);
},
startEditing
:
function
()
{
this
.
editing
(
true
);
startEditing
:
function
()
{
this
.
editing
(
true
);
var
self
=
this
;
setTimeout
(
function
()
{
$
(
self
.
el
).
parent
().
find
(
'
input.edit
'
).
focus
();
setTimeout
(
function
()
{
$
(
self
.
el
).
parent
().
find
(
'
input.edit
'
).
focus
();
},
0
);
},
stopEditing
:
function
()
{
var
text
=
$
.
trim
(
this
.
title
()
);
stopEditing
:
function
()
{
var
text
=
$
.
trim
(
this
.
title
()
);
if
(
text
)
{
this
.
title
(
text
);
if
(
text
)
{
this
.
title
(
text
);
}
else
{
this
.
remove
();
}
this
.
editing
(
false
);
this
.
editing
(
false
);
},
remove
:
function
()
{
todoapp
.
todos
.
remove
(
this
);
remove
:
function
()
{
todoapp
.
todos
.
remove
(
this
);
},
visible
:
function
()
{
visible
:
function
()
{
var
filter
=
todoapp
.
filter
(),
completed
=
this
.
completed
();
return
filter
===
''
||
(
filter
===
'
completed
'
&&
completed
)
||
(
filter
===
'
active
'
&&
!
completed
);
(
filter
===
'
completed
'
&&
completed
)
||
(
filter
===
'
active
'
&&
!
completed
);
},
klass
:
function
()
{
if
(
this
.
editing
()
)
{
klass
:
function
()
{
if
(
this
.
editing
()
)
{
return
'
editing
'
;
}
if
(
this
.
completed
()
)
{
if
(
this
.
completed
()
)
{
return
'
completed
'
;
}
else
{
return
''
;
...
...
@@ -64,66 +66,66 @@
completedCount
:
0
,
filter
:
''
},
{
initialize
:
function
()
{
var
self
=
this
;
initialize
:
function
()
{
var
self
=
this
;
self
.
todos
=
o_O
.
array
(
this
.
todos
()
);
self
.
todos
=
o_O
.
array
(
this
.
todos
()
);
this
.
todos
.
on
(
'
set:completed set:title add remove
'
,
function
()
{
var
completed
=
self
.
todos
.
filter
(
function
(
todo
)
{
return
todo
.
completed
();
this
.
todos
.
on
(
'
set:completed set:title add remove
'
,
function
()
{
var
completed
=
self
.
todos
.
filter
(
function
(
todo
)
{
return
todo
.
completed
();
});
self
.
completedCount
(
completed
.
length
);
self
.
persist
();
});
self
.
completedCount
(
completed
.
length
);
self
.
persis
t
();
});
this
.
remainingCount
=
o_O
(
function
()
{
return
self
.
todos
.
count
()
-
self
.
completedCoun
t
();
});
this
.
remainingCount
=
o_O
(
function
()
{
return
self
.
todos
.
count
()
-
self
.
completedCount
();
});
// writeable computed observable
// handles marking all complete/incomplete
// or retrieving if this is true
this
.
allCompleted
=
o_O
(
function
(
v
)
{
if
(
!
arguments
.
length
)
{
return
!
self
.
remainingCount
();
}
// writeable computed observable
// handles marking all complete/incomplete
// or retrieving if this is true
this
.
allCompleted
=
o_O
(
function
(
v
)
{
if
(
!
arguments
.
length
)
{
return
!
self
.
remainingCount
();
}
self
.
todos
.
each
(
function
(
todo
)
{
todo
.
completed
(
v
);
});
self
.
todos
.
each
(
function
(
todo
)
{
todo
.
completed
(
v
);
return
v
;
});
},
return
v
;
});
},
add
:
function
()
{
var
text
=
$
.
trim
(
this
.
current
()
);
add
:
function
()
{
var
text
=
$
.
trim
(
this
.
current
());
if
(
text
)
{
this
.
todos
.
unshift
(
Todo
({
title
:
text
}));
this
.
current
(
''
);
}
},
if
(
text
)
{
this
.
todos
.
unshift
(
Todo
({
title
:
text
}));
this
.
current
(
''
);
}
},
removeCompleted
:
function
()
{
this
.
todos
.
remove
(
function
(
todo
)
{
return
todo
.
completed
();
});
return
false
;
},
removeCompleted
:
function
()
{
this
.
todos
.
remove
(
function
(
todo
)
{
return
todo
.
completed
();
});
return
false
;
},
persist
:
function
()
{
localStorage
[
'
todos-o_O
'
]
=
JSON
.
stringify
(
this
.
todos
.
toJSON
()
);
},
persist
:
function
()
{
localStorage
[
'
todos-o_O
'
]
=
JSON
.
stringify
(
this
.
todos
.
toJSON
()
);
},
pluralize
:
function
(
word
,
count
)
{
return
word
+
(
count
===
1
?
''
:
'
s
'
);
}
});
pluralize
:
function
(
word
,
count
)
{
return
word
+
(
count
===
1
?
''
:
'
s
'
);
}
});
function
main
()
{
// load todos
...
...
@@ -131,12 +133,12 @@
todos
=
[];
try
{
todos
=
JSON
.
parse
(
localStorage
[
'
todos-o_O
'
]
);
}
catch
(
e
)
{}
todos
=
JSON
.
parse
(
localStorage
[
'
todos-o_O
'
]
);
}
catch
(
e
)
{}
// create models
for
(
i
=
0
,
l
=
todos
.
length
;
i
<
l
;
i
++
)
{
todos
[
i
]
=
Todo
.
create
(
todos
[
i
]
);
for
(
i
=
0
,
l
=
todos
.
length
;
i
<
l
;
i
++
)
{
todos
[
i
]
=
Todo
.
create
(
todos
[
i
]
);
}
// create app
...
...
@@ -149,25 +151,25 @@
// setup Routing
o_O
.
router
()
.
add
(
'
*filter
'
,
function
(
filter
)
{
todoapp
.
filter
(
filter
);
.
add
(
'
*filter
'
,
function
(
filter
)
{
todoapp
.
filter
(
filter
);
$
(
'
#filters a
'
)
.
removeClass
(
'
selected
'
)
.
filter
(
'
[href="#/
'
+
filter
+
'
"]
'
)
.
filter
(
'
[href="#/
'
+
filter
+
'
"]
'
)
.
addClass
(
'
selected
'
);
})
.
start
();
}
// a custom binding to handle the enter key
o_O
.
bindings
.
enterKey
=
function
(
func
,
$el
)
{
o_O
.
bindings
.
enterKey
=
function
(
func
,
$el
)
{
var
ENTER_KEY
=
13
,
context
=
this
;
$el
.
keyup
(
function
(
e
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
func
.
call
(
context
);
$el
.
keyup
(
function
(
e
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
func
.
call
(
context
);
}
});
};
...
...
@@ -177,4 +179,4 @@
// kick it off
main
();
})(
window
);
})(
window
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment