* Plupload - multi-runtime File Uploader
* Copyright 2013, Moxiecode Systems AB
* Released under GPL License.
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
* Copyright 2013, Moxiecode Systems AB
* Released under GPL License.
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
* Modified for WordPress, Silverlight and Flash runtimes support was removed.
* See https://core.trac.wordpress.org/ticket/41755.
;(function(window, o, undef) {
var delay = window.setTimeout
// convert plupload features to caps acceptable by mOxie
function normalizeCaps(settings) {
var features = settings.required_features, caps = {};
function resolve(feature, value, strict) {
// Feature notation is deprecated, use caps (this thing here is required for backward compatibility)
jpgresize: 'send_binary_string',
pngresize: 'send_binary_string',
progress: 'report_upload_progress',
multi_selection: 'select_multiple',
dragdrop: 'drag_and_drop',
drop_element: 'drag_and_drop',
headers: 'send_custom_headers',
urlstream_upload: 'send_binary_string',
canSendBinary: 'send_binary',
triggerDialog: 'summon_file_dialog'
caps[map[feature]] = value;
if (typeof(features) === 'string') {
plupload.each(features.split(/\s*,\s*/), function(feature) {
} else if (typeof(features) === 'object') {
plupload.each(features, function(value, feature) {
} else if (features === true) {
// check settings for required features
if (settings.chunk_size > 0) {
if (settings.resize.enabled || !settings.multipart) {
caps.send_binary_string = true;
plupload.each(settings, function(value, feature) {
resolve(feature, !!value, true); // strict check
// WP: only html runtimes.
settings.runtimes = 'html5,html4';
* Plupload version will be replaced on build.
* The state of the queue before it has started and after it has finished
* Upload process is running
* File is queued for upload
* File has failed to be uploaded
* File has been uploaded successfully
// Error constants used by the Error event
* Generic error for example if an exception is thrown inside Silverlight.
* @property GENERIC_ERROR
* HTTP transport error. For example if the server produces a HTTP status other than 200.
* Generic I/O error. For example if it wasn't possible to open the file stream on local machine.
* @property SECURITY_ERROR
* Initialization error. Will be triggered if no runtime was initialized.
* File size error. If the user selects a file that is too large it will be blocked and an error of this type will be triggered.
* @property FILE_SIZE_ERROR
* File extension error. If the user selects a file that isn't valid according to the filters setting.
* @property FILE_EXTENSION_ERROR
FILE_EXTENSION_ERROR : -601,
* Duplicate file error. If prevent_duplicates is set to true and user selects the same file again.
* @property FILE_DUPLICATE_ERROR
FILE_DUPLICATE_ERROR : -602,
* Runtime will try to detect if image is proper one. Otherwise will throw this error.
* @property IMAGE_FORMAT_ERROR
IMAGE_FORMAT_ERROR : -700,
* While working on files runtime may run out of memory and will throw this error.
* Each runtime has an upper limit on a dimension of the image it can handle. If bigger, will throw this error.
* @property IMAGE_DIMENSIONS_ERROR
IMAGE_DIMENSIONS_ERROR : -702,
* Mime type lookup table.
* In some cases sniffing is the only way around :(
* Gets the true type of the built-in object (better version of typeof).
* @credits Angus Croll (http://javascriptweblog.wordpress.com/)
* @param {Object} o Object to check.
* @return {String} Object [[Class]]
* Extends the specified object with another object.
* @param {Object} target Object to extend.
* @param {Object..} obj Multiple objects to extend with.
* @return {Object} Same as target, the extended object.
* Generates an unique ID. This is 99.99% unique since it takes the current time and 5 random numbers.
* The only way a user would be able to get the same ID is if the two persons at the same exact millisecond manages
* to get 5 the same random numbers between 0-65535 it also uses a counter so each call will be guaranteed to be page unique.
* It's more probable for the earth to be hit with an asteriod. You can also if you want to be 100% sure set the plupload.guidPrefix property
* @return {String} Virtually unique id.
* Get array of DOM Elements by their ids.
* @param {String} id Identifier of the DOM Element
getAll : function get(ids) {
if (plupload.typeOf(ids) !== 'array') {
el = plupload.get(ids[i]);
return els.length ? els : null;
@param {String} id Identifier of the DOM Element
* Executes the callback function for each item in array/object. If you return false in the
* callback it will break the loop.
* @param {Object} obj Object to iterate.
* @param {function} callback Callback function to execute for each item.
* Returns the absolute x, y position of an Element. The position will be returned in a object with x, y fields.
* @param {Element} node HTML element or element id to get x, y position from.
* @param {Element} root Optional root element to stop calculations at.
* @return {object} Absolute position of the specified element object with x, y fields.
* Returns the size of the specified node in pixels.
* @param {Node} node Node to get the size of.
* @return {Object} Object with a w and h property.
* Encodes the specified string.
* @param {String} s String to encode.
* @return {String} Encoded string.
xmlEncode : function(str) {
var xmlEncodeChars = {'<' : 'lt', '>' : 'gt', '&' : 'amp', '"' : 'quot', '\'' : '#39'}, xmlEncodeRegExp = /[<>&\"\']/g;
return str ? ('' + str).replace(xmlEncodeRegExp, function(chr) {
return xmlEncodeChars[chr] ? '&' + xmlEncodeChars[chr] + ';' : chr;
* Forces anything into an array.
* @param {Object} obj Object with length field.
* @return {Array} Array object containing all items.
* Find an element in array and return its index if present, otherwise return -1.
* @param {mixed} needle Element to find
* @return {Int} Index of the element, or -1 if not found
* Extends the language pack object with new items.
* @param {Object} pack Language pack items to add.
* @return {Object} Extended language pack object.
* Translates the specified string by checking for the english string in the language pack lookup.
* @param {String} str String to look for.
* @return {String} Translated string or the input string if it wasn't found.
* Checks if object is empty.
* @param {Object} obj Object to check.
isEmptyObj : o.isEmptyObj,
* Checks if specified DOM element has specified class.
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Class name
* Adds specified className to specified DOM element.
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Class name
* Removes specified className from specified DOM element.
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Class name
removeClass : o.removeClass,
* Returns a given computed style of a DOM element.
* @param {Object} obj DOM element like object.
* @param {String} name Style you want to get from the DOM element
* Adds an event handler to the specified object and store reference to the handler
* in objects internal Plupload registry (@see removeEvent).
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Name to add event listener to.
* @param {Function} callback Function to call when event occurs.
* @param {String} (optional) key that might be used to add specifity to the event record.
* Remove event handler from the specified object. If third argument (callback)
* is not specified remove all events with the specified name.