2016-04-17 02:45:17 +00:00
|
|
|
'use strict';
|
2016-04-12 02:14:38 +00:00
|
|
|
|
2016-06-04 07:00:31 +00:00
|
|
|
angular.module('forms').directive('onEnterOrTabKey', ['$rootScope', function($rootScope){
|
2016-04-12 02:14:38 +00:00
|
|
|
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-06-04 07:00:31 +00:00
|
|
|
|
2016-04-12 02:14:38 +00:00
|
|
|
var keyCode = event.which || event.keyCode;
|
2016-06-04 07:00:31 +00:00
|
|
|
console.log('keyCode is: '+keyCode);
|
|
|
|
|
|
|
|
if((keyCode === 13 || keyCode === 9) && !event.shiftKey) {
|
2016-05-13 23:52:28 +00:00
|
|
|
event.preventDefault();
|
2016-04-12 02:14:38 +00:00
|
|
|
$rootScope.$apply(function() {
|
2016-06-04 07:00:31 +00:00
|
|
|
$rootScope.$eval($attrs.onEnterOrTabKey);
|
2016-04-12 02:14:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-04-29 04:57:04 +00:00
|
|
|
};
|
2016-04-12 02:14:38 +00:00
|
|
|
}]);
|