Commit a9a0d679 authored by Arthur Verschaeve's avatar Arthur Verschaeve

Revert on escape for `angularjs_require` app

parent e5adfb0c
...@@ -63,7 +63,6 @@ module.exports = [ ...@@ -63,7 +63,6 @@ module.exports = [
'TodoMVC - serenadejs, Editing, should cancel edits on escape', 'TodoMVC - serenadejs, Editing, should cancel edits on escape',
'TodoMVC - thorax, Editing, should cancel edits on escape', 'TodoMVC - thorax, Editing, should cancel edits on escape',
'TodoMVC - typescript-angular, Editing, should cancel edits on escape', 'TodoMVC - typescript-angular, Editing, should cancel edits on escape',
'TodoMVC - angularjs_require, Editing, should cancel edits on escape',
'TodoMVC - flight, Editing, should cancel edits on escape', 'TodoMVC - flight, Editing, should cancel edits on escape',
'TodoMVC - thorax_lumbar, Editing, should cancel edits on escape', 'TodoMVC - thorax_lumbar, Editing, should cancel edits on escape',
'TodoMVC - backbone_require, Editing, should cancel edits on escape', 'TodoMVC - backbone_require, Editing, should cancel edits on escape',
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<button class="destroy" ng-click="removeTodo(todo)"></button> <button class="destroy" ng-click="removeTodo(todo)"></button>
</div> </div>
<form ng-submit="doneEditing(todo)"> <form ng-submit="doneEditing(todo)">
<input class="edit" ng-trim="false" ng-model="todo.title" ng-blur="doneEditing(todo)" todo-focus="todo == editedTodo"> <input class="edit" ng-trim="false" ng-model="todo.title" ng-blur="doneEditing(todo)" todo-escape="revertEditing(todo)" todo-focus="todo == editedTodo">
</form> </form>
</li> </li>
</ul> </ul>
......
...@@ -52,6 +52,8 @@ define(['app', 'services/todoStorage'], function (app) { ...@@ -52,6 +52,8 @@ define(['app', 'services/todoStorage'], function (app) {
$scope.editTodo = function (todo) { $scope.editTodo = function (todo) {
$scope.editedTodo = todo; $scope.editedTodo = todo;
// Clone the original todo to restore it on demand.
$scope.originalTodo = angular.copy(todo);
}; };
...@@ -64,6 +66,10 @@ define(['app', 'services/todoStorage'], function (app) { ...@@ -64,6 +66,10 @@ define(['app', 'services/todoStorage'], function (app) {
} }
}; };
$scope.revertEditing = function (todo) {
todos[todos.indexOf(todo)] = $scope.originalTodo;
$scope.doneEditing($scope.originalTodo);
};
$scope.removeTodo = function (todo) { $scope.removeTodo = function (todo) {
todos.splice(todos.indexOf(todo), 1); todos.splice(todos.indexOf(todo), 1);
......
/*global define*/
define(['app'], function (app) {
'use strict';
app.directive('todoEscape', function () {
var ESCAPE_KEY = 27;
return function (scope, elem, attrs) {
elem.bind('keydown', function (event) {
if (event.keyCode === ESCAPE_KEY) {
scope.$apply(attrs.todoEscape);
}
});
};
});
});
...@@ -12,6 +12,6 @@ require.config({ ...@@ -12,6 +12,6 @@ require.config({
} }
}); });
require(['angular', 'app', 'controllers/todo', 'directives/todoFocus'], function (angular) { require(['angular', 'app', 'controllers/todo', 'directives/todoFocus', 'directives/todoEscape'], function (angular) {
angular.bootstrap(document, ['todomvc']); angular.bootstrap(document, ['todomvc']);
}); });
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