Commit 92219b0dd96c63321c68c1d021802c6f71b66bba
1 parent
2be6d09901
Exists in
master
Seleccion de imagen
Showing
2 changed files
with
4 additions
and
4 deletions
Show diff stats
package.json
1 | { | 1 | { |
2 | "name": "foca-directivas", | 2 | "name": "foca-directivas", |
3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
4 | "description": "Directivas para usarse en los productos Debo Suite", | 4 | "description": "Directivas para usarse en los productos Debo Suite", |
5 | "main": "index.js", | 5 | "main": "index.js", |
6 | "scripts": { | 6 | "scripts": { |
7 | "test": "echo \"Error: no test specified\" && exit 1", | 7 | "test": "echo \"Error: no test specified\" && exit 1", |
8 | "compile": "gulp uglify", | 8 | "compile": "gulp uglify", |
9 | "postinstall": "npm run compile && gulp clean-post-install", | 9 | "postinstall": "npm run compile && gulp clean-post-install", |
10 | "install-dev": "npm install -D angular gulp gulp-clean gulp-concat gulp-jshint gulp-rename gulp-replace gulp-uglify jquery jshint pump" | 10 | "install-dev": "npm install -D angular gulp gulp-clean gulp-concat gulp-jshint gulp-rename gulp-replace gulp-uglify jquery jshint pump" |
11 | }, | 11 | }, |
12 | "pre-commit": [ | 12 | "pre-commit": [ |
13 | "gulp-pre-commit" | 13 | "gulp-pre-commit" |
14 | ], | 14 | ], |
15 | "repository": { | 15 | "repository": { |
16 | "type": "git", | 16 | "type": "git", |
17 | "url": "https://debo.suite.repo/modulos-npm/foca-directivas.git" | 17 | "url": "https://debo.suite.repo/modulos-npm/foca-directivas.git" |
18 | }, | 18 | }, |
19 | "author": "Nicolás Guarnieri", | 19 | "author": "Nicolás Guarnieri", |
20 | "license": "ISC", | 20 | "license": "ISC", |
21 | "peerDependencies": { | 21 | "peerDependencies": { |
22 | "angular": "^1.7.4", | 22 | "angular": "^1.7.4", |
23 | "gulp": "^3.9.1", | 23 | "gulp": "^3.9.1", |
24 | "gulp-concat": "^2.6.1", | 24 | "gulp-concat": "^2.6.1", |
25 | "gulp-jshint": "^2.1.0", | 25 | "gulp-jshint": "^2.1.0", |
26 | "gulp-rename": "^1.4.0", | 26 | "gulp-rename": "^1.4.0", |
27 | "gulp-replace": "^1.0.0", | 27 | "gulp-replace": "^1.0.0", |
28 | "gulp-uglify": "^3.0.1", | 28 | "gulp-uglify": "^3.0.1", |
29 | "jquery": "^3.3.1", | 29 | "jquery": "^3.3.1", |
30 | "jshint": "^2.9.6", | 30 | "jshint": "^2.9.6", |
31 | "pump": "^3.0.0" | 31 | "pump": "^3.0.0" |
32 | }, | 32 | }, |
33 | "devDependencies": { | 33 | "devDependencies": { |
34 | "angular": "^1.7.5", | 34 | "angular": "^1.7.5", |
35 | "gulp": "^3.9.1", | 35 | "gulp": "^3.9.1", |
36 | "gulp-clean": "^0.4.0", | 36 | "gulp-clean": "^0.4.0", |
37 | "gulp-concat": "^2.6.1", | 37 | "gulp-concat": "^2.6.1", |
38 | "gulp-jshint": "^2.1.0", | 38 | "gulp-jshint": "^2.1.0", |
39 | "gulp-rename": "^1.4.0", | 39 | "gulp-rename": "^1.4.0", |
40 | "gulp-replace": "^1.0.0", | 40 | "gulp-replace": "^1.0.0", |
41 | "gulp-uglify": "^3.0.1", | 41 | "gulp-uglify": "^3.0.1", |
42 | "jquery": "^3.3.1", | 42 | "jquery": "^3.4.1", |
43 | "jshint": "^2.9.6", | 43 | "jshint": "^2.9.6", |
44 | "pump": "^3.0.0" | 44 | "pump": "^3.0.0" |
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 |
src/js/ngFileModel-directive.js
1 | angular.module('focaDirectivas') | 1 | angular.module('focaDirectivas') |
2 | .directive('ngFileModel', ['$parse', function ($parse) { | 2 | .directive('ngFileModel', ['$parse', function ($compile) { |
3 | return { | 3 | return { |
4 | restrict: 'A', | 4 | restrict: 'A', |
5 | link: function (scope, element, attrs) { | 5 | link: function (scope, element, attrs) { |
6 | var model = $parse(attrs.ngFileModel); | 6 | var model = $compile(attrs.ngFileModel); |
7 | var isMultiple = attrs.multiple; | 7 | var isMultiple = attrs.multiple; |
8 | var modelSetter = model.assign; | 8 | var modelSetter = model.assign; |
9 | element.bind('change', function () { | 9 | element.bind('change', function () { |
10 | var promesas = []; | 10 | var promesas = []; |
11 | angular.forEach(element[0].files, function (item) { | 11 | angular.forEach(element[0].files, function (item) { |
12 | promesas.push(new Promise(function(resolve, reject) { | 12 | promesas.push(new Promise(function(resolve, reject) { |
13 | var reader = new FileReader(); | 13 | var reader = new FileReader(); |
14 | reader.readAsDataURL(item); | 14 | reader.readAsDataURL(item); |
15 | reader.onload = function(){ | 15 | reader.onload = function(){ |
16 | var value = { | 16 | var value = { |
17 | name: item.name, | 17 | name: item.name, |
18 | url: URL.createObjectURL(item), | 18 | url: URL.createObjectURL(item), |
19 | size: item.size, | 19 | size: item.size, |
20 | base64: reader.result, | 20 | base64: reader.result, |
21 | _file: item | 21 | _file: item |
22 | }; | 22 | }; |
23 | resolve(value); | 23 | resolve(value); |
24 | }; | 24 | }; |
25 | reader.onerror = function (error) { | 25 | reader.onerror = function (error) { |
26 | reject(error); | 26 | reject(error); |
27 | }; | 27 | }; |
28 | })); | 28 | })); |
29 | }); | 29 | }); |
30 | 30 | ||
31 | Promise.all(promesas).then(function(values){ | 31 | Promise.all(promesas).then(function(values) { |
32 | scope.$apply(function () { | 32 | scope.$apply(function () { |
33 | if (isMultiple) { | 33 | if (isMultiple) { |
34 | modelSetter(scope, values); | 34 | modelSetter(scope, values); |
35 | } else { | 35 | } else { |
36 | modelSetter(scope, values[0]); | 36 | modelSetter(scope, values[0]); |
37 | } | 37 | } |
38 | }); | 38 | }); |
39 | }); | 39 | }); |
40 | }); | 40 | }); |
41 | } | 41 | } |
42 | }; | 42 | }; |
43 | }]); | 43 | }]); |
44 | 44 |