New sgEnter Angular directive

pull/91/head
Francis Lachapelle 2015-01-29 10:55:47 -05:00
parent 862068eeb5
commit 7f74d5a3d9
1 changed files with 23 additions and 1 deletions

View File

@ -114,6 +114,28 @@
/* Factory registration in Angular module */
.factory('sgDialog', Dialog.$factory)
/**
* sgEnter - A directive evaluated when the enter key is pressed
* @memberof SOGo.UIDesktop
* @example:
<input type="text"
sg-enter="save($index)" />
*/
.directive('sgEnter', function() {
var ENTER_KEY = 13;
return function(scope, element, attrs) {
element.bind("keydown keypress", function(event) {
if (event.which === ENTER_KEY) {
scope.$apply(function() {
scope.$eval(attrs.sgEnter);
});
event.preventDefault();
}
});
};
})
/**
* sgEscape - A directive evaluated when the escape key is pressed
* @memberof SOGo.UIDesktop
@ -125,7 +147,7 @@
.directive('sgEscape', function() {
var ESCAPE_KEY = 27;
return function(scope, elem, attrs) {
elem.bind('keydown', function (event) {
elem.bind('keydown', function(event) {
if (event.keyCode === ESCAPE_KEY) {
scope.$apply(attrs.sgEscape);
}