Commit 1c739d6f authored by Sindre Sorhus's avatar Sindre Sorhus

Backbone app - code style

parent 1877dd10
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Backbone.js • TodoMVC</title> <title>Backbone.js • TodoMVC</title>
<link rel="stylesheet" href="components/todomvc-common/base.css"> <link rel="stylesheet" href="components/todomvc-common/base.css">
</head> </head>
<body> <body>
<section id="todoapp"> <section id="todoapp">
<header id="header"> <header id="header">
<h1>todos</h1> <h1>todos</h1>
...@@ -60,5 +60,5 @@ ...@@ -60,5 +60,5 @@
<script src="js/views/app.js"></script> <script src="js/views/app.js"></script>
<script src="js/routers/router.js"></script> <script src="js/routers/router.js"></script>
<script src="js/app.js"></script> <script src="js/app.js"></script>
</body> </body>
</html> </html>
/*global $*/ /*global $ */
/*jshint unused:false*/ /*jshint unused:false */
var app = app || {}; var app = app || {};
var ENTER_KEY = 13; var ENTER_KEY = 13;
$(function () { $(function () {
'use strict'; 'use strict';
// Kick things off by creating the **App**. // kick things off by creating the `App`
new app.AppView(); new app.AppView();
}); });
...@@ -10,7 +10,6 @@ var app = app || {}; ...@@ -10,7 +10,6 @@ var app = app || {};
// The collection of todos is backed by *localStorage* instead of a remote // The collection of todos is backed by *localStorage* instead of a remote
// server. // server.
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: app.Todo,
...@@ -46,5 +45,4 @@ var app = app || {}; ...@@ -46,5 +45,4 @@ var app = app || {};
// Create our global collection of **Todos**. // Create our global collection of **Todos**.
app.Todos = new TodoList(); app.Todos = new TodoList();
})();
}());
/*global Backbone*/ /*global Backbone */
var app = app || {}; var app = app || {};
(function () { (function () {
...@@ -9,7 +9,6 @@ var app = app || {}; ...@@ -9,7 +9,6 @@ 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({ 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.
defaults: { defaults: {
...@@ -23,7 +22,5 @@ var app = app || {}; ...@@ -23,7 +22,5 @@ var app = app || {};
completed: !this.get('completed') completed: !this.get('completed')
}); });
} }
}); });
})();
}());
/*global Backbone*/ /*global Backbone */
var app = app || {}; var app = app || {};
(function () { (function () {
...@@ -6,7 +6,6 @@ var app = app || {}; ...@@ -6,7 +6,6 @@ var app = app || {};
// Todo Router // Todo Router
// ---------- // ----------
var Workspace = Backbone.Router.extend({ var Workspace = Backbone.Router.extend({
routes: { routes: {
'*filter': 'setFilter' '*filter': 'setFilter'
...@@ -24,5 +23,4 @@ var app = app || {}; ...@@ -24,5 +23,4 @@ var app = app || {};
app.TodoRouter = new Workspace(); app.TodoRouter = new Workspace();
Backbone.history.start(); Backbone.history.start();
})();
}());
/*global Backbone _ $ ENTER_KEY*/ /*global Backbone _ $ ENTER_KEY */
var app = app || {}; var app = app || {};
$(function ($) { $(function ($) {
......
/*global Backbone _ $ ENTER_KEY*/ /*global Backbone _ $ ENTER_KEY */
var app = app || {}; var app = app || {};
$(function () { $(function () {
...@@ -9,7 +9,6 @@ $(function () { ...@@ -9,7 +9,6 @@ $(function () {
// The DOM element for a todo item... // The DOM element for a todo item...
app.TodoView = Backbone.View.extend({ app.TodoView = Backbone.View.extend({
//... is a list tag. //... is a list tag.
tagName: 'li', tagName: 'li',
...@@ -38,7 +37,6 @@ $(function () { ...@@ -38,7 +37,6 @@ $(function () {
render: function () { render: function () {
this.$el.html(this.template(this.model.toJSON())); this.$el.html(this.template(this.model.toJSON()));
this.$el.toggleClass('completed', this.model.get('completed')); this.$el.toggleClass('completed', this.model.get('completed'));
this.toggleVisible(); this.toggleVisible();
this.$input = this.$('.edit'); this.$input = this.$('.edit');
return this; return this;
......
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