Commit 7405c80f authored by Aaron Boushley's avatar Aaron Boushley

Upgraded libs. Resolving other issues.

Bolding items left.
Trim todo input and prevent whitespace only todos.
Change content to title in model.
Double click on item div instead of just title.
Removed unused jslitmus.js.
parent de0428e0
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<script src="js/libs/json2.js"></script> <script src="js/libs/json2.js"></script>
<script src="js/libs/jquery-1.7.1.min.js"></script> <script src="js/libs/jquery-1.7.1.min.js"></script>
<script src="js/libs/underscore-1.1.6.js"></script> <script src="js/libs/underscore.js"></script>
<script src="js/libs/backbone.js"></script> <script src="js/libs/backbone.js"></script>
<script src="js/libs/backbone-localstorage.js"></script> <script src="js/libs/backbone-localstorage.js"></script>
<script src="js/app.js"></script> <script src="js/app.js"></script>
...@@ -46,17 +46,17 @@ ...@@ -46,17 +46,17 @@
<script type="text/template" id="item-template"> <script type="text/template" id="item-template">
<div class="view"> <div class="view">
<input class="toggle" type="checkbox" <%= done ? 'checked="checked"' : '' %> /> <input class="toggle" type="checkbox" <%= done ? 'checked="checked"' : '' %> />
<label><%= content %></label> <label><%= title %></label>
<a class="destroy"></a> <a class="destroy"></a>
</div> </div>
<input class="edit" type="text" value="<%= content %>" /> <input class="edit" type="text" value="<%= title %>" />
</script> </script>
<script type="text/template" id="stats-template"> <script type="text/template" id="stats-template">
<% if (done) { %> <% if (done) { %>
<a id="clear-completed">Clear <%= done %> completed <%= done == 1 ? 'item' : 'items' %></a> <a id="clear-completed">Clear <%= done %> completed <%= done == 1 ? 'item' : 'items' %></a>
<% } %> <% } %>
<div class="todo-count"><%= remaining %> <%= remaining == 1 ? 'item' : 'items' %> left.</div> <div class="todo-count"><b><%= remaining %></b> <%= remaining == 1 ? 'item' : 'items' %> left</div>
</script> </script>
</body> </body>
......
...@@ -9,19 +9,19 @@ $(function(){ ...@@ -9,19 +9,19 @@ $(function(){
// Todo Model // Todo Model
// ---------- // ----------
// Our basic **Todo** model has `content`, `order`, and `done` attributes. // Our basic **Todo** model has `title`, `order`, and `done` attributes.
var Todo = Backbone.Model.extend({ var Todo = Backbone.Model.extend({
// Default attributes for the todo. // Default attributes for the todo.
defaults: { defaults: {
content: "empty todo...", title: "empty todo...",
done: false done: false
}, },
// Ensure that each todo created has `content`. // Ensure that each todo created has `title`.
initialize: function() { initialize: function() {
if (!this.get("content")) { if (!this.get("title")) {
this.set({"content": this.defaults.content}); this.set({"title": this.defaults.title});
} }
}, },
...@@ -92,7 +92,7 @@ $(function(){ ...@@ -92,7 +92,7 @@ $(function(){
// The DOM events specific to an item. // The DOM events specific to an item.
events: { events: {
"click .toggle" : "toggleDone", "click .toggle" : "toggleDone",
"dblclick label" : "edit", "dblclick .view" : "edit",
"click a.destroy" : "clear", "click a.destroy" : "clear",
"keypress .edit" : "updateOnEnter", "keypress .edit" : "updateOnEnter",
"blur .edit" : "close" "blur .edit" : "close"
...@@ -106,7 +106,7 @@ $(function(){ ...@@ -106,7 +106,7 @@ $(function(){
this.model.bind('destroy', this.remove, this); this.model.bind('destroy', this.remove, this);
}, },
// Re-render the contents of the todo item. // Re-render the titles of the todo item.
render: function() { render: function() {
var $el = $(this.el); var $el = $(this.el);
$el.html(this.template(this.model.toJSON())); $el.html(this.template(this.model.toJSON()));
...@@ -129,7 +129,7 @@ $(function(){ ...@@ -129,7 +129,7 @@ $(function(){
// Close the `"editing"` mode, saving changes to the todo. // Close the `"editing"` mode, saving changes to the todo.
close: function() { close: function() {
this.model.save({content: this.input.val()}); this.model.save({title: this.input.val()});
$(this.el).removeClass("editing"); $(this.el).removeClass("editing");
}, },
...@@ -220,9 +220,9 @@ $(function(){ ...@@ -220,9 +220,9 @@ $(function(){
// Generate the attributes for a new Todo item. // Generate the attributes for a new Todo item.
newAttributes: function() { newAttributes: function() {
return { return {
content: this.input.val(), title: this.input.val().trim(),
order: Todos.nextOrder(), order: Todos.nextOrder(),
done: false done: false
}; };
}, },
...@@ -230,6 +230,8 @@ $(function(){ ...@@ -230,6 +230,8 @@ $(function(){
// persisting it to *localStorage*. // persisting it to *localStorage*.
createOnEnter: function(e) { createOnEnter: function(e) {
if (e.keyCode != 13) return; if (e.keyCode != 13) return;
if (!this.input.val().trim()) return;
Todos.create(this.newAttributes()); Todos.create(this.newAttributes());
this.input.val(''); this.input.val('');
}, },
......
This diff is collapsed.
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