2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sgEnter - A directive evaluated when the enter key is pressed
|
|
|
|
* @memberof SOGo.Common
|
|
|
|
* @ngInject
|
|
|
|
* @example:
|
|
|
|
|
|
|
|
<input type="text"
|
|
|
|
sg-enter="save($index)" />
|
|
|
|
*/
|
|
|
|
function sgEnter() {
|
|
|
|
var ENTER_KEY = 13;
|
|
|
|
return function(scope, element, attrs) {
|
|
|
|
element.bind("keydown keypress", function(event) {
|
|
|
|
if (event.which === ENTER_KEY) {
|
2015-09-16 22:15:04 +02:00
|
|
|
scope.$apply(attrs.sgEnter);
|
2015-05-06 04:06:13 +02:00
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.Common')
|
|
|
|
.directive('sgEnter', sgEnter);
|
|
|
|
})();
|