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
9fd0c4f7
Commit
9fd0c4f7
authored
Jul 01, 2012
by
addyosmani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First set of fixes for model level routing.
parent
15c813f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
25 deletions
+27
-25
architecture-examples/backbone/js/app.js
architecture-examples/backbone/js/app.js
+27
-25
No files found.
architecture-examples/backbone/js/app.js
View file @
9fd0c4f7
// Load the application once the DOM is ready, using `jQuery.ready`:
$
(
function
(){
var
currentFilter
=
""
;
// Todo Model
// ----------
...
...
@@ -172,7 +174,7 @@ $(function(){
this
.
input
=
this
.
$
(
"
#new-todo
"
);
this
.
allCheckbox
=
this
.
$
(
"
#toggle-all
"
)[
0
];
Todos
.
on
(
'
add
'
,
this
.
ad
completed
,
this
);
Todos
.
on
(
'
add
'
,
this
.
ad
dOne
,
this
);
Todos
.
on
(
'
reset
'
,
this
.
addAll
,
this
);
Todos
.
on
(
'
all
'
,
this
.
render
,
this
);
...
...
@@ -207,14 +209,28 @@ $(function(){
// Add a single todo item to the list by creating a view for it, and
// appending its element to the `<ul>`.
ad
completed
:
function
(
todo
)
{
ad
dOne
:
function
(
todo
)
{
var
view
=
new
TodoView
({
model
:
todo
});
this
.
$
(
"
#todo-list
"
).
append
(
view
.
render
().
el
);
},
// Add all items in the **Todos** collection at once.
addAll
:
function
()
{
Todos
.
each
(
this
.
adcompleted
,
this
);
this
.
$
(
"
#todo-list
"
).
html
(
''
);
switch
(
currentFilter
){
case
"
active
"
:
_
.
each
(
Todos
.
remaining
(),
this
.
addOne
);
break
;
case
"
completed
"
:
_
.
each
(
Todos
.
completed
(),
this
.
addOne
);
break
;
default
:
Todos
.
each
(
this
.
addOne
,
this
);
break
;
}
},
// Generate the attributes for a new Todo item.
...
...
@@ -253,36 +269,22 @@ $(function(){
var
Router
=
Backbone
.
Router
.
extend
({
routes
:{
"
/:filter
"
:
"
f
ilter
"
,
"
/:*
"
:
"
f
ilter
"
"
/:filter
"
:
"
setF
ilter
"
,
"
/:*
"
:
"
setF
ilter
"
},
f
ilter
:
function
(
param
){
setF
ilter
:
function
(
param
){
//this.$todos = $('#todo-list');
//this.$todoItems = this.$todos.find('li');
//this.$todoscompleted = this.$todos.find('.completed');
switch
(
param
){
default
:
//this.$todoItems.show();
console
.
log
(
Todos
);
break
;
case
'
active
'
:
//this.$todoItems.show().not('.completed').hide();
console
.
log
(
Todos
.
remaining
());
break
;
case
'
completed
'
:
console
.
log
(
Todos
.
completed
());
//this.$todoItems.show();
//this.$todoscompleted.hide();
break
;
}
currentFilter
=
param
;
Todos
.
trigger
(
'
reset
'
);
// Currently not working on navigation.
$
(
'
#filters li a
'
)
.
removeClass
(
'
selected
'
)
.
filter
(
"
[href='#/
"
+
param
+
"
']
"
)
.
addClass
(
'
selected
'
);
}
});
...
...
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