sogo/UI/WebServerResources/js/Common/sgEnter.directive.js
Francis Lachapelle 1dc5f0d412 (js) New file structure for Angular modules
JavaScript files are now merged by the 'js' Grunt task.
2015-06-12 12:01:21 -04:00

33 lines
731 B
JavaScript

/* -*- 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) {
scope.$apply(function() {
scope.$eval(attrs.sgEnter);
});
event.preventDefault();
}
});
};
}
angular
.module('SOGo.Common')
.directive('sgEnter', sgEnter);
})();