: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @param {Object} obj DOM element to remove event listener(s) from.
* @param {String} name Name of event listener to remove.
* @param {Function|String} (optional) might be a callback or unique key to match.
removeEvent: o.removeEvent,
* Remove all kind of events from the specified object
* @method removeAllEvents
* @param {Object} obj DOM element to remove event listeners from.
* @param {String} (optional) unique key to match, when removing events.
removeAllEvents: o.removeAllEvents,
* Cleans the specified name from national characters (diacritics). The result will be a name with only a-z, 0-9 and _.
* @param {String} s String to clean up.
* @return {String} Cleaned string.
cleanName : function(name) {
/[\300-\306]/g, 'A', /[\340-\346]/g, 'a',
/\307/g, 'C', /\347/g, 'c',
/[\310-\313]/g, 'E', /[\350-\353]/g, 'e',
/[\314-\317]/g, 'I', /[\354-\357]/g, 'i',
/\321/g, 'N', /\361/g, 'n',
/[\322-\330]/g, 'O', /[\362-\370]/g, 'o',
/[\331-\334]/g, 'U', /[\371-\374]/g, 'u'
for (i = 0; i < lookup.length; i += 2) {
name = name.replace(lookup[i], lookup[i + 1]);
name = name.replace(/\s+/g, '_');
name = name.replace(/[^a-z0-9_\-\.]+/gi, '');
* Builds a full url out of a base URL and an object with items to append as query string items.
* @param {String} url Base URL to append query string items to.
* @param {Object} items Name/value object to serialize as a querystring.
* @return {String} String with url + serialized query string items.
buildUrl : function(url, items) {
plupload.each(items, function(value, name) {
query += (query ? '&' : '') + encodeURIComponent(name) + '=' + encodeURIComponent(value);
url += (url.indexOf('?') > 0 ? '&' : '?') + query;
* Formats the specified number as a size string for example 1024 becomes 1 KB.
* @param {Number} size Size to format as string.
* @return {String} Formatted size string.
formatSize : function(size) {
if (size === undef || /\D/.test(size)) {
return plupload.translate('N/A');
function round(num, precision) {
return Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision);
var boundary = Math.pow(1024, 4);
return round(size / boundary, 1) + " " + plupload.translate('tb');
if (size > (boundary/=1024)) {
return round(size / boundary, 1) + " " + plupload.translate('gb');
if (size > (boundary/=1024)) {
return round(size / boundary, 1) + " " + plupload.translate('mb');
return Math.round(size / 1024) + " " + plupload.translate('kb');
return size + " " + plupload.translate('b');
* Parses the specified size string into a byte value. For example 10kb becomes 10240.
* @param {String|Number} size String to parse or number to just pass through.
* @return {Number} Size in bytes.
parseSize : o.parseSizeStr,
* A way to predict what runtime will be choosen in the current environment with the
* @param {Object|String} config Plupload settings to check
* @param {String} [runtimes] Comma-separated list of runtimes to check against
* @return {String} Type of compatible runtime
predictRuntime : function(config, runtimes) {
up = new plupload.Uploader(config);
runtime = o.Runtime.thatCan(up.getOption().required_features, runtimes || config.runtimes);
* Registers a filter that will be executed for each file added to the queue.
* If callback returns false, file will not be added.
* Callback receives two arguments: a value for the filter as it was specified in settings.filters
* and a file to be filtered. Callback is executed in the context of uploader instance.
* @param {String} name Name of the filter by which it can be referenced in settings.filters
* @param {String} cb Callback - the actual routine that every added file must pass
addFileFilter: function(name, cb) {
plupload.addFileFilter('mime_types', function(filters, file, cb) {
if (filters.length && !filters.regexp.test(file.name)) {
code : plupload.FILE_EXTENSION_ERROR,
message : plupload.translate('File extension error.'),
plupload.addFileFilter('max_file_size', function(maxSize, file, cb) {
maxSize = plupload.parseSize(maxSize);
if (file.size !== undef && maxSize && file.size > maxSize) {
code : plupload.FILE_SIZE_ERROR,
message : plupload.translate('File size error.'),
plupload.addFileFilter('prevent_duplicates', function(value, file, cb) {
var ii = this.files.length;
// Compare by name and size (size might be 0 or undefined, but still equivalent for both)
if (file.name === this.files[ii].name && file.size === this.files[ii].size) {
code : plupload.FILE_DUPLICATE_ERROR,
message : plupload.translate('Duplicate file error.'),
@param {Object} settings For detailed information about each option check documentation.
@param {String|DOMElement} settings.browse_button id of the DOM element or DOM element itself to use as file dialog trigger.
@param {String} settings.url URL of the server-side upload handler.
@param {Number|String} [settings.chunk_size=0] Chunk size in bytes to slice the file into. Shorcuts with b, kb, mb, gb, tb suffixes also supported. `e.g. 204800 or "204800b" or "200kb"`. By default - disabled.
@param {Boolean} [settings.send_chunk_number=true] Whether to send chunks and chunk numbers, or total and offset bytes.
@param {String|DOMElement} [settings.container] id of the DOM element or DOM element itself that will be used to wrap uploader structures. Defaults to immediate parent of the `browse_button` element.
@param {String|DOMElement} [settings.drop_element] id of the DOM element or DOM element itself to use as a drop zone for Drag-n-Drop.
@param {String} [settings.file_data_name="file"] Name for the file field in Multipart formated message.
@param {Object} [settings.filters={}] Set of file type filters.
@param {Array} [settings.filters.mime_types=[]] List of file types to accept, each one defined by title and list of extensions. `e.g. {title : "Image files", extensions : "jpg,jpeg,gif,png"}`. Dispatches `plupload.FILE_EXTENSION_ERROR`
@param {String|Number} [settings.filters.max_file_size=0] Maximum file size that the user can pick, in bytes. Optionally supports b, kb, mb, gb, tb suffixes. `e.g. "10mb" or "1gb"`. By default - not set. Dispatches `plupload.FILE_SIZE_ERROR`.
@param {Boolean} [settings.filters.prevent_duplicates=false] Do not let duplicates into the queue. Dispatches `plupload.FILE_DUPLICATE_ERROR`.
@param {String} [settings.flash_swf_url] URL of the Flash swf. (Not used in WordPress)
@param {Object} [settings.headers] Custom headers to send with the upload. Hash of name/value pairs.
@param {Number} [settings.max_retries=0] How many times to retry the chunk or file, before triggering Error event.
@param {Boolean} [settings.multipart=true] Whether to send file and additional parameters as Multipart formated message.
@param {Object} [settings.multipart_params] Hash of key/value pairs to send with every file upload.
@param {Boolean} [settings.multi_selection=true] Enable ability to select multiple files at once in file dialog.
@param {String|Object} [settings.required_features] Either comma-separated list or hash of required features that chosen runtime should absolutely possess.
@param {Object} [settings.resize] Enable resizng of images on client-side. Applies to `image/jpeg` and `image/png` only. `e.g. {width : 200, height : 200, quality : 90, crop: true}`
@param {Number} [settings.resize.width] If image is bigger, it will be resized.
@param {Number} [settings.resize.height] If image is bigger, it will be resized.
@param {Number} [settings.resize.quality=90] Compression quality for jpegs (1-100).
@param {Boolean} [settings.resize.crop=false] Whether to crop images to exact dimensions. By default they will be resized proportionally.
@param {String} [settings.runtimes="html5,html4"] Comma separated list of runtimes, that Plupload will try in turn, moving to the next if previous fails.
@param {String} [settings.silverlight_xap_url] URL of the Silverlight xap. (Not used in WordPress)
@param {Boolean} [settings.unique_names=false] If true will generate unique filenames for uploaded files.
@param {Boolean} [settings.send_file_name=true] Whether to send file name as additional argument - 'name' (required for chunked uploads and some other cases where file name cannot be sent via normal ways).
plupload.Uploader = function(options) {
Fires when the current RunTime has been initialized.
@param {plupload.Uploader} uploader Uploader instance sending the event.
Fires after the init event incase you need to perform actions there.
@param {plupload.Uploader} uploader Uploader instance sending the event.
Fires when the option is changed in via uploader.setOption().
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {String} name Name of the option that was changed
@param {Mixed} value New value for the specified option
@param {Mixed} oldValue Previous value of the option
Fires when the silverlight/flash or other shim needs to move.
@param {plupload.Uploader} uploader Uploader instance sending the event.
Fires when the overall state is being changed for the upload queue.
@param {plupload.Uploader} uploader Uploader instance sending the event.
Fires when browse_button is clicked and browse dialog shows.
@param {plupload.Uploader} uploader Uploader instance sending the event.
Fires for every filtered file before it is added to the queue.
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file Another file that has to be added to the queue.
Fires when the file queue is changed. In other words when files are added/removed to the files array of the uploader instance.
@param {plupload.Uploader} uploader Uploader instance sending the event.
Fires after files were filtered and added to the queue.
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {Array} files Array of file objects that were added to queue by the user.
Fires when file is removed from the queue.
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {Array} files Array of files that got removed.
Fires just before a file is uploaded. Can be used to cancel the upload for the specified file
by returning false from the handler.
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File to be uploaded.
Fires when a file is to be uploaded by the runtime.
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File to be uploaded.
Fires while a file is being uploaded. Use this event to update the current file upload progress.
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File that is currently being uploaded.
Fires when file chunk is uploaded.
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File that the chunk was uploaded for.
@param {Object} result Object with response properties.
@param {Number} result.offset The amount of bytes the server has received so far, including this chunk.
@param {Number} result.total The size of the file.
@param {String} result.response The response body sent by the server.
@param {Number} result.status The HTTP status code sent by the server.
@param {String} result.responseHeaders All the response headers as a single string.
Fires when a file is successfully uploaded.
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File that was uploaded.
@param {Object} result Object with response properties.
@param {String} result.response The response body sent by the server.
@param {Number} result.status The HTTP status code sent by the server.
@param {String} result.responseHeaders All the response headers as a single string.
Fires when all files in a queue are uploaded.
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {Array} files Array of file objects that was added to queue/selected by the user.
Fires when a error occurs.
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {Object} error Contains code, message and sometimes file and other details.
@param {Number} error.code The plupload error code.
@param {String} error.message Description of the error (uses i18n).
Fires when destroy method is called.
@param {plupload.Uploader} uploader Uploader instance sending the event.
var uid = plupload.guid()
if (this.state == plupload.STARTED) {
// Find first QUEUED file
for (i = 0; i < files.length; i++) {
if (!file && files[i].status == plupload.QUEUED) {
if (this.trigger("BeforeUpload", file)) {
file.status = plupload.UPLOADING;
this.trigger("UploadFile", file);
// All files are DONE or FAILED
if (count == files.length) {
if (this.state !== plupload.STOPPED) {
this.state = plupload.STOPPED;
this.trigger("StateChanged");
this.trigger("UploadComplete", files);
function calcFile(file) {
file.percent = file.size > 0 ? Math.ceil(file.loaded / file.size * 100) : 100;
// Check status, size, loaded etc on all files
for (i = 0; i < files.length; i++) {
if (file.size !== undef) {
// We calculate totals based on original file size
total.size += file.origSize;
// Since we cannot predict file size after resize, we do opposite and
// interpolate loaded amount to match magnitude of total
total.loaded += file.loaded * file.origSize / file.size;
if (file.status == plupload.DONE) {
} else if (file.status == plupload.FAILED) {
// If we couldn't calculate a total file size then use the number of files to calc percent
if (total.size === undef) {
total.percent = files.length > 0 ? Math.ceil(total.uploaded / files.length * 100) : 0;
total.bytesPerSec = Math.ceil(total.loaded / ((+new Date() - startTime || 1) / 1000.0));
total.percent = total.size > 0 ? Math.ceil(total.loaded / total.size * 100) : 0;
var ctrl = fileInputs[0] || fileDrops[0];