/* @ author Kamal*/ 'use strict'; commonsApp.directive( 'escapeToClose', ['$document','$parse', function($document, $parse) { return { restrict: 'A', link: function($scope, elem, attr) { var fn = $parse(attr['escapeToClose']); //Escape event var escapeEvent = function(e) { if (e.which == 27) // if we have got this far, then we are good to go with processing the command passed in via the click-outside attribute return $scope.$apply(function () { return fn($scope); }); }; // assign the document keypress handler to a variable so we can un-register it when the directive is destroyed $document.on('keyup', escapeEvent); // when the scope is destroyed, clean up the documents click handler as we don't want it hanging around $scope.$on('$destroy', function() { $document.off('keyup', escapeEvent); }); } }; }]); commonsApp.directive( 'submitToEnter', ['$document','$parse', function($document, $parse) { return { restrict: 'A', link: function($scope, elem, attr) { var fn = $parse(attr['submitToEnter']); //Escape event var enterEvent = function(e) { if (e.which == 13) // if we have got this far, then we are good to go with processing the command passed in via the click-outside attribute return $scope.$apply(function () { return fn($scope); }); }; // assign the document keypress handler to a variable so we can un-register it when the directive is destroyed $document.on('keyup', enterEvent); // when the scope is destroyed, clean up the documents click handler as we don't want it hanging around $scope.$on('$destroy', function() { $document.off('keyup', enterEvent); }); } }; }]);