2016-04-17 02:45:17 +00:00
|
|
|
'use strict';
|
2016-04-12 02:14:38 +00:00
|
|
|
|
|
|
|
angular.module('forms').directive('onEnterKey', ['$rootScope', function($rootScope){
|
|
|
|
return {
|
2016-04-29 04:57:04 +00:00
|
|
|
restrict: 'A',
|
2016-04-12 02:14:38 +00:00
|
|
|
link: function($scope, $element, $attrs) {
|
2016-04-17 02:45:17 +00:00
|
|
|
$element.bind('keydown keypress', function(event) {
|
2016-04-12 02:14:38 +00:00
|
|
|
var keyCode = event.which || event.keyCode;
|
2016-05-14 00:35:52 +00:00
|
|
|
if(keyCode === 13 && !event.shiftKey) {
|
2016-05-13 23:52:28 +00:00
|
|
|
event.preventDefault();
|
2016-04-12 02:14:38 +00:00
|
|
|
$rootScope.$apply(function() {
|
|
|
|
$rootScope.$eval($attrs.onEnterKey);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-04-29 04:57:04 +00:00
|
|
|
};
|
2016-04-12 02:14:38 +00:00
|
|
|
}]);
|