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
55065f19
Commit
55065f19
authored
Feb 17, 2013
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backbone: jshint style
parent
879f666c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
51 deletions
+59
-51
architecture-examples/backbone/js/app.js
architecture-examples/backbone/js/app.js
+4
-1
architecture-examples/backbone/js/collections/todos.js
architecture-examples/backbone/js/collections/todos.js
+9
-8
architecture-examples/backbone/js/models/todo.js
architecture-examples/backbone/js/models/todo.js
+3
-2
architecture-examples/backbone/js/routers/router.js
architecture-examples/backbone/js/routers/router.js
+4
-3
architecture-examples/backbone/js/views/app.js
architecture-examples/backbone/js/views/app.js
+19
-18
architecture-examples/backbone/js/views/todos.js
architecture-examples/backbone/js/views/todos.js
+20
-19
No files found.
architecture-examples/backbone/js/app.js
View file @
55065f19
/*global $*/
/*jshint unused:false*/
var
app
=
app
||
{};
var
ENTER_KEY
=
13
;
$
(
function
()
{
$
(
function
()
{
'
use strict
'
;
// Kick things off by creating the **App**.
new
app
.
AppView
();
...
...
architecture-examples/backbone/js/collections/todos.js
View file @
55065f19
/*global Backbone Store*/
var
app
=
app
||
{};
(
function
()
{
(
function
()
{
'
use strict
'
;
// Todo Collection
...
...
@@ -17,28 +18,28 @@ var app = app || {};
localStorage
:
new
Store
(
'
todos-backbone
'
),
// Filter down the list of all todo items that are finished.
completed
:
function
()
{
return
this
.
filter
(
function
(
todo
)
{
completed
:
function
()
{
return
this
.
filter
(
function
(
todo
)
{
return
todo
.
get
(
'
completed
'
);
});
},
// Filter down the list to only todo items that are still not finished.
remaining
:
function
()
{
return
this
.
without
.
apply
(
this
,
this
.
completed
()
);
remaining
:
function
()
{
return
this
.
without
.
apply
(
this
,
this
.
completed
()
);
},
// We keep the Todos in sequential order, despite being saved by unordered
// GUID in the database. This generates the next order number for new items.
nextOrder
:
function
()
{
if
(
!
this
.
length
)
{
nextOrder
:
function
()
{
if
(
!
this
.
length
)
{
return
1
;
}
return
this
.
last
().
get
(
'
order
'
)
+
1
;
},
// Todos are sorted by their original insertion order.
comparator
:
function
(
todo
)
{
comparator
:
function
(
todo
)
{
return
todo
.
get
(
'
order
'
);
}
});
...
...
architecture-examples/backbone/js/models/todo.js
View file @
55065f19
/*global Backbone*/
var
app
=
app
||
{};
(
function
()
{
(
function
()
{
'
use strict
'
;
// Todo Model
...
...
@@ -17,7 +18,7 @@ var app = app || {};
},
// Toggle the `completed` state of this todo item.
toggle
:
function
()
{
toggle
:
function
()
{
this
.
save
({
completed
:
!
this
.
get
(
'
completed
'
)
});
...
...
architecture-examples/backbone/js/routers/router.js
View file @
55065f19
/*global Backbone*/
var
app
=
app
||
{};
(
function
()
{
(
function
()
{
'
use strict
'
;
// Todo Router
// ----------
var
Workspace
=
Backbone
.
Router
.
extend
({
routes
:{
routes
:
{
'
*filter
'
:
'
setFilter
'
},
setFilter
:
function
(
param
)
{
setFilter
:
function
(
param
)
{
// Set the current filter to be used
app
.
TodoFilter
=
param
.
trim
()
||
''
;
...
...
architecture-examples/backbone/js/views/app.js
View file @
55065f19
/*global Backbone _ $ ENTER_KEY*/
var
app
=
app
||
{};
$
(
function
(
$
)
{
$
(
function
(
$
)
{
'
use strict
'
;
// The Application
...
...
@@ -14,7 +15,7 @@ $(function( $ ) {
el
:
'
#todoapp
'
,
// Our template for the line of statistics at the bottom of the app.
statsTemplate
:
_
.
template
(
$
(
'
#stats-template
'
).
html
()
),
statsTemplate
:
_
.
template
(
$
(
'
#stats-template
'
).
html
()
),
// Delegated events for creating new items, and clearing completed ones.
events
:
{
...
...
@@ -26,7 +27,7 @@ $(function( $ ) {
// At initialization we bind to the relevant events on the `Todos`
// collection, when items are added or changed. Kick things off by
// loading any preexisting todos that might be saved in *localStorage*.
initialize
:
function
()
{
initialize
:
function
()
{
this
.
allCheckbox
=
this
.
$
(
'
#toggle-all
'
)[
0
];
this
.
$input
=
this
.
$
(
'
#new-todo
'
);
this
.
$footer
=
this
.
$
(
'
#footer
'
);
...
...
@@ -43,11 +44,11 @@ $(function( $ ) {
// Re-rendering the App just means refreshing the statistics -- the rest
// of the app doesn't change.
render
:
function
()
{
render
:
function
()
{
var
completed
=
app
.
Todos
.
completed
().
length
;
var
remaining
=
app
.
Todos
.
remaining
().
length
;
if
(
app
.
Todos
.
length
)
{
if
(
app
.
Todos
.
length
)
{
this
.
$main
.
show
();
this
.
$footer
.
show
();
...
...
@@ -58,7 +59,7 @@ $(function( $ ) {
this
.
$
(
'
#filters li a
'
)
.
removeClass
(
'
selected
'
)
.
filter
(
'
[href="#/
'
+
(
app
.
TodoFilter
||
''
)
+
'
"]
'
)
.
filter
(
'
[href="#/
'
+
(
app
.
TodoFilter
||
''
)
+
'
"]
'
)
.
addClass
(
'
selected
'
);
}
else
{
this
.
$main
.
hide
();
...
...
@@ -70,27 +71,27 @@ $(function( $ ) {
// Add a single todo item to the list by creating a view for it, and
// appending its element to the `<ul>`.
addOne
:
function
(
todo
)
{
addOne
:
function
(
todo
)
{
var
view
=
new
app
.
TodoView
({
model
:
todo
});
$
(
'
#todo-list
'
).
append
(
view
.
render
().
el
);
$
(
'
#todo-list
'
).
append
(
view
.
render
().
el
);
},
// Add all items in the **Todos** collection at once.
addAll
:
function
()
{
addAll
:
function
()
{
this
.
$
(
'
#todo-list
'
).
html
(
''
);
app
.
Todos
.
each
(
this
.
addOne
,
this
);
},
filterOne
:
function
(
todo
)
{
filterOne
:
function
(
todo
)
{
todo
.
trigger
(
'
visible
'
);
},
filterAll
:
function
()
{
filterAll
:
function
()
{
app
.
Todos
.
each
(
this
.
filterOne
,
this
);
},
// Generate the attributes for a new Todo item.
newAttributes
:
function
()
{
newAttributes
:
function
()
{
return
{
title
:
this
.
$input
.
val
().
trim
(),
order
:
app
.
Todos
.
nextOrder
(),
...
...
@@ -100,25 +101,25 @@ $(function( $ ) {
// If you hit return in the main input field, create new **Todo** model,
// persisting it to *localStorage*.
createOnEnter
:
function
(
e
)
{
if
(
e
.
which
!==
ENTER_KEY
||
!
this
.
$input
.
val
().
trim
()
)
{
createOnEnter
:
function
(
e
)
{
if
(
e
.
which
!==
ENTER_KEY
||
!
this
.
$input
.
val
().
trim
()
)
{
return
;
}
app
.
Todos
.
create
(
this
.
newAttributes
()
);
app
.
Todos
.
create
(
this
.
newAttributes
()
);
this
.
$input
.
val
(
''
);
},
// Clear all completed todo items, destroying their models.
clearCompleted
:
function
()
{
clearCompleted
:
function
()
{
_
.
invoke
(
app
.
Todos
.
completed
(),
'
destroy
'
);
return
false
;
},
toggleAllComplete
:
function
()
{
toggleAllComplete
:
function
()
{
var
completed
=
this
.
allCheckbox
.
checked
;
app
.
Todos
.
each
(
function
(
todo
)
{
app
.
Todos
.
each
(
function
(
todo
)
{
todo
.
save
({
'
completed
'
:
completed
});
...
...
architecture-examples/backbone/js/views/todos.js
View file @
55065f19
/*global Backbone _ $ ENTER_KEY*/
var
app
=
app
||
{};
$
(
function
()
{
$
(
function
()
{
'
use strict
'
;
// Todo Item View
...
...
@@ -13,7 +14,7 @@ $(function() {
tagName
:
'
li
'
,
// Cache the template function for a single item.
template
:
_
.
template
(
$
(
'
#item-template
'
).
html
()
),
template
:
_
.
template
(
$
(
'
#item-template
'
).
html
()
),
// The DOM events specific to an item.
events
:
{
...
...
@@ -27,50 +28,50 @@ $(function() {
// The TodoView listens for changes to its model, re-rendering. Since there's
// a one-to-one correspondence between a **Todo** and a **TodoView** in this
// app, we set a direct reference on the model for convenience.
initialize
:
function
()
{
initialize
:
function
()
{
this
.
listenTo
(
this
.
model
,
'
change
'
,
this
.
render
);
this
.
listenTo
(
this
.
model
,
'
destroy
'
,
this
.
remove
);
this
.
listenTo
(
this
.
model
,
'
visible
'
,
this
.
toggleVisible
);
},
// Re-render the titles of the todo item.
render
:
function
()
{
this
.
$el
.
html
(
this
.
template
(
this
.
model
.
toJSON
()
)
);
this
.
$el
.
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
render
:
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
());
toggleVisible
:
function
()
{
this
.
$el
.
toggleClass
(
'
hidden
'
,
this
.
isHidden
());
},
isHidden
:
function
()
{
isHidden
:
function
()
{
var
isCompleted
=
this
.
model
.
get
(
'
completed
'
);
return
(
// hidden cases only
(
!
isCompleted
&&
app
.
TodoFilter
===
'
completed
'
)
||
(
isCompleted
&&
app
.
TodoFilter
===
'
active
'
)
return
(
// hidden cases only
(
!
isCompleted
&&
app
.
TodoFilter
===
'
completed
'
)
||
(
isCompleted
&&
app
.
TodoFilter
===
'
active
'
)
);
},
// Toggle the `"completed"` state of the model.
toggleCompleted
:
function
()
{
toggleCompleted
:
function
()
{
this
.
model
.
toggle
();
},
// Switch this view into `"editing"` mode, displaying the input field.
edit
:
function
()
{
edit
:
function
()
{
this
.
$el
.
addClass
(
'
editing
'
);
this
.
$input
.
focus
();
},
// Close the `"editing"` mode, saving changes to the todo.
close
:
function
()
{
close
:
function
()
{
var
value
=
this
.
$input
.
val
().
trim
();
if
(
value
)
{
if
(
value
)
{
this
.
model
.
save
({
title
:
value
});
}
else
{
this
.
clear
();
...
...
@@ -80,14 +81,14 @@ $(function() {
},
// If you hit `enter`, we're through editing the item.
updateOnEnter
:
function
(
e
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
updateOnEnter
:
function
(
e
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
this
.
close
();
}
},
// Remove the item, destroy the model from *localStorage* and delete its view.
clear
:
function
()
{
clear
:
function
()
{
this
.
model
.
destroy
();
}
});
...
...
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