Commit 52f2a8a1 authored by Ryan Eastridge's avatar Ryan Eastridge

always use window.app

parent e67022dd
......@@ -68,6 +68,9 @@
app: Handlebars.compile($('script[data-template-name="app"]').html()),
stats: Handlebars.compile($('script[data-template-name="stats"]').html())
};
//initialize the app object
window.app = {};
</script>
<script src="js/models/todo.js"></script>
<script src="js/collections/todos.js"></script>
......
var app = app || {};
(function() {
'use strict';
......@@ -11,7 +9,7 @@ var app = app || {};
var TodoList = Backbone.Collection.extend({
// Reference to this collection's model.
model: app.Todo,
model: window.app.Todo,
// Save all of the todo items under the `"todos"` namespace.
localStorage: new Store('todos-backbone'),
......@@ -44,6 +42,6 @@ var app = app || {};
});
// Create our global collection of **Todos**.
app.Todos = new TodoList();
window.app.Todos = new TodoList();
}());
var app = app || {};
(function() {
'use strict';
......@@ -7,7 +5,7 @@ var app = app || {};
// ----------
// Our basic **Todo** model has `title`, `order`, and `completed` attributes.
app.Todo = Backbone.Model.extend({
window.app.Todo = Backbone.Model.extend({
// Default attributes for the todo
// and ensure that each todo created has `title` and `completed` keys.
......@@ -25,11 +23,11 @@ var app = app || {};
isVisible: function () {
var isCompleted = this.get('completed');
if (app.TodoFilter === '') {
if (window.app.TodoFilter === '') {
return true;
} else if (app.TodoFilter === 'completed') {
} else if (window.app.TodoFilter === 'completed') {
return isCompleted;
} else if (app.TodoFilter === 'active') {
} else if (window.app.TodoFilter === 'active') {
return !isCompleted;
}
}
......
var app = app || {};
(function() {
'use strict';
// Todo Router
// ----------
app.TodoRouter = new (Thorax.Router.extend({
window.app.TodoRouter = new (Thorax.Router.extend({
routes: {
'': 'setFilter',
':filter': 'setFilter'
......
var app = app || {};
$(function( $ ) {
'use strict';
......@@ -30,7 +28,7 @@ $(function( $ ) {
// global Todos collection available to the template.
// Load any preexisting todos that might be saved in *localStorage*.
initialize: function() {
this.todosCollection = app.Todos;
this.todosCollection = window.app.Todos;
this.todosCollection.fetch();
this.render();
},
......@@ -50,7 +48,7 @@ $(function( $ ) {
newAttributes: function() {
return {
title: this.$('#new-todo').val().trim(),
order: app.Todos.nextOrder(),
order: window.app.Todos.nextOrder(),
completed: false
};
},
......@@ -62,14 +60,14 @@ $(function( $ ) {
return;
}
app.Todos.create( this.newAttributes() );
window.app.Todos.create( this.newAttributes() );
this.$('#new-todo').val('');
},
toggleAllComplete: function() {
var completed = this.$('#toggle-all')[0].checked;
app.Todos.each(function( todo ) {
window.app.Todos.each(function( todo ) {
todo.save({
'completed': completed
});
......
......@@ -31,10 +31,10 @@ Thorax.View.extend({
// be called to generate the context / scope that the template
// will be called with. "context" defaults to "return this"
context: function() {
var remaining = app.Todos.remaining().length;
var remaining = window.app.Todos.remaining().length;
return {
itemText: remaining === 1 ? 'item' : 'items',
completed: app.Todos.completed().length,
completed: window.app.Todos.completed().length,
remaining: remaining
};
},
......@@ -43,7 +43,7 @@ Thorax.View.extend({
highlightFilter: function() {
this.$('#filters li a')
.removeClass('selected')
.filter('[href="#/' + ( app.TodoFilter || '' ) + '"]')
.filter('[href="#/' + ( window.app.TodoFilter || '' ) + '"]')
.addClass('selected');
}
});
\ No newline at end of file
var app = app || {};
$(function() {
'use strict';
......
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