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
Eugene Shen
todomvc
Commits
be29feaf
Commit
be29feaf
authored
Nov 08, 2011
by
Addy Osmani
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #27 from sindresorhus/master
jQuery example - added count on Clear button
parents
32fdff67
d6dfa8c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
16 deletions
+29
-16
todo-example/jquery/index.html
todo-example/jquery/index.html
+1
-3
todo-example/jquery/js/app.js
todo-example/jquery/js/app.js
+28
-13
No files found.
todo-example/jquery/index.html
View file @
be29feaf
...
...
@@ -30,9 +30,7 @@
<ul
class=
"items"
></ul>
<footer>
<a
class=
"clear"
>
Clear completed
</a>
<div
class=
"count"
>
<span
class=
"countVal"
></span>
items left
</div>
<div
class=
"count"
></div>
</footer>
</div>
<div
id=
'instructions'
>
...
...
todo-example/jquery/js/app.js
View file @
be29feaf
...
...
@@ -25,13 +25,20 @@ jQuery(function($){
uuid
+=
(
i
==
12
?
4
:
(
i
==
16
?
(
random
&
3
|
8
)
:
random
)).
toString
(
16
);
}
return
uuid
;
},
pluralize
:
function
(
count
,
word
)
{
return
count
===
1
?
word
:
word
+
'
s
'
;
}
};
var
App
=
{
init
:
function
()
{
this
.
element
=
$
(
'
#todoapp
'
);
this
.
todoList
=
$
(
'
.items
'
);
this
.
$template
=
$
(
'
#todo-template
'
);
this
.
$todoApp
=
$
(
'
#todoapp
'
);
this
.
$todoList
=
this
.
$todoApp
.
find
(
'
.items
'
);
this
.
$footer
=
this
.
$todoApp
.
find
(
'
footer
'
);
this
.
$count
=
this
.
$footer
.
find
(
'
.count
'
);
this
.
$clearBtn
=
this
.
$footer
.
find
(
'
.clear
'
);
// localStorage support
this
.
store
=
new
Store
(
'
todoapp
'
);
this
.
todos
=
this
.
store
.
get
(
'
todos
'
)
||
[];
...
...
@@ -39,18 +46,14 @@ jQuery(function($){
this
.
render
();
},
render
:
function
()
{
var
template
=
$
(
'
#todo-template
'
)
.
tmpl
(
this
.
todos
);
this
.
todoList
.
html
(
template
);
this
.
render
ActiveTodoCount
();
var
html
=
this
.
$template
.
tmpl
(
this
.
todos
);
this
.
$todoList
.
html
(
html
);
this
.
render
Footer
();
this
.
store
.
set
(
'
todos
'
,
this
.
todos
);
// Only show the footer when there are at least one todo.
$
(
'
footer
'
).
toggle
(
!!
this
.
todos
.
length
);
// Only show the clear button when there are done todos.
$
(
'
.clear
'
).
toggle
(
!!
(
this
.
todos
.
length
-
this
.
renderActiveTodoCount
()
)
);
},
bindEvents
:
function
()
{
var
elem
=
this
.
element
,
list
=
this
.
todoList
;
var
elem
=
this
.
$todoApp
,
list
=
this
.
$
todoList
;
elem
.
on
(
'
click
'
,
'
.clear
'
,
this
.
destroyDone
);
elem
.
on
(
'
submit
'
,
'
form
'
,
this
.
create
);
list
.
on
(
'
change
'
,
'
input[type="checkbox"]
'
,
this
.
toggle
);
...
...
@@ -59,16 +62,28 @@ jQuery(function($){
list
.
on
(
'
blur
'
,
'
input[type="text"]
'
,
this
.
update
);
list
.
on
(
'
click
'
,
'
.destroy
'
,
this
.
destroy
);
},
renderA
ctiveTodoCount
:
function
()
{
a
ctiveTodoCount
:
function
()
{
var
count
=
0
;
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
if
(
!
val
.
done
)
{
count
++
;
}
});
$
(
'
.countVal
'
).
text
(
count
);
return
count
;
},
renderFooter
:
function
()
{
var
todoCount
=
this
.
todos
.
length
,
activeTodos
=
this
.
activeTodoCount
(),
completedTodos
=
todoCount
-
activeTodos
,
countTitle
=
'
<b>
'
+
activeTodos
+
'
</b>
'
+
Utils
.
pluralize
(
activeTodos
,
'
item
'
)
+
'
left
'
;
clearTitle
=
'
Clear
'
+
completedTodos
+
'
completed
'
+
Utils
.
pluralize
(
completedTodos
,
'
item
'
);
// Only show the footer when there are at least one todo.
this
.
$footer
.
toggle
(
!!
todoCount
);
// Active todo count
this
.
$count
.
html
(
countTitle
);
// Toggle clear button and update title
this
.
$clearBtn
.
text
(
clearTitle
).
toggle
(
!!
completedTodos
);
},
destroyDone
:
function
()
{
// Reverse loop; since we are dynamically removing items from the todos array
for
(
var
i
=
App
.
todos
.
length
;
i
--
;
)
{
...
...
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