From 2744fdacc50f582d8dc57fc894753a5d7deb9d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s?= Date: Wed, 3 Oct 2018 18:16:20 -0300 Subject: [PATCH] directiva focus --- .gitignore | 8 ++++++ .jshintrc | 64 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 8 +++++- gulpfile.js | 41 ++++++++++++++++++++++++++++++ package.json | 44 ++++++++++++++++++++++++++++++++ src/js/app.js | 1 + src/js/focus-directive.js | 23 +++++++++++++++++ 7 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 src/js/app.js create mode 100644 src/js/focus-directive.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e4084f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ + +dist/ + +node_modules/ + +package-lock\.json + +tmp/ diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..dd429f7 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,64 @@ +{ + /* + * ENVIRONMENTS + * ================= + */ + + // Define globals exposed by modern browsers. + "browser": true, + + // Define globals exposed by jQuery. + "jquery": true, + + // Define globals exposed by Node.js. + "node": true, + + // Allow ES6. + "esversion": 6, + + /* + * ENFORCING OPTIONS + * ================= + */ + + // Force all variable names to use either camelCase style or UPPER_CASE + // with underscores. + "camelcase": true, + + // Prohibit use of == and != in favor of === and !==. + "eqeqeq": true, + + // Enforce tab width of 2 spaces. + "indent": 4, + + // Prohibit use of a variable before it is defined. + "latedef": true, + + // Enforce line length to 100 characters + "maxlen": 100, + + // Require capitalized names for constructor functions. + "newcap": true, + + // Enforce use of single quotation marks for strings. + "quotmark": "single", + + // Enforce placing 'use strict' at the top function scope + "strict": false, + + // Prohibit use of explicitly undeclared variables. + "undef": true, + + // Warn when variables are defined but never used. + "unused": true, + + // Para que funcione en angular + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], + /* + * RELAXING OPTIONS + * ================= + */ + + // Suppress warnings about == null comparisons. + "eqnull": true +} diff --git a/README.md b/README.md index 6713dcd..df86b33 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ -foca-directivas +# Directivas para usarse en los productos Debo Suite + +## foca-focus +Si la expresion introducida es verdadera el elemento se le aplica un focus +
+
+
diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..e88e020 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,41 @@ +const concat = require('gulp-concat'); +const rename = require('gulp-rename'); +const uglify = require('gulp-uglify'); +const gulp = require('gulp'); +const pump = require('pump'); +const jshint = require('gulp-jshint'); +const replace = require('gulp-replace'); + +var paths = { + srcJS: 'src/js/*.js', + tmp: 'tmp', + dist: 'dist/' +}; + +gulp.task('uglify', function() { + pump( + [ + gulp.src([ + paths.srcJS + ]), + concat('foca-directivas.js'), + gulp.dest(paths.tmp), + rename('foca-directivas.min.js'), + uglify(), + gulp.dest(paths.dist) + ] + ); +}); + +gulp.task('pre-commit', function() { + pump( + [ + gulp.src(paths.srcJS), + jshint('.jshintrc'), + jshint.reporter('default'), + jshint.reporter('fail') + ] + ); + + gulp.start('uglify'); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..9a33376 --- /dev/null +++ b/package.json @@ -0,0 +1,44 @@ +{ + "name": "foca-directivas", + "version": "0.0.1", + "description": "Directivas para usarse en los productos Debo Suite", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "gulp uglify", + "pre-commit": [ + "gulp-pre-commit" + ], + "postinstall": "npm run compile && rm -R src && rm -R tmp && rm .jshintrc && rm gulpfile.js", + }, + "repository": { + "type": "git", + "url": "https://192.168.0.11/modulos-npm/foca-directivas.git" + }, + "author": "Nicolás Guarnieri", + "license": "ISC", + "peerDependencies": { + "angular": "^1.7.4", + "gulp": "^3.9.1", + "gulp-concat": "^2.6.1", + "gulp-jshint": "^2.1.0", + "gulp-rename": "^1.4.0", + "gulp-replace": "^1.0.0", + "gulp-uglify": "^3.0.1", + "jquery": "^3.3.1", + "jshint": "^2.9.6", + "pump": "^3.0.0" + }, + "devDependencies": { + "angular": "^1.7.4", + "gulp": "^3.9.1", + "gulp-concat": "^2.6.1", + "gulp-jshint": "^2.1.0", + "gulp-rename": "^1.4.0", + "gulp-replace": "^1.0.0", + "gulp-uglify": "^3.0.1", + "jquery": "^3.3.1", + "jshint": "^2.9.6", + "pump": "^3.0.0" + } +} diff --git a/src/js/app.js b/src/js/app.js new file mode 100644 index 0000000..0ae3324 --- /dev/null +++ b/src/js/app.js @@ -0,0 +1 @@ +angular.module('focaDirectivas', []); diff --git a/src/js/focus-directive.js b/src/js/focus-directive.js new file mode 100644 index 0000000..c743df2 --- /dev/null +++ b/src/js/focus-directive.js @@ -0,0 +1,23 @@ +angular.module('focaDirectivas') + .directive('focaFocus', ['$timeout', '$parse', function($timeout, $parse) { + var checkDirectivePrerequisites = function (attrs) { + if (!attrs.focaFocus && attrs.focaFocus != "") { + throw "focaFocus missing attribute to evaluate"; + } + } + + return { + restrict: "A", + link: function (scope, element, attrs, ctrls) { + checkDirectivePrerequisites(attrs); + + scope.$watch(attrs.focaFocus, function (currentValue, lastValue) { + if(currentValue == true) { + $timeout(function () { + element.focus(); + }); + } + }); + } + }; + }]); -- 1.9.1