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
d57de54a
Commit
d57de54a
authored
Feb 26, 2013
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Thorax: jshint style
parent
669bdfe1
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
99 additions
and
87 deletions
+99
-87
labs/architecture-examples/thorax/js/app.js
labs/architecture-examples/thorax/js/app.js
+9
-6
labs/architecture-examples/thorax/js/collections/todos.js
labs/architecture-examples/thorax/js/collections/todos.js
+11
-10
labs/architecture-examples/thorax/js/models/todo.js
labs/architecture-examples/thorax/js/models/todo.js
+3
-2
labs/architecture-examples/thorax/js/routers/router.js
labs/architecture-examples/thorax/js/routers/router.js
+3
-2
labs/architecture-examples/thorax/js/views/app.js
labs/architecture-examples/thorax/js/views/app.js
+10
-9
labs/architecture-examples/thorax/js/views/stats.js
labs/architecture-examples/thorax/js/views/stats.js
+52
-48
labs/architecture-examples/thorax/js/views/todo-item.js
labs/architecture-examples/thorax/js/views/todo-item.js
+11
-10
No files found.
labs/architecture-examples/thorax/js/app.js
View file @
d57de54a
/*global $, Thorax, Backbone*/
/*jshint unused:false*/
var
ENTER_KEY
=
13
;
$
(
function
()
{
$
(
function
()
{
'
use strict
'
;
// Kick things off by creating the **App**.
var
view
=
new
Thorax
.
Views
[
'
app
'
]
({
collection
:
window
.
app
.
Todos
});
view
.
appendTo
(
'
body
'
);
Backbone
.
history
.
start
();
var
view
=
new
Thorax
.
Views
.
app
({
collection
:
window
.
app
.
Todos
});
view
.
appendTo
(
'
body
'
);
Backbone
.
history
.
start
();
});
labs/architecture-examples/thorax/js/collections/todos.js
View file @
d57de54a
(
function
()
{
/*global Thorax, Store*/
(
function
()
{
'
use strict
'
;
// Todo Collection
...
...
@@ -15,28 +16,28 @@
localStorage
:
new
Store
(
'
todos-backbone-thorax
'
),
// 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
'
);
}
});
...
...
@@ -44,7 +45,7 @@
// Create our global collection of **Todos**.
window
.
app
.
Todos
=
new
TodoList
();
// Ensure that we always have data available
window
.
app
.
Todos
.
fetch
();
// Ensure that we always have data available
window
.
app
.
Todos
.
fetch
();
}());
labs/architecture-examples/thorax/js/models/todo.js
View file @
d57de54a
(
function
()
{
/*global Thorax*/
(
function
()
{
'
use strict
'
;
// Todo Model
...
...
@@ -15,7 +16,7 @@
},
// Toggle the `completed` state of this todo item.
toggle
:
function
()
{
toggle
:
function
()
{
this
.
save
({
completed
:
!
this
.
get
(
'
completed
'
)
});
...
...
labs/architecture-examples/thorax/js/routers/router.js
View file @
d57de54a
(
function
()
{
/*global Backbone*/
(
function
()
{
'
use strict
'
;
// Todo Router
...
...
@@ -10,7 +11,7 @@
'
:filter
'
:
'
setFilter
'
},
setFilter
:
function
(
param
)
{
setFilter
:
function
(
param
)
{
// Set the current filter to be used
window
.
app
.
TodoFilter
=
param
?
param
.
trim
().
replace
(
/^
\/
/
,
''
)
:
''
;
// Thorax listens for a `filter` event which will
...
...
labs/architecture-examples/thorax/js/views/app.js
View file @
d57de54a
$
(
function
(
$
)
{
/*global Thorax, $, ENTER_KEY*/
$
(
function
()
{
'
use strict
'
;
// The Application
...
...
@@ -23,7 +24,7 @@ $(function( $ ) {
rendered
:
'
toggleToggleAllButton
'
},
toggleToggleAllButton
:
function
()
{
toggleToggleAllButton
:
function
()
{
var
toggleInput
=
this
.
$
(
'
#toggle-all
'
)[
0
];
if
(
toggleInput
)
{
toggleInput
.
checked
=
!
this
.
collection
.
remaining
().
length
;
...
...
@@ -32,12 +33,12 @@ $(function( $ ) {
// When this function is specified, items will only be shown
// when this function returns true
itemFilter
:
function
(
model
)
{
itemFilter
:
function
(
model
)
{
return
model
.
isVisible
();
},
// Generate the attributes for a new Todo item.
newAttributes
:
function
()
{
newAttributes
:
function
()
{
return
{
title
:
this
.
$
(
'
#new-todo
'
).
val
().
trim
(),
order
:
this
.
collection
.
nextOrder
(),
...
...
@@ -47,18 +48,18 @@ $(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
.
$
(
'
#new-todo
'
).
val
().
trim
()
)
{
createOnEnter
:
function
(
e
)
{
if
(
e
.
which
!==
ENTER_KEY
||
!
this
.
$
(
'
#new-todo
'
).
val
().
trim
()
)
{
return
;
}
this
.
collection
.
create
(
this
.
newAttributes
()
);
this
.
collection
.
create
(
this
.
newAttributes
()
);
this
.
$
(
'
#new-todo
'
).
val
(
''
);
},
toggleAllComplete
:
function
()
{
toggleAllComplete
:
function
()
{
var
completed
=
this
.
$
(
'
#toggle-all
'
)[
0
].
checked
;
this
.
collection
.
each
(
function
(
todo
)
{
this
.
collection
.
each
(
function
(
todo
)
{
todo
.
save
({
completed
:
completed
});
...
...
labs/architecture-examples/thorax/js/views/stats.js
View file @
d57de54a
/*global Thorax, _*/
'
use strict
'
;
Thorax
.
View
.
extend
({
name
:
'
stats
'
,
events
:
{
'
click #clear-completed
'
:
'
clearCompleted
'
,
// The "rendered" event is triggered by Thorax each time render()
// is called and the result of the template has been appended
// to the View's $el
rendered
:
'
highlightFilter
'
},
initialize
:
function
()
{
// Whenever the Todos collection changes re-render the stats
// render() needs to be called with no arguments, otherwise calling
// it with arguments will insert the arguments as content
this
.
listenTo
(
window
.
app
.
Todos
,
'
all
'
,
_
.
debounce
(
function
()
{
this
.
render
();
}));
},
// Clear all completed todo items, destroying their models.
clearCompleted
:
function
()
{
_
.
each
(
window
.
app
.
Todos
.
completed
(),
function
(
todo
)
{
todo
.
destroy
();
});
return
false
;
},
// Each time the stats view is rendered this function will
// be called to generate the context / scope that the template
// will be called with. "context" defaults to "return this"
context
:
function
()
{
var
remaining
=
window
.
app
.
Todos
.
remaining
().
length
;
return
{
itemText
:
remaining
===
1
?
'
item
'
:
'
items
'
,
completed
:
window
.
app
.
Todos
.
completed
().
length
,
remaining
:
remaining
};
},
// Highlight which filter will appear to be active
highlightFilter
:
function
()
{
this
.
$
(
'
#filters li a
'
)
.
removeClass
(
'
selected
'
)
.
filter
(
'
[href="#/
'
+
(
window
.
app
.
TodoFilter
||
''
)
+
'
"]
'
)
.
addClass
(
'
selected
'
);
}
});
\ No newline at end of file
name
:
'
stats
'
,
events
:
{
'
click #clear-completed
'
:
'
clearCompleted
'
,
// The "rendered" event is triggered by Thorax each time render()
// is called and the result of the template has been appended
// to the View's $el
rendered
:
'
highlightFilter
'
},
initialize
:
function
()
{
// Whenever the Todos collection changes re-render the stats
// render() needs to be called with no arguments, otherwise calling
// it with arguments will insert the arguments as content
this
.
listenTo
(
window
.
app
.
Todos
,
'
all
'
,
_
.
debounce
(
function
()
{
this
.
render
();
}));
},
// Clear all completed todo items, destroying their models.
clearCompleted
:
function
()
{
_
.
each
(
window
.
app
.
Todos
.
completed
(),
function
(
todo
)
{
todo
.
destroy
();
});
return
false
;
},
// Each time the stats view is rendered this function will
// be called to generate the context / scope that the template
// will be called with. "context" defaults to "return this"
context
:
function
()
{
var
remaining
=
window
.
app
.
Todos
.
remaining
().
length
;
return
{
itemText
:
remaining
===
1
?
'
item
'
:
'
items
'
,
completed
:
window
.
app
.
Todos
.
completed
().
length
,
remaining
:
remaining
};
},
// Highlight which filter will appear to be active
highlightFilter
:
function
()
{
this
.
$
(
'
#filters li a
'
)
.
removeClass
(
'
selected
'
)
.
filter
(
'
[href="#/
'
+
(
window
.
app
.
TodoFilter
||
''
)
+
'
"]
'
)
.
addClass
(
'
selected
'
);
}
});
labs/architecture-examples/thorax/js/views/todo-item.js
View file @
d57de54a
$
(
function
()
{
/*global Thorax, $, ENTER_KEY*/
$
(
function
()
{
'
use strict
'
;
// Todo Item View
...
...
@@ -23,27 +24,27 @@ $(function() {
// The "rendered" event is triggered by Thorax each time render()
// is called and the result of the template has been appended
// to the View's $el
rendered
:
function
()
{
this
.
$el
.
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
rendered
:
function
()
{
this
.
$el
.
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
}
},
// 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
.
$
(
'
.edit
'
).
focus
();
},
// Close the `"editing"` mode, saving changes to the todo.
close
:
function
()
{
close
:
function
()
{
var
value
=
this
.
$
(
'
.edit
'
).
val
().
trim
();
if
(
value
)
{
if
(
value
)
{
this
.
model
.
save
({
title
:
value
});
}
else
{
this
.
clear
();
...
...
@@ -53,14 +54,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