Skip to content
Snippets Groups Projects
Commit 32ee33e6 authored by Nithin David Thomas's avatar Nithin David Thomas Committed by Fady Samir Sadek
Browse files

Dijon: Cancel editing on escape key press (#1856)

parent 5619b6cf
No related branches found
No related tags found
No related merge requests found
......@@ -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 );
......
......@@ -16,6 +16,7 @@
return {
system: undefined, //inject
enterKey: undefined,
escapeKey: undefined,
todosModel: undefined, //inject
setup: function() {
var self = this;
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment