Commit 596d6dd51b75a866c4454dd0820cfecf973c3f3f
Exists in
master
and in
1 other branch
Merge branch 'master' of https://debo.suite.repo/modulos-npm/foca-directivas
Showing
3 changed files
Show diff stats
src/js/escKey-directive.js
| 1 | angular.module('focaDirectivas') | 1 | angular.module('focaDirectivas') |
| 2 | .directive('escKey', function() { | 2 | .directive('escKey', function() { |
| 3 | return function(scope, element, attrs) { | 3 | return function(scope, element, attrs) { |
| 4 | element.bind('keydown keypress', function(event) { | 4 | element.bind('keydown keypress', function(event) { |
| 5 | if(event.which === 27) { // 27 = esc key | 5 | if(event.which === 27) { // 27 = esc key |
| 6 | scope.$apply(function (){ | 6 | scope.$apply(function() { |
| 7 | scope.$eval(attrs.escKey); | 7 | scope.$eval(attrs.escKey); |
| 8 | }); | 8 | }); |
| 9 | event.preventDefault(); | 9 | event.preventDefault(); |
| 10 | } | 10 | } |
| 11 | }); | 11 | }); |
| 12 | }; | 12 | }; |
| 13 | }); | 13 | }); |
| 14 | 14 |
src/js/focus-directive.js
| 1 | angular.module('focaDirectivas') | 1 | angular.module('focaDirectivas') |
| 2 | .directive('focaFocus', ['$timeout', '$parse', function($timeout, $parse) { | 2 | .directive('focaFocus', ['$timeout', '$parse', function($timeout, $parse) { |
| 3 | var checkDirectivePrerequisites = function (attrs) { | 3 | var checkDirectivePrerequisites = function (attrs) { |
| 4 | if (!attrs.focaFocus && attrs.focaFocus != "") { | 4 | if (!attrs.focaFocus && attrs.focaFocus != "") { |
| 5 | throw "focaFocus missing attribute to evaluate"; | 5 | throw "focaFocus missing attribute to evaluate"; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | return { | 9 | return { |
| 10 | restrict: "A", | 10 | restrict: "A", |
| 11 | link: function (scope, element, attrs, ctrls) { | 11 | link: function(scope, element, attrs, ctrls) { |
| 12 | checkDirectivePrerequisites(attrs); | 12 | checkDirectivePrerequisites(attrs); |
| 13 | 13 | ||
| 14 | scope.$watch(attrs.focaFocus, function (currentValue, lastValue) { | 14 | scope.$watch(attrs.focaFocus, function(currentValue, lastValue) { |
| 15 | if(currentValue == true) { | 15 | if(currentValue == true) { |
| 16 | $timeout(function () { | 16 | $timeout(function() { |
| 17 | element.focus(); | 17 | element.focus(); |
| 18 | }); | 18 | }); |
| 19 | } | 19 | } |
| 20 | }); | 20 | }); |
| 21 | } | 21 | } |
| 22 | }; | 22 | }; |
| 23 | }]); | 23 | }]); |
| 24 | 24 |
src/js/tecladoVirtual-directive.js
| File was created | 1 | angular.module('focaDirectivas') | |
| 2 | .directive('tecladoVirtual', function() { | ||
| 3 | return function(scope, elem, attrs) { | ||
| 4 | elem.bind('blur', function() { | ||
| 5 | scope.$emit('blur'); | ||
| 6 | }); | ||
| 7 | elem.bind('focus', function() { | ||
| 8 | scope.$emit('focus'); | ||
| 9 | }); | ||
| 10 | }; | ||
| 11 | }); | ||
| 1 | angular.module('focaDirectivas') | 12 |