-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng-file-model.min.js
40 lines (40 loc) · 1.45 KB
/
ng-file-model.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(function () {
"use strict";
angular.module("ng-file-model", []).directive("ngFileModel", [
function () {
return {
scope: {
ngFileModel: "=",
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
var reader = new FileReader();
reader.onload = function (loadEvent) {
var matches = loadEvent.currentTarget.result.match(/[€ƒ©£§³]+/gm);
if (matches != undefined && matches.length > 200) {
reader.readAsText(changeEvent.target.files[0], "UTF-8");
} else {
scope.$apply(function () {
scope.ngFileModel = {
lastModified: changeEvent.target.files[0].lastModified,
lastModifiedDate:
changeEvent.target.files[0].lastModifiedDate,
name: changeEvent.target.files[0].name,
size: changeEvent.target.files[0].size,
type: changeEvent.target.files[0].type,
data: loadEvent.currentTarget.result,
};
});
}
};
reader.readAsText(changeEvent.target.files[0], "ISO-8859-1");
});
},
};
},
]);
if (typeof exports !== "undefined") {
exports["default"] = angular.module("ng-file-model");
module.exports = exports["default"];
}
})();