1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 14:17:49 +02:00

plupload upgraded to v2.3.6

This commit is contained in:
Cameron
2018-11-23 13:24:14 -08:00
parent 0adf60f9e7
commit 96647b445e
19 changed files with 3241 additions and 2576 deletions

View File

@@ -37,7 +37,7 @@ if($_GET['action'] == 'youtube' )
}
// TODO use library manager
e107::js('core', 'plupload/plupload.full.js', 'jquery', 2);
e107::js('core', 'plupload/plupload.full.min.js', 'jquery', 2);
e107::css('core', 'plupload/jquery.plupload.queue/css/jquery.plupload.queue.css', 'jquery');
e107::js('core', 'plupload/jquery.plupload.queue/jquery.plupload.queue.min.js', 'jquery', 2);
e107::js('core', 'core/mediaManager.js',"jquery",5);

View File

@@ -911,6 +911,16 @@ console.log('Bbcode: '+bbcode);
}
},
init: {
BeforeUpload: function(e,file)
{
},
BeforeChunkUpload: function(uploader, file, post, currentBlob, currentOffset)
{
//console.log(file);
// currentBlob.name=file.name;
},
FilesAdded: function (up, files)
{

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 399 B

After

Width:  |  Height:  |  Size: 111 B

View File

@@ -73,7 +73,7 @@ used as it is.
@param {Boolean} [settings.rename=false] Enable ability to rename files in the queue.
@param {Boolean} [settings.multiple_queues=true] Re-activate the widget after each upload procedure.
*/
;(function($, o) {
;(function($, plupload) {
var uploaders = {};
function _(str) {
@@ -198,7 +198,7 @@ used as it is.
$('span.plupload_total_status', target).html(uploader.total.percent + '%');
$('div.plupload_progress_bar', target).css('width', uploader.total.percent + '%');
$('span.plupload_upload_status', target).html(
o.sprintf(_('Uploaded %d/%d files'), uploader.total.uploaded, uploader.files.length)
plupload.sprintf(_('Uploaded %d/%d files'), uploader.total.uploaded, uploader.files.length)
);
}
@@ -247,7 +247,7 @@ used as it is.
if (uploader.total.queued === 0) {
$('span.plupload_add_text', target).html(_('Add Files'));
} else {
$('span.plupload_add_text', target).html(o.sprintf(_('%d files queued'), uploader.total.queued));
$('span.plupload_add_text', target).html(plupload.sprintf(_('%d files queued'), uploader.total.queued));
}
$('a.plupload_start', target).toggleClass('plupload_disabled', uploader.files.length == (uploader.total.uploaded + uploader.total.failed));
@@ -279,6 +279,11 @@ used as it is.
if (!settings.unique_names && settings.rename) {
target.on('click', '#' + id + '_filelist div.plupload_file_name span', function(e) {
var targetSpan = $(e.target), file, parts, name, ext = "";
var fileContainer = targetSpan.closest('li');
if (!fileContainer.hasClass('plupload_delete')) {
return;
}
// Get file name and split out name and extension
file = up.getFile(targetSpan.parents('li')[0].id);
@@ -425,4 +430,4 @@ used as it is.
return uploaders[$(this[0]).attr('id')];
}
};
})(jQuery, mOxie);
})(jQuery, plupload);

File diff suppressed because one or more lines are too long

View File

@@ -330,6 +330,10 @@
display: block;
}
.plupload_files_queued .plupload_droptext {
display: none;
}
.plupload_buttons, .plupload_upload_status {float: left}
.plupload_message {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@@ -408,10 +408,14 @@ $.widget("ui.plupload", {
}
this.filelist.on('click', function(e) {
if ($(e.target).hasClass('plupload_action_icon')) {
self.removeFile($(e.target).closest('.plupload_file').attr('id'));
var me = $(e.target), fileContainer;
if (me.hasClass('plupload_action_icon')) {
fileContainer = me.closest('.plupload_file');
if (fileContainer.hasClass('plupload_delete')) {
self.removeFile(fileContainer.attr('id'));
e.preventDefault();
}
}
});
uploader = this.uploader = uploaders[id] = new plupload.Uploader($.extend(this.options, options));
@@ -454,19 +458,19 @@ $.widget("ui.plupload", {
switch (err.code) {
case plupload.FILE_EXTENSION_ERROR:
details = o.sprintf(_("File: %s"), err.file.name);
details = plupload.sprintf(_("File: %s"), err.file.name);
break;
case plupload.FILE_SIZE_ERROR:
details = o.sprintf(_("File: %s, size: %d, max file size: %d"), err.file.name, plupload.formatSize(err.file.size), plupload.formatSize(plupload.parseSize(up.getOption('filters').max_file_size)));
details = plupload.sprintf(_("File: %s, size: %d, max file size: %d"), err.file.name, plupload.formatSize(err.file.size), plupload.formatSize(plupload.parseSize(up.getOption('filters').max_file_size)));
break;
case plupload.FILE_DUPLICATE_ERROR:
details = o.sprintf(_("%s already present in the queue."), err.file.name);
details = plupload.sprintf(_("%s already present in the queue."), err.file.name);
break;
case self.FILE_COUNT_ERROR:
details = o.sprintf(_("Upload element accepts only %d file(s) at a time. Extra files were stripped."), up.getOption('filters').max_file_count || 0);
details = plupload.sprintf(_("Upload element accepts only %d file(s) at a time. Extra files were stripped."), up.getOption('filters').max_file_count || 0);
break;
case plupload.IMAGE_FORMAT_ERROR :
@@ -479,7 +483,7 @@ $.widget("ui.plupload", {
/* // This needs a review
case plupload.IMAGE_DIMENSIONS_ERROR :
details = o.sprintf(_('Resoultion out of boundaries! <b>%s</b> runtime supports images only up to %wx%hpx.'), up.runtime, up.features.maxWidth, up.features.maxHeight);
details = plupload.sprintf(_('Resoultion out of boundaries! <b>%s</b> runtime supports images only up to %wx%hpx.'), up.runtime, up.features.maxWidth, up.features.maxHeight);
break; */
case plupload.HTTP_ERROR:
@@ -864,7 +868,7 @@ $.widget("ui.plupload", {
up.disableBrowse();
}
$('.plupload_upload_status', this.element).html(o.sprintf(_('Uploaded %d/%d files'), up.total.uploaded, up.files.length));
$('.plupload_upload_status', this.element).html(plupload.sprintf(_('Uploaded %d/%d files'), up.total.uploaded, up.files.length));
$('.plupload_header_content', this.element).addClass('plupload_header_content_bw');
}
else if (plupload.STOPPED === up.state) {
@@ -895,9 +899,12 @@ $.widget("ui.plupload", {
if (up.total.queued === 0) {
$('.ui-button-text', this.browse_button).html(_('Add Files'));
} else {
$('.ui-button-text', this.browse_button).html(o.sprintf(_('%d files queued'), up.total.queued));
$('.ui-button-text', this.browse_button).html(plupload.sprintf(_('%d files queued'), up.total.queued));
}
// have a helper class on a container expressing whether it has files queued or not
this.container.toggleClass('plupload_files_queued', up.files.length);
up.refresh();
},
@@ -978,7 +985,7 @@ $.widget("ui.plupload", {
.html(plupload.formatSize(up.total.size))
.end()
.find('.plupload_upload_status')
.html(o.sprintf(_('Uploaded %d/%d files'), up.total.uploaded, up.files.length));
.html(plupload.sprintf(_('Uploaded %d/%d files'), up.total.uploaded, up.files.length));
},
@@ -1058,7 +1065,8 @@ $.widget("ui.plupload", {
function preloadThumb(file, cb) {
var img = new o.Image();
var img = new o.image.Image();
var resolveUrl = o.core.utils.Url.resolveUrl;
img.onload = function() {
var thumb = $('#' + file.id + ' .plupload_file_thumb', self.filelist);
@@ -1066,9 +1074,10 @@ $.widget("ui.plupload", {
width: self.options.thumb_width,
height: self.options.thumb_height,
crop: true,
fit: true,
preserveHeaders: false,
swf_url: o.resolveUrl(self.options.flash_swf_url),
xap_url: o.resolveUrl(self.options.silverlight_xap_url)
swf_url: resolveUrl(self.options.flash_swf_url),
xap_url: resolveUrl(self.options.silverlight_xap_url)
});
};
@@ -1143,7 +1152,7 @@ $.widget("ui.plupload", {
}
$.each(files, function(i, file) {
var ext = o.Mime.getFileExtension(file.name) || 'none';
var ext = o.core.utils.Mime.getFileExtension(file.name) || 'none';
html += file_html.replace(/\{(\w+)\}/g, function($0, $1) {
switch ($1) {
@@ -1198,7 +1207,7 @@ $.widget("ui.plupload", {
}
// ugly fix for IE6 - make content area stretchable
if (o.Env.browser === 'IE' && o.Env.version < 7) {
if (plupload.ua.browser === 'IE' && plupload.ua.version < 7) {
this.content.attr('style', 'height:expression(document.getElementById("' + this.id + '_container' + '").clientHeight - ' + (view === 'list' ? 132 : 102) + ')');
}
@@ -1270,14 +1279,20 @@ $.widget("ui.plupload", {
var self = this;
this.filelist.dblclick(function(e) {
var nameSpan = $(e.target), nameInput, file, parts, name, ext = "";
var nameInput, fileContainer, file, parts, name, ext = "";
var nameSpan = $(e.target);
if (!nameSpan.hasClass('plupload_file_name_wrapper')) {
return;
}
fileContainer = nameSpan.closest('.plupload_file');
if (!fileContainer.hasClass('plupload_delete')) {
return;
}
// Get file name and split out name and extension
file = self.uploader.getFile(nameSpan.closest('.plupload_file')[0].id);
file = self.uploader.getFile(fileContainer[0].id);
name = file.name;
parts = /^(.+)(\.[^.]+)$/.exec(name);
if (parts) {
@@ -1340,4 +1355,4 @@ $.widget("ui.plupload", {
}
});
} (window, document, plupload, mOxie, jQuery));
} (window, document, plupload, moxie, jQuery));

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
/**
* Plupload - multi-runtime File Uploader
* v2.1.9
* v2.3.6
*
* Copyright 2013, Moxiecode Systems AB
* Released under GPL License.
@@ -8,8 +8,23 @@
* License: http://www.plupload.com/license
* Contributing: http://www.plupload.com/contributing
*
* Date: 2016-05-15
* Date: 2017-11-03
*/
;(function (global, factory) {
var extract = function() {
var ctx = {};
factory.apply(ctx, arguments);
return ctx.plupload;
};
if (typeof define === "function" && define.amd) {
define("plupload", ['./moxie'], extract);
} else if (typeof module === "object" && module.exports) {
module.exports = extract(require('./moxie'));
} else {
global.plupload = extract(global.moxie);
}
}(this || window, function(moxie) {
/**
* Plupload.js
*
@@ -20,13 +35,12 @@
* Contributing: http://www.plupload.com/contributing
*/
/*global mOxie:true */
;(function(exports, o, undef) {
;(function(window, o, undef) {
var delay = window.setTimeout
, fileFilters = {}
;
var delay = window.setTimeout;
var fileFilters = {};
var u = o.core.utils;
var Runtime = o.runtime.Runtime;
// convert plupload features to caps acceptable by mOxie
function normalizeCaps(settings) {
@@ -65,14 +79,18 @@ function normalizeCaps(settings) {
});
} else if (features === true) {
// check settings for required features
if (settings.chunk_size > 0) {
if (settings.chunk_size && settings.chunk_size > 0) {
caps.slice_blob = true;
}
if (settings.resize.enabled || !settings.multipart) {
if (!plupload.isEmptyObj(settings.resize) || settings.multipart === false) {
caps.send_binary_string = true;
}
if (settings.http_method) {
caps.use_http_method = settings.http_method;
}
plupload.each(settings, function(value, feature) {
resolve(feature, !!value, true); // strict check
});
@@ -94,7 +112,7 @@ var plupload = {
* @static
* @final
*/
VERSION : '2.1.9',
VERSION : '2.3.6',
/**
* The state of the queue before it has started and after it has finished
@@ -196,7 +214,8 @@ var plupload = {
INIT_ERROR : -500,
/**
* 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.
* File size error. If the user selects a file that is too large or is empty it will be blocked and
* an error of this type will be triggered.
*
* @property FILE_SIZE_ERROR
* @static
@@ -250,6 +269,15 @@ var plupload = {
*/
IMAGE_DIMENSIONS_ERROR : -702,
/**
* Expose whole moxie (#1469).
*
* @property moxie
* @type Object
* @final
*/
moxie: o,
/**
* Mime type lookup table.
*
@@ -257,12 +285,12 @@ var plupload = {
* @type Object
* @final
*/
mimeTypes : o.mimes,
mimeTypes : u.Mime.mimes,
/**
* In some cases sniffing is the only way around :(
*/
ua: o.ua,
ua: u.Env,
/**
* Gets the true type of the built-in object (better version of typeof).
@@ -273,7 +301,7 @@ var plupload = {
* @param {Object} o Object to check.
* @return {String} Object [[Class]]
*/
typeOf: o.typeOf,
typeOf: u.Basic.typeOf,
/**
* Extends the specified object with another object.
@@ -284,7 +312,7 @@ var plupload = {
* @param {Object..} obj Multiple objects to extend with.
* @return {Object} Same as target, the extended object.
*/
extend : o.extend,
extend : u.Basic.extend,
/**
* Generates an unique ID. This is 99.99% unique since it takes the current time and 5 random numbers.
@@ -297,7 +325,7 @@ var plupload = {
* @static
* @return {String} Virtually unique id.
*/
guid : o.guid,
guid : u.Basic.guid,
/**
* Get array of DOM Elements by their ids.
@@ -331,7 +359,7 @@ var plupload = {
@param {String} id Identifier of the DOM Element
@return {Node}
*/
get: o.get,
get: u.Dom.get,
/**
* Executes the callback function for each item in array/object. If you return false in the
@@ -342,7 +370,7 @@ var plupload = {
* @param {Object} obj Object to iterate.
* @param {function} callback Callback function to execute for each item.
*/
each : o.each,
each : u.Basic.each,
/**
* Returns the absolute x, y position of an Element. The position will be returned in a object with x, y fields.
@@ -353,7 +381,7 @@ var plupload = {
* @param {Element} root Optional root element to stop calculations at.
* @return {object} Absolute position of the specified element object with x, y fields.
*/
getPos : o.getPos,
getPos : u.Dom.getPos,
/**
* Returns the size of the specified node in pixels.
@@ -363,7 +391,7 @@ var plupload = {
* @param {Node} node Node to get the size of.
* @return {Object} Object with a w and h property.
*/
getSize : o.getSize,
getSize : u.Dom.getSize,
/**
* Encodes the specified string.
@@ -389,7 +417,7 @@ var plupload = {
* @param {Object} obj Object with length field.
* @return {Array} Array object containing all items.
*/
toArray : o.toArray,
toArray : u.Basic.toArray,
/**
* Find an element in array and return its index if present, otherwise return -1.
@@ -400,7 +428,21 @@ var plupload = {
* @param {Array} array
* @return {Int} Index of the element, or -1 if not found
*/
inArray : o.inArray,
inArray : u.Basic.inArray,
/**
Recieve an array of functions (usually async) to call in sequence, each function
receives a callback as first argument that it should call, when it completes. Finally,
after everything is complete, main callback is called. Passing truthy value to the
callback as a first argument will interrupt the sequence and invoke main callback
immediately.
@method inSeries
@static
@param {Array} queue Array of functions to call in sequence
@param {Function} cb Main callback that is called in the end, or in case of error
*/
inSeries: u.Basic.inSeries,
/**
* Extends the language pack object with new items.
@@ -410,7 +452,7 @@ var plupload = {
* @param {Object} pack Language pack items to add.
* @return {Object} Extended language pack object.
*/
addI18n : o.addI18n,
addI18n : o.core.I18n.addI18n,
/**
* Translates the specified string by checking for the english string in the language pack lookup.
@@ -420,7 +462,15 @@ var plupload = {
* @param {String} str String to look for.
* @return {String} Translated string or the input string if it wasn't found.
*/
translate : o.translate,
translate : o.core.I18n.translate,
/**
* Pseudo sprintf implementation - simple way to replace tokens with specified values.
*
* @param {String} str String with tokens
* @return {String} String with replaced tokens
*/
sprintf : u.Basic.sprintf,
/**
* Checks if object is empty.
@@ -430,7 +480,7 @@ var plupload = {
* @param {Object} obj Object to check.
* @return {Boolean}
*/
isEmptyObj : o.isEmptyObj,
isEmptyObj : u.Basic.isEmptyObj,
/**
* Checks if specified DOM element has specified class.
@@ -440,7 +490,7 @@ var plupload = {
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Class name
*/
hasClass : o.hasClass,
hasClass : u.Dom.hasClass,
/**
* Adds specified className to specified DOM element.
@@ -450,7 +500,7 @@ var plupload = {
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Class name
*/
addClass : o.addClass,
addClass : u.Dom.addClass,
/**
* Removes specified className from specified DOM element.
@@ -460,7 +510,7 @@ var plupload = {
* @param {Object} obj DOM element like object to add handler to.
* @param {String} name Class name
*/
removeClass : o.removeClass,
removeClass : u.Dom.removeClass,
/**
* Returns a given computed style of a DOM element.
@@ -470,7 +520,7 @@ var plupload = {
* @param {Object} obj DOM element like object.
* @param {String} name Style you want to get from the DOM element
*/
getStyle : o.getStyle,
getStyle : u.Dom.getStyle,
/**
* Adds an event handler to the specified object and store reference to the handler
@@ -483,7 +533,7 @@ var plupload = {
* @param {Function} callback Function to call when event occurs.
* @param {String} (optional) key that might be used to add specifity to the event record.
*/
addEvent : o.addEvent,
addEvent : u.Events.addEvent,
/**
* Remove event handler from the specified object. If third argument (callback)
@@ -495,7 +545,7 @@ var plupload = {
* @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,
removeEvent: u.Events.removeEvent,
/**
* Remove all kind of events from the specified object
@@ -505,7 +555,7 @@ var plupload = {
* @param {Object} obj DOM element to remove event listeners from.
* @param {String} (optional) unique key to match, when removing events.
*/
removeAllEvents: o.removeAllEvents,
removeAllEvents: u.Events.removeAllEvents,
/**
* Cleans the specified name from national characters (diacritics). The result will be a name with only a-z, 0-9 and _.
@@ -551,7 +601,7 @@ var plupload = {
* @param {Object} items Name/value object to serialize as a querystring.
* @return {String} String with url + serialized query string items.
*/
buildUrl : function(url, items) {
buildUrl: function(url, items) {
var query = '';
plupload.each(items, function(value, name) {
@@ -617,7 +667,7 @@ var plupload = {
* @param {String|Number} size String to parse or number to just pass through.
* @return {Number} Size in bytes.
*/
parseSize : o.parseSizeStr,
parseSize : u.Basic.parseSizeStr,
/**
@@ -634,7 +684,7 @@ var plupload = {
var up, runtime;
up = new plupload.Uploader(config);
runtime = o.Runtime.thatCan(up.getOption().required_features, runtimes || config.runtimes);
runtime = Runtime.thatCan(up.getOption().required_features, runtimes || config.runtimes);
up.destroy();
return runtime;
},
@@ -709,6 +759,19 @@ plupload.addFileFilter('prevent_duplicates', function(value, file, cb) {
cb(true);
});
plupload.addFileFilter('prevent_empty', function(value, file, cb) {
if (value && !file.size && file.size !== undef) {
this.trigger('Error', {
code : plupload.FILE_SIZE_ERROR,
message : plupload.translate('File size error.'),
file : file
});
cb(false);
} else {
cb(true);
}
});
/**
@class Uploader
@@ -716,18 +779,18 @@ plupload.addFileFilter('prevent_duplicates', function(value, file, cb) {
@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 {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 {Boolean} [settings.filters.prevent_duplicates=false] Do not let duplicates into the queue. Dispatches `plupload.FILE_DUPLICATE_ERROR`.
@param {Boolean} [settings.filters.prevent_empty=true] Do not let empty files into the queue (IE10 is known to hang for example when trying to upload such). Dispatches `plupload.FILE_SIZE_ERROR`.
@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 {String} [settings.http_method="POST"] HTTP method to use during upload (only PUT or POST allowed).
@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.
@@ -740,8 +803,11 @@ plupload.addFileFilter('prevent_duplicates', function(value, file, cb) {
@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.send_chunk_number=true] Whether to send chunks and chunk numbers, or total and offset bytes.
@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).
@param {String} settings.url URL of the server-side upload handler.
@param {Boolean} [settings.unique_names=false] If true will generate unique filenames for uploaded files.
*/
plupload.Uploader = function(options) {
/**
@@ -848,6 +914,18 @@ plupload.Uploader = function(options) {
@param {plupload.File} file File that is currently being uploaded.
*/
/**
* Fires just before a chunk is uploaded. This event enables you to override settings
* on the uploader instance before the chunk is uploaded.
*
* @event BeforeChunkUpload
* @param {plupload.Uploader} uploader Uploader instance sending the event.
* @param {plupload.File} file File to be uploaded.
* @param {Object} args POST params to be sent.
* @param {Blob} chunkBlob Current blob.
* @param {offset} offset Current offset.
*/
/**
Fires when file chunk is uploaded.
@@ -949,6 +1027,8 @@ plupload.Uploader = function(options) {
function calc() {
var i, file;
var loaded;
var loadedDuringCurrentSession = 0;
// Reset stats
total.reset();
@@ -963,7 +1043,13 @@ plupload.Uploader = function(options) {
// 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;
loaded = file.loaded * file.origSize / file.size;
if (!file.completeTimestamp || file.completeTimestamp > startTime) {
loadedDuringCurrentSession += loaded;
}
total.loaded += loaded;
} else {
total.size = undef;
}
@@ -981,7 +1067,7 @@ plupload.Uploader = function(options) {
if (total.size === undef) {
total.percent = files.length > 0 ? Math.ceil(total.uploaded / files.length * 100) : 0;
} else {
total.bytesPerSec = Math.ceil(total.loaded / ((+new Date() - startTime || 1) / 1000.0));
total.bytesPerSec = Math.ceil(loadedDuringCurrentSession / ((+new Date() - startTime || 1) / 1000.0));
total.percent = total.size > 0 ? Math.ceil(total.loaded / total.size * 100) : 0;
}
}
@@ -996,17 +1082,6 @@ plupload.Uploader = function(options) {
}
function runtimeCan(file, cap) {
if (file.ruid) {
var info = o.Runtime.getInfo(file.ruid);
if (info) {
return info.can(cap);
}
}
return false;
}
function bindEventListeners() {
this.bind('FilesAdded FilesRemoved', function(up) {
up.trigger('QueueChanged');
@@ -1056,7 +1131,7 @@ plupload.Uploader = function(options) {
if (settings.browse_button) {
plupload.each(settings.browse_button, function(el) {
queue.push(function(cb) {
var fileInput = new o.FileInput(plupload.extend({}, options, {
var fileInput = new o.file.FileInput(plupload.extend({}, options, {
accept: settings.filters.mime_types,
name: settings.file_data_name,
multiple: settings.multi_selection,
@@ -1065,10 +1140,10 @@ plupload.Uploader = function(options) {
}));
fileInput.onready = function() {
var info = o.Runtime.getInfo(this.ruid);
var info = Runtime.getInfo(this.ruid);
// for backward compatibility
o.extend(self.features, {
plupload.extend(self.features, {
chunks: info.can('slice_blob'),
multipart: info.can('send_multipart'),
multi_selection: info.can('select_multiple')
@@ -1087,17 +1162,17 @@ plupload.Uploader = function(options) {
if (!disabled) {
if (settings.browse_button_hover) {
if ('mouseenter' === e.type) {
o.addClass(el, settings.browse_button_hover);
plupload.addClass(el, settings.browse_button_hover);
} else if ('mouseleave' === e.type) {
o.removeClass(el, settings.browse_button_hover);
plupload.removeClass(el, settings.browse_button_hover);
}
}
if (settings.browse_button_active) {
if ('mousedown' === e.type) {
o.addClass(el, settings.browse_button_active);
plupload.addClass(el, settings.browse_button_active);
} else if ('mouseup' === e.type) {
o.removeClass(el, settings.browse_button_active);
plupload.removeClass(el, settings.browse_button_active);
}
}
}
@@ -1121,15 +1196,15 @@ plupload.Uploader = function(options) {
if (settings.drop_element) {
plupload.each(settings.drop_element, function(el) {
queue.push(function(cb) {
var fileDrop = new o.FileDrop(plupload.extend({}, options, {
var fileDrop = new o.file.FileDrop(plupload.extend({}, options, {
drop_zone: el
}));
fileDrop.onready = function() {
var info = o.Runtime.getInfo(this.ruid);
var info = Runtime.getInfo(this.ruid);
// for backward compatibility
o.extend(self.features, {
plupload.extend(self.features, {
chunks: info.can('slice_blob'),
multipart: info.can('send_multipart'),
dragdrop: info.can('drag_and_drop')
@@ -1155,7 +1230,7 @@ plupload.Uploader = function(options) {
}
o.inSeries(queue, function() {
plupload.inSeries(queue, function() {
if (typeof(cb) === 'function') {
cb(inited);
}
@@ -1163,8 +1238,8 @@ plupload.Uploader = function(options) {
}
function resizeImage(blob, params, cb) {
var img = new o.Image();
function resizeImage(blob, params, runtimeOptions, cb) {
var img = new o.image.Image();
try {
img.onload = function() {
@@ -1176,22 +1251,25 @@ plupload.Uploader = function(options) {
!params.crop
) {
this.destroy();
return cb(blob);
}
cb(blob);
} else {
// otherwise downsize
img.downsize(params.width, params.height, params.crop, params.preserve_headers);
}
};
img.onresize = function() {
cb(this.getAsBlob(blob.type, params.quality));
var resizedBlob = this.getAsBlob(blob.type, params.quality);
this.destroy();
cb(resizedBlob);
};
img.onerror = function() {
img.bind('error runtimeerror', function() {
this.destroy();
cb(blob);
};
});
img.load(blob);
img.load(blob, runtimeOptions);
} catch(ex) {
cb(blob);
}
@@ -1225,6 +1303,10 @@ plupload.Uploader = function(options) {
}
break;
case 'http_method':
settings[option] = value.toUpperCase() === 'PUT' ? 'PUT' : 'POST';
break;
case 'unique_names':
settings[option] = value;
if (value) {
@@ -1248,7 +1330,11 @@ plupload.Uploader = function(options) {
// if file format filters are being updated, regenerate the matching expressions
if (value.mime_types) {
settings.filters.mime_types.regexp = (function(filters) {
if (plupload.typeOf(value.mime_types) === 'string') {
value.mime_types = o.core.utils.Mime.mimes2extList(value.mime_types);
}
value.mime_types.regexp = (function(filters) {
var extensionsRegExp = [];
plupload.each(filters, function(filter) {
@@ -1262,17 +1348,20 @@ plupload.Uploader = function(options) {
});
return new RegExp('(' + extensionsRegExp.join('|') + ')$', 'i');
}(settings.filters.mime_types));
}(value.mime_types));
settings.filters.mime_types = value.mime_types;
}
break;
case 'resize':
if (init) {
plupload.extend(settings.resize, value, {
enabled: true
});
if (value) {
settings.resize = plupload.extend({
preserve_headers: true,
crop: false
}, value);
} else {
settings.resize = value;
settings.resize = false;
}
break;
@@ -1329,7 +1418,7 @@ plupload.Uploader = function(options) {
initControls.call(self, settings, function(inited) {
if (inited) {
self.runtime = o.Runtime.getInfo(getRUID()).type;
self.runtime = Runtime.getInfo(getRUID()).type;
self.trigger('Init', { runtime: self.runtime });
self.trigger('PostInit');
} else {
@@ -1357,13 +1446,20 @@ plupload.Uploader = function(options) {
function onUploadFile(up, file) {
var url = up.settings.url
, chunkSize = up.settings.chunk_size
, retries = up.settings.max_retries
, features = up.features
, offset = 0
, blob
;
var url = up.settings.url;
var chunkSize = up.settings.chunk_size;
var retries = up.settings.max_retries;
var features = up.features;
var offset = 0;
var blob;
var runtimeOptions = {
runtime_order: up.settings.runtimes,
required_caps: up.settings.required_features,
preferred_caps: preferred_caps,
swf_url: up.settings.flash_swf_url,
xap_url: up.settings.silverlight_xap_url
};
// make sure we start at a predictable offset
if (file.loaded) {
@@ -1388,7 +1484,7 @@ plupload.Uploader = function(options) {
}
function uploadNextChunk() {
var chunkBlob, formData, args = {}, curChunkSize;
var chunkBlob, args = {}, curChunkSize;
// make sure that file wasn't cancelled and upload is not stopped in general
if (file.status !== plupload.UPLOADING || up.state === plupload.STOPPED) {
@@ -1420,7 +1516,15 @@ plupload.Uploader = function(options) {
}
}
xhr = new o.XMLHttpRequest();
if (up.trigger('BeforeChunkUpload', file, args, chunkBlob, offset)) {
uploadChunk(args, chunkBlob, curChunkSize);
}
}
function uploadChunk(args, chunkBlob, curChunkSize) {
var formData;
xhr = new o.xhr.XMLHttpRequest();
// Do we have upload progress support
if (xhr.upload) {
@@ -1432,7 +1536,7 @@ plupload.Uploader = function(options) {
xhr.onload = function() {
// check if upload made itself through
if (xhr.status >= 400) {
if (xhr.status < 200 || xhr.status >= 400) {
handleError();
return;
}
@@ -1455,7 +1559,7 @@ plupload.Uploader = function(options) {
});
// stock Android browser doesn't fire upload progress events, but in chunking mode we can fake them
if (o.Env.browser === 'Android Browser') {
if (plupload.ua.browser === 'Android Browser') {
// doesn't harm in general, but is not required anywhere else
up.trigger('UploadProgress', file);
}
@@ -1476,6 +1580,7 @@ plupload.Uploader = function(options) {
up.trigger('UploadProgress', file);
file.status = plupload.DONE;
file.completeTimestamp = +new Date();
up.trigger('FileUploaded', file, {
response : xhr.responseText,
@@ -1494,19 +1599,18 @@ plupload.Uploader = function(options) {
xhr.onloadend = function() {
this.destroy();
xhr = null;
};
// Build multipart request
if (up.settings.multipart && features.multipart) {
xhr.open("post", url, true);
xhr.open(up.settings.http_method, url, true);
// Set custom headers
plupload.each(up.settings.headers, function(value, name) {
xhr.setRequestHeader(name, value);
});
formData = new o.FormData();
formData = new o.xhr.FormData();
// Add multipart params
plupload.each(plupload.extend(args, up.settings.multipart_params), function(value, name) {
@@ -1515,42 +1619,34 @@ plupload.Uploader = function(options) {
// Add file and send it
formData.append(up.settings.file_data_name, chunkBlob);
xhr.send(formData, {
runtime_order: up.settings.runtimes,
required_caps: up.settings.required_features,
preferred_caps: preferred_caps,
swf_url: up.settings.flash_swf_url,
xap_url: up.settings.silverlight_xap_url
});
xhr.send(formData, runtimeOptions);
} else {
// if no multipart, send as binary stream
url = plupload.buildUrl(up.settings.url, plupload.extend(args, up.settings.multipart_params));
xhr.open("post", url, true);
xhr.setRequestHeader('Content-Type', 'application/octet-stream'); // Binary stream header
xhr.open(up.settings.http_method, url, true);
// Set custom headers
plupload.each(up.settings.headers, function(value, name) {
xhr.setRequestHeader(name, value);
});
xhr.send(chunkBlob, {
runtime_order: up.settings.runtimes,
required_caps: up.settings.required_features,
preferred_caps: preferred_caps,
swf_url: up.settings.flash_swf_url,
xap_url: up.settings.silverlight_xap_url
});
// do not set Content-Type, if it was defined previously (see #1203)
if (!xhr.hasRequestHeader('Content-Type')) {
xhr.setRequestHeader('Content-Type', 'application/octet-stream'); // Binary stream header
}
xhr.send(chunkBlob, runtimeOptions);
}
}
blob = file.getSource();
// Start uploading chunks
if (up.settings.resize.enabled && runtimeCan(blob, 'send_binary_string') && !!~o.inArray(blob.type, ['image/jpeg', 'image/png'])) {
if (!plupload.isEmptyObj(up.settings.resize) && plupload.inArray(blob.type, ['image/jpeg', 'image/png']) !== -1) {
// Resize if required
resizeImage.call(this, blob, up.settings.resize, function(resizedBlob) {
resizeImage(blob, up.settings.resize, runtimeOptions, function(resizedBlob) {
blob = resizedBlob;
file.size = resizedBlob.size;
uploadNextChunk();
@@ -1607,6 +1703,7 @@ plupload.Uploader = function(options) {
// Set failed status if an error occured on a file
else if (err.code === plupload.HTTP_ERROR) {
err.file.status = plupload.FAILED;
err.file.completeTimestamp = +new Date();
calcFile(err.file);
// Upload next file but detach it from the error event
@@ -1653,26 +1750,24 @@ plupload.Uploader = function(options) {
// Default settings
settings = {
runtimes: o.Runtime.order,
max_retries: 0,
chunk_size: 0,
multipart: true,
multi_selection: true,
file_data_name: 'file',
flash_swf_url: 'js/Moxie.swf',
silverlight_xap_url: 'js/Moxie.xap',
filters: {
mime_types: [],
max_file_size: 0,
prevent_duplicates: false,
max_file_size: 0
},
resize: {
enabled: false,
preserve_headers: true,
crop: false
prevent_empty: true
},
flash_swf_url: 'js/Moxie.swf',
http_method: 'POST',
max_retries: 0,
multipart: true,
multi_selection: true,
resize: false,
runtimes: Runtime.order,
send_file_name: true,
send_chunk_number: true
send_chunk_number: true,
silverlight_xap_url: 'js/Moxie.xap'
};
@@ -1770,7 +1865,7 @@ plupload.Uploader = function(options) {
if (self.getOption(el) === null) {
err = {
code : plupload.INIT_ERROR,
message : plupload.translate("'%' specified, but cannot be found.")
message : plupload.sprintf(plupload.translate("%s specified, but cannot be found."), el)
}
return false;
}
@@ -1784,7 +1879,7 @@ plupload.Uploader = function(options) {
if (!settings.browse_button && !settings.drop_element) {
return self.trigger('Error', {
code : plupload.INIT_ERROR,
message : plupload.translate("You must specify either 'browse_button' or 'drop_element'.")
message : plupload.translate("You must specify either browse_button or drop_element.")
});
}
@@ -1800,7 +1895,7 @@ plupload.Uploader = function(options) {
}
if (inited) {
self.runtime = o.Runtime.getInfo(getRUID()).type;
self.runtime = Runtime.getInfo(getRUID()).type;
self.trigger('Init', { runtime: self.runtime });
self.trigger('PostInit');
} else {
@@ -1935,7 +2030,7 @@ plupload.Uploader = function(options) {
function filterFile(file, cb) {
var queue = [];
o.each(self.settings.filters, function(rule, name) {
plupload.each(self.settings.filters, function(rule, name) {
if (fileFilters[name]) {
queue.push(function(cb) {
fileFilters[name].call(self, rule, file, function(res) {
@@ -1944,19 +2039,19 @@ plupload.Uploader = function(options) {
});
}
});
o.inSeries(queue, cb);
plupload.inSeries(queue, cb);
}
/**
* @method resolveFile
* @private
* @param {o.File|o.Blob|plupload.File|File|Blob|input[type="file"]} file
* @param {moxie.file.File|moxie.file.Blob|plupload.File|File|Blob|input[type="file"]} file
*/
function resolveFile(file) {
var type = o.typeOf(file);
var type = plupload.typeOf(file);
// o.File
if (file instanceof o.File) {
// moxie.file.File
if (file instanceof o.file.File) {
if (!file.ruid && !file.isDetached()) {
if (!ruid) { // weird case
return false;
@@ -1966,8 +2061,8 @@ plupload.Uploader = function(options) {
}
resolveFile(new plupload.File(file));
}
// o.Blob
else if (file instanceof o.Blob) {
// moxie.file.Blob
else if (file instanceof o.file.Blob) {
resolveFile(file.getSource());
file.destroy();
}
@@ -1993,18 +2088,18 @@ plupload.Uploader = function(options) {
});
}
// native File or blob
else if (o.inArray(type, ['file', 'blob']) !== -1) {
resolveFile(new o.File(null, file));
else if (plupload.inArray(type, ['file', 'blob']) !== -1) {
resolveFile(new o.file.File(null, file));
}
// input[type="file"]
else if (type === 'node' && o.typeOf(file.files) === 'filelist') {
else if (type === 'node' && plupload.typeOf(file.files) === 'filelist') {
// if we are dealing with input[type="file"]
o.each(file.files, resolveFile);
plupload.each(file.files, resolveFile);
}
// mixed array of any supported types (see above)
else if (type === 'array') {
fileName = null; // should never happen, but unset anyway to avoid funny situations
o.each(file, resolveFile);
plupload.each(file, resolveFile);
}
}
@@ -2013,7 +2108,7 @@ plupload.Uploader = function(options) {
resolveFile(file);
if (queue.length) {
o.inSeries(queue, function() {
plupload.inSeries(queue, function() {
// if any files left after filtration, trigger FilesAdded
if (filesAdded.length) {
self.trigger("FilesAdded", filesAdded);
@@ -2039,11 +2134,12 @@ plupload.Uploader = function(options) {
},
/**
* Removes part of the queue and returns the files removed. This will also trigger the FilesRemoved and QueueChanged events.
* Removes part of the queue and returns the files removed. This will also trigger the
* FilesRemoved and QueueChanged events.
*
* @method splice
* @param {Number} start (Optional) Start index to remove from.
* @param {Number} length (Optional) Lengh of items to remove.
* @param {Number} [start=0] Start index to remove from.
* @param {Number} [length] Number of files to remove (defaults to number of files in the queue).
* @return {Array} Array of files that was removed.
*/
splice : function(start, length) {
@@ -2164,7 +2260,7 @@ plupload.Uploader = function(options) {
});
};
plupload.Uploader.prototype = o.EventTarget.instance;
plupload.Uploader.prototype = o.core.EventTarget.instance;
/**
* Constructs a new file instance.
@@ -2207,13 +2303,22 @@ plupload.File = (function() {
*/
type: file.type || '',
/**
* Relative path to the file inside a directory
*
* @property relativePath
* @type String
* @default ''
*/
relativePath: file.relativePath || '',
/**
* File size in bytes (may change after client-side manupilation).
*
* @property size
* @type Number
*/
size: file.size || file.fileSize,
size: file.fileSize || file.size,
/**
* Original file size in bytes.
@@ -2221,7 +2326,7 @@ plupload.File = (function() {
* @property origSize
* @type Number
*/
origSize: file.size || file.fileSize,
origSize: file.fileSize || file.size,
/**
* Number of bytes uploaded of the files total size.
@@ -2256,6 +2361,15 @@ plupload.File = (function() {
*/
lastModifiedDate: file.lastModifiedDate || (new Date()).toLocaleString(), // Thu Aug 23 2012 19:40:00 GMT+0400 (GET)
/**
* Set when file becomes plupload.DONE or plupload.FAILED. Is used to calculate proper plupload.QueueProgress.bytesPerSec.
* @private
* @property completeTimestamp
* @type {Number}
*/
completeTimestamp: 0,
/**
* Returns native window.File object, when it's available.
*
@@ -2264,7 +2378,7 @@ plupload.File = (function() {
*/
getNative: function() {
var file = this.getSource().getSource();
return o.inArray(o.typeOf(file), ['blob', 'file']) !== -1 ? file : null;
return plupload.inArray(plupload.typeOf(file), ['blob', 'file']) !== -1 ? file : null;
},
/**
@@ -2376,6 +2490,8 @@ plupload.File = (function() {
};
};
window.plupload = plupload;
exports.plupload = plupload;
}(window, mOxie));
}(this, moxie));
}));

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long