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
1f2793f1
Commit
1f2793f1
authored
May 15, 2012
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jQuery: Use templating on the footer too
parent
8e1adcf4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
13 deletions
+22
-13
architecture-examples/jquery/css/app.css
architecture-examples/jquery/css/app.css
+4
-0
architecture-examples/jquery/index.html
architecture-examples/jquery/index.html
+6
-1
architecture-examples/jquery/js/app.js
architecture-examples/jquery/js/app.js
+12
-12
No files found.
architecture-examples/jquery/css/app.css
0 → 100644
View file @
1f2793f1
#main
,
#footer
{
display
:
none
;
}
\ No newline at end of file
architecture-examples/jquery/index.html
View file @
1f2793f1
...
...
@@ -5,6 +5,7 @@
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge,chrome=1"
>
<title>
jQuery • TodoMVC
</title>
<link
rel=
"stylesheet"
href=
"../../assets/base.css"
>
<link
rel=
"stylesheet"
href=
"css/app.css"
>
<!--[if IE]>
<script src="../../assets/ie.js"></script>
<![endif]-->
...
...
@@ -30,7 +31,7 @@
<p>
App and template by
<a
href=
"http://github.com/sindresorhus"
>
Sindre Sorhus
</a></p>
<p>
Part of
<a
href=
"http://todomvc.com"
>
TodoMVC
</a></p>
</footer>
<script
type=
"text/x-handlebars-template"
id=
"todo
-template"
>
<script
id=
"todo-template"
type=
"text/x-handlebars
-template"
>
{{
#
this
}}
<
li
{{
#
if
completed
}}
class
=
"
completed
"
{{
/if}} data-id="{{id}}"
>
<
div
class
=
"
view
"
>
...
...
@@ -42,6 +43,10 @@
<
/li
>
{{
/
this
}}
</script>
<script
id=
"footer-template"
type=
"text/x-handlebars-template"
>
<
span
id
=
"
todo-count
"
><
strong
>
{{
activeTodoCount
}}
<
/strong> {{activeTodoWord}} left</
span
>
{{
#
if
completedTodos
}}
<
button
id
=
"
clear-completed
"
>
Clear
completed
({{
completedTodos
}})
<
/button>{{/i
f
}}
</script>
<script
src=
"../../assets/base.js"
></script>
<script
src=
"../../assets/jquery.min.js"
></script>
<script
src=
"../../assets/handlebars.min.js"
></script>
...
...
architecture-examples/jquery/js/app.js
View file @
1f2793f1
...
...
@@ -19,7 +19,8 @@ jQuery(function( $ ) {
this
.
render
();
},
cacheElements
:
function
()
{
this
.
template
=
Handlebars
.
compile
(
$
(
'
#todo-template
'
).
html
()
);
this
.
todoTemplate
=
Handlebars
.
compile
(
$
(
'
#todo-template
'
).
html
()
);
this
.
footerTemplate
=
Handlebars
.
compile
(
$
(
'
#footer-template
'
).
html
()
);
this
.
$todoApp
=
$
(
'
#todoapp
'
);
this
.
$newTodo
=
$
(
'
#new-todo
'
);
this
.
$toggleAll
=
$
(
'
#toggle-all
'
);
...
...
@@ -41,7 +42,7 @@ jQuery(function( $ ) {
var
list
=
this
.
$todoList
;
this
.
$newTodo
.
on
(
'
keyup
'
,
this
.
create
);
this
.
$toggleAll
.
on
(
'
change
'
,
this
.
toggleAll
);
this
.
$
clearBtn
.
on
(
'
click
'
,
this
.
destroyCompleted
);
this
.
$
footer
.
on
(
'
click
'
,
'
#clear-completed
'
,
this
.
destroyCompleted
);
list
.
on
(
'
change
'
,
'
.toggle
'
,
this
.
toggle
);
list
.
on
(
'
dblclick
'
,
'
.view
'
,
this
.
edit
);
list
.
on
(
'
keypress
'
,
'
.edit
'
,
this
.
blurOnEnter
);
...
...
@@ -49,7 +50,7 @@ jQuery(function( $ ) {
list
.
on
(
'
click
'
,
'
.destroy
'
,
this
.
destroy
);
},
render
:
function
()
{
this
.
$todoList
.
html
(
this
.
template
(
this
.
todos
)
);
this
.
$todoList
.
html
(
this
.
t
odoT
emplate
(
this
.
todos
)
);
this
.
$main
.
toggle
(
!!
this
.
todos
.
length
);
this
.
$toggleAll
.
prop
(
'
checked
'
,
!
this
.
activeTodoCount
()
);
this
.
renderFooter
();
...
...
@@ -57,16 +58,15 @@ jQuery(function( $ ) {
},
renderFooter
:
function
()
{
var
todoCount
=
this
.
todos
.
length
,
activeTodos
=
this
.
activeTodoCount
(),
completedTodos
=
todoCount
-
activeTodos
,
countTitle
=
'
<strong>
'
+
activeTodos
+
'
</strong>
'
+
Utils
.
pluralize
(
activeTodos
,
'
item
'
)
+
'
left
'
,
clearTitle
=
'
Clear completed (
'
+
completedTodos
+
'
)
'
;
// Only show the footer when there are at least one todo.
activeTodoCount
=
this
.
activeTodoCount
(),
footer
=
{
activeTodoCount
:
activeTodoCount
,
activeTodoWord
:
Utils
.
pluralize
(
activeTodoCount
,
'
item
'
),
completedTodos
:
todoCount
-
activeTodoCount
};
this
.
$footer
.
toggle
(
!!
todoCount
);
// Active todo count
this
.
$count
.
html
(
countTitle
);
// Toggle clear button and update title
this
.
$clearBtn
.
text
(
clearTitle
).
toggle
(
!!
completedTodos
);
this
.
$footer
.
html
(
this
.
footerTemplate
(
footer
)
);
},
toggleAll
:
function
()
{
var
isChecked
=
$
(
this
).
prop
(
'
checked
'
);
...
...
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