Skip to content

Commit 4d837fb

Browse files
committed
Small tweaks to jQuery example
- Use the base.css - Trim whitespace on new todo - Trim whitespace on todo update, and remove todo if empty - Reset the checked state of "Mark all as complete", when the "Clear completed" button is clicked
1 parent d947e48 commit 4d837fb

File tree

3 files changed

+11
-217
lines changed

3 files changed

+11
-217
lines changed

architecture-examples/jquery/css/app.css

Lines changed: 0 additions & 208 deletions
This file was deleted.

architecture-examples/jquery/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<title>jQuery - TodoMVC</title>
6-
<link rel="stylesheet" href="css/app.css">
6+
<link rel="stylesheet" href="../../assets/base.css">
77
</head>
88
<body>
99
<div id="todoapp">

architecture-examples/jquery/js/app.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ jQuery(function($) {
9797
todos.splice( l, 1 );
9898
}
9999
}
100+
App.$toggleAll.attr( 'checked', false );
100101
App.render();
101102
},
102103
// Accepts an element from inside the ".item" div and returns the corresponding todo in the todos array.
@@ -110,16 +111,13 @@ jQuery(function($) {
110111
});
111112
},
112113
create: function(e) {
113-
if ( e.which !== App.ENTER_KEY ) {
114-
return;
115-
}
116114
var $input = $(this),
117-
inputVal = $input.val();
118-
if ( !inputVal ) {
115+
val = $.trim( $input.val() );
116+
if ( e.which !== App.ENTER_KEY || !val ) {
119117
return;
120118
}
121119
App.todos.push({
122-
title: inputVal,
120+
title: val,
123121
id: Utils.uuid(),
124122
done: false
125123
});
@@ -143,9 +141,13 @@ jQuery(function($) {
143141
update: function() {
144142
var val = $(this).removeClass('editing').val();
145143
App.getTodo( this, function(i) {
146-
this.todos[i].title = val;
144+
if ( val ) {
145+
this.todos[i].title = val;
146+
} else {
147+
this.todos.splice( i, 1 );
148+
}
149+
this.render();
147150
});
148-
App.render();
149151
},
150152
destroy: function() {
151153
App.getTodo( this, function(i) {

0 commit comments

Comments
 (0)