This repository was archived by the owner on Nov 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathclient.js
148 lines (125 loc) · 5.51 KB
/
client.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* AngularJS directive for Fine Uploader UI jQuery (traditional endpoints).
* Maintained by Widen Enterprises.
*
* This example:
* - Delegates error messages to the dialog element.
* - Generates client-side pre-upload image previews (where supported).
* - Allows files to be excluded based on extension and MIME type (where supported).
* - Determines the most appropriate upload button and drop zone text based on browser capabilities.
* - Renders larger image preview on-demand in a dialog element.
* - Keeps an aggregate progress bar up-to-date based on upload status for all files.
* - Enables delete file support.
* - Ensure newly submitted files are added to the top of the visible list.
* - Enables chunking & auto-resume support.
*
* Requirements:
* - Fine Uploader 5.4 or 5.5
* - Dialog element polyfill 0.4.2
* - AngularJS 1.5
*/
(function() {
function isTouchDevice() {
return "ontouchstart" in window || navigator.msMaxTouchPoints > 0;
}
function initButtonText($scope) {
var input = document.createElement("input");
input.setAttribute("multiple", "true");
if (input.multiple === true && !qq.android()) {
$scope.uploadButtonText = "Select Files";
}
else {
$scope.uploadButtonText = "Select a File";
}
}
function initDropZoneText($scope, $interpolate) {
if (qq.supportedFeatures.folderDrop && !isTouchDevice()) {
$scope.dropZoneText = "Drop Files or Folders Here";
}
else if (qq.supportedFeatures.fileDrop && !isTouchDevice()) {
$scope.dropZoneText = "Drop Files Here";
}
else {
$scope.dropZoneText = $scope.$eval($interpolate("Press '{{uploadButtonText}}'"));
}
}
function bindToRenderedTemplate($compile, $scope, $interpolate, element) {
$compile(element.contents())($scope);
initButtonText($scope);
initDropZoneText($scope, $interpolate);
}
function openLargerPreview($scope, uploader, modal, size, fileId) {
uploader.drawThumbnail(fileId, new Image(), size).then(function(image) {
$scope.largePreviewUri = image.src;
$scope.$apply();
modal.showModal();
});
}
function closePreview(modal) {
modal.close();
}
angular.module("fineUploaderDirective", [])
.directive("fineUploader", function($compile, $interpolate) {
return {
restrict: "A",
replace: true,
link: function($scope, element, attrs) {
var endpoint = attrs.uploadServer,
notAvailablePlaceholderPath = attrs.notAvailablePlaceholder,
waitingPlaceholderPath = attrs.waitingPlaceholder,
acceptFiles = attrs.allowedMimes,
sizeLimit = attrs.maxFileSize,
largePreviewSize = parseInt(attrs.largePreviewSize),
allowedExtensions = JSON.parse(attrs.allowedExtensions),
previewDialog = document.querySelector('.large-preview'),
uploader = new qq.FineUploader({
debug: true,
element: element[0],
request: {endpoint: endpoint},
validation: {
acceptFiles: acceptFiles,
allowedExtensions: allowedExtensions,
sizeLimit: sizeLimit
},
deleteFile: {
endpoint: endpoint,
enabled: true
},
thumbnails: {
placeholders: {
notAvailablePath: notAvailablePlaceholderPath,
waitingPath: waitingPlaceholderPath
}
},
display: {
prependFiles: true
},
failedUploadTextDisplay: {
mode: "custom"
},
retry: {
enableAuto: true
},
chunking: {
enabled: true
},
resume: {
enabled: true
},
callbacks: {
onSubmitted: function(id, name) {
var fileEl = this.getItemByFileId(id),
thumbnailEl = fileEl.querySelector('.thumbnail-button');
thumbnailEl.addEventListener('click', function() {
openLargerPreview($scope, uploader, previewDialog, largePreviewSize, id);
});
}
}
});
dialogPolyfill.registerDialog(previewDialog);
$scope.closePreview = closePreview.bind(this, previewDialog);
bindToRenderedTemplate($compile, $scope, $interpolate, element);
}
}
});
})();