Skip to content

Commit

Permalink
Dijon: Cancel editing on escape key press (tastejs#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
nithindavid authored and FadySamirSadek committed Jun 25, 2018
1 parent 5619b6c commit 32ee33e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/dijon/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var dijondemo = {};

// Values
this.system.mapValue( 'enterKey', 13 );
this.system.mapValue( 'escapeKey', 27 );
this.system.mapValue( 'uuidUtil', ns.utils.Utils );
this.system.mapValue( 'pluralizeUtil', ns.utils.Utils );

Expand Down
9 changes: 8 additions & 1 deletion examples/dijon/js/views/TodoListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
return {
system: undefined, //inject
enterKey: undefined,
escapeKey: undefined,
todosModel: undefined, //inject
setup: function() {
var self = this;
Expand All @@ -26,9 +27,15 @@
$todoList.on( 'dblclick', 'label', function() {
$( this ).closest('li').addClass('editing').find('.edit').focus();
} );
$todoList.on( 'keypress', '.edit', function( e ) {
$todoList.on( 'keydown', '.edit', function( e ) {
if ( e.which === self.enterKey ) {
e.target.blur();
} else if ( e.which === self.escapeKey ) {
var todoEl = $( this ).closest('li'),
id = todoEl.data('id'),
val = $.trim( todoEl.find('label').html());
todoEl.removeClass('editing');
self.system.notify( 'TodoListView:setTitleOfTodo', id, val);
}
});
$todoList.on( 'blur', '.edit', function() {
Expand Down

0 comments on commit 32ee33e

Please sign in to comment.