Commit 38abc5ff authored by Peter Müller's avatar Peter Müller

Prevent global leakage of 'use strict' directive

parent 193752e8
/*global Thorax, _*/ /*global Thorax, _*/
'use strict'; (function () {
'use strict';
Thorax.View.extend({
name: 'stats', Thorax.View.extend({
name: 'stats',
events: {
'click #clear-completed': 'clearCompleted', events: {
// The "rendered" event is triggered by Thorax each time render() 'click #clear-completed': 'clearCompleted',
// is called and the result of the template has been appended // The "rendered" event is triggered by Thorax each time render()
// to the View's $el // is called and the result of the template has been appended
rendered: 'highlightFilter' // to the View's $el
}, rendered: 'highlightFilter'
},
initialize: function () {
// Whenever the Todos collection changes re-render the stats initialize: function () {
// render() needs to be called with no arguments, otherwise calling // Whenever the Todos collection changes re-render the stats
// it with arguments will insert the arguments as content // render() needs to be called with no arguments, otherwise calling
this.listenTo(window.app.Todos, 'all', _.debounce(function () { // it with arguments will insert the arguments as content
this.render(); this.listenTo(window.app.Todos, 'all', _.debounce(function () {
})); this.render();
}, }));
},
// Clear all completed todo items, destroying their models.
clearCompleted: function () { // Clear all completed todo items, destroying their models.
_.each(window.app.Todos.completed(), function (todo) { clearCompleted: function () {
todo.destroy(); _.each(window.app.Todos.completed(), function (todo) {
}); todo.destroy();
});
return false;
}, return false;
},
// Each time the stats view is rendered this function will
// be called to generate the context / scope that the template // Each time the stats view is rendered this function will
// will be called with. "context" defaults to "return this" // be called to generate the context / scope that the template
context: function () { // will be called with. "context" defaults to "return this"
var remaining = window.app.Todos.remaining().length; context: function () {
return { var remaining = window.app.Todos.remaining().length;
itemText: remaining === 1 ? 'item' : 'items', return {
completed: window.app.Todos.completed().length, itemText: remaining === 1 ? 'item' : 'items',
remaining: remaining completed: window.app.Todos.completed().length,
}; remaining: remaining
}, };
},
// Highlight which filter will appear to be active
highlightFilter: function () { // Highlight which filter will appear to be active
this.$('#filters li a') highlightFilter: function () {
.removeClass('selected') this.$('#filters li a')
.filter('[href="#/' + (window.app.TodoFilter || '') + '"]') .removeClass('selected')
.addClass('selected'); .filter('[href="#/' + (window.app.TodoFilter || '') + '"]')
} .addClass('selected');
}); }
});
})();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment