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
4869d71a
Commit
4869d71a
authored
Jul 08, 2013
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
angularjs: add escape behavior
parent
ba9a2fc9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
2 deletions
+37
-2
architecture-examples/angularjs/index.html
architecture-examples/angularjs/index.html
+2
-1
architecture-examples/angularjs/js/controllers/todoCtrl.js
architecture-examples/angularjs/js/controllers/todoCtrl.js
+8
-1
architecture-examples/angularjs/js/directives/todoEscape.js
architecture-examples/angularjs/js/directives/todoEscape.js
+18
-0
architecture-examples/angularjs/test/unit/todoCtrlSpec.js
architecture-examples/angularjs/test/unit/todoCtrlSpec.js
+9
-0
No files found.
architecture-examples/angularjs/index.html
View file @
4869d71a
...
...
@@ -26,7 +26,7 @@
<button
class=
"destroy"
ng-click=
"removeTodo(todo)"
></button>
</div>
<form
ng-submit=
"doneEditing(todo)"
>
<input
class=
"edit"
ng-model=
"todo.title"
todo-blur=
"doneEditing(todo)"
todo-focus=
"todo == editedTodo"
>
<input
class=
"edit"
ng-model=
"todo.title"
todo-
escape=
"revertEditing(todo)"
todo-
blur=
"doneEditing(todo)"
todo-focus=
"todo == editedTodo"
>
</form>
</li>
</ul>
...
...
@@ -66,5 +66,6 @@
<script
src=
"js/services/todoStorage.js"
></script>
<script
src=
"js/directives/todoFocus.js"
></script>
<script
src=
"js/directives/todoBlur.js"
></script>
<script
src=
"js/directives/todoEscape.js"
></script>
</body>
</html>
architecture-examples/angularjs/js/controllers/todoCtrl.js
View file @
4869d71a
/*global todomvc */
/*global todomvc
, angular
*/
'
use strict
'
;
/**
...
...
@@ -47,6 +47,8 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
$scope
.
editTodo
=
function
(
todo
)
{
$scope
.
editedTodo
=
todo
;
// Clone the original todo to restore it on demand.
$scope
.
originalTodo
=
angular
.
extend
({},
todo
);
};
$scope
.
doneEditing
=
function
(
todo
)
{
...
...
@@ -58,6 +60,11 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
}
};
$scope
.
revertEditing
=
function
(
todo
)
{
todos
[
todos
.
indexOf
(
todo
)]
=
$scope
.
originalTodo
;
$scope
.
doneEditing
(
$scope
.
originalTodo
);
};
$scope
.
removeTodo
=
function
(
todo
)
{
todos
.
splice
(
todos
.
indexOf
(
todo
),
1
);
};
...
...
architecture-examples/angularjs/js/directives/todoEscape.js
0 → 100644
View file @
4869d71a
/*global todomvc */
'
use strict
'
;
/**
* Directive that executes an expression when the element it is applied to gets
* an `escape` keydown event.
*/
todomvc
.
directive
(
'
todoBlur
'
,
function
()
{
var
ESCAPE_KEY
=
27
;
return
function
(
scope
,
elem
,
attrs
)
{
elem
.
bind
(
'
keydown
'
,
function
(
event
)
{
if
(
event
.
keyCode
===
ESCAPE_KEY
)
{
scope
.
$apply
(
attrs
.
todoEscape
);
}
});
};
});
architecture-examples/angularjs/test/unit/todoCtrlSpec.js
View file @
4869d71a
...
...
@@ -172,6 +172,15 @@
scope
.
$digest
();
expect
(
scope
.
completedCount
).
toBe
(
5
);
});
it
(
'
revertTodo() get a Todo to its previous state
'
,
function
()
{
var
todo
=
todoList
[
0
];
scope
.
editTodo
(
todo
);
todo
.
title
=
'
Unicorn sparkly skypuffles.
'
;
scope
.
revertEditing
(
todo
);
scope
.
$digest
();
expect
(
scope
.
todos
[
0
].
title
).
toBe
(
'
Uncompleted Item 0
'
);
});
});
});
}());
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