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
d14b9463
Commit
d14b9463
authored
Jun 19, 2014
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #919 from dprotti/typescriptbackbone824
Typescript-backbone: fixes for #824
parents
8253bfd4
600abbac
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
9 deletions
+48
-9
labs/architecture-examples/typescript-backbone/js/app.js
labs/architecture-examples/typescript-backbone/js/app.js
+25
-5
labs/architecture-examples/typescript-backbone/js/app.ts
labs/architecture-examples/typescript-backbone/js/app.ts
+23
-4
No files found.
labs/architecture-examples/typescript-backbone/js/app.js
View file @
d14b9463
...
...
@@ -132,8 +132,9 @@ var TodoView = (function (_super) {
'
click .check
'
:
'
toggleDone
'
,
'
dblclick label.todo-content
'
:
'
edit
'
,
'
click button.destroy
'
:
'
clear
'
,
'
keypress .todo-input
'
:
'
updateOnEnter
'
,
'
blur .todo-input
'
:
'
close
'
'
keypress .edit
'
:
'
updateOnEnter
'
,
'
keydown .edit
'
:
'
revertOnEscape
'
,
'
blur .edit
'
:
'
close
'
};
_super
.
call
(
this
,
options
);
...
...
@@ -165,14 +166,32 @@ var TodoView = (function (_super) {
// Close the `'editing'` mode, saving changes to the todo.
TodoView
.
prototype
.
close
=
function
()
{
this
.
model
.
save
({
content
:
this
.
input
.
val
()
});
var
trimmedValue
=
this
.
input
.
val
().
trim
();
if
(
trimmedValue
)
{
this
.
model
.
save
({
content
:
trimmedValue
});
}
else
{
this
.
clear
();
}
this
.
$el
.
removeClass
(
'
editing
'
);
};
// If you hit `enter`, we're through editing the item.
TodoView
.
prototype
.
updateOnEnter
=
function
(
e
)
{
if
(
e
.
keyCode
==
TodoView
.
ENTER_KEY
)
close
();
if
(
e
.
which
==
TodoView
.
ENTER_KEY
)
this
.
close
();
};
// If you're pressing `escape` we revert your change by simply leaving
// the `editing` state.
TodoView
.
prototype
.
revertOnEscape
=
function
(
e
)
{
if
(
e
.
which
==
TodoView
.
ESC_KEY
)
{
this
.
$el
.
removeClass
(
'
editing
'
);
// Also reset the hidden input back to the original value.
this
.
input
.
val
(
this
.
model
.
get
(
'
content
'
));
}
};
// Remove the item, destroy the model.
...
...
@@ -180,6 +199,7 @@ var TodoView = (function (_super) {
this
.
model
.
clear
();
};
TodoView
.
ENTER_KEY
=
13
;
TodoView
.
ESC_KEY
=
27
;
return
TodoView
;
})(
Backbone
.
View
);
...
...
labs/architecture-examples/typescript-backbone/js/app.ts
View file @
d14b9463
...
...
@@ -179,6 +179,7 @@ class TodoView extends Backbone.View {
input
:
any
;
static
ENTER_KEY
:
number
=
13
;
static
ESC_KEY
:
number
=
27
;
constructor
(
options
?
)
{
//... is a list tag.
...
...
@@ -189,8 +190,9 @@ class TodoView extends Backbone.View {
'
click .check
'
:
'
toggleDone
'
,
'
dblclick label.todo-content
'
:
'
edit
'
,
'
click button.destroy
'
:
'
clear
'
,
'
keypress .todo-input
'
:
'
updateOnEnter
'
,
'
blur .todo-input
'
:
'
close
'
'
keypress .edit
'
:
'
updateOnEnter
'
,
'
keydown .edit
'
:
'
revertOnEscape
'
,
'
blur .edit
'
:
'
close
'
};
super
(
options
);
...
...
@@ -223,13 +225,30 @@ class TodoView extends Backbone.View {
// Close the `'editing'` mode, saving changes to the todo.
close
()
{
this
.
model
.
save
({
content
:
this
.
input
.
val
()
});
var
trimmedValue
=
this
.
input
.
val
().
trim
();
if
(
trimmedValue
)
{
this
.
model
.
save
({
content
:
trimmedValue
});
}
else
{
this
.
clear
();
}
this
.
$el
.
removeClass
(
'
editing
'
);
}
// If you hit `enter`, we're through editing the item.
updateOnEnter
(
e
)
{
if
(
e
.
keyCode
==
TodoView
.
ENTER_KEY
)
close
();
if
(
e
.
which
==
TodoView
.
ENTER_KEY
)
this
.
close
();
}
// If you're pressing `escape` we revert your change by simply leaving
// the `editing` state.
revertOnEscape
(
e
)
{
if
(
e
.
which
==
TodoView
.
ESC_KEY
)
{
this
.
$el
.
removeClass
(
'
editing
'
);
// Also reset the hidden input back to the original value.
this
.
input
.
val
(
this
.
model
.
get
(
'
content
'
));
}
}
// Remove the item, destroy the model.
...
...
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