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
02b43564
Commit
02b43564
authored
Dec 22, 2013
by
Addy Osmani
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #746 from passy/bb-revert-amaze
Backbone: Add revert on escape
parents
bf2698d5
3ff62d28
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
architecture-examples/backbone/js/app.js
architecture-examples/backbone/js/app.js
+1
-0
architecture-examples/backbone/js/views/todo-view.js
architecture-examples/backbone/js/views/todo-view.js
+18
-1
No files found.
architecture-examples/backbone/js/app.js
View file @
02b43564
...
...
@@ -2,6 +2,7 @@
/*jshint unused:false */
var
app
=
app
||
{};
var
ENTER_KEY
=
13
;
var
ESC_KEY
=
27
;
$
(
function
()
{
'
use strict
'
;
...
...
architecture-examples/backbone/js/views/todo-view.js
View file @
02b43564
/*global Backbone, jQuery, _, ENTER_KEY */
/*global Backbone, jQuery, _, ENTER_KEY
, ESC_KEY
*/
var
app
=
app
||
{};
(
function
(
$
)
{
...
...
@@ -21,6 +21,7 @@ var app = app || {};
'
dblclick label
'
:
'
edit
'
,
'
click .destroy
'
:
'
clear
'
,
'
keypress .edit
'
:
'
updateOnEnter
'
,
'
keydown .edit
'
:
'
revertOnEscape
'
,
'
blur .edit
'
:
'
close
'
},
...
...
@@ -70,6 +71,14 @@ var app = app || {};
var
value
=
this
.
$input
.
val
();
var
trimmedValue
=
value
.
trim
();
// We don't want to handle blur events from an item that is no
// longer being edited. Relying on the CSS class here has the
// benefit of us not having to maintain state in the DOM and the
// JavaScript logic.
if
(
!
this
.
$el
.
hasClass
(
'
editing
'
))
{
return
;
}
if
(
trimmedValue
)
{
this
.
model
.
save
({
title
:
trimmedValue
});
...
...
@@ -93,6 +102,14 @@ var app = app || {};
}
},
// If you're pressing `escape` we revert your change by simply leaving
// the `editing` state.
revertOnEscape
:
function
(
e
)
{
if
(
e
.
which
===
ESC_KEY
)
{
this
.
$el
.
removeClass
(
'
editing
'
);
}
},
// Remove the item, destroy the model from *localStorage* and delete its view.
clear
:
function
()
{
this
.
model
.
destroy
();
...
...
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