Commit 15be3631 authored by Pascal Hartig's avatar Pascal Hartig

Merge pull request #873 from cliffhall/gh-pages

Fix outstanding issues with PureMVC implementation
parents 27a39afd 534e6832
......@@ -110,7 +110,7 @@ puremvc.define({
addTodo: function( newTodo ) {
newTodo.id = this.getUuid();
this.todos.push( newTodo );
this.todos.unshift( newTodo );
this.todosModified();
},
......
......@@ -50,6 +50,7 @@ puremvc.define({
// INSTANCE MEMBERS
{
ENTER_KEY: 13,
ESC_KEY: 27,
addEventListener: function ( type, listener, useCapture ){
todomvc.view.event.AppEvents.addEventListener ( this.todoApp, type, listener, useCapture );
......@@ -63,6 +64,18 @@ puremvc.define({
todomvc.view.event.AppEvents.dispatchEvent( this.todoApp, event );
},
abandonEditTodo: function( event ) {
var todo, todoId, div, inputEditTodo;
inputEditTodo = event.target;
todoId = inputEditTodo.getAttribute( 'data-todo-id' )
todo = this.getTodoById( todoId );
inputEditTodo.value = todo.title;
inputEditTodo.completed = todo.completed;
div = document.getElementById( 'li_' + todoId );
div.className = 'view';
this.newTodoField.focus();
},
dispatchToggleComplete: function( event ) {
var todo, toggleItemCompleteEvent;
todo = this.getTodoById( event.target.getAttribute( 'data-todo-id' ) );
......@@ -167,6 +180,7 @@ puremvc.define({
todoId = this.getAttribute( 'data-todo-id' );
div = document.getElementById( 'li_' + todoId );
inputEditTodo = document.getElementById( 'input_' + todoId );
inputEditTodo.setAttribute( 'data-todo-id', todoId );
div.className = 'editing';
inputEditTodo.focus();
......@@ -184,6 +198,13 @@ puremvc.define({
this.component.dispatchUpdateTodo( event );
}
});
todomvc.view.event.AppEvents.addEventListener( inputEditTodo, 'keydown', function( event ) {
if ( event.keyCode === this.component.ESC_KEY ) {
this.component.abandonEditTodo( event );
}
});
todomvc.view.event.AppEvents.addEventListener( inputEditTodo, 'blur', function( event ) {
this.component.dispatchUpdateTodo( event );
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment