mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-05 16:35:10 +00:00
New sgEnter Angular directive
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user