directives.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /* Directives for DOM manipulation and interaction. */
  3. /* Directive that can be used to make an input field react to the press of Enter. */
  4. eventManApp.directive('eventmanPressEnter', function () {
  5. return function (scope, element, attrs) {
  6. element.bind("keydown keypress", function (event) {
  7. if(event.which === 13) {
  8. scope.$apply(function (){
  9. scope.$eval(attrs.ngEnter);
  10. });
  11. event.preventDefault();
  12. }
  13. });
  14. };
  15. });
  16. eventManApp.directive('eventmanFocus', function () {
  17. function link(scope, element, attrs) {
  18. element[0].focus();
  19. };
  20. return {
  21. link: link
  22. };
  23. });
  24. eventManApp.directive('resetFocus', function () {
  25. function link(scope, element, attrs) {
  26. element.on('click', function() {
  27. // FIXME: that's so wrong! We need to make the new directive communicate.
  28. var el = angular.element(document.querySelector('#query-persons'));
  29. el.length && el[0].focus();
  30. });
  31. };
  32. return {
  33. link: link
  34. };
  35. });
  36. eventManApp.directive('escKey', function() {
  37. return function(scope, element, attrs) {
  38. element.bind('keydown keypress', function(evt) {
  39. if (evt.which === 27) {
  40. scope.$apply(function() {
  41. scope.$eval(attrs.escKey);
  42. });
  43. evt.preventDefault();
  44. }
  45. });
  46. };
  47. });