From c7bb44ee73f35127647ba1760d26ce66fb2c6aa4 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 20 Mar 2013 16:26:36 +0000 Subject: [PATCH] Latest jquery-fileupload assets --- .../cors/jquery.postmessage-transport.js | 0 .../cors/jquery.xdr-transport.js | 0 .../jquery-fileupload/jquery.fileupload-fp.js | 12 +- .../jquery-fileupload/jquery.fileupload-ui.js | 36 ++-- .../jquery-fileupload/jquery.fileupload.js | 183 +++++++++++------- .../jquery.iframe-transport.js | 0 .../javascripts/jquery-fileupload/main.js | 83 ++++++++ .../vendor/jquery.ui.widget.js | 2 +- .../jquery.fileupload-ui-noscript.css | 27 +++ ...pload-ui.scss => jquery.fileupload-ui.css} | 23 ++- vendor/assets/stylesheets/style.css | 15 ++ 11 files changed, 277 insertions(+), 104 deletions(-) mode change 100755 => 100644 vendor/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js mode change 100755 => 100644 vendor/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js mode change 100755 => 100644 vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js mode change 100755 => 100644 vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js mode change 100755 => 100644 vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js mode change 100755 => 100644 vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js create mode 100644 vendor/assets/javascripts/jquery-fileupload/main.js mode change 100755 => 100644 vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js create mode 100644 vendor/assets/stylesheets/jquery.fileupload-ui-noscript.css rename vendor/assets/stylesheets/{jquery.fileupload-ui.scss => jquery.fileupload-ui.css} (76%) create mode 100644 vendor/assets/stylesheets/style.css diff --git a/vendor/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js b/vendor/assets/javascripts/jquery-fileupload/cors/jquery.postmessage-transport.js old mode 100755 new mode 100644 diff --git a/vendor/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js b/vendor/assets/javascripts/jquery-fileupload/cors/jquery.xdr-transport.js old mode 100755 new mode 100644 diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js b/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js old mode 100755 new mode 100644 index fdf18fb..c782f1e --- a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js +++ b/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-fp.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload File Processing Plugin 1.2.1 + * jQuery File Upload File Processing Plugin 1.2.3 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2012, Sebastian Tschan @@ -62,9 +62,13 @@ // fileupload widget (via file input selection, drag & drop or add // API call). See the basic file upload widget for more information: add: function (e, data) { - $(this).fileupload('process', data).done(function () { - data.submit(); - }); + if (data.autoUpload || (data.autoUpload !== false && + ($(this).data('blueimp-fileupload') || + $(this).data('fileupload')).options.autoUpload)) { + $(this).fileupload('process', data).done(function () { + data.submit(); + }); + } } }, diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js b/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js old mode 100755 new mode 100644 index a23efdb..0386fb2 --- a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js +++ b/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload-ui.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload User Interface Plugin 7.3 + * jQuery File Upload User Interface Plugin 7.4.1 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2010, Sebastian Tschan @@ -263,7 +263,7 @@ // Callback for upload progress events: progress: function (e, data) { if (data.context) { - var progress = parseInt(data.loaded / data.total * 100, 10); + var progress = Math.floor(data.loaded / data.total * 100); data.context.find('.progress') .attr('aria-valuenow', progress) .find('.bar').css( @@ -275,7 +275,7 @@ // Callback for global upload progress events: progressall: function (e, data) { var $this = $(this), - progress = parseInt(data.loaded / data.total * 100, 10), + progress = Math.floor(data.loaded / data.total * 100), globalProgressNode = $this.find('.fileupload-progress'), extendedProgressNode = globalProgressNode .find('.progress-extended'); @@ -422,7 +422,7 @@ _formatTime: function (seconds) { var date = new Date(seconds * 1000), - days = parseInt(seconds / 86400, 10); + days = Math.floor(seconds / 86400); days = days ? days + 'd ' : ''; return days + ('0' + date.getUTCHours()).slice(-2) + ':' + @@ -519,6 +519,12 @@ // so we have to resolve manually: dfd.resolveWith(node); } + node.on('remove', function () { + // If the element is removed before the + // transition finishes, transition events are + // not triggered, resolve manually: + dfd.resolveWith(node); + }); }, { maxWidth: options.previewMaxWidth, @@ -607,7 +613,7 @@ _transition: function (node) { var dfd = $.Deferred(); - if ($.support.transition && node.hasClass('fade')) { + if ($.support.transition && node.hasClass('fade') && node.is(':visible')) { node.bind( $.support.transition.end, function (e) { @@ -632,27 +638,28 @@ this._on(fileUploadButtonBar.find('.start'), { click: function (e) { e.preventDefault(); - filesList.find('.start button').click(); + filesList.find('.start').click(); } }); this._on(fileUploadButtonBar.find('.cancel'), { click: function (e) { e.preventDefault(); - filesList.find('.cancel button').click(); + filesList.find('.cancel').click(); } }); this._on(fileUploadButtonBar.find('.delete'), { click: function (e) { e.preventDefault(); - filesList.find('.delete input:checked') - .siblings('button').click(); + filesList.find('.toggle:checked') + .closest('.template-download') + .find('.delete').click(); fileUploadButtonBar.find('.toggle') .prop('checked', false); } }); this._on(fileUploadButtonBar.find('.toggle'), { change: function (e) { - filesList.find('.delete input').prop( + filesList.find('.toggle').prop( 'checked', $(e.currentTarget).is(':checked') ); @@ -662,7 +669,8 @@ _destroyButtonBarEventHandlers: function () { this._off( - this.element.find('.fileupload-buttonbar button'), + this.element.find('.fileupload-buttonbar') + .find('.start, .cancel, .delete'), 'click' ); this._off( @@ -674,9 +682,9 @@ _initEventHandlers: function () { this._super(); this._on(this.options.filesContainer, { - 'click .start button': this._startHandler, - 'click .cancel button': this._cancelHandler, - 'click .delete button': this._deleteHandler + 'click .start': this._startHandler, + 'click .cancel': this._cancelHandler, + 'click .delete': this._deleteHandler }); this._initButtonBarEventHandlers(); }, diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js b/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js old mode 100755 new mode 100644 index 04caf69..de33499 --- a/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js +++ b/vendor/assets/javascripts/jquery-fileupload/jquery.fileupload.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload Plugin 5.21 + * jQuery File Upload Plugin 5.26 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2010, Sebastian Tschan @@ -33,21 +33,6 @@ $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader); $.support.xhrFormDataFileUpload = !!window.FormData; - // The form.elements propHook is added to filter serialized elements - // to not include file inputs in jQuery 1.9.0. - // This hooks directly into jQuery.fn.serializeArray. - // For more info, see http://bugs.jquery.com/ticket/13306 - $.propHooks.elements = { - get: function (form) { - if ($.nodeName(form, 'form')) { - return $.grep(form.elements, function (elem) { - return !$.nodeName(elem, 'input') || elem.type !== 'file'; - }); - } - return null; - } - }; - // The fileupload widget listens for change events on file input fields defined // via fileInput setting and paste or drop events of the given dropZone. // In addition to the default jQuery Widget methods, the fileupload widget @@ -127,6 +112,8 @@ progressInterval: 100, // Interval in milliseconds to calculate progress bitrate: bitrateInterval: 500, + // By default, uploads are started automatically when adding files: + autoUpload: true, // Additional form data to be sent along with the file uploads can be set // using this option, which accepts an array of objects with name and @@ -151,7 +138,11 @@ // handlers using jQuery's Deferred callbacks: // data.submit().done(func).fail(func).always(func); add: function (e, data) { - data.submit(); + if (data.autoUpload || (data.autoUpload !== false && + ($(this).data('blueimp-fileupload') || + $(this).data('fileupload')).options.autoUpload)) { + data.submit(); + } }, // Other callbacks: @@ -270,10 +261,17 @@ return total; }, + _initProgressObject: function (obj) { + obj._progress = { + loaded: 0, + total: 0, + bitrate: 0 + }; + }, + _onProgress: function (e, data) { if (e.lengthComputable) { var now = +(new Date()), - total, loaded; if (data._time && data.progressInterval && (now - data._time < data.progressInterval) && @@ -281,16 +279,19 @@ return; } data._time = now; - total = data.total || this._getTotal(data.files); - loaded = parseInt( - e.loaded / e.total * (data.chunkSize || total), - 10 + loaded = Math.floor( + e.loaded / e.total * (data.chunkSize || data._progress.total) ) + (data.uploadedBytes || 0); - this._loaded += loaded - (data.loaded || data.uploadedBytes || 0); - data.lengthComputable = true; - data.loaded = loaded; - data.total = total; - data.bitrate = data._bitrateTimer.getBitrate( + // Add the difference from the previously loaded state + // to the global loaded counter: + this._progress.loaded += (loaded - data._progress.loaded); + this._progress.bitrate = this._bitrateTimer.getBitrate( + now, + this._progress.loaded, + data.bitrateInterval + ); + data._progress.loaded = data.loaded = loaded; + data._progress.bitrate = data.bitrate = data._bitrateTimer.getBitrate( now, loaded, data.bitrateInterval @@ -301,16 +302,7 @@ this._trigger('progress', e, data); // Trigger a global progress event for all current file uploads, // including ajax calls queued for sequential file uploads: - this._trigger('progressall', e, { - lengthComputable: true, - loaded: this._loaded, - total: this._total, - bitrate: this._bitrateTimer.getBitrate( - now, - this._loaded, - data.bitrateInterval - ) - }); + this._trigger('progressall', e, this._progress); } }, @@ -495,6 +487,21 @@ return options; }, + // jQuery 1.6 doesn't provide .state(), + // while jQuery 1.8+ removed .isRejected() and .isResolved(): + _getDeferredState: function (deferred) { + if (deferred.state) { + return deferred.state(); + } + if (deferred.isResolved()) { + return 'resolved'; + } + if (deferred.isRejected()) { + return 'rejected'; + } + return 'pending'; + }, + // Maps jqXHR callbacks to the equivalent // methods of the given Promise object: _enhancePromise: function (promise) { @@ -519,6 +526,33 @@ return this._enhancePromise(promise); }, + // Adds convenience methods to the callback arguments: + _addConvenienceMethods: function (e, data) { + var that = this; + data.submit = function () { + if (this.state() !== 'pending') { + data.jqXHR = this.jqXHR = + (that._trigger('submit', e, this) !== false) && + that._onSend(e, this); + } + return this.jqXHR || that._getXHRPromise(); + }; + data.abort = function () { + if (this.jqXHR) { + return this.jqXHR.abort(); + } + return this._getXHRPromise(); + }; + data.state = function () { + if (this.jqXHR) { + return that._getDeferredState(this.jqXHR); + } + }; + data.progress = function () { + return this._progress; + }; + }, + // Parses the Range header from the server response // and returns the uploaded bytes: _getUploadedBytes: function (jqXHR) { @@ -561,9 +595,10 @@ ); } // The chunk upload method: - upload = function (i) { + upload = function () { // Clone the options object for each chunk upload: - var o = $.extend({}, options); + var o = $.extend({}, options), + currentLoaded = o._progress.loaded; o.blob = slice.call( file, ub, @@ -585,10 +620,10 @@ .done(function (result, textStatus, jqXHR) { ub = that._getUploadedBytes(jqXHR) || (ub + o.chunkSize); - // Create a progress event if upload is done and no progress - // event has been invoked for this chunk, or there has been - // no progress event with loaded equaling total: - if (!o.loaded || o.loaded < o.total) { + // Create a progress event if no final progress event + // with loaded equaling total has been triggered + // for this chunk: + if (o._progress.loaded === currentLoaded) { that._onProgress($.Event('progress', { lengthComputable: true, loaded: ub - o.uploadedBytes, @@ -640,20 +675,27 @@ this._trigger('start'); // Set timer for global bitrate progress calculation: this._bitrateTimer = new this._BitrateTimer(); + // Reset the global progress values: + this._progress.loaded = this._progress.total = 0; + this._progress.bitrate = 0; } + if (!data._progress) { + data._progress = {}; + } + data._progress.loaded = data.loaded = data.uploadedBytes || 0; + data._progress.total = data.total = this._getTotal(data.files) || 1; + data._progress.bitrate = data.bitrate = 0; this._active += 1; // Initialize the global progress values: - this._loaded += data.uploadedBytes || 0; - this._total += this._getTotal(data.files); + this._progress.loaded += data.loaded; + this._progress.total += data.total; }, _onDone: function (result, textStatus, jqXHR, options) { - if (!this._isXHRUpload(options) || !options.loaded || - options.loaded < options.total) { - var total = this._getTotal(options.files) || 1; - // Create a progress event for each iframe load, - // or if there has been no progress event with - // loaded equaling total for XHR uploads: + var total = options._progress.total; + if (options._progress.loaded < total) { + // Create a progress event if no final progress event + // with loaded equaling total has been triggered: this._onProgress($.Event('progress', { lengthComputable: true, loaded: total, @@ -674,8 +716,8 @@ if (options.recalculateProgress) { // Remove the failed (error or abort) file upload from // the global progress calculation: - this._loaded -= options.loaded || options.uploadedBytes || 0; - this._total -= options.total || this._getTotal(options.files); + this._progress.loaded -= options._progress.loaded; + this._progress.total -= options._progress.total; } }, @@ -688,13 +730,13 @@ // The stop callback is triggered when all uploads have // been completed, equivalent to the global ajaxStop event: this._trigger('stop'); - // Reset the global progress values: - this._loaded = this._total = 0; - this._bitrateTimer = null; } }, _onSend: function (e, data) { + if (!data.submit) { + this._addConvenienceMethods(e, data); + } var that = this, jqXHR, aborted, @@ -725,15 +767,9 @@ options.limitConcurrentUploads > that._sending) { // Start the next queued upload, // that has not been aborted: - var nextSlot = that._slots.shift(), - isPending; + var nextSlot = that._slots.shift(); while (nextSlot) { - // jQuery 1.6 doesn't provide .state(), - // while jQuery 1.8+ removed .isRejected(): - isPending = nextSlot.state ? - nextSlot.state() === 'pending' : - !nextSlot.isRejected(); - if (isPending) { + if (that._getDeferredState(nextSlot) === 'pending') { nextSlot.resolve(); break; } @@ -805,12 +841,8 @@ var newData = $.extend({}, data); newData.files = fileSet ? element : [element]; newData.paramName = paramNameSet[index]; - newData.submit = function () { - newData.jqXHR = this.jqXHR = - (that._trigger('submit', e, this) !== false) && - that._onSend(e, this); - return this.jqXHR; - }; + that._initProgressObject(newData); + that._addConvenienceMethods(e, newData); result = that._trigger('add', e, newData); return result; }); @@ -1084,12 +1116,17 @@ this._initSpecialOptions(); this._slots = []; this._sequence = this._getXHRPromise(true); - this._sending = this._active = this._loaded = this._total = 0; + this._sending = this._active = 0; + this._initProgressObject(this); this._initEventHandlers(); }, - _destroy: function () { - this._destroyEventHandlers(); + // This method is exposed to the widget API and allows to query + // the widget upload progress. + // It returns an object with loaded, total and bitrate properties + // for the running uploads: + progress: function () { + return this._progress; }, // This method is exposed to the widget API and allows adding files diff --git a/vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js b/vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js old mode 100755 new mode 100644 diff --git a/vendor/assets/javascripts/jquery-fileupload/main.js b/vendor/assets/javascripts/jquery-fileupload/main.js new file mode 100644 index 0000000..dbabd8f --- /dev/null +++ b/vendor/assets/javascripts/jquery-fileupload/main.js @@ -0,0 +1,83 @@ +/* + * jQuery File Upload Plugin JS Example 7.0 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2010, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global $, window, document */ + +$(function () { + 'use strict'; + + // Initialize the jQuery File Upload widget: + $('#fileupload').fileupload({ + // Uncomment the following to send cross-domain cookies: + //xhrFields: {withCredentials: true}, + url: 'server/php/' + }); + + // Enable iframe cross-domain access via redirect option: + $('#fileupload').fileupload( + 'option', + 'redirect', + window.location.href.replace( + /\/[^\/]*$/, + '/cors/result.html?%s' + ) + ); + + if (window.location.hostname === 'blueimp.github.com') { + // Demo settings: + $('#fileupload').fileupload('option', { + url: '//jquery-file-upload.appspot.com/', + maxFileSize: 5000000, + acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, + process: [ + { + action: 'load', + fileTypes: /^image\/(gif|jpeg|png)$/, + maxFileSize: 20000000 // 20MB + }, + { + action: 'resize', + maxWidth: 1440, + maxHeight: 900 + }, + { + action: 'save' + } + ] + }); + // Upload server status check for browsers with CORS support: + if ($.support.cors) { + $.ajax({ + url: '//jquery-file-upload.appspot.com/', + type: 'HEAD' + }).fail(function () { + $('') + .text('Upload server currently unavailable - ' + + new Date()) + .appendTo('#fileupload'); + }); + } + } else { + // Load existing files: + $.ajax({ + // Uncomment the following to send cross-domain cookies: + //xhrFields: {withCredentials: true}, + url: $('#fileupload').fileupload('option', 'url'), + dataType: 'json', + context: $('#fileupload')[0] + }).done(function (result) { + $(this).fileupload('option', 'done') + .call(this, null, {result: result}); + }); + } + +}); diff --git a/vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js b/vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js old mode 100755 new mode 100644 index f5d71a1..fd2948f --- a/vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js +++ b/vendor/assets/javascripts/jquery-fileupload/vendor/jquery.ui.widget.js @@ -1,5 +1,5 @@ /* - * jQuery UI Widget 1.10.0+amd + * jQuery UI Widget 1.10.1+amd * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2013 jQuery Foundation and other contributors diff --git a/vendor/assets/stylesheets/jquery.fileupload-ui-noscript.css b/vendor/assets/stylesheets/jquery.fileupload-ui-noscript.css new file mode 100644 index 0000000..c450485 --- /dev/null +++ b/vendor/assets/stylesheets/jquery.fileupload-ui-noscript.css @@ -0,0 +1,27 @@ +@charset "UTF-8"; +/* + * jQuery File Upload UI Plugin NoScript CSS 1.0 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2012, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +.fileinput-button input { + position: static; + opacity: 1; + filter: none; + transform: none; + font-size: inherit; + direction: inherit; +} + +.fileinput-button span, +.fileinput-button i, +.fileupload-buttonbar .delete, +.fileupload-buttonbar .toggle { + display: none; +} diff --git a/vendor/assets/stylesheets/jquery.fileupload-ui.scss b/vendor/assets/stylesheets/jquery.fileupload-ui.css similarity index 76% rename from vendor/assets/stylesheets/jquery.fileupload-ui.scss rename to vendor/assets/stylesheets/jquery.fileupload-ui.css index 58a7315..4f994f2 100644 --- a/vendor/assets/stylesheets/jquery.fileupload-ui.scss +++ b/vendor/assets/stylesheets/jquery.fileupload-ui.css @@ -1,6 +1,6 @@ -@charset 'UTF-8'; +@charset "UTF-8"; /* - * jQuery File Upload UI Plugin CSS 6.3 + * jQuery File Upload UI Plugin CSS 7.4 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2010, Sebastian Tschan @@ -21,11 +21,10 @@ top: 0; right: 0; margin: 0; - border: solid transparent; - border-width: 0 0 100px 200px; opacity: 0; filter: alpha(opacity=0); - -moz-transform: translate(-300px, 0) scale(4); + transform: translate(-300px, 0) scale(4); + font-size: 23px; direction: ltr; cursor: pointer; } @@ -37,7 +36,7 @@ width: 200px; } .progress-animated .bar { - background: image-url('progressbar.gif') !important; + background: url(../img/progressbar.gif) !important; filter: none; } .fileupload-loading { @@ -45,7 +44,7 @@ left: 50%; width: 128px; height: 128px; - background: image-url('loading.gif') center no-repeat; + background: url(../img/loading.gif) center no-repeat; display: none; } .fileupload-processing .fileupload-loading { @@ -54,16 +53,19 @@ /* Fix for IE 6: */ * html .fileinput-button { - line-height: 22px; + line-height: 24px; margin: 1px -3px 0 0; } /* Fix for IE 7: */ * + html .fileinput-button { + padding: 2px 15px; margin: 1px 0 0 0; } -@media (max-width: 480px) { +@media (max-width: 767px) { + .fileupload-buttonbar .toggle, + .files .toggle, .files .btn span { display: none; } @@ -78,7 +80,4 @@ .files .progress { width: 20px; } - .files .delete { - width: 60px; - } } diff --git a/vendor/assets/stylesheets/style.css b/vendor/assets/stylesheets/style.css new file mode 100644 index 0000000..87244e4 --- /dev/null +++ b/vendor/assets/stylesheets/style.css @@ -0,0 +1,15 @@ +@charset "UTF-8"; +/* + * jQuery File Upload Plugin CSS Example 1.0.1 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2012, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://www.opensource.org/licenses/MIT + */ + +body{ + padding-top: 60px; +}