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 @@
...
@@ -30,9 +30,7 @@
<ul
class=
"items"
></ul>
<ul
class=
"items"
></ul>
<footer>
<footer>
<a
class=
"clear"
>
Clear completed
</a>
<a
class=
"clear"
>
Clear completed
</a>
<div
class=
"count"
>
<div
class=
"count"
></div>
<span
class=
"countVal"
></span>
items left
</div>
</footer>
</footer>
</div>
</div>
<div
id=
'instructions'
>
<div
id=
'instructions'
>
...
...
todo-example/jquery/js/app.js
View file @
be29feaf
...
@@ -25,13 +25,20 @@ jQuery(function($){
...
@@ -25,13 +25,20 @@ jQuery(function($){
uuid
+=
(
i
==
12
?
4
:
(
i
==
16
?
(
random
&
3
|
8
)
:
random
)).
toString
(
16
);
uuid
+=
(
i
==
12
?
4
:
(
i
==
16
?
(
random
&
3
|
8
)
:
random
)).
toString
(
16
);
}
}
return
uuid
;
return
uuid
;
},
pluralize
:
function
(
count
,
word
)
{
return
count
===
1
?
word
:
word
+
'
s
'
;
}
}
};
};
var
App
=
{
var
App
=
{
init
:
function
()
{
init
:
function
()
{
this
.
element
=
$
(
'
#todoapp
'
);
this
.
$template
=
$
(
'
#todo-template
'
);
this
.
todoList
=
$
(
'
.items
'
);
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
// localStorage support
this
.
store
=
new
Store
(
'
todoapp
'
);
this
.
store
=
new
Store
(
'
todoapp
'
);
this
.
todos
=
this
.
store
.
get
(
'
todos
'
)
||
[];
this
.
todos
=
this
.
store
.
get
(
'
todos
'
)
||
[];
...
@@ -39,18 +46,14 @@ jQuery(function($){
...
@@ -39,18 +46,14 @@ jQuery(function($){
this
.
render
();
this
.
render
();
},
},
render
:
function
()
{
render
:
function
()
{
var
template
=
$
(
'
#todo-template
'
)
.
tmpl
(
this
.
todos
);
var
html
=
this
.
$template
.
tmpl
(
this
.
todos
);
this
.
todoList
.
html
(
template
);
this
.
$todoList
.
html
(
html
);
this
.
render
ActiveTodoCount
();
this
.
render
Footer
();
this
.
store
.
set
(
'
todos
'
,
this
.
todos
);
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
()
{
bindEvents
:
function
()
{
var
elem
=
this
.
element
,
var
elem
=
this
.
$todoApp
,
list
=
this
.
todoList
;
list
=
this
.
$
todoList
;
elem
.
on
(
'
click
'
,
'
.clear
'
,
this
.
destroyDone
);
elem
.
on
(
'
click
'
,
'
.clear
'
,
this
.
destroyDone
);
elem
.
on
(
'
submit
'
,
'
form
'
,
this
.
create
);
elem
.
on
(
'
submit
'
,
'
form
'
,
this
.
create
);
list
.
on
(
'
change
'
,
'
input[type="checkbox"]
'
,
this
.
toggle
);
list
.
on
(
'
change
'
,
'
input[type="checkbox"]
'
,
this
.
toggle
);
...
@@ -59,16 +62,28 @@ jQuery(function($){
...
@@ -59,16 +62,28 @@ jQuery(function($){
list
.
on
(
'
blur
'
,
'
input[type="text"]
'
,
this
.
update
);
list
.
on
(
'
blur
'
,
'
input[type="text"]
'
,
this
.
update
);
list
.
on
(
'
click
'
,
'
.destroy
'
,
this
.
destroy
);
list
.
on
(
'
click
'
,
'
.destroy
'
,
this
.
destroy
);
},
},
renderA
ctiveTodoCount
:
function
()
{
a
ctiveTodoCount
:
function
()
{
var
count
=
0
;
var
count
=
0
;
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
if
(
!
val
.
done
)
{
if
(
!
val
.
done
)
{
count
++
;
count
++
;
}
}
});
});
$
(
'
.countVal
'
).
text
(
count
);
return
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
()
{
destroyDone
:
function
()
{
// Reverse loop; since we are dynamically removing items from the todos array
// Reverse loop; since we are dynamically removing items from the todos array
for
(
var
i
=
App
.
todos
.
length
;
i
--
;
)
{
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