Skip to content

Commit 71b61e8

Browse files
Arthur AgombartArthur Agombart
authored andcommitted
feat: make fileLoaded event as output type
1 parent b1873a9 commit 71b61e8

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

dist/angularjs-input-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
/***/ (function(module, exports, __webpack_require__) {
8080

8181
"use strict";
82-
eval("\n\nfunction _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance\"); }\n\nfunction _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar InputFileComponent =\n/*#__PURE__*/\nfunction () {\n InputFileComponent.$inject = [\"$timeout\", \"$element\", \"$attrs\"];\n\n /** @ngInject */\n function InputFileComponent($timeout, $element, $attrs) {\n _classCallCheck(this, InputFileComponent);\n\n this.$timeout = $timeout;\n this.$element = $element;\n this.$attrs = $attrs;\n }\n\n _createClass(InputFileComponent, [{\n key: \"$onInit\",\n value: function $onInit() {\n var _this = this;\n\n this.openSelectorRegister({\n handler: function handler() {\n return _this.openSelector();\n }\n });\n }\n }, {\n key: \"$postLink\",\n value: function $postLink() {\n var _this2 = this;\n\n var inputElement = this.$element[0].getElementsByTagName('input')[0]; // If there is a multiple attribute different than \"false\"\n\n if (this.$attrs.multiple !== 'false' && (this.$attrs.multiple === '' || this.$attrs.multiple)) {\n inputElement.setAttribute('multiple', '');\n }\n\n inputElement.addEventListener('change', function (event) {\n return _this2.onInputChange(event);\n }, false);\n }\n }, {\n key: \"openSelector\",\n value: function openSelector() {\n this.$element.find('input')[0].click();\n }\n }, {\n key: \"onInputChange\",\n value: function onInputChange(event) {\n var _this3 = this;\n\n var inputFiles = event.target.files;\n var files = [];\n\n var fileLoaded = _toConsumableArray(inputFiles).map(function (inputFile) {\n return new Promise(function (resolve, reject) {\n if (!_this3.fileFormat) {\n resolve(inputFile);\n return;\n }\n\n var reader = new FileReader(); // See event handlers of `FileReader` here:\n // https://developer.mozilla.org/en-US/docs/Web/API/FileReader#Properties\n // Catch errors to reject\n\n reader.onabort = reject;\n reader.onerror = reject; // Encapsulatized function for contextualized file + $timeout for proper angularJs refresh\n\n reader.onload = function (infos) {\n return function (readerEvent) {\n return _this3.$timeout(function () {\n var fileLoaded = {\n infos: infos,\n file: readerEvent.target.result\n };\n files.push(fileLoaded);\n resolve(fileLoaded);\n });\n };\n }({\n name: inputFile.name,\n size: inputFile.size,\n type: inputFile.type,\n lastModified: inputFile.lastModified\n });\n\n switch (_this3.fileFormat) {\n case 'Text':\n reader.readAsText(inputFile);\n break;\n\n case 'Base64':\n reader.readAsDataURL(inputFile);\n break;\n\n case 'ArrayBuffer':\n default:\n reader.readAsArrayBuffer(inputFile);\n }\n });\n });\n\n return Promise.all(fileLoaded).then(function (response) {\n if (_this3.filesLoaded) {\n _this3.filesLoaded(response);\n }\n });\n }\n }]);\n\n return InputFileComponent;\n}();\n\nangular.module('angularjs-input-file', []).component('inputFile', {\n template: \"\\n <input type=\\\"file\\\" \\n id=\\\"{{ $ctrl.id }}\\\"\\n accept=\\\"{{ $ctrl.accept }}\\\" />\",\n controller: InputFileComponent,\n bindings: {\n inputId: '@',\n accept: '@',\n fileFormat: '@',\n fileType: '@',\n filesLoaded: '<',\n openSelectorRegister: '&'\n }\n});\n\n//# sourceURL=webpack:///./src/input-file.component.js?");
82+
eval("\n\nfunction _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }\n\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance\"); }\n\nfunction _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter); }\n\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar InputFileComponent =\n/*#__PURE__*/\nfunction () {\n InputFileComponent.$inject = [\"$timeout\", \"$element\", \"$attrs\"];\n\n /** @ngInject */\n function InputFileComponent($timeout, $element, $attrs) {\n _classCallCheck(this, InputFileComponent);\n\n this.$timeout = $timeout;\n this.$element = $element;\n this.$attrs = $attrs;\n }\n\n _createClass(InputFileComponent, [{\n key: \"$onInit\",\n value: function $onInit() {\n var _this = this;\n\n this.openSelectorRegister({\n handler: function handler() {\n return _this.openSelector();\n }\n });\n }\n }, {\n key: \"$postLink\",\n value: function $postLink() {\n var _this2 = this;\n\n var inputElement = this.$element[0].getElementsByTagName('input')[0]; // If there is a multiple attribute different than \"false\"\n\n if (this.$attrs.multiple !== 'false' && (this.$attrs.multiple === '' || this.$attrs.multiple)) {\n inputElement.setAttribute('multiple', '');\n }\n\n inputElement.addEventListener('change', function (event) {\n return _this2.onInputChange(event);\n }, false);\n }\n }, {\n key: \"openSelector\",\n value: function openSelector() {\n this.$element.find('input')[0].click();\n }\n }, {\n key: \"onInputChange\",\n value: function onInputChange(event) {\n var _this3 = this;\n\n var inputFiles = event.target.files;\n var files = [];\n\n var fileLoaded = _toConsumableArray(inputFiles).map(function (inputFile) {\n return new Promise(function (resolve, reject) {\n if (!_this3.fileFormat) {\n resolve(inputFile);\n return;\n }\n\n var reader = new FileReader(); // See event handlers of `FileReader` here:\n // https://developer.mozilla.org/en-US/docs/Web/API/FileReader#Properties\n // Catch errors to reject\n\n reader.onabort = reject;\n reader.onerror = reject; // Encapsulatized function for contextualized file + $timeout for proper angularJs refresh\n\n reader.onload = function (infos) {\n return function (readerEvent) {\n return _this3.$timeout(function () {\n var fileLoaded = {\n infos: infos,\n file: readerEvent.target.result\n };\n files.push(fileLoaded);\n resolve(fileLoaded);\n });\n };\n }({\n name: inputFile.name,\n size: inputFile.size,\n type: inputFile.type,\n lastModified: inputFile.lastModified\n });\n\n switch (_this3.fileFormat) {\n case 'Text':\n reader.readAsText(inputFile);\n break;\n\n case 'Base64':\n reader.readAsDataURL(inputFile);\n break;\n\n case 'ArrayBuffer':\n default:\n reader.readAsArrayBuffer(inputFile);\n }\n });\n });\n\n return Promise.all(fileLoaded).then(function (response) {\n if (_this3.filesLoaded) {\n _this3.filesLoaded({\n files: response\n });\n }\n });\n }\n }]);\n\n return InputFileComponent;\n}();\n\nangular.module('angularjs-input-file', []).component('inputFile', {\n template: \"\\n <input type=\\\"file\\\" \\n id=\\\"{{ $ctrl.id }}\\\"\\n accept=\\\"{{ $ctrl.accept }}\\\" />\",\n controller: InputFileComponent,\n bindings: {\n inputId: '@',\n accept: '@',\n fileFormat: '@',\n fileType: '@',\n filesLoaded: '&',\n openSelectorRegister: '&'\n }\n});\n\n//# sourceURL=webpack:///./src/input-file.component.js?");
8383

8484
/***/ })
8585

src/input-file.component.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class InputFileComponent {
7373

7474
return Promise.all(fileLoaded).then(response => {
7575
if (this.filesLoaded) {
76-
this.filesLoaded(response);
76+
this.filesLoaded({
77+
files: response
78+
});
7779
}
7880
});
7981
}
@@ -90,7 +92,7 @@ angular.module('angularjs-input-file', []).component('inputFile', {
9092
accept: '@',
9193
fileFormat: '@',
9294
fileType: '@',
93-
filesLoaded: '<',
95+
filesLoaded: '&',
9496
openSelectorRegister: '&'
9597
}
9698
});

0 commit comments

Comments
 (0)