/**
* jquery.ui.plupload.js
*
* Copyright 2013, Moxiecode Systems AB
* Released under GPL License.
*
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*
* Depends:
* jquery.ui.core.js
* jquery.ui.widget.js
* jquery.ui.button.js
* jquery.ui.progressbar.js
*
* Optionally:
* jquery.ui.sortable.js
*/
/* global jQuery:true */
/**
jQuery UI based implementation of the Plupload API - multi-runtime file uploading API.
To use the widget you must include _jQuery_ and _jQuery UI_ bundle (including `ui.core`, `ui.widget`, `ui.button`,
`ui.progressbar` and `ui.sortable`).
In general the widget is designed the way that you do not usually need to do anything to it after you instantiate it.
But! You still can intervenue, to some extent, in case you need to. Although, due to the fact that widget is based on
_jQuery UI_ widget factory, there are some specifics. See examples below for more details.
@example
Your browser doesn't have Flash, Silverlight or HTML5 support.
@example
// Invoking methods:
$('#uploader').plupload(options);
// Display welcome message in the notification area
$('#uploader').plupload('notify', 'info', "This might be obvious, but you need to click 'Add Files' to add some files.");
@example
// Subscribing to the events...
// ... on initialization:
$('#uploader').plupload({
...
viewchanged: function(event, args) {
// stuff ...
}
});
// ... or after initialization
$('#uploader').on("viewchanged", function(event, args) {
// stuff ...
});
@class UI.Plupload
@constructor
@param {Object} settings For detailed information about each option check documentation.
@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 {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 {Number} [settings.filters.max_file_count=0] Limit the number of files that can reside in the queue at the same time (default is 0 - no limit).
@param {String} [settings.flash_swf_url] URL of the Flash swf.
@param {Object} [settings.headers] Custom headers to send with the upload. Hash of name/value pairs.
@param {Number|String} [settings.max_file_size] 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 {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 {Boolean} [settings.prevent_duplicates=false] Do not let duplicates into the queue. Dispatches `plupload.FILE_DUPLICATE_ERROR`.
@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,flash,silverlight,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.
@param {Boolean} [settings.unique_names=false] If true will generate unique filenames for uploaded files.
@param {Boolean} [settings.autostart=false] Whether to auto start uploading right after file selection.
@param {Boolean} [settings.dragdrop=true] Enable ability to add file to the queue by drag'n'dropping them from the desktop.
@param {Boolean} [settings.rename=false] Enable ability to rename files in the queue.
@param {Boolean} [settings.sortable=false] Enable ability to sort files in the queue, changing their uploading priority.
@param {Object} [settings.buttons] Control the visibility of functional buttons.
@param {Boolean} [settings.buttons.browse=true] Display browse button.
@param {Boolean} [settings.buttons.start=true] Display start button.
@param {Boolean} [settings.buttons.stop=true] Display stop button.
@param {Object} [settings.views] Control various views of the file queue.
@param {Boolean} [settings.views.list=true] Enable list view.
@param {Boolean} [settings.views.thumbs=false] Enable thumbs view.
@param {String} [settings.views.default='list'] Default view.
@param {Boolean} [settings.views.remember=true] Whether to remember the current view (requires jQuery Cookie plugin).
@param {Boolean} [settings.multiple_queues=true] Re-activate the widget after each upload procedure.
*/
;(function(window, document, plupload, o, $) {
/**
Dispatched when the widget is initialized and ready.
@event ready
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Dispatched when file dialog is closed.
@event selected
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {Array} files Array of selected files represented by plupload.File objects
*/
/**
Dispatched when file dialog is closed.
@event removed
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {Array} files Array of removed files represented by plupload.File objects
*/
/**
Dispatched when upload is started.
@event started
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Dispatched when upload is stopped.
@event stopped
@param {plupload.Uploader} uploader Uploader instance sending the event.
*/
/**
Dispatched during the upload process.
@event progress
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File that is being uploaded (includes loaded and percent properties among others).
@param {Number} size Total file size in bytes.
@param {Number} loaded Number of bytes uploaded of the files total size.
@param {Number} percent Number of percentage uploaded of the file.
*/
/**
Dispatched when file is uploaded.
@event uploaded
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {plupload.File} file File that was uploaded.
@param {Enum} status Status constant matching the plupload states QUEUED, UPLOADING, FAILED, DONE.
*/
/**
Dispatched when upload of the whole queue is complete.
@event complete
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {Array} files Array of uploaded files represented by plupload.File objects
*/
/**
Dispatched when the view is changed, e.g. from `list` to `thumbs` or vice versa.
@event viewchanged
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {String} type Current view type.
*/
/**
Dispatched when error of some kind is detected.
@event error
@param {plupload.Uploader} uploader Uploader instance sending the event.
@param {String} error Error message.
@param {plupload.File} file File that was uploaded.
@param {Enum} status Status constant matching the plupload states QUEUED, UPLOADING, FAILED, DONE.
*/
var uploaders = {};
function _(str) {
return plupload.translate(str) || str;
}
function renderUI(obj) {
obj.id = obj.attr('id');
obj.html(
'
' +
'
' +
'
' +
'
' +
'
' +
'
' + _("Select files") + '
' +
'
' + _("Add files to the upload queue and click the start button.") + '