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
ad60850c
Commit
ad60850c
authored
Nov 26, 2015
by
Dave Methvin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
thorax_lumbar: Cancel editing using Escape key
Ref #789
parent
5cd9e6d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
10 deletions
+42
-10
examples/thorax_lumbar/public/todomvc.js
examples/thorax_lumbar/public/todomvc.js
+21
-5
examples/thorax_lumbar/src/js/app.js
examples/thorax_lumbar/src/js/app.js
+3
-0
examples/thorax_lumbar/src/js/views/todo-item.js
examples/thorax_lumbar/src/js/views/todo-item.js
+18
-5
No files found.
examples/thorax_lumbar/public/todomvc.js
View file @
ad60850c
...
@@ -91,6 +91,7 @@ module.routes = {"":"setFilter",":filter":"setFilter"};
...
@@ -91,6 +91,7 @@ module.routes = {"":"setFilter",":filter":"setFilter"};
}());
}());
;;
;;
/*global Thorax, ENTER_KEY, ESCAPE_KEY*/
$
(
function
()
{
$
(
function
()
{
'
use strict
'
;
'
use strict
'
;
...
@@ -111,7 +112,7 @@ $(function () {
...
@@ -111,7 +112,7 @@ $(function () {
'
click .toggle
'
:
'
toggleCompleted
'
,
'
click .toggle
'
:
'
toggleCompleted
'
,
'
dblclick label
'
:
'
edit
'
,
'
dblclick label
'
:
'
edit
'
,
'
click .destroy
'
:
'
clear
'
,
'
click .destroy
'
:
'
clear
'
,
'
key
press .edit
'
:
'
updateOnEnt
er
'
,
'
key
up .edit
'
:
'
keyListen
er
'
,
'
blur .edit
'
:
'
close
'
,
'
blur .edit
'
:
'
close
'
,
// The "rendered" event is triggered by Thorax each time render()
// The "rendered" event is triggered by Thorax each time render()
// is called and the result of the template has been appended
// is called and the result of the template has been appended
...
@@ -129,11 +130,16 @@ $(function () {
...
@@ -129,11 +130,16 @@ $(function () {
// Switch this view into `"editing"` mode, displaying the input field.
// Switch this view into `"editing"` mode, displaying the input field.
edit
:
function
()
{
edit
:
function
()
{
this
.
$el
.
addClass
(
'
editing
'
);
this
.
$el
.
addClass
(
'
editing
'
);
this
.
$
(
'
.edit
'
).
focus
();
this
.
$
(
'
.edit
'
).
val
(
this
.
model
.
get
(
'
title
'
)).
focus
();
},
},
// Close the `"editing"` mode
, saving changes to the todo
.
// Close the `"editing"` mode.
close
:
function
()
{
close
:
function
()
{
// If editing was cancelled, don't save
if
(
!
this
.
$el
.
hasClass
(
'
editing
'
))
{
return
;
}
var
value
=
this
.
$
(
'
.edit
'
).
val
().
trim
();
var
value
=
this
.
$
(
'
.edit
'
).
val
().
trim
();
if
(
value
)
{
if
(
value
)
{
...
@@ -145,10 +151,17 @@ $(function () {
...
@@ -145,10 +151,17 @@ $(function () {
this
.
$el
.
removeClass
(
'
editing
'
);
this
.
$el
.
removeClass
(
'
editing
'
);
},
},
// If you hit `enter`, we're through editing the item.
// User cancelled editing, don't update the todo.
updateOnEnter
:
function
(
e
)
{
cancelEdits
:
function
()
{
this
.
$el
.
removeClass
(
'
editing
'
);
},
// Enter completes the editing, Escape cancels it
keyListener
:
function
(
e
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
this
.
close
();
this
.
close
();
}
else
if
(
e
.
which
===
ESCAPE_KEY
)
{
this
.
cancelEdits
();
}
}
},
},
...
@@ -305,7 +318,10 @@ Thorax.templates['src/templates/app'] = Handlebars.compile('<section id=\"todoap
...
@@ -305,7 +318,10 @@ Thorax.templates['src/templates/app'] = Handlebars.compile('<section id=\"todoap
}());
}());
;;
;;
/*global Thorax, Backbone*/
/*jshint unused:false*/
var
ENTER_KEY
=
13
;
var
ENTER_KEY
=
13
;
var
ESCAPE_KEY
=
27
;
$
(
function
()
{
$
(
function
()
{
// Kick things off by creating the **App**.
// Kick things off by creating the **App**.
...
...
examples/thorax_lumbar/src/js/app.js
View file @
ad60850c
/*global Thorax, Backbone*/
/*jshint unused:false*/
var
ENTER_KEY
=
13
;
var
ENTER_KEY
=
13
;
var
ESCAPE_KEY
=
27
;
$
(
function
()
{
$
(
function
()
{
// Kick things off by creating the **App**.
// Kick things off by creating the **App**.
...
...
examples/thorax_lumbar/src/js/views/todo-item.js
View file @
ad60850c
/*global Thorax, ENTER_KEY, ESCAPE_KEY*/
$
(
function
()
{
$
(
function
()
{
'
use strict
'
;
'
use strict
'
;
...
@@ -18,7 +19,7 @@ $(function () {
...
@@ -18,7 +19,7 @@ $(function () {
'
click .toggle
'
:
'
toggleCompleted
'
,
'
click .toggle
'
:
'
toggleCompleted
'
,
'
dblclick label
'
:
'
edit
'
,
'
dblclick label
'
:
'
edit
'
,
'
click .destroy
'
:
'
clear
'
,
'
click .destroy
'
:
'
clear
'
,
'
key
press .edit
'
:
'
updateOnEnt
er
'
,
'
key
up .edit
'
:
'
keyListen
er
'
,
'
blur .edit
'
:
'
close
'
,
'
blur .edit
'
:
'
close
'
,
// The "rendered" event is triggered by Thorax each time render()
// The "rendered" event is triggered by Thorax each time render()
// is called and the result of the template has been appended
// is called and the result of the template has been appended
...
@@ -36,11 +37,16 @@ $(function () {
...
@@ -36,11 +37,16 @@ $(function () {
// Switch this view into `"editing"` mode, displaying the input field.
// Switch this view into `"editing"` mode, displaying the input field.
edit
:
function
()
{
edit
:
function
()
{
this
.
$el
.
addClass
(
'
editing
'
);
this
.
$el
.
addClass
(
'
editing
'
);
this
.
$
(
'
.edit
'
).
focus
();
this
.
$
(
'
.edit
'
).
val
(
this
.
model
.
get
(
'
title
'
)).
focus
();
},
},
// Close the `"editing"` mode
, saving changes to the todo
.
// Close the `"editing"` mode.
close
:
function
()
{
close
:
function
()
{
// If editing was cancelled, don't save
if
(
!
this
.
$el
.
hasClass
(
'
editing
'
))
{
return
;
}
var
value
=
this
.
$
(
'
.edit
'
).
val
().
trim
();
var
value
=
this
.
$
(
'
.edit
'
).
val
().
trim
();
if
(
value
)
{
if
(
value
)
{
...
@@ -52,10 +58,17 @@ $(function () {
...
@@ -52,10 +58,17 @@ $(function () {
this
.
$el
.
removeClass
(
'
editing
'
);
this
.
$el
.
removeClass
(
'
editing
'
);
},
},
// If you hit `enter`, we're through editing the item.
// User cancelled editing, don't update the todo.
updateOnEnter
:
function
(
e
)
{
cancelEdits
:
function
()
{
this
.
$el
.
removeClass
(
'
editing
'
);
},
// Enter completes the editing, Escape cancels it
keyListener
:
function
(
e
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
if
(
e
.
which
===
ENTER_KEY
)
{
this
.
close
();
this
.
close
();
}
else
if
(
e
.
which
===
ESCAPE_KEY
)
{
this
.
cancelEdits
();
}
}
},
},
...
...
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