1/* 2 * jQuery File Upload Processing Plugin 3 * https://github.com/blueimp/jQuery-File-Upload 4 * 5 * © Sebastian Tschan 6 * https://blueimp.net 7 * 8 * Licensed under the MIT license: 9 * https://opensource.org/licenses/MIT 10 */ 11 12/* global define, require */ 13 14(function (factory) { 15 'use strict'; 16 if (typeof define === 'function' && define.amd) { 17 // Register as an anonymous AMD module: 18 define(['jquery', './jquery.fileupload'], factory); 19 } else if (typeof exports === 'object') { 20 // Node/CommonJS: 21 factory(require('jquery'), require('./jquery.fileupload')); 22 } else { 23 // Browser globals: 24 factory(window.jQuery); 25 } 26})(function ($) { 27 'use strict'; 28 29 var originalAdd = $.blueimp.fileupload.prototype.options.add; 30 31 // The File Upload Processing plugin extends the fileupload widget 32 // with file processing functionality: 33 $.widget('blueimp.fileupload', $.blueimp.fileupload, { 34 options: { 35 // The list of processing actions: 36 processQueue: [ 37 ], 38 add: function (e, data) { 39 var $this = $(this); 40 data.process(function () { 41 return $this.fileupload('process', data); 42 }); 43 originalAdd.call(this, e, data); 44 } 45 }, 46 47 processActions: { 48 49 }, 50 51 _processFile: function (data, originalData) { 52 var that = this, 53 // eslint-disable-next-line new-cap 54 dfd = $.Deferred().resolveWith(that, [data]), 55 chain = dfd.promise(); 56 this._trigger('process', null, data); 57 $.each(data.processQueue, function (i, settings) { 58 var func = function (data) { 59 if (originalData.errorThrown) { 60 // eslint-disable-next-line new-cap 61 return $.Deferred().rejectWith(that, [originalData]).promise(); 62 } 63 return that.processActions[settings.action].call( 64 that, 65 data, 66 settings 67 ); 68 }; 69 chain = chain[that._promisePipe](func, settings.always && func); 70 }); 71 chain 72 .done(function () { 73 that._trigger('processdone', null, data); 74 that._trigger('processalways', null, data); 75 }) 76 .fail(function () { 77 that._trigger('processfail', null, data); 78 that._trigger('processalways', null, data); 79 }); 80 return chain; 81 }, 82 83 // Replaces the settings of each processQueue item that 84 // are strings starting with an "@", using the remaining 85 // substring as key for the option map, 86 // e.g. "@autoUpload" is replaced with options.autoUpload: 87 _transformProcessQueue: function (options) { 88 var processQueue = []; 89 $.each(options.processQueue, function () { 90 var settings = {}, 91 action = this.action, 92 prefix = this.prefix === true ? action : this.prefix; 93 $.each(this, function (key, value) { 94 if ($.type(value) === 'string' && value.charAt(0) === '@') { 95 settings[key] = 96 options[ 97 value.slice(1) || 98 (prefix 99 ? prefix + key.charAt(0).toUpperCase() + key.slice(1) 100 : key) 101 ]; 102 } else { 103 settings[key] = value; 104 } 105 }); 106 processQueue.push(settings); 107 }); 108 options.processQueue = processQueue; 109 }, 110 111 // Returns the number of files currently in the processsing queue: 112 processing: function () { 113 return this._processing; 114 }, 115 116 // Processes the files given as files property of the data parameter, 117 // returns a Promise object that allows to bind callbacks: 118 process: function (data) { 119 var that = this, 120 options = $.extend({}, this.options, data); 121 if (options.processQueue && options.processQueue.length) { 122 this._transformProcessQueue(options); 123 if (this._processing === 0) { 124 this._trigger('processstart'); 125 } 126 $.each(data.files, function (index) { 127 var opts = index ? $.extend({}, options) : options, 128 func = function () { 129 if (data.errorThrown) { 130 // eslint-disable-next-line new-cap 131 return $.Deferred().rejectWith(that, [data]).promise(); 132 } 133 return that._processFile(opts, data); 134 }; 135 opts.index = index;
136 that._processing += 1; 137 that._processingQueue = that._processingQueue[that._promisePipe]( 138 func, 139 func 140 ).always(function () { 141 that._processing -= 1; 142 if (that._processing === 0) { 143 that._trigger('processstop'); 144 } 145 }); 146 }); 147 } 148 return this._processingQueue; 149 }, 150 151 _create: function () { 152 this._super(); 153 this._processing = 0; 154 // eslint-disable-next-line new-cap 155 this._processingQueue = $.Deferred().resolveWith(this).promise(); 156 } 157 }); 158});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.