New sgEnter Angular directive
parent
862068eeb5
commit
7f74d5a3d9
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue