Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eugene Shen
todomvc
Commits
73ebf519
Commit
73ebf519
authored
Feb 27, 2012
by
Ryan Niemeyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove todo item, if edited item is blank or just whitespace
parent
53d5a335
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
12 deletions
+15
-12
architecture-examples/knockoutjs/index.html
architecture-examples/knockoutjs/index.html
+2
-2
architecture-examples/knockoutjs/js/app.js
architecture-examples/knockoutjs/js/app.js
+13
-10
No files found.
architecture-examples/knockoutjs/index.html
View file @
73ebf519
...
...
@@ -17,13 +17,13 @@
<label
for=
"toggle-all"
>
Mark all as complete
</label>
<ul
id=
"todo-list"
data-bind=
"foreach: todos"
>
<li
data-bind=
"css: { done: done, editing: editing }"
>
<div
class=
"view"
data-bind=
"event: { dblclick:
edit
}"
>
<div
class=
"view"
data-bind=
"event: { dblclick:
$root.editItem
}"
>
<input
class=
"toggle"
type=
"checkbox"
data-bind=
"checked: done"
>
<label
data-bind=
"text: content"
></label>
<a
class=
"destroy"
href=
"#"
data-bind=
"click: $root.remove"
></a>
</div>
<input
class=
"edit"
type=
"text"
data-bind=
"value: content, valueUpdate: 'afterkeydown', enterKey:
stopEditing, selectAndFocus: editing, event: { blur:
stopEditing }"
/>
data-bind=
"value: content, valueUpdate: 'afterkeydown', enterKey:
$root.stopEditing, selectAndFocus: editing, event: { blur: $root.
stopEditing }"
/>
</li>
</ul>
</section>
...
...
architecture-examples/knockoutjs/js/app.js
View file @
73ebf519
...
...
@@ -68,16 +68,6 @@
this
.
editing
=
ko
.
observable
(
false
);
};
//can place methods on prototype, as there can be many todos
ko
.
utils
.
extend
(
Todo
.
prototype
,
{
edit
:
function
()
{
this
.
editing
(
true
);
},
stopEditing
:
function
()
{
this
.
editing
(
false
);
}
});
//our main view model
var
ViewModel
=
function
(
todos
)
{
var
self
=
this
;
...
...
@@ -111,6 +101,19 @@
});
};
//edit an item
self
.
editItem
=
function
(
item
)
{
item
.
editing
(
true
);
};
//stop editing an item. Remove the item, if it is now empty
self
.
stopEditing
=
function
(
item
)
{
item
.
editing
(
false
);
if
(
!
item
.
content
().
trim
())
{
self
.
remove
(
item
);
}
};
//count of all completed todos
self
.
completedCount
=
ko
.
computed
(
function
()
{
return
ko
.
utils
.
arrayFilter
(
self
.
todos
(),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment