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
418c930a
Commit
418c930a
authored
Feb 14, 2014
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #848 from Munter/thorax-strict
Thorax: Prevent global leakage of 'use strict' directive
parents
5d060c01
38abc5ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
51 deletions
+53
-51
labs/architecture-examples/thorax/js/views/stats.js
labs/architecture-examples/thorax/js/views/stats.js
+53
-51
No files found.
labs/architecture-examples/thorax/js/views/stats.js
View file @
418c930a
/*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
'
);
}
});
(
function
()
{
'
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
'
);
}
});
})();
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