PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | assets/js/fileuploader.js +227 -232 5.0 → 6.2.1 View file →
@@ -12,10 +12,10 @@
12 12
13 13 /**
14 14 * Adds all missing properties from second obj to first obj
15 15 */
16 -qq.extend = function(first, second){
17 - for (var prop in second){
16 +qq.extend = function (first, second) {
17 + for (var prop in second) {
18 18 first[prop] = second[prop];
19 19 }
20 20 };
21 21
@@ -22,9 +22,9 @@
22 22 /**
23 23 * Searches for a given element in the array, returns -1 if it is not present.
24 24 * @param {Number} [from] The index at which to begin the search
25 25 */
26 -qq.indexOf = function(arr, elt, from){
26 +qq.indexOf = function (arr, elt, from) {
27 27 if (arr.indexOf) return arr.indexOf(elt, from);
28 28
29 29 from = from || 0;
30 30 var len = arr.length;
@@ -30,10 +30,10 @@
30 30 var len = arr.length;
31 31
32 32 if (from < 0) from += len;
33 33
34 - for (; from < len; from++){
35 - if (from in arr && arr[from] === elt){
34 + for (; from < len; from++) {
35 + if (from in arr && arr[from] === elt) {
36 36 return from;
37 37 }
38 38 }
39 39 return -1;
@@ -38,11 +38,11 @@
38 38 }
39 39 return -1;
40 40 };
41 41
42 -qq.getUniqueId = (function(){
42 +qq.getUniqueId = (function () {
43 43 var id = 0;
44 - return function(){
44 + return function () {
45 45 return id++;
46 46 };
47 47 })();
48 48
@@ -48,24 +48,24 @@
48 48
49 49 //
50 50 // Events
51 51
52 -qq.attach = function(element, type, fn){
53 - if (element.addEventListener){
52 +qq.attach = function (element, type, fn) {
53 + if (element.addEventListener) {
54 54 element.addEventListener(type, fn, false);
55 - } else if (element.attachEvent){
55 + } else if (element.attachEvent) {
56 56 element.attachEvent('on' + type, fn);
57 57 }
58 58 };
59 -qq.detach = function(element, type, fn){
60 - if (element.removeEventListener){
59 +qq.detach = function (element, type, fn) {
60 + if (element.removeEventListener) {
61 61 element.removeEventListener(type, fn, false);
62 - } else if (element.attachEvent){
62 + } else if (element.attachEvent) {
63 63 element.detachEvent('on' + type, fn);
64 64 }
65 65 };
66 66
67 -qq.preventDefault = function(e){
67 +qq.preventDefault = function (e) {
68 68 e.preventDefault();
69 69 };
70 70
71 71 //
@@ -73,20 +73,20 @@
73 73
74 74 /**
75 75 * Insert node a before node b.
76 76 */
77 -qq.insertBefore = function(a, b){
77 +qq.insertBefore = function (a, b) {
78 78 b.parentNode.insertBefore(a, b);
79 79 };
80 -qq.remove = function(element){
80 +qq.remove = function (element) {
81 81 element.parentNode.removeChild(element);
82 82 };
83 83
84 -qq.contains = function(parent, descendant){
84 +qq.contains = function (parent, descendant) {
85 85 // compareposition returns false in this case
86 86 if (parent == descendant) return true;
87 87
88 - if (parent.contains){
88 + if (parent.contains) {
89 89 return parent.contains(descendant);
90 90 } else {
91 91 return !!(descendant.compareDocumentPosition(parent) & 8);
92 92 }
@@ -95,11 +95,11 @@
95 95 /**
96 96 * Creates and returns element from html string
97 97 * Uses innerHTML to create an element
98 98 */
99 -qq.toElement = (function(){
99 +qq.toElement = (function () {
100 100 var div = document.createElement('div');
101 - return function(html){
101 + return function (html) {
102 102 div.innerHTML = html;
103 103 var element = div.firstChild;
104 104 div.removeChild(element);
105 105 return element;
@@ -112,30 +112,30 @@
112 112 /**
113 113 * Sets styles for an element.
114 114 * Fixes opacity in IE6-8.
115 115 */
116 -qq.css = function(element, styles){
117 - if (styles.opacity != null){
118 - if (typeof element.style.opacity != 'string' && typeof(element.filters) != 'undefined'){
116 +qq.css = function (element, styles) {
117 + if (styles.opacity != null) {
118 + if (typeof element.style.opacity != 'string' && typeof (element.filters) != 'undefined') {
119 119 styles.filter = 'alpha(opacity=' + Math.round(100 * styles.opacity) + ')';
120 120 }
121 121 }
122 122 qq.extend(element.style, styles);
123 123 };
124 -qq.hasClass = function(element, name){
124 +qq.hasClass = function (element, name) {
125 125 var re = new RegExp('(^| )' + name + '( |$)');
126 126 return re.test(element.className);
127 127 };
128 -qq.addClass = function(element, name){
129 - if (!qq.hasClass(element, name)){
128 +qq.addClass = function (element, name) {
129 + if (!qq.hasClass(element, name)) {
130 130 element.className += ' ' + name;
131 131 }
132 132 };
133 -qq.removeClass = function(element, name){
133 +qq.removeClass = function (element, name) {
134 134 var re = new RegExp('(^| )' + name + '( |$)');
135 135 element.className = element.className.replace(re, ' ').replace(/^\s+|\s+$/g, "");
136 136 };
137 -qq.setText = function(element, text){
137 +qq.setText = function (element, text) {
138 138 element.innerText = text;
139 139 element.textContent = text;
140 140 };
141 141
@@ -141,14 +141,14 @@
141 141
142 142 //
143 143 // Selecting elements
144 144
145 -qq.children = function(element){
145 +qq.children = function (element) {
146 146 var children = [],
147 147 child = element.firstChild;
148 148
149 - while (child){
150 - if (child.nodeType == 1){
149 + while (child) {
150 + if (child.nodeType == 1) {
151 151 children.push(child);
152 152 }
153 153 child = child.nextSibling;
154 154 }
@@ -155,10 +155,10 @@
155 155
156 156 return children;
157 157 };
158 158
159 -qq.getByClass = function(element, className){
160 - if (element.querySelectorAll){
159 +qq.getByClass = function (element, className) {
160 + if (element.querySelectorAll) {
161 161 return element.querySelectorAll('.' + className);
162 162 }
163 163
164 164 var result = [];
@@ -164,10 +164,10 @@
164 164 var result = [];
165 165 var candidates = element.getElementsByTagName("*");
166 166 var len = candidates.length;
167 167
168 - for (var i = 0; i < len; i++){
169 - if (qq.hasClass(candidates[i], className)){
168 + for (var i = 0; i < len; i++) {
169 + if (qq.hasClass(candidates[i], className)) {
170 170 result.push(candidates[i]);
171 171 }
172 172 }
173 173 return result;
@@ -188,16 +188,16 @@
188 188 * @param Object JSON-Object
189 189 * @param String current querystring-part
190 190 * @return String encoded querystring
191 191 */
192 -qq.obj2url = function(obj, temp, prefixDone){
192 +qq.obj2url = function (obj, temp, prefixDone) {
193 193 var uristrings = [],
194 194 prefix = '&',
195 - add = function(nextObj, i){
195 + add = function (nextObj, i) {
196 196 var nextTemp = temp
197 197 ? (/\[\]$/.test(temp)) // prevent double-encoding
198 - ? temp
199 - : temp+'['+i+']'
198 + ? temp
199 + : temp + '[' + i + ']'
200 200 : i;
201 201 if ((nextTemp != 'undefined') && (i != 'undefined')) {
202 202 uristrings.push(
203 203 (typeof nextObj === 'object')
@@ -202,10 +202,10 @@
202 202 uristrings.push(
203 203 (typeof nextObj === 'object')
204 204 ? qq.obj2url(nextObj, nextTemp, true)
205 205 : (Object.prototype.toString.call(nextObj) === '[object Function]')
206 - ? encodeURIComponent(nextTemp) + '=' + encodeURIComponent(nextObj())
207 - : encodeURIComponent(nextTemp) + '=' + encodeURIComponent(nextObj)
206 + ? encodeURIComponent(nextTemp) + '=' + encodeURIComponent(nextObj())
207 + : encodeURIComponent(nextTemp) + '=' + encodeURIComponent(nextObj)
208 208 );
209 209 }
210 210 };
211 211
@@ -212,16 +212,16 @@
212 212 if (!prefixDone && temp) {
213 213 prefix = (/\?/.test(temp)) ? (/\?$/.test(temp)) ? '' : '&' : '?';
214 214 uristrings.push(temp);
215 215 uristrings.push(qq.obj2url(obj));
216 - } else if ((Object.prototype.toString.call(obj) === '[object Array]') && (typeof obj != 'undefined') ) {
216 + } else if ((Object.prototype.toString.call(obj) === '[object Array]') && (typeof obj != 'undefined')) {
217 217 // we wont use a for-in-loop on an array (performance)
218 - for (var i = 0, len = obj.length; i < len; ++i){
218 + for (var i = 0, len = obj.length; i < len; ++i) {
219 219 add(obj[i], i);
220 220 }
221 - } else if ((typeof obj != 'undefined') && (obj !== null) && (typeof obj === "object")){
221 + } else if ((typeof obj != 'undefined') && (obj !== null) && (typeof obj === "object")) {
222 222 // for anything else but a scalar, we will use for-in-loop
223 - for (var i in obj){
223 + for (var i in obj) {
224 224 add(obj[i], i);
225 225 }
226 226 } else {
227 227 uristrings.push(encodeURIComponent(temp) + '=' + encodeURIComponent(obj));
@@ -242,9 +242,9 @@
242 242
243 243 /**
244 244 * Creates upload button, validates upload, but doesn't create file list or dd.
245 245 */
246 -qq.FileUploaderBasic = function(o){
246 +qq.FileUploaderBasic = function (o) {
247 247 this._options = {
248 248 // set to true to see the server response
249 249 debug: false,
250 250 action: '/server/upload',
@@ -257,12 +257,12 @@
257 257 sizeLimit: 0,
258 258 minSizeLimit: 0,
259 259 // events
260 260 // return false to cancel submit
261 - onSubmit: function(id, fileName){},
262 - onProgress: function(id, fileName, loaded, total){},
263 - onComplete: function(id, fileName, responseJSON){},
264 - onCancel: function(id, fileName){},
261 + onSubmit: function (id, fileName) { },
262 + onProgress: function (id, fileName, loaded, total) { },
263 + onComplete: function (id, fileName, responseJSON) { },
264 + onCancel: function (id, fileName) { },
265 265 // messages
266 266 messages: {
267 267 typeError: "{file} has invalid extension. Only {extensions} are allowed.",
268 268 sizeError: "{file} is too large, maximum file size is {sizeLimit}.",
@@ -269,9 +269,9 @@
269 269 minSizeError: "{file} is too small, minimum file size is {minSizeLimit}.",
270 270 emptyError: "{file} is empty, please select files again without it.",
271 271 onLeave: "The files are being uploaded, if you leave now the upload will be cancelled."
272 272 },
273 - showMessage: function(message){
273 + showMessage: function (message) {
274 274 alert(message);
275 275 }
276 276 };
277 277 qq.extend(this._options, o);
@@ -279,9 +279,9 @@
279 279 // number of files being uploaded
280 280 this._filesInProgress = 0;
281 281 this._handler = this._createUploadHandler();
282 282
283 - if (this._options.button){
283 + if (this._options.button) {
284 284 this._button = this._createUploadButton(this._options.button);
285 285 }
286 286
287 287 this._preventLeaveInProgress();
@@ -287,30 +287,30 @@
287 287 this._preventLeaveInProgress();
288 288 };
289 289
290 290 qq.FileUploaderBasic.prototype = {
291 - setParams: function(params){
291 + setParams: function (params) {
292 292 this._options.params = params;
293 293 },
294 - getInProgress: function(){
294 + getInProgress: function () {
295 295 return this._filesInProgress;
296 296 },
297 - _createUploadButton: function(element){
297 + _createUploadButton: function (element) {
298 298 var self = this;
299 299
300 300 return new qq.UploadButton({
301 301 element: element,
302 302 multiple: this._options.multiple && qq.UploadHandlerXhr.isSupported(),
303 - onChange: function(input){
303 + onChange: function (input) {
304 304 self._onInputChange(input);
305 305 }
306 306 });
307 307 },
308 - _createUploadHandler: function(){
308 + _createUploadHandler: function () {
309 309 var self = this,
310 310 handlerClass;
311 311
312 - if(qq.UploadHandlerXhr.isSupported()){
312 + if (qq.UploadHandlerXhr.isSupported()) {
313 313 handlerClass = 'UploadHandlerXhr';
314 314 } else {
315 315 handlerClass = 'UploadHandlerForm';
316 316 }
@@ -318,17 +318,17 @@
318 318 var handler = new qq[handlerClass]({
319 319 debug: this._options.debug,
320 320 action: this._options.action,
321 321 maxConnections: this._options.maxConnections,
322 - onProgress: function(id, fileName, loaded, total){
322 + onProgress: function (id, fileName, loaded, total) {
323 323 self._onProgress(id, fileName, loaded, total);
324 324 self._options.onProgress(id, fileName, loaded, total);
325 325 },
326 - onComplete: function(id, fileName, result){
326 + onComplete: function (id, fileName, result) {
327 327 self._onComplete(id, fileName, result);
328 328 self._options.onComplete(id, fileName, result);
329 329 },
330 - onCancel: function(id, fileName){
330 + onCancel: function (id, fileName) {
331 331 self._onCancel(id, fileName);
332 332 self._options.onCancel(id, fileName);
333 333 }
334 334 });
@@ -334,13 +334,13 @@
334 334 });
335 335
336 336 return handler;
337 337 },
338 - _preventLeaveInProgress: function(){
338 + _preventLeaveInProgress: function () {
339 339 var self = this;
340 340
341 - qq.attach(window, 'beforeunload', function(e){
342 - if (!self._filesInProgress){
341 + qq.attach(window, 'beforeunload', function (e) {
342 + if (!self._filesInProgress) {
343 343 return;
344 344 }
345 345
346 346 var e = e || window.event;
@@ -347,56 +347,56 @@
347 347 // for webkit
348 348 return self._options.messages.onLeave;
349 349 });
350 350 },
351 - _onSubmit: function(id, fileName){
351 + _onSubmit: function (id, fileName) {
352 352 this._filesInProgress++;
353 353 },
354 - _onProgress: function(id, fileName, loaded, total){
354 + _onProgress: function (id, fileName, loaded, total) {
355 355 },
356 - _onComplete: function(id, fileName, result){
356 + _onComplete: function (id, fileName, result) {
357 357 this._filesInProgress--;
358 - if (result.error){
358 + if (result.error) {
359 359 this._options.showMessage(result.error);
360 360 }
361 361 },
362 - _onCancel: function(id, fileName){
362 + _onCancel: function (id, fileName) {
363 363 this._filesInProgress--;
364 364 },
365 - _onInputChange: function(input){
366 - if (this._handler instanceof qq.UploadHandlerXhr){
365 + _onInputChange: function (input) {
366 + if (this._handler instanceof qq.UploadHandlerXhr) {
367 367 this._uploadFileList(input.files);
368 368 } else {
369 - if (this._validateFile(input)){
369 + if (this._validateFile(input)) {
370 370 this._uploadFile(input);
371 371 }
372 372 }
373 373 this._button.reset();
374 374 },
375 - _uploadFileList: function(files){
376 - for (var i=0; i<files.length; i++){
377 - if ( !this._validateFile(files[i])){
375 + _uploadFileList: function (files) {
376 + for (var i = 0; i < files.length; i++) {
377 + if (!this._validateFile(files[i])) {
378 378 return;
379 379 }
380 380 }
381 381
382 - for (var i=0; i<files.length; i++){
382 + for (var i = 0; i < files.length; i++) {
383 383 this._uploadFile(files[i]);
384 384 }
385 385 },
386 - _uploadFile: function(fileContainer){
386 + _uploadFile: function (fileContainer) {
387 387 var id = this._handler.add(fileContainer);
388 388 var fileName = this._handler.getName(id);
389 389
390 - if (this._options.onSubmit(id, fileName) !== false){
390 + if (this._options.onSubmit(id, fileName) !== false) {
391 391 this._onSubmit(id, fileName);
392 392 this._handler.upload(id, this._options.params);
393 393 }
394 394 },
395 - _validateFile: function(file){
395 + _validateFile: function (file) {
396 396 var name, size;
397 397
398 - if (file.value){
398 + if (file.value) {
399 399 // it is a file input
400 400 // get input value and remove path to normalize
401 401 name = file.value.replace(/.*(\/|\\)/, "");
402 402 } else {
@@ -404,21 +404,21 @@
404 404 name = file.fileName != null ? file.fileName : file.name;
405 405 size = file.fileSize != null ? file.fileSize : file.size;
406 406 }
407 407
408 - if (! this._isAllowedExtension(name)){
408 + if (!this._isAllowedExtension(name)) {
409 409 this._error('typeError', name);
410 410 return false;
411 411
412 - } else if (size === 0){
412 + } else if (size === 0) {
413 413 this._error('emptyError', name);
414 414 return false;
415 415
416 - } else if (size && this._options.sizeLimit && size > this._options.sizeLimit){
416 + } else if (size && this._options.sizeLimit && size > this._options.sizeLimit) {
417 417 this._error('sizeError', name);
418 418 return false;
419 419
420 - } else if (size && size < this._options.minSizeLimit){
420 + } else if (size && size < this._options.minSizeLimit) {
421 421 this._error('minSizeError', name);
422 422 return false;
423 423 }
424 424
@@ -423,11 +423,11 @@
423 423 }
424 424
425 425 return true;
426 426 },
427 - _error: function(code, fileName){
427 + _error: function (code, fileName) {
428 428 var message = this._options.messages[code];
429 - function r(name, replacement){
429 + function r(name, replacement) {
430 430 message = message.replace(name, replacement);
431 431 }
432 432
433 433 r('{file}', this._formatFileName(fileName));
@@ -436,24 +436,24 @@
436 436 r('{minSizeLimit}', this._formatSize(this._options.minSizeLimit));
437 437
438 438 this._options.showMessage(message);
439 439 },
440 - _formatFileName: function(name){
441 - if (name.length > 33){
440 + _formatFileName: function (name) {
441 + if (name.length > 33) {
442 442 name = name.slice(0, 19) + '...' + name.slice(-13);
443 443 }
444 444 return name;
445 445 },
446 - _isAllowedExtension: function(fileName){
446 + _isAllowedExtension: function (fileName) {
447 447 var ext = (-1 !== fileName.indexOf('.')) ? fileName.replace(/.*[.]/, '').toLowerCase() : '';
448 448 var allowed = this._options.allowedExtensions;
449 449
450 - if (!allowed.length){
450 + if (!allowed.length) {
451 451 return true;
452 452 }
453 453
454 - for (var i=0; i<allowed.length; i++){
455 - if (allowed[i].toLowerCase() == ext){
454 + for (var i = 0; i < allowed.length; i++) {
455 + if (allowed[i].toLowerCase() == ext) {
456 456 return true;
457 457 }
458 458 }
459 459
@@ -458,9 +458,9 @@
458 458 }
459 459
460 460 return false;
461 461 },
462 - _formatSize: function(bytes){
462 + _formatSize: function (bytes) {
463 463 var i = -1;
464 464 do {
465 465 bytes = bytes / 1024;
466 466 i++;
@@ -474,9 +474,9 @@
474 474 /**
475 475 * Class that creates upload widget with drag-and-drop and file list
476 476 * @inherits qq.FileUploaderBasic
477 477 */
478 -qq.FileUploader = function(o){
478 +qq.FileUploader = function (o) {
479 479 // call parent constructor
480 480 qq.FileUploaderBasic.apply(this, arguments);
481 481
482 482 // additional options
@@ -485,26 +485,26 @@
485 485 // if set, will be used instead of qq-upload-list in template
486 486 listElement: null,
487 487
488 488 template: '<div class="qq-uploader">' +
489 - '<div class="mainwp-upload-button-area">' +
490 - '<div class="ui labeled icon massive green button qq-upload-button"><i class="upload icon"></i> Upload Now </div>' +
491 - '</div>' +
492 - '<div class="qq-upload-drop-area ui raised green padded segment"><span>Drop files here to upload</span></div>' +
493 - '<div class="ui hidden divider"></div>' +
494 - '<div class="ui middle aligned divided selection list qq-upload-list"></div>' +
495 - '</div>',
489 + '<div class="mainwp-upload-button-area">' +
490 + '<div class="ui labeled icon massive green button qq-upload-button"><i class="upload icon"></i> Upload Now </div>' +
491 + '</div>' +
492 + '<div class="qq-upload-drop-area"><span>Drop files here to upload</span></div>' +
493 + '<div class="ui hidden divider"></div>' +
494 + '<div class="ui middle aligned divided list qq-upload-list"></div>' +
495 + '</div>',
496 496
497 497 // template for one item in file list
498 498 fileTemplate: '<div class="item file-uploaded-item" style="padding:0!important;">' +
499 - '<div class="ui grid" style="margin:0!important;">' +
500 - '<div class="four column row">' +
501 - '<div class="left aligned middle aligned column"><span class="qq-upload-file"></span></div>' +
502 - '<div class="middle aligned column"><span class="qq-upload-size"></span></div>' +
503 - '<div class="middle aligned column"><span class="qq-upload-spinner"><i class="notched circle loading icon"></i> Uploading...</span><span class="qq-upload-msg-success qq-upload-msg-fail"></span></div>' +
504 - '<div class="right aligned middle aligned column"><a class="ui mini button basic red qq-upload-cancel" href="#">Cancel Upload</a> <span class="qq-upload-add-to-favorites"><a class="ui mini button basic" href="#">Add to Favorites</a></span> <a class="ui mini button basic red qq-upload-cancel-install" href="#">Remove Item</a></div>' +
505 - '</div>' +
506 - '</div>',
499 + '<div class="ui grid" style="margin:0!important;">' +
500 + '<div class="four column row">' +
501 + '<div class="left aligned middle aligned column"><span class="qq-upload-file"></span></div>' +
502 + '<div class="middle aligned column"><span class="qq-upload-size"></span></div>' +
503 + '<div class="middle aligned column"><span class="qq-upload-spinner"><i class="notched circle loading icon"></i> Uploading...</span><span class="qq-upload-msg-success qq-upload-msg-fail"></span></div>' +
504 + '<div class="right aligned middle aligned column"><a class="ui mini button basic red qq-upload-cancel" href="#">Cancel Upload</a> <a class="ui mini button basic red qq-upload-cancel-install" href="#">Remove Item</a></div>' +
505 + '</div>' +
506 + '</div>',
507 507
508 508 classes: {
509 509 // used to get elements from templates
510 510 button: 'qq-upload-button',
@@ -516,9 +516,9 @@
516 516 spinner: 'qq-upload-spinner',
517 517 size: 'qq-upload-size',
518 518 cancel: 'qq-upload-cancel',
519 519 cancel_install: 'qq-upload-cancel-install',
520 - add_to_favor: 'qq-upload-add-to-favorites',
520 + add_to_favor: 'qq-upload-add-to-favorites',
521 521
522 522 // added to list item when upload completes
523 523 // used in css to hide progress spinner
524 524 success: 'qq-upload-success',
@@ -538,9 +538,9 @@
538 538
539 539 this._button = this._createUploadButton(this._find(this._element, 'button'));
540 540
541 541 this._bindCancelEvent();
542 - this._bindCancelInstallEvent();
542 + this._bindCancelInstallEvent();
543 543 this._setupDragDrop();
544 544 };
545 545
546 546 // inherit from Basic Uploader
@@ -549,33 +549,33 @@
549 549 qq.extend(qq.FileUploader.prototype, {
550 550 /**
551 551 * Gets one of the elements listed in this._options.classes
552 552 **/
553 - _find: function(parent, type){
553 + _find: function (parent, type) {
554 554 var element = qq.getByClass(parent, this._options.classes[type])[0];
555 - if (!element){
555 + if (!element) {
556 556 throw new Error('element not found ' + type);
557 557 }
558 558
559 559 return element;
560 560 },
561 - _setupDragDrop: function(){
561 + _setupDragDrop: function () {
562 562 var self = this,
563 563 dropArea = this._find(this._element, 'drop');
564 564
565 565 var dz = new qq.UploadDropZone({
566 566 element: dropArea,
567 - onEnter: function(e){
567 + onEnter: function (e) {
568 568 qq.addClass(dropArea, self._classes.dropActive);
569 569 e.stopPropagation();
570 570 },
571 - onLeave: function(e){
571 + onLeave: function (e) {
572 572 e.stopPropagation();
573 573 },
574 - onLeaveNotDescendants: function(e){
574 + onLeaveNotDescendants: function (e) {
575 575 qq.removeClass(dropArea, self._classes.dropActive);
576 576 },
577 - onDrop: function(e){
577 + onDrop: function (e) {
578 578 dropArea.style.display = 'none';
579 579 qq.removeClass(dropArea, self._classes.dropActive);
580 580 self._uploadFileList(e.dataTransfer.files);
581 581 }
@@ -582,28 +582,28 @@
582 582 });
583 583
584 584 dropArea.style.display = 'none';
585 585
586 - qq.attach(document, 'dragenter', function(e){
586 + qq.attach(document, 'dragenter', function (e) {
587 587 if (!dz._isValidFileDrag(e)) return;
588 588
589 589 dropArea.style.display = 'block';
590 590 });
591 - qq.attach(document, 'dragleave', function(e){
591 + qq.attach(document, 'dragleave', function (e) {
592 592 if (!dz._isValidFileDrag(e)) return;
593 593
594 594 var relatedTarget = document.elementFromPoint(e.clientX, e.clientY);
595 595 // only fire when leaving document out
596 - if ( ! relatedTarget || relatedTarget.nodeName == "HTML"){
596 + if (!relatedTarget || relatedTarget.nodeName == "HTML") {
597 597 dropArea.style.display = 'none';
598 598 }
599 599 });
600 600 },
601 - _onSubmit: function(id, fileName){
601 + _onSubmit: function (id, fileName) {
602 602 qq.FileUploaderBasic.prototype._onSubmit.apply(this, arguments);
603 603 this._addToList(id, fileName);
604 604 },
605 - _onProgress: function(id, fileName, loaded, total){
605 + _onProgress: function (id, fileName, loaded, total) {
606 606 qq.FileUploaderBasic.prototype._onProgress.apply(this, arguments);
607 607
608 608 var item = this._getItemByFileId(id);
609 609 var size = this._find(item, 'size');
@@ -609,9 +609,9 @@
609 609 var size = this._find(item, 'size');
610 610 size.style.display = 'inline';
611 611
612 612 var text;
613 - if (loaded != total){
613 + if (loaded != total) {
614 614 text = Math.round(loaded / total * 100) + '% from ' + this._formatSize(total);
615 615 } else {
616 616 text = this._formatSize(total);
617 617 }
@@ -617,9 +617,9 @@
617 617 }
618 618
619 619 qq.setText(size, text);
620 620 },
621 - _onComplete: function(id, fileName, result){
621 + _onComplete: function (id, fileName, result) {
622 622 qq.FileUploaderBasic.prototype._onComplete.apply(this, arguments);
623 623
624 624 // mark completed
625 625 var item = this._getItemByFileId(id);
@@ -624,25 +624,22 @@
624 624 // mark completed
625 625 var item = this._getItemByFileId(id);
626 626 qq.remove(this._find(item, 'cancel'));
627 627 qq.remove(this._find(item, 'spinner'));
628 - if (result.success){
628 + if (result.success) {
629 629 qq.addClass(item, this._classes.success);
630 630 //MAINWP custom code
631 631 totalSuccess++;
632 632 this._find(item, 'file').setAttribute('filename', fileName);
633 - this._find(item, 'cancel_install').style.display = 'inline';
634 - this._find(item, 'success_msg' ).innerHTML = 'Upload completed.';
635 - if (qq.hasClass(this._element, 'favorites-extension-enabled')){
636 - this._find(item, 'add_to_favor').style.display = 'inline';
637 - }
633 + this._find(item, 'cancel_install').style.display = 'inline';
634 + this._find(item, 'success_msg').innerHTML = '<span data-tooltip="Upload completed successfully." data-inverted="" data-position="left center"><i class="green check icon"></i></span>'; //MAINWP custom code
638 635 //MAINWP custom code
639 636 } else {
640 637 qq.addClass(item, this._classes.fail);
641 - this._find( item, 'fail_msg' ).innerHTML = 'Upload failed.'; //MAINWP custom code
638 + this._find(item, 'fail_msg').innerHTML = '<span data-tooltip="Upload failed." data-inverted="" data-position="left center"><i class="red times icon"></i></span>'; //MAINWP custom code
642 639 }
643 640 },
644 - _addToList: function(id, fileName){
641 + _addToList: function (id, fileName) {
645 642 var item = qq.toElement(this._options.fileTemplate);
646 643 item.qqFileId = id;
647 644
648 645 var fileElement = this._find(item, 'file');
@@ -648,18 +645,16 @@
648 645 var fileElement = this._find(item, 'file');
649 646 qq.setText(fileElement, this._formatFileName(fileName));
650 647 this._find(item, 'size').style.display = 'none';
651 648 this._find(item, 'cancel_install').style.display = 'none';
652 - this._find(item, 'add_to_favor').style.display = 'none';
653 -
654 649 this._listElement.appendChild(item);
655 650 },
656 - _getItemByFileId: function(id){
651 + _getItemByFileId: function (id) {
657 652 var item = this._listElement.firstChild;
658 653
659 654 // there can't be txt nodes in dynamically created list
660 655 // and we can use nextSibling
661 - while (item){
656 + while (item) {
662 657 if (item.qqFileId == id) return item;
663 658 item = item.nextSibling;
664 659 }
665 660 },
@@ -665,17 +660,17 @@
665 660 },
666 661 /**
667 662 * delegate click event for cancel link
668 663 **/
669 - _bindCancelEvent: function(){
664 + _bindCancelEvent: function () {
670 665 var self = this,
671 666 list = this._listElement;
672 667
673 - qq.attach(list, 'click', function(e){
668 + qq.attach(list, 'click', function (e) {
674 669 e = e || window.event;
675 670 var target = e.target || e.srcElement;
676 671
677 - if (qq.hasClass(target, self._classes.cancel)){
672 + if (qq.hasClass(target, self._classes.cancel)) {
678 673 qq.preventDefault(e);
679 674
680 675 var item = target.parentNode.parentNode.parentNode.parentNode;
681 676 self._handler.cancel(item.qqFileId);
@@ -682,33 +677,33 @@
682 677 qq.remove(item);
683 678 }
684 679 });
685 680 },
686 - _bindCancelInstallEvent: function(){
681 + _bindCancelInstallEvent: function () {
687 682 var self = this,
688 683 list = this._listElement;
689 684
690 - qq.attach(list, 'click', function(e){
685 + qq.attach(list, 'click', function (e) {
691 686 e = e || window.event;
692 687 var target = e.target || e.srcElement;
693 688
694 - if (qq.hasClass(target, self._classes.cancel_install)){
689 + if (qq.hasClass(target, self._classes.cancel_install)) {
695 690 qq.preventDefault(e);
696 691 var item = target.parentNode.parentNode.parentNode.parentNode;
697 692 qq.remove(item);
698 693 }
699 694 });
700 - },
695 + },
701 696 });
702 697
703 -qq.UploadDropZone = function(o){
698 +qq.UploadDropZone = function (o) {
704 699 this._options = {
705 700 element: null,
706 - onEnter: function(e){},
707 - onLeave: function(e){},
701 + onEnter: function (e) { },
702 + onLeave: function (e) { },
708 703 // is not fired when leaving element by hovering descendants
709 - onLeaveNotDescendants: function(e){},
710 - onDrop: function(e){}
704 + onLeaveNotDescendants: function (e) { },
705 + onDrop: function (e) { }
711 706 };
712 707 qq.extend(this._options, o);
713 708
714 709 this._element = this._options.element;
@@ -717,14 +712,14 @@
717 712 this._attachEvents();
718 713 };
719 714
720 715 qq.UploadDropZone.prototype = {
721 - _disableDropOutside: function(e){
716 + _disableDropOutside: function (e) {
722 717 // run only once for all instances
723 - if (!qq.UploadDropZone.dropOutsideDisabled ){
718 + if (!qq.UploadDropZone.dropOutsideDisabled) {
724 719
725 - qq.attach(document, 'dragover', function(e){
726 - if (e.dataTransfer){
720 + qq.attach(document, 'dragover', function (e) {
721 + if (e.dataTransfer) {
727 722 e.dataTransfer.dropEffect = 'none';
728 723 e.preventDefault();
729 724 }
730 725 });
@@ -731,16 +726,16 @@
731 726
732 727 qq.UploadDropZone.dropOutsideDisabled = true;
733 728 }
734 729 },
735 - _attachEvents: function(){
730 + _attachEvents: function () {
736 731 var self = this;
737 732
738 - qq.attach(self._element, 'dragover', function(e){
733 + qq.attach(self._element, 'dragover', function (e) {
739 734 if (!self._isValidFileDrag(e)) return;
740 735
741 736 var effect = e.dataTransfer.effectAllowed;
742 - if (effect == 'move' || effect == 'linkMove'){
737 + if (effect == 'move' || effect == 'linkMove') {
743 738 e.dataTransfer.dropEffect = 'move'; // for FF (only move allowed)
744 739 } else {
745 740 e.dataTransfer.dropEffect = 'copy'; // for Chrome
746 741 }
@@ -748,15 +743,15 @@
748 743 e.stopPropagation();
749 744 e.preventDefault();
750 745 });
751 746
752 - qq.attach(self._element, 'dragenter', function(e){
747 + qq.attach(self._element, 'dragenter', function (e) {
753 748 if (!self._isValidFileDrag(e)) return;
754 749
755 750 self._options.onEnter(e);
756 751 });
757 752
758 - qq.attach(self._element, 'dragleave', function(e){
753 + qq.attach(self._element, 'dragleave', function (e) {
759 754 if (!self._isValidFileDrag(e)) return;
760 755
761 756 self._options.onLeave(e);
762 757
@@ -766,9 +761,9 @@
766 761
767 762 self._options.onLeaveNotDescendants(e);
768 763 });
769 764
770 - qq.attach(self._element, 'drop', function(e){
765 + qq.attach(self._element, 'drop', function (e) {
771 766 if (!self._isValidFileDrag(e)) return;
772 767
773 768 e.preventDefault();
774 769 self._options.onDrop(e);
@@ -773,11 +768,11 @@
773 768 e.preventDefault();
774 769 self._options.onDrop(e);
775 770 });
776 771 },
777 - _isValidFileDrag: function(e){
772 + _isValidFileDrag: function (e) {
778 773 var dt = e.dataTransfer,
779 - // do not check dt.types.contains in webkit, because it crashes safari 4
774 + // do not check dt.types.contains in webkit, because it crashes safari 4
780 775 isWebkit = navigator.userAgent.indexOf("AppleWebKit") > -1;
781 776
782 777 // dt.effectAllowed is none in Safari 5
783 778 // dt.types.contains check is for firefox
@@ -786,9 +781,9 @@
786 781
787 782 }
788 783 };
789 784
790 -qq.UploadButton = function(o){
785 +qq.UploadButton = function (o) {
791 786 this._options = {
792 787 element: null,
793 788 // if set to true adds multiple attribute to file input
794 789 multiple: false,
@@ -793,9 +788,9 @@
793 788 // if set to true adds multiple attribute to file input
794 789 multiple: false,
795 790 // name attribute of file input
796 791 name: 'file',
797 - onChange: function(input){},
792 + onChange: function (input) { },
798 793 hoverClass: 'qq-upload-button-hover',
799 794 focusClass: 'qq-upload-button-focus'
800 795 };
801 796
@@ -816,14 +811,14 @@
816 811 };
817 812
818 813 qq.UploadButton.prototype = {
819 814 /* returns file input element */
820 - getInput: function(){
815 + getInput: function () {
821 816 return this._input;
822 817 },
823 818 /* cleans/recreates the file input */
824 - reset: function(){
825 - if (this._input.parentNode){
819 + reset: function () {
820 + if (this._input.parentNode) {
826 821 qq.remove(this._input);
827 822 }
828 823
829 824 qq.removeClass(this._element, this._options.focusClass);
@@ -828,12 +823,12 @@
828 823
829 824 qq.removeClass(this._element, this._options.focusClass);
830 825 this._input = this._createInput();
831 826 },
832 - _createInput: function(){
827 + _createInput: function () {
833 828 var input = document.createElement("input");
834 829
835 - if (this._options.multiple){
830 + if (this._options.multiple) {
836 831 input.setAttribute("multiple", "multiple");
837 832 }
838 833
839 834 input.setAttribute("type", "file");
@@ -856,28 +851,28 @@
856 851
857 852 this._element.appendChild(input);
858 853
859 854 var self = this;
860 - qq.attach(input, 'change', function(){
855 + qq.attach(input, 'change', function () {
861 856 self._options.onChange(input);
862 857 });
863 858
864 - qq.attach(input, 'mouseover', function(){
859 + qq.attach(input, 'mouseover', function () {
865 860 qq.addClass(self._element, self._options.hoverClass);
866 861 });
867 - qq.attach(input, 'mouseout', function(){
862 + qq.attach(input, 'mouseout', function () {
868 863 qq.removeClass(self._element, self._options.hoverClass);
869 864 });
870 - qq.attach(input, 'focus', function(){
865 + qq.attach(input, 'focus', function () {
871 866 qq.addClass(self._element, self._options.focusClass);
872 867 });
873 - qq.attach(input, 'blur', function(){
868 + qq.attach(input, 'blur', function () {
874 869 qq.removeClass(self._element, self._options.focusClass);
875 870 });
876 871
877 872 // IE and Opera, unfortunately have 2 tab stops on file input
878 873 // which is unacceptable in our case, disable keyboard access
879 - if (window.attachEvent){
874 + if (window.attachEvent) {
880 875 // it is IE or Opera
881 876 input.setAttribute('tabIndex', "-1");
882 877 }
883 878
@@ -887,17 +882,17 @@
887 882
888 883 /**
889 884 * Class for uploading files, uploading itself is handled by child classes
890 885 */
891 -qq.UploadHandlerAbstract = function(o){
886 +qq.UploadHandlerAbstract = function (o) {
892 887 this._options = {
893 888 debug: false,
894 889 action: '/upload.php',
895 890 // maximum number of concurrent uploads
896 891 maxConnections: 999,
897 - onProgress: function(id, fileName, loaded, total){},
898 - onComplete: function(id, fileName, response){},
899 - onCancel: function(id, fileName){}
892 + onProgress: function (id, fileName, loaded, total) { },
893 + onComplete: function (id, fileName, response) { },
894 + onCancel: function (id, fileName) { }
900 895 };
901 896 qq.extend(this._options, o);
902 897
903 898 this._queue = [];
@@ -904,9 +899,9 @@
904 899 // params for files in queue
905 900 this._params = [];
906 901 };
907 902 qq.UploadHandlerAbstract.prototype = {
908 - log: function(str){
903 + log: function (str) {
909 904 if (this._options.debug && window.console) console.log('[uploader] ' + str);
910 905 },
911 906 /**
912 907 * Adds file or file input to the queue
@@ -911,13 +906,13 @@
911 906 /**
912 907 * Adds file or file input to the queue
913 908 * @returns id
914 909 **/
915 - add: function(file){},
910 + add: function (file) { },
916 911 /**
917 912 * Sends the file identified by id and additional query params to the server
918 913 */
919 - upload: function(id, params){
914 + upload: function (id, params) {
920 915 var len = this._queue.push(id);
921 916
922 917 var copy = {};
923 918 qq.extend(copy, params);
@@ -923,9 +918,9 @@
923 918 qq.extend(copy, params);
924 919 this._params[id] = copy;
925 920
926 921 // if too many active uploads, wait...
927 - if (len <= this._options.maxConnections){
922 + if (len <= this._options.maxConnections) {
928 923 this._upload(id, this._params[id]);
929 924 }
930 925 },
931 926 /**
@@ -930,9 +925,9 @@
930 925 },
931 926 /**
932 927 * Cancels file upload by id
933 928 */
934 - cancel: function(id){
929 + cancel: function (id) {
935 930 this._cancel(id);
936 931 this._dequeue(id);
937 932 },
938 933 /**
@@ -937,10 +932,10 @@
937 932 },
938 933 /**
939 934 * Cancells all uploads
940 935 */
941 - cancelAll: function(){
942 - for (var i=0; i<this._queue.length; i++){
936 + cancelAll: function () {
937 + for (var i = 0; i < this._queue.length; i++) {
943 938 this._cancel(this._queue[i]);
944 939 }
945 940 this._queue = [];
946 941 },
@@ -946,39 +941,39 @@
946 941 },
947 942 /**
948 943 * Returns name of the file identified by id
949 944 */
950 - getName: function(id){},
945 + getName: function (id) { },
951 946 /**
952 947 * Returns size of the file identified by id
953 948 */
954 - getSize: function(id){},
949 + getSize: function (id) { },
955 950 /**
956 951 * Returns id of files being uploaded or
957 952 * waiting for their turn
958 953 */
959 - getQueue: function(){
954 + getQueue: function () {
960 955 return this._queue;
961 956 },
962 957 /**
963 958 * Actual upload method
964 959 */
965 - _upload: function(id){},
960 + _upload: function (id) { },
966 961 /**
967 962 * Actual cancel method
968 963 */
969 - _cancel: function(id){},
964 + _cancel: function (id) { },
970 965 /**
971 966 * Removes element from queue, starts upload of next
972 967 */
973 - _dequeue: function(id){
968 + _dequeue: function (id) {
974 969 var i = qq.indexOf(this._queue, id);
975 970 this._queue.splice(i, 1);
976 971
977 972 var max = this._options.maxConnections;
978 973
979 - if (this._queue.length >= max && i < max){
980 - var nextId = this._queue[max-1];
974 + if (this._queue.length >= max && i < max) {
975 + var nextId = this._queue[max - 1];
981 976 this._upload(nextId, this._params[nextId]);
982 977 }
983 978 }
984 979 };
@@ -986,9 +981,9 @@
986 981 /**
987 982 * Class for uploading files using form and iframe
988 983 * @inherits qq.UploadHandlerAbstract
989 984 */
990 -qq.UploadHandlerForm = function(o){
985 +qq.UploadHandlerForm = function (o) {
991 986 qq.UploadHandlerAbstract.apply(this, arguments);
992 987
993 988 this._inputs = {};
994 989 };
@@ -995,9 +990,9 @@
995 990 // @inherits qq.UploadHandlerAbstract
996 991 qq.extend(qq.UploadHandlerForm.prototype, qq.UploadHandlerAbstract.prototype);
997 992
998 993 qq.extend(qq.UploadHandlerForm.prototype, {
999 - add: function(fileInput){
994 + add: function (fileInput) {
1000 995 fileInput.setAttribute('name', 'qqfile');
1001 996 var id = 'qq-upload-handler-iframe' + qq.getUniqueId();
1002 997
1003 998 this._inputs[id] = fileInput;
@@ -1002,25 +997,25 @@
1002 997
1003 998 this._inputs[id] = fileInput;
1004 999
1005 1000 // remove file input from DOM
1006 - if (fileInput.parentNode){
1001 + if (fileInput.parentNode) {
1007 1002 qq.remove(fileInput);
1008 1003 }
1009 1004
1010 1005 return id;
1011 1006 },
1012 - getName: function(id){
1007 + getName: function (id) {
1013 1008 // get input value and remove path to normalize
1014 1009 return this._inputs[id].value.replace(/.*(\/|\\)/, "");
1015 1010 },
1016 - _cancel: function(id){
1011 + _cancel: function (id) {
1017 1012 this._options.onCancel(id, this.getName(id));
1018 1013
1019 1014 delete this._inputs[id];
1020 1015
1021 1016 var iframe = document.getElementById(id);
1022 - if (iframe){
1017 + if (iframe) {
1023 1018 // to cancel request set src to something else
1024 1019 // we use src="javascript:false;" because it doesn't
1025 1020 // trigger ie6 prompt on https
1026 1021 iframe.setAttribute('src', 'javascript:false;');
@@ -1027,12 +1022,12 @@
1027 1022
1028 1023 qq.remove(iframe);
1029 1024 }
1030 1025 },
1031 - _upload: function(id, params){
1026 + _upload: function (id, params) {
1032 1027 var input = this._inputs[id];
1033 1028
1034 - if (!input){
1029 + if (!input) {
1035 1030 throw new Error('file with passed id was not added, or already uploaded or cancelled');
1036 1031 }
1037 1032
1038 1033 var fileName = this.getName(id);
@@ -1041,9 +1036,9 @@
1041 1036 var form = this._createForm(iframe, params);
1042 1037 form.appendChild(input);
1043 1038
1044 1039 var self = this;
1045 - this._attachLoadEvent(iframe, function(){
1040 + this._attachLoadEvent(iframe, function () {
1046 1041 self.log('iframe loaded');
1047 1042
1048 1043 var response = self._getIframeContentJSON(iframe);
1049 1044
@@ -1051,9 +1046,9 @@
1051 1046 self._dequeue(id);
1052 1047
1053 1048 delete self._inputs[id];
1054 1049 // timeout added to fix busy state in FF3.6
1055 - setTimeout(function(){
1050 + setTimeout(function () {
1056 1051 qq.remove(iframe);
1057 1052 }, 1);
1058 1053 });
1059 1054
@@ -1061,14 +1056,14 @@
1061 1056 qq.remove(form);
1062 1057
1063 1058 return id;
1064 1059 },
1065 - _attachLoadEvent: function(iframe, callback){
1066 - qq.attach(iframe, 'load', function(){
1060 + _attachLoadEvent: function (iframe, callback) {
1061 + qq.attach(iframe, 'load', function () {
1067 1062 // when we remove iframe from dom
1068 1063 // the request stops, but in IE load
1069 1064 // event fires
1070 - if (!iframe.parentNode){
1065 + if (!iframe.parentNode) {
1071 1066 return;
1072 1067 }
1073 1068
1074 1069 // fixing Opera 10.53
@@ -1073,9 +1068,9 @@
1073 1068
1074 1069 // fixing Opera 10.53
1075 1070 if (iframe.contentDocument &&
1076 1071 iframe.contentDocument.body &&
1077 - iframe.contentDocument.body.innerHTML == "false"){
1072 + iframe.contentDocument.body.innerHTML == "false") {
1078 1073 // In Opera event is fired second time
1079 1074 // when body.innerHTML changed from false
1080 1075 // to server response approx. after 1 sec
1081 1076 // when we upload file with iframe
@@ -1087,11 +1082,11 @@
1087 1082 },
1088 1083 /**
1089 1084 * Returns json object received by iframe from server.
1090 1085 */
1091 - _getIframeContentJSON: function(iframe){
1086 + _getIframeContentJSON: function (iframe) {
1092 1087 // iframe.contentWindow.document - for IE<7
1093 - var doc = iframe.contentDocument ? iframe.contentDocument: iframe.contentWindow.document,
1088 + var doc = iframe.contentDocument ? iframe.contentDocument : iframe.contentWindow.document,
1094 1089 response;
1095 1090
1096 1091 this.log("converting iframe's innerHTML to JSON");
1097 1092 this.log("innerHTML = " + doc.body.innerHTML);
@@ -1097,9 +1092,9 @@
1097 1092 this.log("innerHTML = " + doc.body.innerHTML);
1098 1093
1099 1094 try {
1100 1095 response = eval("(" + doc.body.innerHTML + ")");
1101 - } catch(err){
1096 + } catch {
1102 1097 response = {};
1103 1098 }
1104 1099
1105 1100 return response;
@@ -1106,9 +1101,9 @@
1106 1101 },
1107 1102 /**
1108 1103 * Creates iframe with unique name
1109 1104 */
1110 - _createIframe: function(id){
1105 + _createIframe: function (id) {
1111 1106 // We can't use following code as the name attribute
1112 1107 // won't be properly registered in IE6, and new window
1113 1108 // on form submit will open
1114 1109 // var iframe = document.createElement('iframe');
@@ -1126,9 +1121,9 @@
1126 1121 },
1127 1122 /**
1128 1123 * Creates form, that will be submitted to iframe
1129 1124 */
1130 - _createForm: function(iframe, params){
1125 + _createForm: function (iframe, params) {
1131 1126 // We can't use the following code in IE6
1132 1127 // var form = document.createElement('form');
1133 1128 // form.setAttribute('method', 'post');
1134 1129 // form.setAttribute('enctype', 'multipart/form-data');
@@ -1149,9 +1144,9 @@
1149 1144 /**
1150 1145 * Class for uploading files using xhr
1151 1146 * @inherits qq.UploadHandlerAbstract
1152 1147 */
1153 -qq.UploadHandlerXhr = function(o){
1148 +qq.UploadHandlerXhr = function (o) {
1154 1149 qq.UploadHandlerAbstract.apply(this, arguments);
1155 1150
1156 1151 this._files = [];
1157 1152 this._xhrs = [];
@@ -1160,16 +1155,16 @@
1160 1155 this._loaded = [];
1161 1156 };
1162 1157
1163 1158 // static method
1164 -qq.UploadHandlerXhr.isSupported = function(){
1159 +qq.UploadHandlerXhr.isSupported = function () {
1165 1160 var input = document.createElement('input');
1166 1161 input.type = 'file';
1167 1162
1168 1163 return (
1169 - 'multiple' in input &&
1170 - typeof File != "undefined" &&
1171 - typeof (new XMLHttpRequest()).upload != "undefined" );
1164 + 'multiple' in input &&
1165 + typeof File != "undefined" &&
1166 + typeof (new XMLHttpRequest()).upload != "undefined");
1172 1167 };
1173 1168
1174 1169 // @inherits qq.UploadHandlerAbstract
1175 1170 qq.extend(qq.UploadHandlerXhr.prototype, qq.UploadHandlerAbstract.prototype)
@@ -1178,21 +1173,21 @@
1178 1173 /**
1179 1174 * Adds file to the queue
1180 1175 * Returns id to use with upload, cancel
1181 1176 **/
1182 - add: function(file){
1183 - if (!(file instanceof File)){
1177 + add: function (file) {
1178 + if (!(file instanceof File)) {
1184 1179 throw new Error('Passed obj in not a File (in qq.UploadHandlerXhr)');
1185 1180 }
1186 1181
1187 1182 return this._files.push(file) - 1;
1188 1183 },
1189 - getName: function(id){
1184 + getName: function (id) {
1190 1185 var file = this._files[id];
1191 1186 // fix missing name in Safari 4
1192 1187 return file.fileName != null ? file.fileName : file.name;
1193 1188 },
1194 - getSize: function(id){
1189 + getSize: function (id) {
1195 1190 var file = this._files[id];
1196 1191 return file.fileSize != null ? file.fileSize : file.size;
1197 1192 },
1198 1193 /**
@@ -1197,9 +1192,9 @@
1197 1192 },
1198 1193 /**
1199 1194 * Returns uploaded bytes for file identified by id
1200 1195 */
1201 - getLoaded: function(id){
1196 + getLoaded: function (id) {
1202 1197 return this._loaded[id] || 0;
1203 1198 },
1204 1199 /**
1205 1200 * Sends the file identified by id and additional query params to the server
@@ -1204,9 +1199,9 @@
1204 1199 /**
1205 1200 * Sends the file identified by id and additional query params to the server
1206 1201 * @param {Object} params name-value string pairs
1207 1202 */
1208 - _upload: function(id, params){
1203 + _upload: function (id, params) {
1209 1204 var file = this._files[id],
1210 1205 name = this.getName(id),
1211 1206 size = this.getSize(id);
1212 1207
@@ -1214,17 +1209,17 @@
1214 1209
1215 1210 var xhr = this._xhrs[id] = new XMLHttpRequest();
1216 1211 var self = this;
1217 1212
1218 - xhr.upload.onprogress = function(e){
1219 - if (e.lengthComputable){
1213 + xhr.upload.onprogress = function (e) {
1214 + if (e.lengthComputable) {
1220 1215 self._loaded[id] = e.loaded;
1221 1216 self._options.onProgress(id, name, e.loaded, e.total);
1222 1217 }
1223 1218 };
1224 1219
1225 - xhr.onreadystatechange = function(){
1226 - if (xhr.readyState == 4){
1220 + xhr.onreadystatechange = function () {
1221 + if (xhr.readyState == 4) {
1227 1222 self._onComplete(id, xhr);
1228 1223 }
1229 1224 };
1230 1225
@@ -1237,9 +1232,9 @@
1237 1232 xhr.setRequestHeader("X-File-Name", encodeURIComponent(name));
1238 1233 xhr.setRequestHeader("Content-Type", "application/octet-stream");
1239 1234 xhr.send(file);
1240 1235 },
1241 - _onComplete: function(id, xhr){
1236 + _onComplete: function (id, xhr) {
1242 1237 // the request was aborted/cancelled
1243 1238 if (!this._files[id]) return;
1244 1239
1245 1240 var name = this.getName(id);
@@ -1246,9 +1241,9 @@
1246 1241 var size = this.getSize(id);
1247 1242
1248 1243 this._options.onProgress(id, name, size, size);
1249 1244
1250 - if (xhr.status == 200){
1245 + if (xhr.status == 200) {
1251 1246 this.log("xhr - server response received");
1252 1247 this.log("responseText = " + xhr.responseText);
1253 1248
1254 1249 var response;
@@ -1254,9 +1249,9 @@
1254 1249 var response;
1255 1250
1256 1251 try {
1257 1252 response = eval("(" + xhr.responseText + ")");
1258 - } catch(err){
1253 + } catch (err) {
1259 1254 response = {};
1260 1255 }
1261 1256
1262 1257 this._options.onComplete(id, name, response);
@@ -1268,15 +1263,15 @@
1268 1263 this._files[id] = null;
1269 1264 this._xhrs[id] = null;
1270 1265 this._dequeue(id);
1271 1266 },
1272 - _cancel: function(id){
1267 + _cancel: function (id) {
1273 1268 this._options.onCancel(id, this.getName(id));
1274 1269
1275 1270 this._files[id] = null;
1276 1271
1277 - if (this._xhrs[id]){
1272 + if (this._xhrs[id]) {
1278 1273 this._xhrs[id].abort();
1279 1274 this._xhrs[id] = null;
1280 1275 }
1281 1276 }
1282 1277 });