Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1513 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 1513 Revision 1551
Zeile 1... Zeile 1...
1
/*
1
/*
2
 * jQuery File Upload User Interface Plugin 5.0.17
2
 * jQuery File Upload User Interface Plugin
3
 * https://github.com/blueimp/jQuery-File-Upload
3
 * https://github.com/blueimp/jQuery-File-Upload
4
 *
4
 *
5
 * Copyright 2010, Sebastian Tschan
5
 * Copyright 2010, Sebastian Tschan
6
 * https://blueimp.net
6
 * https://blueimp.net
7
 *
7
 *
8
 * Licensed under the MIT license:
8
 * Licensed under the MIT license:
9
 * http://creativecommons.org/licenses/MIT/
9
 * https://opensource.org/licenses/MIT
10
 */
10
 */
Zeile 11... Zeile 11...
11
 
11
 
12
/*jslint nomen: true, unparam: true, regexp: true */
-
 
Zeile -... Zeile 89...
-
 
89
        return [];
-
 
90
      },
-
 
91
 
-
 
92
      // The add callback is invoked as soon as files are added to the fileupload
-
 
93
      // widget (via file input selection, drag & drop or add API call).
-
 
94
      // See the basic file upload widget for more information:
-
 
95
      add: function (e, data) {
-
 
96
        if (e.isDefaultPrevented()) {
-
 
97
          return false;
-
 
98
        }
-
 
99
        var $this = $(this),
-
 
100
          that = $this.data('blueimp-fileupload') || $this.data('fileupload'),
-
 
101
          options = that.options;
-
 
102
        data.context = that
-
 
103
          ._renderUpload(data.files)
-
 
104
          .data('data', data)
-
 
105
          .addClass('processing');
-
 
106
        options.filesContainer[options.prependFiles ? 'prepend' : 'append'](
-
 
107
          data.context
-
 
108
        );
310
            });
109
        that._forceReflow(data.context);
-
 
110
        that._transition(data.context);
-
 
111
        data
-
 
112
          .process(function () {
-
 
113
            return $this.fileupload('process', data);
-
 
114
          })
-
 
115
          .always(function () {
-
 
116
            data.context
311
        },
117
              .each(function (index) {
-
 
118
                $(this)
-
 
119
                  .find('.size')
-
 
120
                  .text(that._formatFileSize(data.files[index].size));
-
 
121
              })
-
 
122
              .removeClass('processing');
-
 
123
            that._renderPreviews(data);
-
 
124
          })
-
 
125
          .done(function () {
312
 
126
            data.context.find('.edit,.start').prop('disabled', false);
-
 
127
            if (
-
 
128
              that._trigger('added', e, data) !== false &&
-
 
129
              (options.autoUpload || data.autoUpload) &&
-
 
130
              data.autoUpload !== false
-
 
131
            ) {
-
 
132
              data.submit();
-
 
133
            }
313
        _adjustMaxNumberOfFiles: function (operand) {
134
          })
314
            if (typeof this.options.maxNumberOfFiles === 'number') {
135
          .fail(function () {
315
                this.options.maxNumberOfFiles += operand;
136
            if (data.files.error) {
316
                if (this.options.maxNumberOfFiles < 1) {
137
              data.context.each(function (index) {
317
                    this._disableFileInputButton();
138
                var error = data.files[index].error;
-
 
139
                if (error) {
318
                } else {
140
                  $(this).find('.error').text(error);
319
                    this._enableFileInputButton();
141
                }
320
                }
142
              });
-
 
143
            }
321
            }
144
          });
322
        },
145
      },
323
 
146
      // Callback for the start of each file upload request:
324
        _formatFileSize: function (file) {
147
      send: function (e, data) {
325
            if (typeof file.size !== 'number') {
148
        if (e.isDefaultPrevented()) {
326
                return '';
149
          return false;
327
            }
150
        }
328
            if (file.size >= 1000000000) {
151
        var that =
329
                return (file.size / 1000000000).toFixed(2) + ' GB';
-
 
330
            }
152
          $(this).data('blueimp-fileupload') || $(this).data('fileupload');
331
            if (file.size >= 1000000) {
153
        if (
332
                return (file.size / 1000000).toFixed(2) + ' MB';
154
          data.context &&
333
            }
-
 
334
            return (file.size / 1000).toFixed(2) + ' KB';
155
          data.dataType &&
335
        },
156
          data.dataType.substr(0, 6) === 'iframe'
336
 
157
        ) {
337
        _hasError: function (file) {
158
          // Iframe Transport does not support progress events.
338
            if (file.error) {
159
          // In lack of an indeterminate progress bar, we set
339
                return file.error;
160
          // the progress to 100%, showing the full animated bar:
340
            }
161
          data.context
341
            // The number of added files is subtracted from
162
            .find('.progress')
-
 
163
            .addClass(!$.support.transition && 'progress-animated')
342
            // maxNumberOfFiles before validation, so we check if
164
            .attr('aria-valuenow', 100)
343
            // maxNumberOfFiles is below 0 (instead of below 1):
165
            .children()
344
            if (this.options.maxNumberOfFiles < 0) {
166
            .first()
345
                return 'maxNumberOfFiles';
167
            .css('width', '100%');
346
            }
168
        }
347
            // Files are accepted if either the file type or the file name
169
        return that._trigger('sent', e, data);
348
            // matches against the acceptFileTypes regular expression, as
170
      },
349
            // only browsers with support for the File API report the type:
171
      // Callback for successful uploads:
350
            if (!(this.options.acceptFileTypes.test(file.type) ||
172
      done: function (e, data) {
351
                    this.options.acceptFileTypes.test(file.name))) {
173
        if (e.isDefaultPrevented()) {
352
                return 'acceptFileTypes';
174
          return false;
353
            }
175
        }
354
            if (this.options.maxFileSize &&
-
 
355
                    file.size > this.options.maxFileSize) {
-
 
356
                return 'maxFileSize';
176
        var that =
357
            }
177
            $(this).data('blueimp-fileupload') || $(this).data('fileupload'),
358
            if (typeof file.size === 'number' &&
178
          getFilesFromResponse =
359
                    file.size < this.options.minFileSize) {
179
            data.getFilesFromResponse || that.options.getFilesFromResponse,
360
                return 'minFileSize';
180
          files = getFilesFromResponse(data),
361
            }
-
 
362
            return null;
181
          template,
-
 
182
          deferred;
-
 
183
        if (data.context) {
-
 
184
          data.context.each(function (index) {
363
        },
185
            var file = files[index] || { error: 'Empty file upload result' };
-
 
186
            deferred = that._addFinishedDeferreds();
364
 
187
            that._transition($(this)).done(function () {
365
        _validate: function (files) {
188
              var node = $(this);
366
            var that = this,
189
              template = that._renderDownload([file]).replaceAll(node);
-
 
190
              that._forceReflow(template);
367
                valid = !!files.length;
191
              that._transition(template).done(function () {
368
            $.each(files, function (index, file) {
192
                data.context = $(this);
369
                file.error = that._hasError(file);
193
                that._trigger('completed', e, data);
370
                if (file.error) {
194
                that._trigger('finished', e, data);
371
                    valid = false;
-
 
372
                }
195
                deferred.resolve();
373
            });
-
 
374
            return valid;
-
 
375
        },
-
 
376
 
-
 
377
        _uploadTemplateHelper: function (file) {
196
              });
378
            file.sizef = this._formatFileSize(file);
-
 
379
            return file;
-
 
380
        },
197
            });
381
 
198
          });
382
        _renderUploadTemplate: function (files) {
199
        } else {
383
            var that = this;
200
          template = that
384
            return $.tmpl(
-
 
385
                this.options.uploadTemplate,
-
 
386
                $.map(files, function (file) {
201
            ._renderDownload(files)
387
                    return that._uploadTemplateHelper(file);
202
            [that.options.prependFiles ? 'prependTo' : 'appendTo'](
388
                })
-
 
-
 
203
              that.options.filesContainer
389
            );
204
            );
390
        },
205
          that._forceReflow(template);
391
 
206
          deferred = that._addFinishedDeferreds();
392
        _renderUpload: function (files) {
207
          that._transition(template).done(function () {
393
            var that = this,
208
            data.context = $(this);
-
 
209
            that._trigger('completed', e, data);
-
 
210
            that._trigger('finished', e, data);
-
 
211
            deferred.resolve();
-
 
212
          });
-
 
213
        }
394
                options = this.options,
214
      },
395
                tmpl = this._renderUploadTemplate(files),
215
      // Callback for failed (abort or error) uploads:
396
                isValidated = this._validate(files);
216
      fail: function (e, data) {
397
            if (!(tmpl instanceof $)) {
217
        if (e.isDefaultPrevented()) {
398
                return $();
218
          return false;
399
            }
219
        }
400
            tmpl.css('display', 'none');
220
        var that =
401
            // .slice(1).remove().end().first() removes all but the first
221
            $(this).data('blueimp-fileupload') || $(this).data('fileupload'),
402
            // element and selects only the first for the jQuery collection:
222
          template,
403
            tmpl.find('.progress div').slice(
223
          deferred;
404
                isValidated ? 1 : 0
224
        if (data.context) {
-
 
225
          data.context.each(function (index) {
405
            ).remove().end().first()
226
            if (data.errorThrown !== 'abort') {
406
                .progressbar();
227
              var file = data.files[index];
407
            tmpl.find('.start button').slice(
228
              file.error =
408
                this.options.autoUpload || !isValidated ? 0 : 1
229
                file.error || data.errorThrown || data.i18n('unknownError');
409
            ).remove().end().first()
230
              deferred = that._addFinishedDeferreds();
410
                .uibutton({
231
              that._transition($(this)).done(function () {
411
                    text: false,
232
                var node = $(this);
412
                    icons: {primary: 'ui-icon-circle-arrow-e'}
233
                template = that._renderDownload([file]).replaceAll(node);
413
                });
234
                that._forceReflow(template);
414
            tmpl.find('.cancel button').slice(1).remove().end().first()
235
                that._transition(template).done(function () {
-
 
236
                  data.context = $(this);
415
                .uibutton({
237
                  that._trigger('failed', e, data);
416
                    text: false,
-
 
417
                    icons: {primary: 'ui-icon-cancel'}
-
 
418
                });
-
 
419
            tmpl.find('.preview').each(function (index, node) {
-
 
420
                that._loadImage(
-
 
421
                    files[index],
-
 
422
                    function (img) {
-
 
423
                        $(img).hide().appendTo(node).fadeIn();
-
 
424
                    },
-
 
425
                    {
-
 
426
                        maxWidth: options.previewMaxWidth,
-
 
427
                        maxHeight: options.previewMaxHeight,
-
 
428
                        fileTypes: options.previewFileTypes,
238
                  that._trigger('finished', e, data);
429
                        canvas: options.previewAsCanvas
-
 
430
                    }
-
 
431
                );
-
 
432
            });
-
 
433
            return tmpl;
-
 
434
        },
-
 
435
 
-
 
436
        _downloadTemplateHelper: function (file) {
-
 
437
            file.sizef = this._formatFileSize(file);
-
 
438
            return file;
-
 
439
        },
-
 
440
 
-
 
441
        _renderDownloadTemplate: function (files) {
-
 
442
            var that = this;
-
 
443
            return $.tmpl(
-
 
444
                this.options.downloadTemplate,
-
 
445
                $.map(files, function (file) {
-
 
446
                    return that._downloadTemplateHelper(file);
-
 
447
                })
-
 
448
            );
-
 
449
        },
-
 
450
        
-
 
451
        _renderDownload: function (files) {
-
 
452
            var tmpl = this._renderDownloadTemplate(files);
-
 
453
            if (!(tmpl instanceof $)) {
-
 
454
                return $();
-
 
455
            }
-
 
456
            tmpl.css('display', 'none');
-
 
457
            tmpl.find('.delete button').uibutton({
-
 
458
                text: false,
-
 
459
                icons: {primary: 'ui-icon-trash'}
-
 
460
            });
-
 
461
            tmpl.find('a').each(this._enableDragToDesktop);
-
 
462
            return tmpl;
-
 
463
        },
-
 
464
        
-
 
465
        _startHandler: function (e) {
-
 
466
            e.preventDefault();
-
 
467
            var tmpl = $(this).closest('.template-upload'),
-
 
468
                data = tmpl.data('data');
-
 
469
            if (data && data.submit && !data.jqXHR) {
-
 
470
                data.jqXHR = data.submit();
-
 
471
                $(this).fadeOut();
-
 
472
            }
-
 
473
        },
-
 
474
        
-
 
475
        _cancelHandler: function (e) {
-
 
476
            e.preventDefault();
-
 
477
            var tmpl = $(this).closest('.template-upload'),
-
 
478
                data = tmpl.data('data') || {};
-
 
479
            if (!data.jqXHR) {
239
                  deferred.resolve();
-
 
240
                });
-
 
241
              });
480
                data.errorThrown = 'abort';
242
            } else {
-
 
243
              deferred = that._addFinishedDeferreds();
-
 
244
              that._transition($(this)).done(function () {
-
 
245
                $(this).remove();
-
 
246
                that._trigger('failed', e, data);
481
                e.data.fileupload._trigger('fail', e, data);
247
                that._trigger('finished', e, data);
482
            } else {
248
                deferred.resolve();
483
                data.jqXHR.abort();
-
 
484
            }
249
              });
485
        },
250
            }
486
        
251
          });
487
        _deleteHandler: function (e) {
252
        } else if (data.errorThrown !== 'abort') {
488
            e.preventDefault();
253
          data.context = that
-
 
254
            ._renderUpload(data.files)
489
            var button = $(this);
255
            [that.options.prependFiles ? 'prependTo' : 'appendTo'](
490
            e.data.fileupload._trigger('destroy', e, {
256
              that.options.filesContainer
-
 
257
            )
-
 
258
            .data('data', data);
-
 
259
          that._forceReflow(data.context);
491
                context: button.closest('.template-download'),
260
          deferred = that._addFinishedDeferreds();
-
 
261
          that._transition(data.context).done(function () {
-
 
262
            data.context = $(this);
492
                url: button.attr('data-url'),
263
            that._trigger('failed', e, data);
-
 
264
            that._trigger('finished', e, data);
-
 
265
            deferred.resolve();
-
 
266
          });
-
 
267
        } else {
493
                type: button.attr('data-type'),
268
          that._trigger('failed', e, data);
494
                dataType: e.data.fileupload.options.dataType
269
          that._trigger('finished', e, data);
-
 
270
          that._addFinishedDeferreds().resolve();
495
            });
271
        }
-
 
272
      },
-
 
273
      // Callback for upload progress events:
-
 
274
      progress: function (e, data) {
496
        },
275
        if (e.isDefaultPrevented()) {
-
 
276
          return false;
-
 
277
        }
-
 
278
        var progress = Math.floor((data.loaded / data.total) * 100);
497
        
279
        if (data.context) {
498
        _initEventHandlers: function () {
280
          data.context.each(function () {
499
            $.blueimp.fileupload.prototype._initEventHandlers.call(this);
281
            $(this)
500
            var filesList = this.element.find('.files'),
282
              .find('.progress')
501
                eventData = {fileupload: this};
283
              .attr('aria-valuenow', progress)
-
 
284
              .children()
-
 
285
              .first()
-
 
286
              .css('width', progress + '%');
-
 
287
          });
-
 
288
        }
-
 
289
      },
-
 
290
      // Callback for global upload progress events:
-
 
291
      progressall: function (e, data) {
502
            filesList.find('.start button')
292
        if (e.isDefaultPrevented()) {
-
 
293
          return false;
-
 
294
        }
-
 
295
        var $this = $(this),
-
 
296
          progress = Math.floor((data.loaded / data.total) * 100),
503
                .on(
297
          globalProgressNode = $this.find('.fileupload-progress'),
504
                    'click.' + this.options.namespace,
298
          extendedProgressNode = globalProgressNode.find('.progress-extended');
-
 
299
        if (extendedProgressNode.length) {
505
                    eventData,
300
          extendedProgressNode.html(
-
 
301
            (
-
 
302
              $this.data('blueimp-fileupload') || $this.data('fileupload')
-
 
303
            )._renderExtendedProgress(data)
-
 
304
          );
-
 
305
        }
506
                    this._startHandler
306
        globalProgressNode
-
 
307
          .find('.progress')
507
                );
308
          .attr('aria-valuenow', progress)
-
 
309
          .children()
-
 
310
          .first()
-
 
311
          .css('width', progress + '%');
508
            filesList.find('.cancel button')
312
      },
509
                .on(
313
      // Callback for uploads start, equivalent to the global ajaxStart event:
-
 
314
      start: function (e) {
510
                    'click.' + this.options.namespace,
315
        if (e.isDefaultPrevented()) {
-
 
316
          return false;
511
                    eventData,
317
        }
512
                    this._cancelHandler
318
        var that =
513
                );
319
          $(this).data('blueimp-fileupload') || $(this).data('fileupload');
514
            filesList.find('.delete button')
320
        that._resetFinishedDeferreds();
515
                .on(
321
        that
516
                    'click.' + this.options.namespace,
322
          ._transition($(this).find('.fileupload-progress'))
517
                    eventData,
323
          .done(function () {
518
                    this._deleteHandler
-
 
-
 
324
            that._trigger('started', e);
519
                );
325
          });
-
 
326
      },
-
 
327
      // Callback for uploads stop, equivalent to the global ajaxStop event:
-
 
328
      stop: function (e) {
-
 
329
        if (e.isDefaultPrevented()) {
-
 
330
          return false;
520
        },
331
        }
-
 
332
        var that =
521
        
333
            $(this).data('blueimp-fileupload') || $(this).data('fileupload'),
-
 
334
          deferred = that._addFinishedDeferreds();
-
 
335
        $.when.apply($, that._getFinishedDeferreds()).done(function () {
522
        _destroyEventHandlers: function () {
336
          that._trigger('stopped', e);
-
 
337
        });
-
 
338
        that
523
            var filesList = this.element.find('.files');
339
          ._transition($(this).find('.fileupload-progress'))
524
            filesList.find('.start button')
340
          .done(function () {
525
                .die('click.' + this.options.namespace);
341
            $(this)
-
 
342
              .find('.progress')
526
            filesList.find('.cancel button')
343
              .attr('aria-valuenow', '0')
527
                .die('click.' + this.options.namespace);
344
              .children()
-
 
345
              .first()
-
 
346
              .css('width', '0%');
-
 
347
            $(this).find('.progress-extended').html('&nbsp;');
-
 
348
            deferred.resolve();
-
 
349
          });
-
 
350
      },
528
            filesList.find('.delete button')
351
      processstart: function (e) {
-
 
352
        if (e.isDefaultPrevented()) {
529
                .die('click.' + this.options.namespace);
353
          return false;
530
            $.blueimp.fileupload.prototype._destroyEventHandlers.call(this);
354
        }
-
 
355
        $(this).addClass('fileupload-processing');
-
 
356
      },
-
 
357
      processstop: function (e) {
531
        },
358
        if (e.isDefaultPrevented()) {
-
 
359
          return false;
532
 
360
        }
-
 
361
        $(this).removeClass('fileupload-processing');
533
        _initFileUploadButtonBar: function () {
362
      },
534
            var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
363
      // Callback for file deletion:
-
 
364
      destroy: function (e, data) {
-
 
365
        if (e.isDefaultPrevented()) {
535
                filesList = this.element.find('.files'),
366
          return false;
536
                ns = this.options.namespace;
367
        }
537
            fileUploadButtonBar
368
        var that =
538
                .addClass('ui-widget-header ui-corner-top');
369
            $(this).data('blueimp-fileupload') || $(this).data('fileupload'),
539
            this.element.find('.fileinput-button').each(function () {
370
          removeNode = function () {
540
                var fileInput = $(this).find('input:file').detach();
371
            that._transition(data.context).done(function () {
541
                $(this).uibutton({icons: {primary: 'ui-icon-plusthick'}})
-
 
542
                    .append(fileInput);
-
 
543
            });
-
 
544
            fileUploadButtonBar.find('.start')
-
 
545
                .uibutton({icons: {primary: 'ui-icon-circle-arrow-e'}})
-
 
546
                .bind('click.' + ns, function (e) {
372
              $(this).remove();
547
                    e.preventDefault();
-
 
548
                    filesList.find('.start button').click();
-
 
549
                });
-
 
550
            fileUploadButtonBar.find('.cancel')
-
 
551
                .uibutton({icons: {primary: 'ui-icon-cancel'}})
-
 
552
                .bind('click.' + ns, function (e) {
373
              that._trigger('destroyed', e, data);
553
                    e.preventDefault();
-
 
554
                    filesList.find('.cancel button').click();
-
 
555
                });
-
 
556
            fileUploadButtonBar.find('.delete')
-
 
557
                .uibutton({icons: {primary: 'ui-icon-trash'}})
374
            });
558
                .bind('click.' + ns, function (e) {
375
          };
559
                    e.preventDefault();
-
 
560
                    filesList.find('.delete button').click();
-
 
561
                });
-
 
562
        },
376
        if (data.url) {
563
        
-
 
564
        _destroyFileUploadButtonBar: function () {
-
 
565
            this.element.find('.fileupload-buttonbar')
-
 
566
                .removeClass('ui-widget-header ui-corner-top');
377
          data.dataType = data.dataType || that.options.dataType;
567
            this.element.find('.fileinput-button').each(function () {
378
          $.ajax(data)
568
                var fileInput = $(this).find('input:file').detach();
379
            .done(removeNode)
569
                $(this).uibutton('destroy')
-
 
570
                    .append(fileInput);
-
 
571
            });
-
 
572
            this.element.find('.fileupload-buttonbar button')
380
            .fail(function () {
573
                .unbind('click.' + this.options.namespace)
-
 
574
                .uibutton('destroy');
-
 
575
        },
-
 
576
 
-
 
577
        _enableFileInputButton: function () {
-
 
578
            this.element.find('.fileinput-button input:file:disabled')
-
 
579
                .each(function () {
-
 
580
                    var fileInput = $(this),
-
 
581
                        button = fileInput.parent();
381
              that._trigger('destroyfailed', e, data);
582
                    fileInput.detach().prop('disabled', false);
382
            });
583
                    button.uibutton('enable').append(fileInput);
-
 
584
                });
-
 
585
        },
-
 
586
 
-
 
587
        _disableFileInputButton: function () {
-
 
588
            this.element.find('.fileinput-button input:file:enabled')
-
 
589
                .each(function () {
-
 
590
                    var fileInput = $(this),
-
 
591
                        button = fileInput.parent();
383
        } else {
592
                    fileInput.detach().prop('disabled', true);
384
          removeNode();
Zeile 593... Zeile 385...
593
                    button.uibutton('disable').append(fileInput);
385
        }
-
 
386
      }
-
 
387
    },
-
 
388
 
-
 
389
    _resetFinishedDeferreds: function () {
594
                });
390
      this._finishedUploads = [];
595
        },
391
    },
596
 
392
 
-
 
393
    _addFinishedDeferreds: function (deferred) {
-
 
394
      // eslint-disable-next-line new-cap
-
 
395
      var promise = deferred || $.Deferred();
-
 
396
      this._finishedUploads.push(promise);
597
        _initTemplates: function () {
397
      return promise;
-
 
398
    },
-
 
399
 
598
            // Handle cases where the templates are defined
400
    _getFinishedDeferreds: function () {
599
            // after the widget library has been included:
401
      return this._finishedUploads;
-
 
402
    },
600
            if (this.options.uploadTemplate instanceof $ &&
403
 
601
                    !this.options.uploadTemplate.length) {
404
    // Link handler, that allows to download files
602
                this.options.uploadTemplate = $(
405
    // by drag & drop of the links to the desktop:
603
                    this.options.uploadTemplate.selector
406
    _enableDragToDesktop: function () {
604
                );
407
      var link = $(this),
-
 
408
        url = link.prop('href'),
605
            }
409
        name = link.prop('download'),
606
            if (this.options.downloadTemplate instanceof $ &&
410
        type = 'application/octet-stream';
-
 
411
      link.on('dragstart', function (e) {
607
                    !this.options.downloadTemplate.length) {
412
        try {
-
 
413
          e.originalEvent.dataTransfer.setData(
-
 
414
            'DownloadURL',
608
                this.options.downloadTemplate = $(
415
            [type, name, url].join(':')
-
 
416
          );
-
 
417
        } catch (ignore) {
Zeile -... Zeile 418...
-
 
418
          // Ignore exceptions
-
 
419
        }
-
 
420
      });
-
 
421
    },
-
 
422
 
-
 
423
    _formatFileSize: function (bytes) {
-
 
424
      if (typeof bytes !== 'number') {
-
 
425
        return '';
-
 
426
      }
-
 
427
      if (bytes >= 1000000000) {
-
 
428
        return (bytes / 1000000000).toFixed(2) + ' GB';
-
 
429
      }
-
 
430
      if (bytes >= 1000000) {
609
                    this.options.downloadTemplate.selector
431
        return (bytes / 1000000).toFixed(2) + ' MB';
-
 
432
      }
-
 
433
      return (bytes / 1000).toFixed(2) + ' KB';
-
 
434
    },
-
 
435
 
-
 
436
    _formatBitrate: function (bits) {
-
 
437
      if (typeof bits !== 'number') {
-
 
438
        return '';
-
 
439
      }
-
 
440
      if (bits >= 1000000000) {
-
 
441
        return (bits / 1000000000).toFixed(2) + ' Gbit/s';
-
 
442
      }
-
 
443
      if (bits >= 1000000) {
-
 
444
        return (bits / 1000000).toFixed(2) + ' Mbit/s';
-
 
445
      }
-
 
446
      if (bits >= 1000) {
-
 
447
        return (bits / 1000).toFixed(2) + ' kbit/s';
-
 
448
      }
-
 
449
      return bits.toFixed(2) + ' bit/s';
-
 
450
    },
-
 
451
 
-
 
452
    _formatTime: function (seconds) {
-
 
453
      var date = new Date(seconds * 1000),
-
 
454
        days = Math.floor(seconds / 86400);
-
 
455
      days = days ? days + 'd ' : '';
-
 
456
      return (
-
 
457
        days +
-
 
458
        ('0' + date.getUTCHours()).slice(-2) +
-
 
459
        ':' +
-
 
460
        ('0' + date.getUTCMinutes()).slice(-2) +
-
 
461
        ':' +
-
 
462
        ('0' + date.getUTCSeconds()).slice(-2)
-
 
463
      );
-
 
464
    },
-
 
465
 
-
 
466
    _formatPercentage: function (floatValue) {
-
 
467
      return (floatValue * 100).toFixed(2) + ' %';
-
 
468
    },
-
 
469
 
-
 
470
    _renderExtendedProgress: function (data) {
-
 
471
      return (
-
 
472
        this._formatBitrate(data.bitrate) +
-
 
473
        ' | ' +
-
 
474
        this._formatTime(((data.total - data.loaded) * 8) / data.bitrate) +
-
 
475
        ' | ' +
-
 
476
        this._formatPercentage(data.loaded / data.total) +
-
 
477
        ' | ' +
-
 
478
        this._formatFileSize(data.loaded) +
-
 
479
        ' / ' +
-
 
480
        this._formatFileSize(data.total)
-
 
481
      );
-
 
482
    },
-
 
483
 
-
 
484
    _renderTemplate: function (func, files) {
-
 
485
      if (!func) {
-
 
486
        return $();
-
 
487
      }
-
 
488
      var result = func({
-
 
489
        files: files,
-
 
490
        formatFileSize: this._formatFileSize,
610
                );
491
        options: this.options
-
 
492
      });
-
 
493
      if (result instanceof $) {
-
 
494
        return result;
-
 
495
      }
-
 
496
      return $(this.options.templatesContainer).html(result).children();
-
 
497
    },
-
 
498
 
-
 
499
    _renderPreviews: function (data) {
-
 
500
      data.context.find('.preview').each(function (index, elm) {
-
 
501
        $(elm).empty().append(data.files[index].preview);
-
 
502
      });
-
 
503
    },
-
 
504
 
-
 
505
    _renderUpload: function (files) {
-
 
506
      return this._renderTemplate(this.options.uploadTemplate, files);
611
            }
507
    },
-
 
508
 
-
 
509
    _renderDownload: function (files) {
-
 
510
      return this._renderTemplate(this.options.downloadTemplate, files)
-
 
511
        .find('a[download]')
-
 
512
        .each(this._enableDragToDesktop)
-
 
513
        .end();
-
 
514
    },
-
 
515
 
-
 
516
    _editHandler: function (e) {
-
 
517
      e.preventDefault();
-
 
518
      if (!this.options.edit) return;
-
 
519
      var that = this,
-
 
520
        button = $(e.currentTarget),
-
 
521
        template = button.closest('.template-upload'),
-
 
522
        data = template.data('data'),
-
 
523
        index = button.data().index;
612
        },
524
      this.options.edit(data.files[index]).then(function (file) {
-
 
525
        if (!file) return;
-
 
526
        data.files[index] = file;
-
 
527
        data.context.addClass('processing');
613
 
528
        template.find('.edit,.start').prop('disabled', true);
-
 
529
        $(that.element)
-
 
530
          .fileupload('process', data)
614
        _create: function () {
531
          .always(function () {
-
 
532
            template
-
 
533
              .find('.size')
615
            $.blueimp.fileupload.prototype._create.call(this);
534
              .text(that._formatFileSize(data.files[index].size));
-
 
535
            data.context.removeClass('processing');
-
 
536
            that._renderPreviews(data);
616
            this._initTemplates();
537
          })
617
            this.element
538
          .done(function () {
-
 
539
            template.find('.edit,.start').prop('disabled', false);
618
                .addClass('ui-widget');
540
          })
-
 
541
          .fail(function () {
619
            this._initFileUploadButtonBar();
542
            template.find('.edit').prop('disabled', false);
-
 
543
            var error = data.files[index].error;
-
 
544
            if (error) {
620
            this.element.find('.fileupload-content')
545
              template.find('.error').text(error);
621
                .addClass('ui-widget-content ui-corner-bottom');
546
            }
-
 
547
          });
-
 
548
      });
622
            this.element.find('.fileupload-progressbar')
549
    },
623
                .hide().progressbar();
550
 
-
 
551
    _startHandler: function (e) {
-
 
552
      e.preventDefault();
-
 
553
      var button = $(e.currentTarget),
-
 
554
        template = button.closest('.template-upload'),
-
 
555
        data = template.data('data');
-
 
556
      button.prop('disabled', true);
-
 
557
      if (data && data.submit) {
-
 
558
        data.submit();
-
 
559
      }
624
        },
560
    },
-
 
561
 
-
 
562
    _cancelHandler: function (e) {
625
        
563
      e.preventDefault();
-
 
564
      var template = $(e.currentTarget).closest(
-
 
565
          '.template-upload,.template-download'
-
 
566
        ),
-
 
567
        data = template.data('data') || {};
626
        destroy: function () {
568
      data.context = data.context || template;
-
 
569
      if (data.abort) {
-
 
570
        data.abort();
-
 
571
      } else {
-
 
572
        data.errorThrown = 'abort';
-
 
573
        this._trigger('fail', e, data);
627
            this.element.find('.fileupload-progressbar')
574
      }
-
 
575
    },
-
 
576
 
-
 
577
    _deleteHandler: function (e) {
-
 
578
      e.preventDefault();
-
 
579
      var button = $(e.currentTarget);
628
                .progressbar('destroy');
580
      this._trigger(
-
 
581
        'destroy',
629
            this.element.find('.fileupload-content')
582
        e,
-
 
583
        $.extend(
-
 
584
          {
-
 
585
            context: button.closest('.template-download'),
-
 
586
            type: 'DELETE'
630
                .removeClass('ui-widget-content ui-corner-bottom');
587
          },
631
            this._destroyFileUploadButtonBar();
588
          button.data()
-
 
589
        )
-
 
590
      );
-
 
591
    },
-
 
592
 
-
 
593
    _forceReflow: function (node) {
-
 
594
      return $.support.transition && node.length && node[0].offsetWidth;
-
 
595
    },
-
 
596
 
-
 
597
    _transition: function (node) {
-
 
598
      // eslint-disable-next-line new-cap
-
 
599
      var dfd = $.Deferred();
-
 
600
      if (
632
            this.element.removeClass('ui-widget');
601
        $.support.transition &&
633
            $.blueimp.fileupload.prototype.destroy.call(this);
602
        node.hasClass('fade') &&
634
        },
603
        node.is(':visible')
-
 
604
      ) {
635
        
605
        var transitionEndHandler = function (e) {
-
 
606
          // Make sure we don't respond to other transition events
636
        enable: function () {
607
          // in the container element, e.g. from button elements:
-
 
608
          if (e.target === node[0]) {
-
 
609
            node.off($.support.transition.end, transitionEndHandler);
-
 
610
            dfd.resolveWith(node);
-
 
611
          }
-
 
612
        };
-
 
613
        node
-
 
614
          .on($.support.transition.end, transitionEndHandler)
-
 
615
          .toggleClass(this.options.showElementClass);
-
 
616
      } else {
637
            $.blueimp.fileupload.prototype.enable.call(this);
617
        node.toggleClass(this.options.showElementClass);
-
 
618
        dfd.resolveWith(node);
-
 
619
      }
-
 
620
      return dfd;
-
 
621
    },
638
            this.element.find(':ui-button').not('.fileinput-button')
622
 
-
 
623
    _initButtonBarEventHandlers: function () {
639
                .uibutton('enable');
624
      var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
-
 
625
        filesList = this.options.filesContainer;
-
 
626
      this._on(fileUploadButtonBar.find('.start'), {
-
 
627
        click: function (e) {
640
            this._enableFileInputButton();
628
          e.preventDefault();
641
        },
629
          filesList.find('.start').trigger('click');
642
        
630
        }
643
        disable: function () {
631
      });
-
 
632
      this._on(fileUploadButtonBar.find('.cancel'), {
-
 
633
        click: function (e) {
-
 
634
          e.preventDefault();
-
 
635
          filesList.find('.cancel').trigger('click');
-
 
636
        }
-
 
637
      });
-
 
638
      this._on(fileUploadButtonBar.find('.delete'), {
-
 
639
        click: function (e) {
-
 
640
          e.preventDefault();
-
 
641
          filesList
-
 
642
            .find('.toggle:checked')
-
 
643
            .closest('.template-download')
-
 
644
            .find('.delete')
-
 
645
            .trigger('click');
-
 
646
          fileUploadButtonBar.find('.toggle').prop('checked', false);
-
 
647
        }
-
 
648
      });
-
 
649
      this._on(fileUploadButtonBar.find('.toggle'), {
-
 
650
        change: function (e) {
-
 
651
          filesList
Zeile -... Zeile 652...
-
 
652
            .find('.toggle')
-
 
653
            .prop('checked', $(e.currentTarget).is(':checked'));
-
 
654
        }
-
 
655
      });
-
 
656
    },
-
 
657
 
-
 
658
    _destroyButtonBarEventHandlers: function () {
-
 
659
      this._off(
-
 
660
        this.element
-
 
661
          .find('.fileupload-buttonbar')
-
 
662
          .find('.start, .cancel, .delete'),
-
 
663
        'click'
-
 
664
      );
-
 
665
      this._off(this.element.find('.fileupload-buttonbar .toggle'), 'change.');
-
 
666
    },
-
 
667
 
-
 
668
    _initEventHandlers: function () {
644
            this.element.find(':ui-button').not('.fileinput-button')
669
      this._super();
-
 
670
      this._on(this.options.filesContainer, {
-
 
671
        'click .edit': this._editHandler,
-
 
672
        'click .start': this._startHandler,
-
 
673
        'click .cancel': this._cancelHandler,
-
 
674
        'click .delete': this._deleteHandler
-
 
675
      });
-
 
676
      this._initButtonBarEventHandlers();
-
 
677
    },
-
 
678
 
-
 
679
    _destroyEventHandlers: function () {
-
 
680
      this._destroyButtonBarEventHandlers();
-
 
681
      this._off(this.options.filesContainer, 'click');
-
 
682
      this._super();
-
 
683
    },
-
 
684
 
-
 
685
    _enableFileInputButton: function () {
-
 
686
      this.element
-
 
687
        .find('.fileinput-button input')
-
 
688
        .prop('disabled', false)
-
 
689
        .parent()
-
 
690
        .removeClass('disabled');
-
 
691
    },
-
 
692
 
-
 
693
    _disableFileInputButton: function () {
-
 
694
      this.element
-
 
695
        .find('.fileinput-button input')
-
 
696
        .prop('disabled', true)
-
 
697
        .parent()
-
 
698
        .addClass('disabled');
-
 
699
    },
-
 
700
 
-
 
701
    _initTemplates: function () {
-
 
702
      var options = this.options;
-
 
703
      options.templatesContainer = this.document[0].createElement(
-
 
704
        options.filesContainer.prop('nodeName')
-
 
705
      );
-
 
706
      if (tmpl) {
-
 
707
        if (options.uploadTemplateId) {
-
 
708
          options.uploadTemplate = tmpl(options.uploadTemplateId);
Zeile 645... Zeile -...
645
                .uibutton('disable');
-
 
646
            this._disableFileInputButton();
709
        }
-
 
710
        if (options.downloadTemplateId) {
-
 
711
          options.downloadTemplate = tmpl(options.downloadTemplateId);
-
 
712
        }
-
 
713
      }
-
 
714
    },
-
 
715
 
-
 
716
    _initFilesContainer: function () {
-
 
717
      var options = this.options;
-
 
718
      if (options.filesContainer === undefined) {
-
 
719
        options.filesContainer = this.element.find('.files');
-
 
720
      } else if (!(options.filesContainer instanceof $)) {
-
 
721
        options.filesContainer = $(options.filesContainer);
-
 
722
      }
-
 
723
    },
-
 
724
 
-
 
725
    _initSpecialOptions: function () {
-
 
726
      this._super();
-
 
727
      this._initFilesContainer();
-
 
728
      this._initTemplates();
-
 
729
    },
-
 
730
 
-
 
731
    _create: function () {
-
 
732
      this._super();
-
 
733
      this._resetFinishedDeferreds();
-
 
734
      if (!$.support.fileInput) {
-
 
735
        this._disableFileInputButton();
-
 
736
      }
-
 
737
    },
-
 
738
 
-
 
739
    enable: function () {
-
 
740
      var wasDisabled = false;
-
 
741
      if (this.options.disabled) {
-
 
742
        wasDisabled = true;
-
 
743
      }
-
 
744
      this._super();
-
 
745
      if (wasDisabled) {
-
 
746
        this.element.find('input, button').prop('disabled', false);
-
 
747
        this._enableFileInputButton();
-
 
748
      }
-
 
749
    },
-
 
750
 
-
 
751
    disable: function () {
-
 
752
      if (!this.options.disabled) {
-
 
753
        this.element.find('input, button').prop('disabled', true);