json-object-editor 0.9.901 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/app.js +5 -4
- package/css/jif/Read Me.txt +5 -5
- package/css/jif/demo-files/demo.css +153 -153
- package/css/jif/demo-files/demo.js +30 -30
- package/css/jif/demo.html +285 -285
- package/css/jif/fonts/joeiconfont.svg +24 -24
- package/css/jif/ie7/ie7.css +45 -45
- package/css/jif/ie7/ie7.js +46 -46
- package/css/jif/selection.json +573 -573
- package/css/joe.css +6 -6
- package/css/jquery-ui-1.10.4.custom.min.css +5 -5
- package/css/jquery-ui.min.css +6 -6
- package/css/jquery.timepicker.css +72 -72
- package/es5-build/capp/capp.js +1083 -1083
- package/es5-build/js/JsonObjectEditor_es5.jquery.craydent.js +11047 -11047
- package/es5-build/web-components/account-info.js +136 -136
- package/es5-build/web-components/capp-components.js +160 -160
- package/es5-build/web-components/capp-panel.js +85 -85
- package/es5-build/web-components/capp-view.js +73 -73
- package/es5-build/web-components/joe-autocomplete.js +149 -149
- package/es5-build/web-components/joe-button.js +132 -132
- package/es5-build/web-components/joe-card.js +92 -92
- package/es5-build/web-components/joe-component.js +74 -74
- package/es5-build/web-components/joe-field.js +70 -70
- package/es5-build/web-components/joe-list-item.js +176 -176
- package/es5-build/web-components/joe-user-cube.js +100 -100
- package/es5-build/web-components/report-components.js +133 -133
- package/grunt/build +86 -86
- package/grunt/package-lock.json +6301 -2489
- package/grunt/package.json +47 -47
- package/grunt/src +86 -86
- package/js/JsonObjectEditor.jquery.craydent.js +3 -2
- package/js/joe-full.js +11 -10
- package/js/joe.js +12 -11
- package/js/joe_es5.js +11056 -11056
- package/js/jquery.timepicker.min.js +1 -1
- package/js/leaflet.js +8 -8
- package/js/libs/adapter-latest.js +4400 -4400
- package/js/libs/craydent-1.9.2.js +11741 -11741
- package/js/libs/craydent-upload-2.0.0.js +394 -394
- package/js/libs/hammer.min.208.js +6 -6
- package/js/libs/jquery-3.5.1.min.js +2 -2
- package/js/libs/moment.min.js +6 -6
- package/js/native-shim.js +46 -46
- package/js/plugins/c3/c3.min.js +5 -5
- package/js/plugins/c3/d3.v3.min.js +4 -4
- package/js/plugins/threejs/Detector.js +78 -78
- package/js/plugins/threejs/LICENSE +21 -21
- package/js/plugins/threejs/MTLLoader.js +417 -417
- package/js/plugins/threejs/OBJLoader.js +564 -564
- package/js/plugins/threejs/OrbitControls.js +1037 -1037
- package/js/plugins/threejs/README.md +9 -9
- package/js/plugins/threejs/assets/female-croupier-2013-03-26.mtl +3 -3
- package/js/plugins/threejs/index.html +178 -178
- package/js/plugins/threejs/three.js +41507 -41507
- package/package copy.json +62 -0
- package/package.json +12 -13
- package/projectFilesBackup/.idea/workspace.xml +0 -424
|
@@ -1,394 +1,394 @@
|
|
|
1
|
-
/*/---------------------------------------------------------/*/
|
|
2
|
-
/*/ Craydent LLC uploader-v1.1.0 /*/
|
|
3
|
-
/*/ Copyright 2016 (http://craydent.com/about) /*/
|
|
4
|
-
/*/ Dual licensed under the MIT or GPL Version 2 licenses. /*/
|
|
5
|
-
/*/ (http://craydent.com/license) /*/
|
|
6
|
-
/*/---------------------------------------------------------/*/
|
|
7
|
-
function Upload(params) {
|
|
8
|
-
try {
|
|
9
|
-
this._params = params || {};
|
|
10
|
-
this.UploadScript = params.uploadUrl || "";
|
|
11
|
-
|
|
12
|
-
this.useInputBox = !!params.useInputBox;
|
|
13
|
-
this.headers = params.headers || [];
|
|
14
|
-
this.FileUploadMaxSize = params.maxsize || 0;
|
|
15
|
-
this.FileUploadMinSize = params.minsize || 0;
|
|
16
|
-
this.FileUploadMaxFileCount = params.maxfilecount || 0;
|
|
17
|
-
this.UsageMax = params.usagemax || 0;
|
|
18
|
-
this.CurrentUsage = params.currentusage || 0;
|
|
19
|
-
this.fileExtensions = params.fileExtensions || Array();
|
|
20
|
-
this.SuccessFileCount = 0;
|
|
21
|
-
this.FailedFileCount = 0;
|
|
22
|
-
this.crossDomain = params.crossDomain || false;
|
|
23
|
-
this.crossDomainProxy = params.crossDomainProxy;
|
|
24
|
-
this.api_key = params.api_key;
|
|
25
|
-
this.destination_url = params.destination_url;
|
|
26
|
-
|
|
27
|
-
//when upload has finished on the server
|
|
28
|
-
this.onafterupload = function (ev) {
|
|
29
|
-
this.ref.SuccessFileCount++;
|
|
30
|
-
params.onafterupload && params.onafterupload.call(this, ev);
|
|
31
|
-
if (this.ref.SuccessFileCount + this.ref.FailedFileCount == this.ref.files.length) {
|
|
32
|
-
this.ref.oncomplete(this.ref.SuccessFileCount, this.ref.FailedFileCount);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
this.onbeforeupload = params.onbeforeupload || function(){};
|
|
36
|
-
//after drop before processing the files to raw/base64
|
|
37
|
-
this.onbeforefileready = params.onbeforefileready || function (numberOfFiles) {};
|
|
38
|
-
|
|
39
|
-
this.onafterfileready = params.onafterfileready || function (fileObject) {};
|
|
40
|
-
this.onabort = params.onabort || function(){};
|
|
41
|
-
this.onfileload = params.onfileload || function(){};
|
|
42
|
-
this.onloadstart = params.onloadstart || function(){};
|
|
43
|
-
//function to run during the upload progress
|
|
44
|
-
this.onprogress = params.onprogress || function () {};
|
|
45
|
-
|
|
46
|
-
this.ondragenter = params.ondragenter || function () {};
|
|
47
|
-
this.ondragover = params.ondragover || function () {};
|
|
48
|
-
|
|
49
|
-
this.onerror = function (data, status, response) {
|
|
50
|
-
if (isNull(status)) {
|
|
51
|
-
params.onerror && params.onerror.call(this, data);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
this.ref.FailedFileCount++;
|
|
55
|
-
params.onerror && params.onerror.call(this, data, status, response);
|
|
56
|
-
if (this.ref.SuccessFileCount + this.ref.FailedFileCount == this.ref.files.length) {
|
|
57
|
-
this.ref.oncomplete(this.ref.SuccessFileCount, this.ref.FailedFileCount);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
this.onbefore = function (httpRequest, caller) {
|
|
61
|
-
var fileUpload = httpRequest.upload || {};
|
|
62
|
-
fileUpload.ref = caller;
|
|
63
|
-
params.onbefore && params.onbefore.call(this, httpRequest, caller);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
this.onbeforeclear = params.onbeforeclear || function () {};
|
|
67
|
-
this.onafterclear = params.onafterclear || function () {};
|
|
68
|
-
this.onfileselected = params.onfileselected || function () {};
|
|
69
|
-
this.dropZone = params.target;
|
|
70
|
-
this.files = [];
|
|
71
|
-
|
|
72
|
-
var listener = !this.dropZone.addEventListener ? "attachEvent" : "addEventListener";
|
|
73
|
-
|
|
74
|
-
this.dropZone['uploadRef'] = this;
|
|
75
|
-
|
|
76
|
-
//if (!this.useInputBox) {
|
|
77
|
-
this.dropZone[listener]("dragenter", function (ev) {
|
|
78
|
-
try {
|
|
79
|
-
ev = ev ? ev : window.event;
|
|
80
|
-
killPropagation(ev);
|
|
81
|
-
this.uploadRef.ondragenter();
|
|
82
|
-
} catch (e) {
|
|
83
|
-
error('uploadDragEnter', e);
|
|
84
|
-
}
|
|
85
|
-
}, false);
|
|
86
|
-
this.dropZone[listener]("dragover", function (ev) {
|
|
87
|
-
try {
|
|
88
|
-
ev = ev ? ev : window.event;
|
|
89
|
-
killPropagation(ev);
|
|
90
|
-
this.uploadRef.ondragover();
|
|
91
|
-
} catch (e) {
|
|
92
|
-
error('uploadDragOver', e);
|
|
93
|
-
}
|
|
94
|
-
}, false);
|
|
95
|
-
this.dropZone[listener]("drop", function (ev) {
|
|
96
|
-
this.uploadRef.upload(ev);
|
|
97
|
-
}, false);
|
|
98
|
-
// } else {
|
|
99
|
-
var inputbox = document.createElement('input');
|
|
100
|
-
inputbox.type = "file";
|
|
101
|
-
inputbox.uref = this;
|
|
102
|
-
inputbox.setAttribute('onchange',"this.uref.onfileselected(this);");
|
|
103
|
-
console.log('input added');
|
|
104
|
-
this.inputBox = inputbox;
|
|
105
|
-
this.dropZone.appendChild(inputbox);
|
|
106
|
-
// }
|
|
107
|
-
this.isValidFileType = function (ext) {
|
|
108
|
-
try {
|
|
109
|
-
return (this.fileExtensions.isEmpty() || this.fileExtensions.indexOf(ext) != -1);
|
|
110
|
-
} catch (e) {
|
|
111
|
-
error('isValidType', e);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
this.upload = function (ev) {
|
|
116
|
-
try {
|
|
117
|
-
ev = ev || window.event;
|
|
118
|
-
//var dt = !this.useInputBox ? ev.dataTransfer : this.inputBox;
|
|
119
|
-
var dt = (ev && ev.dataTransfer) || (this.useInputBox && this.inputBox);
|
|
120
|
-
var files = dt.files;
|
|
121
|
-
//this.files.append(files);
|
|
122
|
-
var count = files.length;
|
|
123
|
-
this.onbeforefileready(count);
|
|
124
|
-
|
|
125
|
-
killPropagation(ev);
|
|
126
|
-
|
|
127
|
-
if (this.FileUploadMaxFileCount && this.files.length + count > this.FileUploadMaxFileCount) {
|
|
128
|
-
this.onerror("You can not upload more than " + this.FileUploadMaxFileCount + " file(s)");
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
for (var i = 0; i < count && (!this.FileUploadMaxFileCount || this.files.length < this.FileUploadMaxFileCount); i++) {
|
|
132
|
-
var file = this.files[this.files.length] = files[i];
|
|
133
|
-
if (this.FileUploadMinSize && file.size < this.FileUploadMinSize) {
|
|
134
|
-
this.onerror("file is too small, needs to be larger than " + this.FileUploadMinSize + "bytes");
|
|
135
|
-
this.files.splice(i, 1);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (this.FileUploadMaxSize && file.size > this.FileUploadMaxSize) {
|
|
139
|
-
this.onerror("file is too big, needs to be below " + this.FileUploadMaxSize + "bytes");
|
|
140
|
-
this.files.splice(i, 1);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (this.UsageMax && (file.size + this.CurrentUsage > this.UsageMax)) {
|
|
144
|
-
this.onerror("You do not have enough space available to upload this file.");
|
|
145
|
-
this.files.splice(i, 1);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
this.CurrentUsage += file.size;
|
|
150
|
-
var filename = file.name;
|
|
151
|
-
if (window.FileReader) {
|
|
152
|
-
var reader = new FileReader();
|
|
153
|
-
reader.index = i;
|
|
154
|
-
reader.file = file;
|
|
155
|
-
|
|
156
|
-
reader.onloadend = this.processFile;
|
|
157
|
-
reader.uploadRef = this;
|
|
158
|
-
reader.readAsDataURL(file);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
var fileExt = file.type.substring(file.type.indexOf("/") + 1);
|
|
162
|
-
var fileType = file.type.substring(0, file.type.indexOf("/"));
|
|
163
|
-
if (!this.isValidFileType(fileExt)) {
|
|
164
|
-
this.onerror('invalid file type');
|
|
165
|
-
this.files.splice(i, 1);
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
this.onafterfileready(file);
|
|
170
|
-
this.processRequest({
|
|
171
|
-
file: file,
|
|
172
|
-
headers: [{
|
|
173
|
-
type: "If-Modified-Since",
|
|
174
|
-
value: "Mon, 26 Jul 1997 05:00:00 GMT"
|
|
175
|
-
},{
|
|
176
|
-
type: "Cache-Control",
|
|
177
|
-
value: "no-cache"
|
|
178
|
-
},{
|
|
179
|
-
type: "X-Requested-With",
|
|
180
|
-
value: "XMLHttpRequest"
|
|
181
|
-
},{
|
|
182
|
-
type: "X-File-Name",
|
|
183
|
-
value:file.fileName || file.filename || file.name
|
|
184
|
-
},{
|
|
185
|
-
type: "X-File-Size",
|
|
186
|
-
value: file.fileSize
|
|
187
|
-
},{
|
|
188
|
-
type: "X-File-Encoding",
|
|
189
|
-
value: "binary"
|
|
190
|
-
},{
|
|
191
|
-
type: "Content-Type",
|
|
192
|
-
value: "multipart/form-data"
|
|
193
|
-
}].concat(this.headers)
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
} catch (e) {
|
|
197
|
-
error('uploadDrop', e);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
this.processFile = function (ev) {
|
|
201
|
-
try {
|
|
202
|
-
if(ev.contructor == String) {
|
|
203
|
-
ev = eval(ev.replace(/\n/gi, ''));
|
|
204
|
-
}
|
|
205
|
-
var data = ev.target.result;
|
|
206
|
-
var file = ev.target.file;
|
|
207
|
-
var fileExt = file.type.substring(file.type.indexOf("/") + 1);
|
|
208
|
-
var fileType = file.type.substring(0, file.type.indexOf("/"));
|
|
209
|
-
if (!this.uploadRef.isValidFileType(fileExt)) {
|
|
210
|
-
alert("The file type \"" + fileExt + "\" is not of a valid type.");
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
this.uploadRef.onafterfileready(file, data);
|
|
215
|
-
|
|
216
|
-
var headers = [{
|
|
217
|
-
type: "If-Modified-Since",
|
|
218
|
-
value: "Mon, 26 Jul 1997 05:00:00 GMT"
|
|
219
|
-
},{
|
|
220
|
-
type: "Cache-Control",
|
|
221
|
-
value: "no-cache"
|
|
222
|
-
},{
|
|
223
|
-
type: "X-Requested-With",
|
|
224
|
-
value: "XMLHttpRequest"
|
|
225
|
-
},{
|
|
226
|
-
type: "X-File-Name",
|
|
227
|
-
value:file.fileName || file.filename || file.name
|
|
228
|
-
},{
|
|
229
|
-
type: "X-File-Size",
|
|
230
|
-
value: file.fileSize
|
|
231
|
-
},{
|
|
232
|
-
type: "X-File-Encoding",
|
|
233
|
-
value: "base64"
|
|
234
|
-
}/*,
|
|
235
|
-
{type: "Content-Type", value: "multipart/form-data"}*/
|
|
236
|
-
];
|
|
237
|
-
headers = headers.concat(this.uploadRef.headers);
|
|
238
|
-
if (!window.FileReader) {
|
|
239
|
-
var bin = data;
|
|
240
|
-
this.uploadRef.processRequest({
|
|
241
|
-
file: file,
|
|
242
|
-
bin: encodeURIComponent(bin.substring(bin.indexOf("base64,") + 7, bin.length)),
|
|
243
|
-
headers: headers
|
|
244
|
-
});
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
var getBinaryDataReader = new FileReader();
|
|
248
|
-
getBinaryDataReader.uploadRef = this.uploadRef;
|
|
249
|
-
getBinaryDataReader.onloadend = function(evt) {
|
|
250
|
-
evt = evt ? evt : window.event;
|
|
251
|
-
var bin = evt.target.result;
|
|
252
|
-
this.uploadRef.processRequest({
|
|
253
|
-
file: file,
|
|
254
|
-
bin: encodeURIComponent(bin.substring(bin.indexOf("base64,") + 7, bin.length)),
|
|
255
|
-
headers: headers
|
|
256
|
-
});
|
|
257
|
-
};
|
|
258
|
-
getBinaryDataReader.readAsDataURL(file);
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
catch (e) {
|
|
262
|
-
error('processFile', e);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
this.processRequest = function (params) {
|
|
266
|
-
try {
|
|
267
|
-
var file = params.file;
|
|
268
|
-
var headers = params.headers;
|
|
269
|
-
var bin = params.bin || file;
|
|
270
|
-
if (!this.crossDomain) {
|
|
271
|
-
ajax.call(this, {
|
|
272
|
-
method: "POST",
|
|
273
|
-
url: this.UploadScript,
|
|
274
|
-
query: bin,
|
|
275
|
-
headers: headers,
|
|
276
|
-
onfileload: this.onfileload,
|
|
277
|
-
onbefore: this.onbefore,
|
|
278
|
-
onprogress: this.onprogress,
|
|
279
|
-
onabort: this.onabort,
|
|
280
|
-
onerror: this.onerror,
|
|
281
|
-
onloadstart: this.onloadstart,
|
|
282
|
-
context: this,
|
|
283
|
-
onsuccess: this.onafterupload
|
|
284
|
-
});
|
|
285
|
-
} else {
|
|
286
|
-
var encoding = (headers.filter(function(obj){
|
|
287
|
-
return obj.type == "X-File-Encoding";
|
|
288
|
-
})[0]) || {},
|
|
289
|
-
fileName = (headers.filter(function(obj){
|
|
290
|
-
return obj.type == "X-File-Name";
|
|
291
|
-
})[0]) || {},
|
|
292
|
-
// blobs = bin.match(/.{1,1900}/g),
|
|
293
|
-
|
|
294
|
-
totalBytes = bin.length,
|
|
295
|
-
_cuid = cuid(),
|
|
296
|
-
destination = this.destination_url ? 'fields={"destination_url":"' + this.destination_url + '"}&': "",
|
|
297
|
-
key = this.api_key ? "api_key=" + this.api_key + "&": "",
|
|
298
|
-
q = this.crossDomainProxy.indexOf('?') == -1 ? "?" : "&";
|
|
299
|
-
|
|
300
|
-
//for (var i = 0, len = blobs.length, eof = len - 1; i < len; i++) {
|
|
301
|
-
query = q + key + destination + 'files={"'+_cuid+'":{"'+encoding.value+'":"'+bin.substr(0,1500)+'", "type" : "'+file.type+'", "name":"'+fileName.value+'"}}&EOF=false',
|
|
302
|
-
loop_function = function (data, status, xr, context) {
|
|
303
|
-
context.onprogress((totalBytes - bin.length)/totalBytes);
|
|
304
|
-
if (bin.length > 0) {
|
|
305
|
-
var query = q + key + destination + 'files={"'+_cuid+'":{"'+encoding.value+'":"'+bin.substr(0,1500)+'", "type" : "'+file.type+'", "name":"'+fileName.value+'"}}&EOF=';
|
|
306
|
-
bin = bin.substr(1500);
|
|
307
|
-
|
|
308
|
-
if (!bin) {
|
|
309
|
-
query += "true";
|
|
310
|
-
} else {
|
|
311
|
-
query += "false";
|
|
312
|
-
}
|
|
313
|
-
ajax.call(context, {
|
|
314
|
-
dataType: "jsonp",
|
|
315
|
-
url: context.crossDomainProxy + query,
|
|
316
|
-
headers: headers,
|
|
317
|
-
onerror: context.onerror,
|
|
318
|
-
context: context,
|
|
319
|
-
onsuccess: loop_function
|
|
320
|
-
})
|
|
321
|
-
} else {
|
|
322
|
-
context.onsuccess(data);
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
bin = bin.substr(1500);
|
|
326
|
-
|
|
327
|
-
ajax.call(this, {
|
|
328
|
-
dataType: "jsonp",
|
|
329
|
-
url: this.crossDomainProxy + query,//this.UploadScript,
|
|
330
|
-
headers: headers,
|
|
331
|
-
onfileload: this.onfileload,
|
|
332
|
-
onbefore: this.onbefore,
|
|
333
|
-
onabort: this.onabort,
|
|
334
|
-
onerror: this.onerror,
|
|
335
|
-
onloadstart: this.onloadstart,
|
|
336
|
-
context: this,
|
|
337
|
-
onsuccess: loop_function
|
|
338
|
-
});
|
|
339
|
-
// }
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
catch (e) {
|
|
343
|
-
error('processRequest', e);
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
this.clear = function (index) {
|
|
347
|
-
this.onbeforeclear();
|
|
348
|
-
if (!index) {
|
|
349
|
-
this.files = [];
|
|
350
|
-
}
|
|
351
|
-
this.onafterclear();
|
|
352
|
-
if (this.useInputBox) {
|
|
353
|
-
this.inputBox.value = null;
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
this.remove = function (filename, indexOf) {
|
|
357
|
-
if (this.useInputBox) {
|
|
358
|
-
this.inputBox.value = null;
|
|
359
|
-
}
|
|
360
|
-
return this.files.remove(filename, indexOf);
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
catch (e) {
|
|
364
|
-
error('uploadObject', e);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
if (!window.killPropagation) {
|
|
369
|
-
window.killPropagation = function (ev, bubble, returnValue) {
|
|
370
|
-
try {
|
|
371
|
-
ev = ev || window.event;
|
|
372
|
-
bubble = bubble || true;
|
|
373
|
-
returnValue = returnValue || false;
|
|
374
|
-
if (ev.stopPropagation) {
|
|
375
|
-
ev.stopPropagation();
|
|
376
|
-
ev.preventDefault();
|
|
377
|
-
} else {
|
|
378
|
-
ev.cancelBubble = bubble;
|
|
379
|
-
ev.returnValue = returnValue;
|
|
380
|
-
}
|
|
381
|
-
} catch (e) {
|
|
382
|
-
error("killPropagation", e);
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
if (!window.error) {
|
|
387
|
-
window.error = function error(fname, e) {
|
|
388
|
-
var index = window.location.search.indexOf("debug=true");
|
|
389
|
-
if(index != -1) {
|
|
390
|
-
alert("Error in " + fname + "\n" + (e.description || e));
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
|
|
1
|
+
/*/---------------------------------------------------------/*/
|
|
2
|
+
/*/ Craydent LLC uploader-v1.1.0 /*/
|
|
3
|
+
/*/ Copyright 2016 (http://craydent.com/about) /*/
|
|
4
|
+
/*/ Dual licensed under the MIT or GPL Version 2 licenses. /*/
|
|
5
|
+
/*/ (http://craydent.com/license) /*/
|
|
6
|
+
/*/---------------------------------------------------------/*/
|
|
7
|
+
function Upload(params) {
|
|
8
|
+
try {
|
|
9
|
+
this._params = params || {};
|
|
10
|
+
this.UploadScript = params.uploadUrl || "";
|
|
11
|
+
|
|
12
|
+
this.useInputBox = !!params.useInputBox;
|
|
13
|
+
this.headers = params.headers || [];
|
|
14
|
+
this.FileUploadMaxSize = params.maxsize || 0;
|
|
15
|
+
this.FileUploadMinSize = params.minsize || 0;
|
|
16
|
+
this.FileUploadMaxFileCount = params.maxfilecount || 0;
|
|
17
|
+
this.UsageMax = params.usagemax || 0;
|
|
18
|
+
this.CurrentUsage = params.currentusage || 0;
|
|
19
|
+
this.fileExtensions = params.fileExtensions || Array();
|
|
20
|
+
this.SuccessFileCount = 0;
|
|
21
|
+
this.FailedFileCount = 0;
|
|
22
|
+
this.crossDomain = params.crossDomain || false;
|
|
23
|
+
this.crossDomainProxy = params.crossDomainProxy;
|
|
24
|
+
this.api_key = params.api_key;
|
|
25
|
+
this.destination_url = params.destination_url;
|
|
26
|
+
|
|
27
|
+
//when upload has finished on the server
|
|
28
|
+
this.onafterupload = function (ev) {
|
|
29
|
+
this.ref.SuccessFileCount++;
|
|
30
|
+
params.onafterupload && params.onafterupload.call(this, ev);
|
|
31
|
+
if (this.ref.SuccessFileCount + this.ref.FailedFileCount == this.ref.files.length) {
|
|
32
|
+
this.ref.oncomplete(this.ref.SuccessFileCount, this.ref.FailedFileCount);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
this.onbeforeupload = params.onbeforeupload || function(){};
|
|
36
|
+
//after drop before processing the files to raw/base64
|
|
37
|
+
this.onbeforefileready = params.onbeforefileready || function (numberOfFiles) {};
|
|
38
|
+
|
|
39
|
+
this.onafterfileready = params.onafterfileready || function (fileObject) {};
|
|
40
|
+
this.onabort = params.onabort || function(){};
|
|
41
|
+
this.onfileload = params.onfileload || function(){};
|
|
42
|
+
this.onloadstart = params.onloadstart || function(){};
|
|
43
|
+
//function to run during the upload progress
|
|
44
|
+
this.onprogress = params.onprogress || function () {};
|
|
45
|
+
|
|
46
|
+
this.ondragenter = params.ondragenter || function () {};
|
|
47
|
+
this.ondragover = params.ondragover || function () {};
|
|
48
|
+
|
|
49
|
+
this.onerror = function (data, status, response) {
|
|
50
|
+
if (isNull(status)) {
|
|
51
|
+
params.onerror && params.onerror.call(this, data);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.ref.FailedFileCount++;
|
|
55
|
+
params.onerror && params.onerror.call(this, data, status, response);
|
|
56
|
+
if (this.ref.SuccessFileCount + this.ref.FailedFileCount == this.ref.files.length) {
|
|
57
|
+
this.ref.oncomplete(this.ref.SuccessFileCount, this.ref.FailedFileCount);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
this.onbefore = function (httpRequest, caller) {
|
|
61
|
+
var fileUpload = httpRequest.upload || {};
|
|
62
|
+
fileUpload.ref = caller;
|
|
63
|
+
params.onbefore && params.onbefore.call(this, httpRequest, caller);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
this.onbeforeclear = params.onbeforeclear || function () {};
|
|
67
|
+
this.onafterclear = params.onafterclear || function () {};
|
|
68
|
+
this.onfileselected = params.onfileselected || function () {};
|
|
69
|
+
this.dropZone = params.target;
|
|
70
|
+
this.files = [];
|
|
71
|
+
|
|
72
|
+
var listener = !this.dropZone.addEventListener ? "attachEvent" : "addEventListener";
|
|
73
|
+
|
|
74
|
+
this.dropZone['uploadRef'] = this;
|
|
75
|
+
|
|
76
|
+
//if (!this.useInputBox) {
|
|
77
|
+
this.dropZone[listener]("dragenter", function (ev) {
|
|
78
|
+
try {
|
|
79
|
+
ev = ev ? ev : window.event;
|
|
80
|
+
killPropagation(ev);
|
|
81
|
+
this.uploadRef.ondragenter();
|
|
82
|
+
} catch (e) {
|
|
83
|
+
error('uploadDragEnter', e);
|
|
84
|
+
}
|
|
85
|
+
}, false);
|
|
86
|
+
this.dropZone[listener]("dragover", function (ev) {
|
|
87
|
+
try {
|
|
88
|
+
ev = ev ? ev : window.event;
|
|
89
|
+
killPropagation(ev);
|
|
90
|
+
this.uploadRef.ondragover();
|
|
91
|
+
} catch (e) {
|
|
92
|
+
error('uploadDragOver', e);
|
|
93
|
+
}
|
|
94
|
+
}, false);
|
|
95
|
+
this.dropZone[listener]("drop", function (ev) {
|
|
96
|
+
this.uploadRef.upload(ev);
|
|
97
|
+
}, false);
|
|
98
|
+
// } else {
|
|
99
|
+
var inputbox = document.createElement('input');
|
|
100
|
+
inputbox.type = "file";
|
|
101
|
+
inputbox.uref = this;
|
|
102
|
+
inputbox.setAttribute('onchange',"this.uref.onfileselected(this);");
|
|
103
|
+
console.log('input added');
|
|
104
|
+
this.inputBox = inputbox;
|
|
105
|
+
this.dropZone.appendChild(inputbox);
|
|
106
|
+
// }
|
|
107
|
+
this.isValidFileType = function (ext) {
|
|
108
|
+
try {
|
|
109
|
+
return (this.fileExtensions.isEmpty() || this.fileExtensions.indexOf(ext) != -1);
|
|
110
|
+
} catch (e) {
|
|
111
|
+
error('isValidType', e);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
this.upload = function (ev) {
|
|
116
|
+
try {
|
|
117
|
+
ev = ev || window.event;
|
|
118
|
+
//var dt = !this.useInputBox ? ev.dataTransfer : this.inputBox;
|
|
119
|
+
var dt = (ev && ev.dataTransfer) || (this.useInputBox && this.inputBox);
|
|
120
|
+
var files = dt.files;
|
|
121
|
+
//this.files.append(files);
|
|
122
|
+
var count = files.length;
|
|
123
|
+
this.onbeforefileready(count);
|
|
124
|
+
|
|
125
|
+
killPropagation(ev);
|
|
126
|
+
|
|
127
|
+
if (this.FileUploadMaxFileCount && this.files.length + count > this.FileUploadMaxFileCount) {
|
|
128
|
+
this.onerror("You can not upload more than " + this.FileUploadMaxFileCount + " file(s)");
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
for (var i = 0; i < count && (!this.FileUploadMaxFileCount || this.files.length < this.FileUploadMaxFileCount); i++) {
|
|
132
|
+
var file = this.files[this.files.length] = files[i];
|
|
133
|
+
if (this.FileUploadMinSize && file.size < this.FileUploadMinSize) {
|
|
134
|
+
this.onerror("file is too small, needs to be larger than " + this.FileUploadMinSize + "bytes");
|
|
135
|
+
this.files.splice(i, 1);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (this.FileUploadMaxSize && file.size > this.FileUploadMaxSize) {
|
|
139
|
+
this.onerror("file is too big, needs to be below " + this.FileUploadMaxSize + "bytes");
|
|
140
|
+
this.files.splice(i, 1);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (this.UsageMax && (file.size + this.CurrentUsage > this.UsageMax)) {
|
|
144
|
+
this.onerror("You do not have enough space available to upload this file.");
|
|
145
|
+
this.files.splice(i, 1);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.CurrentUsage += file.size;
|
|
150
|
+
var filename = file.name;
|
|
151
|
+
if (window.FileReader) {
|
|
152
|
+
var reader = new FileReader();
|
|
153
|
+
reader.index = i;
|
|
154
|
+
reader.file = file;
|
|
155
|
+
|
|
156
|
+
reader.onloadend = this.processFile;
|
|
157
|
+
reader.uploadRef = this;
|
|
158
|
+
reader.readAsDataURL(file);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
var fileExt = file.type.substring(file.type.indexOf("/") + 1);
|
|
162
|
+
var fileType = file.type.substring(0, file.type.indexOf("/"));
|
|
163
|
+
if (!this.isValidFileType(fileExt)) {
|
|
164
|
+
this.onerror('invalid file type');
|
|
165
|
+
this.files.splice(i, 1);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
this.onafterfileready(file);
|
|
170
|
+
this.processRequest({
|
|
171
|
+
file: file,
|
|
172
|
+
headers: [{
|
|
173
|
+
type: "If-Modified-Since",
|
|
174
|
+
value: "Mon, 26 Jul 1997 05:00:00 GMT"
|
|
175
|
+
},{
|
|
176
|
+
type: "Cache-Control",
|
|
177
|
+
value: "no-cache"
|
|
178
|
+
},{
|
|
179
|
+
type: "X-Requested-With",
|
|
180
|
+
value: "XMLHttpRequest"
|
|
181
|
+
},{
|
|
182
|
+
type: "X-File-Name",
|
|
183
|
+
value:file.fileName || file.filename || file.name
|
|
184
|
+
},{
|
|
185
|
+
type: "X-File-Size",
|
|
186
|
+
value: file.fileSize
|
|
187
|
+
},{
|
|
188
|
+
type: "X-File-Encoding",
|
|
189
|
+
value: "binary"
|
|
190
|
+
},{
|
|
191
|
+
type: "Content-Type",
|
|
192
|
+
value: "multipart/form-data"
|
|
193
|
+
}].concat(this.headers)
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
} catch (e) {
|
|
197
|
+
error('uploadDrop', e);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
this.processFile = function (ev) {
|
|
201
|
+
try {
|
|
202
|
+
if(ev.contructor == String) {
|
|
203
|
+
ev = eval(ev.replace(/\n/gi, ''));
|
|
204
|
+
}
|
|
205
|
+
var data = ev.target.result;
|
|
206
|
+
var file = ev.target.file;
|
|
207
|
+
var fileExt = file.type.substring(file.type.indexOf("/") + 1);
|
|
208
|
+
var fileType = file.type.substring(0, file.type.indexOf("/"));
|
|
209
|
+
if (!this.uploadRef.isValidFileType(fileExt)) {
|
|
210
|
+
alert("The file type \"" + fileExt + "\" is not of a valid type.");
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
this.uploadRef.onafterfileready(file, data);
|
|
215
|
+
|
|
216
|
+
var headers = [{
|
|
217
|
+
type: "If-Modified-Since",
|
|
218
|
+
value: "Mon, 26 Jul 1997 05:00:00 GMT"
|
|
219
|
+
},{
|
|
220
|
+
type: "Cache-Control",
|
|
221
|
+
value: "no-cache"
|
|
222
|
+
},{
|
|
223
|
+
type: "X-Requested-With",
|
|
224
|
+
value: "XMLHttpRequest"
|
|
225
|
+
},{
|
|
226
|
+
type: "X-File-Name",
|
|
227
|
+
value:file.fileName || file.filename || file.name
|
|
228
|
+
},{
|
|
229
|
+
type: "X-File-Size",
|
|
230
|
+
value: file.fileSize
|
|
231
|
+
},{
|
|
232
|
+
type: "X-File-Encoding",
|
|
233
|
+
value: "base64"
|
|
234
|
+
}/*,
|
|
235
|
+
{type: "Content-Type", value: "multipart/form-data"}*/
|
|
236
|
+
];
|
|
237
|
+
headers = headers.concat(this.uploadRef.headers);
|
|
238
|
+
if (!window.FileReader) {
|
|
239
|
+
var bin = data;
|
|
240
|
+
this.uploadRef.processRequest({
|
|
241
|
+
file: file,
|
|
242
|
+
bin: encodeURIComponent(bin.substring(bin.indexOf("base64,") + 7, bin.length)),
|
|
243
|
+
headers: headers
|
|
244
|
+
});
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
var getBinaryDataReader = new FileReader();
|
|
248
|
+
getBinaryDataReader.uploadRef = this.uploadRef;
|
|
249
|
+
getBinaryDataReader.onloadend = function(evt) {
|
|
250
|
+
evt = evt ? evt : window.event;
|
|
251
|
+
var bin = evt.target.result;
|
|
252
|
+
this.uploadRef.processRequest({
|
|
253
|
+
file: file,
|
|
254
|
+
bin: encodeURIComponent(bin.substring(bin.indexOf("base64,") + 7, bin.length)),
|
|
255
|
+
headers: headers
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
getBinaryDataReader.readAsDataURL(file);
|
|
259
|
+
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
error('processFile', e);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
this.processRequest = function (params) {
|
|
266
|
+
try {
|
|
267
|
+
var file = params.file;
|
|
268
|
+
var headers = params.headers;
|
|
269
|
+
var bin = params.bin || file;
|
|
270
|
+
if (!this.crossDomain) {
|
|
271
|
+
ajax.call(this, {
|
|
272
|
+
method: "POST",
|
|
273
|
+
url: this.UploadScript,
|
|
274
|
+
query: bin,
|
|
275
|
+
headers: headers,
|
|
276
|
+
onfileload: this.onfileload,
|
|
277
|
+
onbefore: this.onbefore,
|
|
278
|
+
onprogress: this.onprogress,
|
|
279
|
+
onabort: this.onabort,
|
|
280
|
+
onerror: this.onerror,
|
|
281
|
+
onloadstart: this.onloadstart,
|
|
282
|
+
context: this,
|
|
283
|
+
onsuccess: this.onafterupload
|
|
284
|
+
});
|
|
285
|
+
} else {
|
|
286
|
+
var encoding = (headers.filter(function(obj){
|
|
287
|
+
return obj.type == "X-File-Encoding";
|
|
288
|
+
})[0]) || {},
|
|
289
|
+
fileName = (headers.filter(function(obj){
|
|
290
|
+
return obj.type == "X-File-Name";
|
|
291
|
+
})[0]) || {},
|
|
292
|
+
// blobs = bin.match(/.{1,1900}/g),
|
|
293
|
+
|
|
294
|
+
totalBytes = bin.length,
|
|
295
|
+
_cuid = cuid(),
|
|
296
|
+
destination = this.destination_url ? 'fields={"destination_url":"' + this.destination_url + '"}&': "",
|
|
297
|
+
key = this.api_key ? "api_key=" + this.api_key + "&": "",
|
|
298
|
+
q = this.crossDomainProxy.indexOf('?') == -1 ? "?" : "&";
|
|
299
|
+
|
|
300
|
+
//for (var i = 0, len = blobs.length, eof = len - 1; i < len; i++) {
|
|
301
|
+
query = q + key + destination + 'files={"'+_cuid+'":{"'+encoding.value+'":"'+bin.substr(0,1500)+'", "type" : "'+file.type+'", "name":"'+fileName.value+'"}}&EOF=false',
|
|
302
|
+
loop_function = function (data, status, xr, context) {
|
|
303
|
+
context.onprogress((totalBytes - bin.length)/totalBytes);
|
|
304
|
+
if (bin.length > 0) {
|
|
305
|
+
var query = q + key + destination + 'files={"'+_cuid+'":{"'+encoding.value+'":"'+bin.substr(0,1500)+'", "type" : "'+file.type+'", "name":"'+fileName.value+'"}}&EOF=';
|
|
306
|
+
bin = bin.substr(1500);
|
|
307
|
+
|
|
308
|
+
if (!bin) {
|
|
309
|
+
query += "true";
|
|
310
|
+
} else {
|
|
311
|
+
query += "false";
|
|
312
|
+
}
|
|
313
|
+
ajax.call(context, {
|
|
314
|
+
dataType: "jsonp",
|
|
315
|
+
url: context.crossDomainProxy + query,
|
|
316
|
+
headers: headers,
|
|
317
|
+
onerror: context.onerror,
|
|
318
|
+
context: context,
|
|
319
|
+
onsuccess: loop_function
|
|
320
|
+
})
|
|
321
|
+
} else {
|
|
322
|
+
context.onsuccess(data);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
bin = bin.substr(1500);
|
|
326
|
+
|
|
327
|
+
ajax.call(this, {
|
|
328
|
+
dataType: "jsonp",
|
|
329
|
+
url: this.crossDomainProxy + query,//this.UploadScript,
|
|
330
|
+
headers: headers,
|
|
331
|
+
onfileload: this.onfileload,
|
|
332
|
+
onbefore: this.onbefore,
|
|
333
|
+
onabort: this.onabort,
|
|
334
|
+
onerror: this.onerror,
|
|
335
|
+
onloadstart: this.onloadstart,
|
|
336
|
+
context: this,
|
|
337
|
+
onsuccess: loop_function
|
|
338
|
+
});
|
|
339
|
+
// }
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
catch (e) {
|
|
343
|
+
error('processRequest', e);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
this.clear = function (index) {
|
|
347
|
+
this.onbeforeclear();
|
|
348
|
+
if (!index) {
|
|
349
|
+
this.files = [];
|
|
350
|
+
}
|
|
351
|
+
this.onafterclear();
|
|
352
|
+
if (this.useInputBox) {
|
|
353
|
+
this.inputBox.value = null;
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
this.remove = function (filename, indexOf) {
|
|
357
|
+
if (this.useInputBox) {
|
|
358
|
+
this.inputBox.value = null;
|
|
359
|
+
}
|
|
360
|
+
return this.files.remove(filename, indexOf);
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
catch (e) {
|
|
364
|
+
error('uploadObject', e);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
if (!window.killPropagation) {
|
|
369
|
+
window.killPropagation = function (ev, bubble, returnValue) {
|
|
370
|
+
try {
|
|
371
|
+
ev = ev || window.event;
|
|
372
|
+
bubble = bubble || true;
|
|
373
|
+
returnValue = returnValue || false;
|
|
374
|
+
if (ev.stopPropagation) {
|
|
375
|
+
ev.stopPropagation();
|
|
376
|
+
ev.preventDefault();
|
|
377
|
+
} else {
|
|
378
|
+
ev.cancelBubble = bubble;
|
|
379
|
+
ev.returnValue = returnValue;
|
|
380
|
+
}
|
|
381
|
+
} catch (e) {
|
|
382
|
+
error("killPropagation", e);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
if (!window.error) {
|
|
387
|
+
window.error = function error(fname, e) {
|
|
388
|
+
var index = window.location.search.indexOf("debug=true");
|
|
389
|
+
if(index != -1) {
|
|
390
|
+
alert("Error in " + fname + "\n" + (e.description || e));
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|