SmartIT_Extensions/BMC/smart-it-full-helix/scripts/app/common/ng-enter-directive.js

28 lines
906 B
JavaScript

"use strict";
/**
* Created by igor.samulenko on 3/5/14.
*/
(function () {
'use strict';
angular.module('myitsmApp')
.directive('ngEnter', function () {
return function (scope, element, attrs) {
function keyDownKeyPressHandler(event) {
if (event.which === 13 && !element.prop('readonly')) {
scope.$apply(function () {
scope.$eval(attrs.ngEnter, { $event: event });
});
event.preventDefault();
event.stopPropagation();
}
}
element.on('keydown', keyDownKeyPressHandler);
scope.$on("$destroy", function () {
console.log("ngEnter: unbind events");
element.off('keydown', keyDownKeyPressHandler);
element.off();
});
};
});
}());