Commit 18993a9d31e6734fbe726ea5e515e4fb7f7ff7f8

Authored by Pablo Marco del Pont
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master (pmarco)

See merge request modulos-npm/foca-directivas!7
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
1 angular.module('focaDirectivas') 1 angular.module('focaDirectivas')
2 .directive('tecladoVirtual', function() { 2 .directive('tecladoVirtual', function() {
3 return function( scope, elem, attrs ) { 3 return function(scope, elem, attrs) {
4 elem.bind('blur', function() { 4 elem.bind('blur', function() {
5 scope.$emit('focus', false); 5 scope.$emit('blur');
6 }); 6 });
7 elem.bind('focus', function() { 7 elem.bind('focus', function() {
8 scope.$emit('focus', true); 8 scope.$emit('focus');
9 }); 9 });
10 }; 10 };
11 }); 11 });
12 12