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

always use window.app

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