Commit 2744fdacc50f582d8dc57fc894753a5d7deb9d2d
1 parent
0925c5520c
Exists in
master
directiva focus
Showing
7 changed files
with
188 additions
and
1 deletions
Show diff stats
.gitignore
.jshintrc
... | ... | @@ -0,0 +1,64 @@ |
1 | +{ | |
2 | + /* | |
3 | + * ENVIRONMENTS | |
4 | + * ================= | |
5 | + */ | |
6 | + | |
7 | + // Define globals exposed by modern browsers. | |
8 | + "browser": true, | |
9 | + | |
10 | + // Define globals exposed by jQuery. | |
11 | + "jquery": true, | |
12 | + | |
13 | + // Define globals exposed by Node.js. | |
14 | + "node": true, | |
15 | + | |
16 | + // Allow ES6. | |
17 | + "esversion": 6, | |
18 | + | |
19 | + /* | |
20 | + * ENFORCING OPTIONS | |
21 | + * ================= | |
22 | + */ | |
23 | + | |
24 | + // Force all variable names to use either camelCase style or UPPER_CASE | |
25 | + // with underscores. | |
26 | + "camelcase": true, | |
27 | + | |
28 | + // Prohibit use of == and != in favor of === and !==. | |
29 | + "eqeqeq": true, | |
30 | + | |
31 | + // Enforce tab width of 2 spaces. | |
32 | + "indent": 4, | |
33 | + | |
34 | + // Prohibit use of a variable before it is defined. | |
35 | + "latedef": true, | |
36 | + | |
37 | + // Enforce line length to 100 characters | |
38 | + "maxlen": 100, | |
39 | + | |
40 | + // Require capitalized names for constructor functions. | |
41 | + "newcap": true, | |
42 | + | |
43 | + // Enforce use of single quotation marks for strings. | |
44 | + "quotmark": "single", | |
45 | + | |
46 | + // Enforce placing 'use strict' at the top function scope | |
47 | + "strict": false, | |
48 | + | |
49 | + // Prohibit use of explicitly undeclared variables. | |
50 | + "undef": true, | |
51 | + | |
52 | + // Warn when variables are defined but never used. | |
53 | + "unused": true, | |
54 | + | |
55 | + // Para que funcione en angular | |
56 | + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], | |
57 | + /* | |
58 | + * RELAXING OPTIONS | |
59 | + * ================= | |
60 | + */ | |
61 | + | |
62 | + // Suppress warnings about == null comparisons. | |
63 | + "eqnull": true | |
64 | +} |
README.md
gulpfile.js
... | ... | @@ -0,0 +1,41 @@ |
1 | +const concat = require('gulp-concat'); | |
2 | +const rename = require('gulp-rename'); | |
3 | +const uglify = require('gulp-uglify'); | |
4 | +const gulp = require('gulp'); | |
5 | +const pump = require('pump'); | |
6 | +const jshint = require('gulp-jshint'); | |
7 | +const replace = require('gulp-replace'); | |
8 | + | |
9 | +var paths = { | |
10 | + srcJS: 'src/js/*.js', | |
11 | + tmp: 'tmp', | |
12 | + dist: 'dist/' | |
13 | +}; | |
14 | + | |
15 | +gulp.task('uglify', function() { | |
16 | + pump( | |
17 | + [ | |
18 | + gulp.src([ | |
19 | + paths.srcJS | |
20 | + ]), | |
21 | + concat('foca-directivas.js'), | |
22 | + gulp.dest(paths.tmp), | |
23 | + rename('foca-directivas.min.js'), | |
24 | + uglify(), | |
25 | + gulp.dest(paths.dist) | |
26 | + ] | |
27 | + ); | |
28 | +}); | |
29 | + | |
30 | +gulp.task('pre-commit', function() { | |
31 | + pump( | |
32 | + [ | |
33 | + gulp.src(paths.srcJS), | |
34 | + jshint('.jshintrc'), | |
35 | + jshint.reporter('default'), | |
36 | + jshint.reporter('fail') | |
37 | + ] | |
38 | + ); | |
39 | + | |
40 | + gulp.start('uglify'); | |
41 | +}); |
package.json
... | ... | @@ -0,0 +1,44 @@ |
1 | +{ | |
2 | + "name": "foca-directivas", | |
3 | + "version": "0.0.1", | |
4 | + "description": "Directivas para usarse en los productos Debo Suite", | |
5 | + "main": "index.js", | |
6 | + "scripts": { | |
7 | + "test": "echo \"Error: no test specified\" && exit 1", | |
8 | + "compile": "gulp uglify", | |
9 | + "pre-commit": [ | |
10 | + "gulp-pre-commit" | |
11 | + ], | |
12 | + "postinstall": "npm run compile && rm -R src && rm -R tmp && rm .jshintrc && rm gulpfile.js", | |
13 | + }, | |
14 | + "repository": { | |
15 | + "type": "git", | |
16 | + "url": "https://192.168.0.11/modulos-npm/foca-directivas.git" | |
17 | + }, | |
18 | + "author": "Nicolás Guarnieri", | |
19 | + "license": "ISC", | |
20 | + "peerDependencies": { | |
21 | + "angular": "^1.7.4", | |
22 | + "gulp": "^3.9.1", | |
23 | + "gulp-concat": "^2.6.1", | |
24 | + "gulp-jshint": "^2.1.0", | |
25 | + "gulp-rename": "^1.4.0", | |
26 | + "gulp-replace": "^1.0.0", | |
27 | + "gulp-uglify": "^3.0.1", | |
28 | + "jquery": "^3.3.1", | |
29 | + "jshint": "^2.9.6", | |
30 | + "pump": "^3.0.0" | |
31 | + }, | |
32 | + "devDependencies": { | |
33 | + "angular": "^1.7.4", | |
34 | + "gulp": "^3.9.1", | |
35 | + "gulp-concat": "^2.6.1", | |
36 | + "gulp-jshint": "^2.1.0", | |
37 | + "gulp-rename": "^1.4.0", | |
38 | + "gulp-replace": "^1.0.0", | |
39 | + "gulp-uglify": "^3.0.1", | |
40 | + "jquery": "^3.3.1", | |
41 | + "jshint": "^2.9.6", | |
42 | + "pump": "^3.0.0" | |
43 | + } | |
44 | +} |
src/js/app.js
... | ... | @@ -0,0 +1 @@ |
1 | +angular.module('focaDirectivas', []); |
src/js/focus-directive.js
... | ... | @@ -0,0 +1,23 @@ |
1 | +angular.module('focaDirectivas') | |
2 | + .directive('focaFocus', ['$timeout', '$parse', function($timeout, $parse) { | |
3 | + var checkDirectivePrerequisites = function (attrs) { | |
4 | + if (!attrs.focaFocus && attrs.focaFocus != "") { | |
5 | + throw "focaFocus missing attribute to evaluate"; | |
6 | + } | |
7 | + } | |
8 | + | |
9 | + return { | |
10 | + restrict: "A", | |
11 | + link: function (scope, element, attrs, ctrls) { | |
12 | + checkDirectivePrerequisites(attrs); | |
13 | + | |
14 | + scope.$watch(attrs.focaFocus, function (currentValue, lastValue) { | |
15 | + if(currentValue == true) { | |
16 | + $timeout(function () { | |
17 | + element.focus(); | |
18 | + }); | |
19 | + } | |
20 | + }); | |
21 | + } | |
22 | + }; | |
23 | + }]); |