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
b36d9633
Commit
b36d9633
authored
Aug 25, 2012
by
addyosmani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add changes for #259, started in #260
parent
c6e5015a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
32 deletions
+63
-32
architecture-examples/backbone/js/routers/router.js
architecture-examples/backbone/js/routers/router.js
+3
-2
architecture-examples/backbone/js/views/app.js
architecture-examples/backbone/js/views/app.js
+13
-15
architecture-examples/backbone/js/views/todos.js
architecture-examples/backbone/js/views/todos.js
+14
-0
assets/base.css
assets/base.css
+4
-0
dependency-examples/backbone_require/js/routers/router.js
dependency-examples/backbone_require/js/routers/router.js
+3
-2
dependency-examples/backbone_require/js/views/app.js
dependency-examples/backbone_require/js/views/app.js
+12
-13
dependency-examples/backbone_require/js/views/todos.js
dependency-examples/backbone_require/js/views/todos.js
+14
-0
No files found.
architecture-examples/backbone/js/routers/router.js
View file @
b36d9633
...
...
@@ -15,8 +15,9 @@ var app = app || {};
// Set the current filter to be used
window
.
app
.
TodoFilter
=
param
.
trim
()
||
''
;
// Trigger a collection reset/addAll
window
.
app
.
Todos
.
trigger
(
'
reset
'
);
// Trigger a collection filter event, causing hiding/unhiding
// of Todo view items
window
.
app
.
Todos
.
trigger
(
'
filter
'
);
}
});
...
...
architecture-examples/backbone/js/views/app.js
View file @
b36d9633
...
...
@@ -29,14 +29,15 @@ $(function( $ ) {
initialize
:
function
()
{
this
.
input
=
this
.
$
(
'
#new-todo
'
);
this
.
allCheckbox
=
this
.
$
(
'
#toggle-all
'
)[
0
];
this
.
$footer
=
this
.
$
(
'
#footer
'
);
this
.
$main
=
this
.
$
(
'
#main
'
);
window
.
app
.
Todos
.
on
(
'
add
'
,
this
.
addAll
,
this
);
window
.
app
.
Todos
.
on
(
'
reset
'
,
this
.
addAll
,
this
);
window
.
app
.
Todos
.
on
(
'
change:completed
'
,
this
.
addAll
,
this
);
window
.
app
.
Todos
.
on
(
'
all
'
,
this
.
render
,
this
);
window
.
app
.
Todos
.
on
(
'
change:completed
'
,
this
.
filterOne
,
this
);
window
.
app
.
Todos
.
on
(
"
filter
"
,
this
.
filterAll
,
this
);
this
.
$footer
=
this
.
$
(
'
#footer
'
);
this
.
$main
=
this
.
$
(
'
#main
'
);
window
.
app
.
Todos
.
on
(
'
all
'
,
this
.
render
,
this
);
app
.
Todos
.
fetch
();
},
...
...
@@ -78,18 +79,15 @@ $(function( $ ) {
// Add all items in the **Todos** collection at once.
addAll
:
function
()
{
this
.
$
(
'
#todo-list
'
).
html
(
''
);
app
.
Todos
.
each
(
this
.
addOne
,
this
);
},
switch
(
app
.
TodoFilter
)
{
case
'
active
'
:
_
.
each
(
app
.
Todos
.
remaining
(),
this
.
addOne
);
break
;
case
'
completed
'
:
_
.
each
(
app
.
Todos
.
completed
(),
this
.
addOne
);
break
;
default
:
app
.
Todos
.
each
(
this
.
addOne
,
this
);
break
;
}
filterOne
:
function
(
todo
)
{
todo
.
trigger
(
"
visible
"
);
},
filterAll
:
function
()
{
app
.
Todos
.
each
(
this
.
filterOne
,
this
);
},
// Generate the attributes for a new Todo item.
...
...
architecture-examples/backbone/js/views/todos.js
View file @
b36d9633
...
...
@@ -30,6 +30,7 @@ $(function() {
initialize
:
function
()
{
this
.
model
.
on
(
'
change
'
,
this
.
render
,
this
);
this
.
model
.
on
(
'
destroy
'
,
this
.
remove
,
this
);
this
.
model
.
on
(
'
visible
'
,
this
.
toggleVisible
,
this
);
},
// Re-render the titles of the todo item.
...
...
@@ -37,10 +38,23 @@ $(function() {
this
.
$el
.
html
(
this
.
template
(
this
.
model
.
toJSON
()
)
);
this
.
$el
.
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
this
.
toggleVisible
();
this
.
input
=
this
.
$
(
'
.edit
'
);
return
this
;
},
toggleVisible
:
function
()
{
this
.
$el
.
toggleClass
(
'
hidden
'
,
this
.
isHidden
());
},
isHidden
:
function
()
{
var
isCompleted
=
this
.
model
.
get
(
'
completed
'
);
return
(
// hidden cases only
(
!
isCompleted
&&
app
.
TodoFilter
===
'
completed
'
)
||
(
isCompleted
&&
app
.
TodoFilter
===
'
active
'
)
);
},
// Toggle the `"completed"` state of the model.
togglecompleted
:
function
()
{
this
.
model
.
toggle
();
...
...
assets/base.css
View file @
b36d9633
...
...
@@ -404,3 +404,7 @@ label[for='toggle-all'] {
background
:
none
;
}
}
.hidden
{
display
:
none
;
}
\ No newline at end of file
dependency-examples/backbone_require/js/routers/router.js
View file @
b36d9633
...
...
@@ -14,8 +14,9 @@ define([
// Set the current filter to be used
Common
.
TodoFilter
=
param
.
trim
()
||
''
;
// Trigger a collection reset/addAll
Todos
.
trigger
(
'
reset
'
);
// Trigger a collection filter event, causing hiding/unhiding
// of the Todo view items
Todos
.
trigger
(
'
filter
'
);
}
});
...
...
dependency-examples/backbone_require/js/views/app.js
View file @
b36d9633
...
...
@@ -33,10 +33,12 @@ define([
this
.
$footer
=
this
.
$
(
'
#footer
'
);
this
.
$main
=
this
.
$
(
'
#main
'
);
Todos
.
on
(
'
add
'
,
this
.
add
All
,
this
);
Todos
.
on
(
'
add
'
,
this
.
add
One
,
this
);
Todos
.
on
(
'
reset
'
,
this
.
addAll
,
this
);
Todos
.
on
(
'
change:completed
'
,
this
.
addAll
,
this
);
Todos
.
on
(
'
change:completed
'
,
this
.
filterOne
,
this
);
Todos
.
on
(
"
filter
"
,
this
.
filterAll
,
this
);
Todos
.
on
(
'
all
'
,
this
.
render
,
this
);
Todos
.
fetch
();
},
...
...
@@ -77,20 +79,17 @@ define([
// Add all items in the **Todos** collection at once.
addAll
:
function
()
{
this
.
$
(
'
#todo-list
'
).
html
(
''
);
Todos
.
each
(
this
.
addOne
,
this
);
},
switch
(
Common
.
TodoFilter
)
{
case
'
active
'
:
_
.
each
(
Todos
.
remaining
(),
this
.
addOne
);
break
;
case
'
completed
'
:
_
.
each
(
Todos
.
completed
(),
this
.
addOne
);
break
;
default
:
Todos
.
each
(
this
.
addOne
,
this
);
break
;
}
filterOne
:
function
(
todo
)
{
todo
.
trigger
(
"
visible
"
);
},
filterAll
:
function
()
{
app
.
Todos
.
each
(
this
.
filterOne
,
this
);
},
// Generate the attributes for a new Todo item.
newAttributes
:
function
()
{
return
{
...
...
dependency-examples/backbone_require/js/views/todos.js
View file @
b36d9633
...
...
@@ -27,6 +27,7 @@ define([
initialize
:
function
()
{
this
.
model
.
on
(
'
change
'
,
this
.
render
,
this
);
this
.
model
.
on
(
'
destroy
'
,
this
.
remove
,
this
);
this
.
model
.
on
(
'
visible
'
,
this
.
toggleVisible
,
this
);
},
// Re-render the titles of the todo item.
...
...
@@ -34,10 +35,23 @@ define([
this
.
$el
.
html
(
this
.
template
(
this
.
model
.
toJSON
()
)
);
this
.
$el
.
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
this
.
toggleVisible
();
this
.
input
=
this
.
$
(
'
.edit
'
);
return
this
;
},
toggleVisible
:
function
()
{
this
.
$el
.
toggleClass
(
'
hidden
'
,
this
.
isHidden
());
},
isHidden
:
function
()
{
var
isCompleted
=
this
.
model
.
get
(
'
completed
'
);
return
(
// hidden cases only
(
!
isCompleted
&&
Common
.
TodoFilter
===
'
completed
'
)
||
(
isCompleted
&&
Common
.
TodoFilter
===
'
active
'
)
);
},
// Toggle the `"completed"` state of the model.
togglecompleted
:
function
()
{
this
.
model
.
toggle
();
...
...
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