From e2b43578a677894d23fa526d9201e5a89b231abc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 15 Jun 2011 19:08:40 -0400 Subject: load attachment javascript into template the clean way --- .../attachment/ikiwiki/jquery.fileupload-ui.js | 357 ++++++++++ underlays/attachment/ikiwiki/jquery.fileupload.js | 720 +++++++++++++++++++++ .../attachment/ikiwiki/jquery.iframe-transport.js | 133 ++++ underlays/attachment/ikiwiki/pbar-ani.gif | Bin 0 -> 3323 bytes .../attachments/ikiwiki/jquery.fileupload-ui.css | 8 - .../attachments/ikiwiki/jquery.fileupload-ui.js | 357 ---------- underlays/attachments/ikiwiki/jquery.fileupload.js | 720 --------------------- .../attachments/ikiwiki/jquery.iframe-transport.js | 133 ---- underlays/attachments/ikiwiki/pbar-ani.gif | Bin 3323 -> 0 bytes 9 files changed, 1210 insertions(+), 1218 deletions(-) create mode 100644 underlays/attachment/ikiwiki/jquery.fileupload-ui.js create mode 100644 underlays/attachment/ikiwiki/jquery.fileupload.js create mode 100644 underlays/attachment/ikiwiki/jquery.iframe-transport.js create mode 100644 underlays/attachment/ikiwiki/pbar-ani.gif delete mode 100644 underlays/attachments/ikiwiki/jquery.fileupload-ui.css delete mode 100644 underlays/attachments/ikiwiki/jquery.fileupload-ui.js delete mode 100644 underlays/attachments/ikiwiki/jquery.fileupload.js delete mode 100644 underlays/attachments/ikiwiki/jquery.iframe-transport.js delete mode 100644 underlays/attachments/ikiwiki/pbar-ani.gif (limited to 'underlays') diff --git a/underlays/attachment/ikiwiki/jquery.fileupload-ui.js b/underlays/attachment/ikiwiki/jquery.fileupload-ui.js new file mode 100644 index 000000000..61897ba55 --- /dev/null +++ b/underlays/attachment/ikiwiki/jquery.fileupload-ui.js @@ -0,0 +1,357 @@ +/* + * jQuery File Upload User Interface Plugin 5.0.13 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2010, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://creativecommons.org/licenses/MIT/ + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global window, document, URL, webkitURL, FileReader, jQuery */ + +(function ($) { + 'use strict'; + + // The UI version extends the basic fileupload widget and adds + // a complete user interface based on the given upload/download + // templates. + $.widget('blueimpUI.fileupload', $.blueimp.fileupload, { + + options: { + // By default, files added to the widget are uploaded as soon + // as the user clicks on the start buttons. To enable automatic + // uploads, set the following option to true: + autoUpload: true, + // The file upload template that is given as first argument to the + // jQuery.tmpl method to render the file uploads: + uploadTemplate: $('#template-upload'), + // The file download template, that is given as first argument to the + // jQuery.tmpl method to render the file downloads: + downloadTemplate: $('#template-download'), + // The expected data type of the upload response, sets the dataType + // option of the $.ajax upload requests: + dataType: 'json', + + // The add callback is invoked as soon as files are added to the 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) { + var that = $(this).data('fileupload'); + data.isAdjusted = true; + data.isValidated = that._validate(data.files); + data.context = that._renderUpload(data.files) + .appendTo($(this).find('.files')).fadeIn(function () { + // Fix for IE7 and lower: + $(this).show(); + }).data('data', data); + if ((that.options.autoUpload || data.autoUpload) && + data.isValidated) { + data.jqXHR = data.submit(); + } + }, + // Callback for the start of each file upload request: + send: function (e, data) { + if (!data.isValidated) { + var that = $(this).data('fileupload'); + if (!that._validate(data.files)) { + return false; + } + } + if (data.context && data.dataType && + data.dataType.substr(0, 6) === 'iframe') { + // Iframe Transport does not support progress events. + // In lack of an indeterminate progress bar, we set + // the progress to 100%, showing the full animated bar: + data.context.find('.ui-progressbar').progressbar( + 'value', + parseInt(100, 10) + ); + } + }, + // Callback for successful uploads: + done: function (e, data) { + var that = $(this).data('fileupload'); + if (data.context) { + data.context.each(function (index) { + var file = ($.isArray(data.result) && + data.result[index]) || {error: 'emptyResult'}; + $(this).fadeOut(function () { + that._renderDownload([file]) + .css('display', 'none') + .replaceAll(this) + .fadeIn(function () { + // Fix for IE7 and lower: + $(this).show(); + }); + }); + }); + } else { + that._renderDownload(data.result) + .css('display', 'none') + .appendTo($(this).find('.files')) + .fadeIn(function () { + // Fix for IE7 and lower: + $(this).show(); + }); + } + }, + // Callback for failed (abort or error) uploads: + fail: function (e, data) { + var that = $(this).data('fileupload'); + if (data.context) { + data.context.each(function (index) { + $(this).fadeOut(function () { + if (data.errorThrown !== 'abort') { + var file = data.files[index]; + file.error = file.error || data.errorThrown + || true; + that._renderDownload([file]) + .css('display', 'none') + .replaceAll(this) + .fadeIn(function () { + // Fix for IE7 and lower: + $(this).show(); + }); + } else { + data.context.remove(); + } + }); + }); + } else if (data.errorThrown !== 'abort') { + data.context = that._renderUpload(data.files) + .css('display', 'none') + .appendTo($(this).find('.files')) + .fadeIn(function () { + // Fix for IE7 and lower: + $(this).show(); + }).data('data', data); + } + }, + // Callback for upload progress events: + progress: function (e, data) { + if (data.context) { + data.context.find('.ui-progressbar').progressbar( + 'value', + parseInt(data.loaded / data.total * 100, 10) + ); + } + }, + // Callback for global upload progress events: + progressall: function (e, data) { + $(this).find('.fileupload-progressbar').progressbar( + 'value', + parseInt(data.loaded / data.total * 100, 10) + ); + }, + // Callback for uploads start, equivalent to the global ajaxStart event: + start: function () { + $(this).find('.fileupload-progressbar') + .progressbar('value', 0).fadeIn(); + }, + // Callback for uploads stop, equivalent to the global ajaxStop event: + stop: function () { + $(this).find('.fileupload-progressbar').fadeOut(); + }, + }, + + _createObjectURL: function (file) { + var undef = 'undefined', + urlAPI = (typeof window.createObjectURL !== undef && window) || + (typeof URL !== undef && URL) || + (typeof webkitURL !== undef && webkitURL); + return urlAPI ? urlAPI.createObjectURL(file) : false; + }, + + _revokeObjectURL: function (url) { + var undef = 'undefined', + urlAPI = (typeof window.revokeObjectURL !== undef && window) || + (typeof URL !== undef && URL) || + (typeof webkitURL !== undef && webkitURL); + return urlAPI ? urlAPI.revokeObjectURL(url) : false; + }, + + // Link handler, that allows to download files + // by drag & drop of the links to the desktop: + _enableDragToDesktop: function () { + var link = $(this), + url = link.prop('href'), + name = decodeURIComponent(url.split('/').pop()) + .replace(/:/g, '-'), + type = 'application/octet-stream'; + link.bind('dragstart', function (e) { + try { + e.originalEvent.dataTransfer.setData( + 'DownloadURL', + [type, name, url].join(':') + ); + } catch (err) {} + }); + }, + + _hasError: function (file) { + if (file.error) { + return file.error; + } + return null; + }, + + _validate: function (files) { + var that = this, + valid; + $.each(files, function (index, file) { + file.error = that._hasError(file); + valid = !file.error; + }); + return valid; + }, + + _uploadTemplateHelper: function (file) { + return file; + }, + + _renderUploadTemplate: function (files) { + var that = this; + return $.tmpl( + this.options.uploadTemplate, + $.map(files, function (file) { + return that._uploadTemplateHelper(file); + }) + ); + }, + + _renderUpload: function (files) { + var that = this, + options = this.options, + tmpl = this._renderUploadTemplate(files); + if (!(tmpl instanceof $)) { + return $(); + } + tmpl.css('display', 'none'); + // .slice(1).remove().end().first() removes all but the first + // element and selects only the first for the jQuery collection: + tmpl.find('.progress div').slice(1).remove().end().first() + .progressbar(); + tmpl.find('.start button').slice( + this.options.autoUpload ? 0 : 1 + ).remove().end().first() + .button({ + text: false, + icons: {primary: 'ui-icon-circle-arrow-e'} + }); + tmpl.find('.cancel button').slice(1).remove().end().first() + .button({ + text: false, + icons: {primary: 'ui-icon-cancel'} + }); + return tmpl; + }, + + _downloadTemplateHelper: function (file) { + return file; + }, + + _renderDownloadTemplate: function (files) { + var that = this; + return $.tmpl( + this.options.downloadTemplate, + $.map(files, function (file) { + return that._downloadTemplateHelper(file); + }) + ); + }, + + _renderDownload: function (files) { + var tmpl = this._renderDownloadTemplate(files); + if (!(tmpl instanceof $)) { + return $(); + } + tmpl.css('display', 'none'); + tmpl.find('a').each(this._enableDragToDesktop); + return tmpl; + }, + + _startHandler: function (e) { + e.preventDefault(); + var tmpl = $(this).closest('.template-upload'), + data = tmpl.data('data'); + if (data && data.submit && !data.jqXHR) { + data.jqXHR = data.submit(); + $(this).fadeOut(); + } + }, + + _cancelHandler: function (e) { + e.preventDefault(); + var tmpl = $(this).closest('.template-upload'), + data = tmpl.data('data') || {}; + if (!data.jqXHR) { + data.errorThrown = 'abort'; + e.data.fileupload._trigger('fail', e, data); + } else { + data.jqXHR.abort(); + } + }, + + _initEventHandlers: function () { + $.blueimp.fileupload.prototype._initEventHandlers.call(this); + var filesList = this.element.find('.files'), + eventData = {fileupload: this}; + filesList.find('.start button') + .live( + 'click.' + this.options.namespace, + eventData, + this._startHandler + ); + filesList.find('.cancel button') + .live( + 'click.' + this.options.namespace, + eventData, + this._cancelHandler + ); + }, + + _destroyEventHandlers: function () { + var filesList = this.element.find('.files'); + filesList.find('.start button') + .die('click.' + this.options.namespace); + filesList.find('.cancel button') + .die('click.' + this.options.namespace); + $.blueimp.fileupload.prototype._destroyEventHandlers.call(this); + }, + + _initTemplates: function () { + // Handle cases where the templates are defined + // after the widget library has been included: + if (this.options.uploadTemplate instanceof $ && + !this.options.uploadTemplate.length) { + this.options.uploadTemplate = $( + this.options.uploadTemplate.selector + ); + } + if (this.options.downloadTemplate instanceof $ && + !this.options.downloadTemplate.length) { + this.options.downloadTemplate = $( + this.options.downloadTemplate.selector + ); + } + }, + + _create: function () { + $.blueimp.fileupload.prototype._create.call(this); + this._initTemplates(); + }, + + enable: function () { + $.blueimp.fileupload.prototype.enable.call(this); + }, + + disable: function () { + $.blueimp.fileupload.prototype.disable.call(this); + } + + }); + +}(jQuery)); diff --git a/underlays/attachment/ikiwiki/jquery.fileupload.js b/underlays/attachment/ikiwiki/jquery.fileupload.js new file mode 100644 index 000000000..1e3c6bf97 --- /dev/null +++ b/underlays/attachment/ikiwiki/jquery.fileupload.js @@ -0,0 +1,720 @@ +/* + * jQuery File Upload Plugin 5.0.2 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2010, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://creativecommons.org/licenses/MIT/ + */ + +/*jslint nomen: true, unparam: true, regexp: true */ +/*global document, XMLHttpRequestUpload, Blob, File, FormData, location, jQuery */ + +(function ($) { + 'use strict'; + + // The fileupload widget listens for change events on file input fields + // defined via fileInput setting and drop events of the given dropZone. + // In addition to the default jQuery Widget methods, the fileupload widget + // exposes the "add" and "send" methods, to add or directly send files + // using the fileupload API. + // By default, files added via file input selection, drag & drop or + // "add" method are uploaded immediately, but it is possible to override + // the "add" callback option to queue file uploads. + $.widget('blueimp.fileupload', { + + options: { + // The namespace used for event handler binding on the dropZone and + // fileInput collections. + // If not set, the name of the widget ("fileupload") is used. + namespace: undefined, + // The drop target collection, by the default the complete document. + // Set to null or an empty collection to disable drag & drop support: + dropZone: $(document), + // The file input field collection, that is listened for change events. + // If undefined, it is set to the file input fields inside + // of the widget element on plugin initialization. + // Set to null or an empty collection to disable the change listener. + fileInput: undefined, + // By default, the file input field is replaced with a clone after + // each input field change event. This is required for iframe transport + // queues and allows change events to be fired for the same file + // selection, but can be disabled by setting the following option to false: + replaceFileInput: true, + // The parameter name for the file form data (the request argument name). + // If undefined or empty, the name property of the file input field is + // used, or "files[]" if the file input name property is also empty: + paramName: undefined, + // By default, each file of a selection is uploaded using an individual + // request for XHR type uploads. Set to false to upload file + // selections in one request each: + singleFileUploads: true, + // Set the following option to true to issue all file upload requests + // in a sequential order: + sequentialUploads: false, + // Set the following option to true to force iframe transport uploads: + forceIframeTransport: false, + // By default, XHR file uploads are sent as multipart/form-data. + // The iframe transport is always using multipart/form-data. + // Set to false to enable non-multipart XHR uploads: + multipart: true, + // To upload large files in smaller chunks, set the following option + // to a preferred maximum chunk size. If set to 0, null or undefined, + // or the browser does not support the required Blob API, files will + // be uploaded as a whole. + maxChunkSize: undefined, + // When a non-multipart upload or a chunked multipart upload has been + // aborted, this option can be used to resume the upload by setting + // it to the size of the already uploaded bytes. This option is most + // useful when modifying the options object inside of the "add" or + // "send" callbacks, as the options are cloned for each file upload. + uploadedBytes: undefined, + // By default, failed (abort or error) file uploads are removed from the + // global progress calculation. Set the following option to false to + // prevent recalculating the global progress data: + recalculateProgress: 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 + // value properties, a function returning such an array, a FormData + // object (for XHR file uploads), or a simple object. + // The form of the first fileInput is given as parameter to the function: + formData: function (form) { + return form.serializeArray(); + }, + + // The add callback is invoked as soon as files are added to the fileupload + // widget (via file input selection, drag & drop or add API call). + // If the singleFileUploads option is enabled, this callback will be + // called once for each file in the selection for XHR file uplaods, else + // once for each file selection. + // The upload starts when the submit method is invoked on the data parameter. + // The data object contains a files property holding the added files + // and allows to override plugin options as well as define ajax settings. + // Listeners for this callback can also be bound the following way: + // .bind('fileuploadadd', func); + // data.submit() returns a Promise object and allows to attach additional + // handlers using jQuery's Deferred callbacks: + // data.submit().done(func).fail(func).always(func); + add: function (e, data) { + data.submit(); + }, + + // Other callbacks: + // Callback for the start of each file upload request: + // send: function (e, data) {}, // .bind('fileuploadsend', func); + // Callback for successful uploads: + // done: function (e, data) {}, // .bind('fileuploaddone', func); + // Callback for failed (abort or error) uploads: + // fail: function (e, data) {}, // .bind('fileuploadfail', func); + // Callback for completed (success, abort or error) requests: + // always: function (e, data) {}, // .bind('fileuploadalways', func); + // Callback for upload progress events: + // progress: function (e, data) {}, // .bind('fileuploadprogress', func); + // Callback for global upload progress events: + // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func); + // Callback for uploads start, equivalent to the global ajaxStart event: + // start: function (e) {}, // .bind('fileuploadstart', func); + // Callback for uploads stop, equivalent to the global ajaxStop event: + // stop: function (e) {}, // .bind('fileuploadstop', func); + // Callback for change events of the fileInput collection: + // change: function (e, data) {}, // .bind('fileuploadchange', func); + // Callback for drop events of the dropZone collection: + // drop: function (e, data) {}, // .bind('fileuploaddrop', func); + // Callback for dragover events of the dropZone collection: + // dragover: function (e) {}, // .bind('fileuploaddragover', func); + + // The plugin options are used as settings object for the ajax calls. + // The following are jQuery ajax settings required for the file uploads: + processData: false, + contentType: false, + cache: false + }, + + // A list of options that require a refresh after assigning a new value: + _refreshOptionsList: ['namespace', 'dropZone', 'fileInput'], + + _isXHRUpload: function (options) { + var undef = 'undefined'; + return !options.forceIframeTransport && + typeof XMLHttpRequestUpload !== undef && typeof File !== undef && + (!options.multipart || typeof FormData !== undef); + }, + + _getFormData: function (options) { + var formData; + if (typeof options.formData === 'function') { + return options.formData(options.form); + } else if ($.isArray(options.formData)) { + return options.formData; + } else if (options.formData) { + formData = []; + $.each(options.formData, function (name, value) { + formData.push({name: name, value: value}); + }); + return formData; + } + return []; + }, + + _getTotal: function (files) { + var total = 0; + $.each(files, function (index, file) { + total += file.size || 1; + }); + return total; + }, + + _onProgress: function (e, data) { + if (e.lengthComputable) { + var total = data.total || this._getTotal(data.files), + loaded = parseInt( + e.loaded / e.total * (data.chunkSize || total), + 10 + ) + (data.uploadedBytes || 0); + this._loaded += loaded - (data.loaded || data.uploadedBytes || 0); + data.lengthComputable = true; + data.loaded = loaded; + data.total = total; + // Trigger a custom progress event with a total data property set + // to the file size(s) of the current upload and a loaded data + // property calculated accordingly: + 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 + }); + } + }, + + _initProgressListener: function (options) { + var that = this, + xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr(); + // Accesss to the native XHR object is required to add event listeners + // for the upload progress event: + if (xhr.upload && xhr.upload.addEventListener) { + xhr.upload.addEventListener('progress', function (e) { + that._onProgress(e, options); + }, false); + options.xhr = function () { + return xhr; + }; + } + }, + + _initXHRData: function (options) { + var formData, + file = options.files[0]; + if (!options.multipart || options.blob) { + // For non-multipart uploads and chunked uploads, + // file meta data is not part of the request body, + // so we transmit this data as part of the HTTP headers. + // For cross domain requests, these headers must be allowed + // via Access-Control-Allow-Headers or removed using + // the beforeSend callback: + options.headers = $.extend(options.headers, { + 'X-File-Name': file.name, + 'X-File-Type': file.type, + 'X-File-Size': file.size + }); + if (!options.blob) { + // Non-chunked non-multipart upload: + options.contentType = file.type; + options.data = file; + } else if (!options.multipart) { + // Chunked non-multipart upload: + options.contentType = 'application/octet-stream'; + options.data = options.blob; + } + } + if (options.multipart && typeof FormData !== 'undefined') { + if (options.formData instanceof FormData) { + formData = options.formData; + } else { + formData = new FormData(); + $.each(this._getFormData(options), function (index, field) { + formData.append(field.name, field.value); + }); + } + if (options.blob) { + formData.append(options.paramName, options.blob); + } else { + $.each(options.files, function (index, file) { + // File objects are also Blob instances. + // This check allows the tests to run with + // dummy objects: + if (file instanceof Blob) { + formData.append(options.paramName, file); + } + }); + } + options.data = formData; + } + // Blob reference is not needed anymore, free memory: + options.blob = null; + }, + + _initIframeSettings: function (options) { + // Setting the dataType to iframe enables the iframe transport: + options.dataType = 'iframe ' + (options.dataType || ''); + // The iframe transport accepts a serialized array as form data: + options.formData = this._getFormData(options); + }, + + _initDataSettings: function (options) { + if (this._isXHRUpload(options)) { + if (!this._chunkedUpload(options, true)) { + if (!options.data) { + this._initXHRData(options); + } + this._initProgressListener(options); + } + } else { + this._initIframeSettings(options); + } + }, + + _initFormSettings: function (options) { + // Retrieve missing options from the input field and the + // associated form, if available: + if (!options.form || !options.form.length) { + options.form = $(options.fileInput.prop('form')); + } + if (!options.paramName) { + options.paramName = options.fileInput.prop('name') || + 'files[]'; + } + if (!options.url) { + options.url = options.form.prop('action') || location.href; + } + // The HTTP request method must be "POST" or "PUT": + options.type = (options.type || options.form.prop('method') || '') + .toUpperCase(); + if (options.type !== 'POST' && options.type !== 'PUT') { + options.type = 'POST'; + } + }, + + _getAJAXSettings: function (data) { + var options = $.extend({}, this.options, data); + this._initFormSettings(options); + this._initDataSettings(options); + return options; + }, + + // Maps jqXHR callbacks to the equivalent + // methods of the given Promise object: + _enhancePromise: function (promise) { + promise.success = promise.done; + promise.error = promise.fail; + promise.complete = promise.always; + return promise; + }, + + // Creates and returns a Promise object enhanced with + // the jqXHR methods abort, success, error and complete: + _getXHRPromise: function (resolveOrReject, context, args) { + var dfd = $.Deferred(), + promise = dfd.promise(); + context = context || this.options.context || promise; + if (resolveOrReject === true) { + dfd.resolveWith(context, args); + } else if (resolveOrReject === false) { + dfd.rejectWith(context, args); + } + promise.abort = dfd.promise; + return this._enhancePromise(promise); + }, + + // Uploads a file in multiple, sequential requests + // by splitting the file up in multiple blob chunks. + // If the second parameter is true, only tests if the file + // should be uploaded in chunks, but does not invoke any + // upload requests: + _chunkedUpload: function (options, testOnly) { + var that = this, + file = options.files[0], + fs = file.size, + ub = options.uploadedBytes = options.uploadedBytes || 0, + mcs = options.maxChunkSize || fs, + // Use the Blob methods with the slice implementation + // according to the W3C Blob API specification: + slice = file.webkitSlice || file.mozSlice || file.slice, + upload, + n, + jqXHR, + pipe; + if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) || + options.data) { + return false; + } + if (testOnly) { + return true; + } + if (ub >= fs) { + file.error = 'uploadedBytes'; + return this._getXHRPromise(false); + } + // n is the number of blobs to upload, + // calculated via filesize, uploaded bytes and max chunk size: + n = Math.ceil((fs - ub) / mcs); + // The chunk upload method accepting the chunk number as parameter: + upload = function (i) { + if (!i) { + return that._getXHRPromise(true); + } + // Upload the blobs in sequential order: + return upload(i -= 1).pipe(function () { + // Clone the options object for each chunk upload: + var o = $.extend({}, options); + o.blob = slice.call( + file, + ub + i * mcs, + ub + (i + 1) * mcs + ); + // Store the current chunk size, as the blob itself + // will be dereferenced after data processing: + o.chunkSize = o.blob.size; + // Process the upload data (the blob and potential form data): + that._initXHRData(o); + // Add progress listeners for this chunk upload: + that._initProgressListener(o); + jqXHR = ($.ajax(o) || that._getXHRPromise(false, o.context)) + .done(function () { + // Create a progress event if upload is done and + // no progress event has been invoked for this chunk: + if (!o.loaded) { + that._onProgress($.Event('progress', { + lengthComputable: true, + loaded: o.chunkSize, + total: o.chunkSize + }), o); + } + options.uploadedBytes = o.uploadedBytes + += o.chunkSize; + }); + return jqXHR; + }); + }; + // Return the piped Promise object, enhanced with an abort method, + // which is delegated to the jqXHR object of the current upload, + // and jqXHR callbacks mapped to the equivalent Promise methods: + pipe = upload(n); + pipe.abort = function () { + return jqXHR.abort(); + }; + return this._enhancePromise(pipe); + }, + + _beforeSend: function (e, data) { + if (this._active === 0) { + // the start callback is triggered when an upload starts + // and no other uploads are currently running, + // equivalent to the global ajaxStart event: + this._trigger('start'); + } + this._active += 1; + // Initialize the global progress values: + this._loaded += data.uploadedBytes || 0; + this._total += this._getTotal(data.files); + }, + + _onDone: function (result, textStatus, jqXHR, options) { + if (!this._isXHRUpload(options)) { + // Create a progress event for each iframe load: + this._onProgress($.Event('progress', { + lengthComputable: true, + loaded: 1, + total: 1 + }), options); + } + options.result = result; + options.textStatus = textStatus; + options.jqXHR = jqXHR; + this._trigger('done', null, options); + }, + + _onFail: function (jqXHR, textStatus, errorThrown, options) { + options.jqXHR = jqXHR; + options.textStatus = textStatus; + options.errorThrown = errorThrown; + this._trigger('fail', null, options); + 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); + } + }, + + _onAlways: function (result, textStatus, jqXHR, errorThrown, options) { + this._active -= 1; + options.result = result; + options.textStatus = textStatus; + options.jqXHR = jqXHR; + options.errorThrown = errorThrown; + this._trigger('always', null, options); + if (this._active === 0) { + // 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; + } + }, + + _onSend: function (e, data) { + var that = this, + jqXHR, + pipe, + options = that._getAJAXSettings(data), + send = function (resolve, args) { + jqXHR = jqXHR || ( + (resolve !== false && + that._trigger('send', e, options) !== false && + (that._chunkedUpload(options) || $.ajax(options))) || + that._getXHRPromise(false, options.context, args) + ).done(function (result, textStatus, jqXHR) { + that._onDone(result, textStatus, jqXHR, options); + }).fail(function (jqXHR, textStatus, errorThrown) { + that._onFail(jqXHR, textStatus, errorThrown, options); + }).always(function (a1, a2, a3) { + if (!a3 || typeof a3 === 'string') { + that._onAlways(undefined, a2, a1, a3, options); + } else { + that._onAlways(a1, a2, a3, undefined, options); + } + }); + return jqXHR; + }; + this._beforeSend(e, options); + if (this.options.sequentialUploads) { + // Return the piped Promise object, enhanced with an abort method, + // which is delegated to the jqXHR object of the current upload, + // and jqXHR callbacks mapped to the equivalent Promise methods: + pipe = (this._sequence = this._sequence.pipe(send, send)); + pipe.abort = function () { + if (!jqXHR) { + return send(false, [undefined, 'abort', 'abort']); + } + return jqXHR.abort(); + }; + return this._enhancePromise(pipe); + } + return send(); + }, + + _onAdd: function (e, data) { + var that = this, + result = true, + options = $.extend({}, this.options, data); + if (options.singleFileUploads && this._isXHRUpload(options)) { + $.each(data.files, function (index, file) { + var newData = $.extend({}, data, {files: [file]}); + newData.submit = function () { + return that._onSend(e, newData); + }; + return (result = that._trigger('add', e, newData)); + }); + return result; + } else if (data.files.length) { + data = $.extend({}, data); + data.submit = function () { + return that._onSend(e, data); + }; + return this._trigger('add', e, data); + } + }, + + // File Normalization for Gecko 1.9.1 (Firefox 3.5) support: + _normalizeFile: function (index, file) { + if (file.name === undefined && file.size === undefined) { + file.name = file.fileName; + file.size = file.fileSize; + } + }, + + _replaceFileInput: function (input) { + var inputClone = input.clone(true); + $('
').append(inputClone)[0].reset(); + // Detaching allows to insert the fileInput on another form + // without loosing the file input value: + input.after(inputClone).detach(); + // Replace the original file input element in the fileInput + // collection with the clone, which has been copied including + // event handlers: + this.options.fileInput = this.options.fileInput.map(function (i, el) { + if (el === input[0]) { + return inputClone[0]; + } + return el; + }); + }, + + _onChange: function (e) { + var that = e.data.fileupload, + data = { + files: $.each($.makeArray(e.target.files), that._normalizeFile), + fileInput: $(e.target), + form: $(e.target.form) + }; + if (!data.files.length) { + // If the files property is not available, the browser does not + // support the File API and we add a pseudo File object with + // the input value as name with path information removed: + data.files = [{name: e.target.value.replace(/^.*\\/, '')}]; + } + // Store the form reference as jQuery data for other event handlers, + // as the form property is not available after replacing the file input: + if (data.form.length) { + data.fileInput.data('blueimp.fileupload.form', data.form); + } else { + data.form = data.fileInput.data('blueimp.fileupload.form'); + } + if (that.options.replaceFileInput) { + that._replaceFileInput(data.fileInput); + } + if (that._trigger('change', e, data) === false || + that._onAdd(e, data) === false) { + return false; + } + }, + + _onDrop: function (e) { + var that = e.data.fileupload, + dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer, + data = { + files: $.each( + $.makeArray(dataTransfer && dataTransfer.files), + that._normalizeFile + ) + }; + if (that._trigger('drop', e, data) === false || + that._onAdd(e, data) === false) { + return false; + } + e.preventDefault(); + }, + + _onDragOver: function (e) { + var that = e.data.fileupload, + dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer; + if (that._trigger('dragover', e) === false) { + return false; + } + if (dataTransfer) { + dataTransfer.dropEffect = dataTransfer.effectAllowed = 'copy'; + } + e.preventDefault(); + }, + + _initEventHandlers: function () { + var ns = this.options.namespace || this.name; + this.options.dropZone + .bind('dragover.' + ns, {fileupload: this}, this._onDragOver) + .bind('drop.' + ns, {fileupload: this}, this._onDrop); + this.options.fileInput + .bind('change.' + ns, {fileupload: this}, this._onChange); + }, + + _destroyEventHandlers: function () { + var ns = this.options.namespace || this.name; + this.options.dropZone + .unbind('dragover.' + ns, this._onDragOver) + .unbind('drop.' + ns, this._onDrop); + this.options.fileInput + .unbind('change.' + ns, this._onChange); + }, + + _beforeSetOption: function (key, value) { + this._destroyEventHandlers(); + }, + + _afterSetOption: function (key, value) { + var options = this.options; + if (!options.fileInput) { + options.fileInput = $(); + } + if (!options.dropZone) { + options.dropZone = $(); + } + this._initEventHandlers(); + }, + + _setOption: function (key, value) { + var refresh = $.inArray(key, this._refreshOptionsList) !== -1; + if (refresh) { + this._beforeSetOption(key, value); + } + $.Widget.prototype._setOption.call(this, key, value); + if (refresh) { + this._afterSetOption(key, value); + } + }, + + _create: function () { + var options = this.options; + if (options.fileInput === undefined) { + options.fileInput = this.element.is('input:file') ? + this.element : this.element.find('input:file'); + } else if (!options.fileInput) { + options.fileInput = $(); + } + if (!options.dropZone) { + options.dropZone = $(); + } + this._sequence = this._getXHRPromise(true); + this._active = this._loaded = this._total = 0; + this._initEventHandlers(); + }, + + destroy: function () { + this._destroyEventHandlers(); + $.Widget.prototype.destroy.call(this); + }, + + enable: function () { + $.Widget.prototype.enable.call(this); + this._initEventHandlers(); + }, + + disable: function () { + this._destroyEventHandlers(); + $.Widget.prototype.disable.call(this); + }, + + // This method is exposed to the widget API and allows adding files + // using the fileupload API. The data parameter accepts an object which + // must have a files property and can contain additional options: + // .fileupload('add', {files: filesList}); + add: function (data) { + if (!data || this.options.disabled) { + return; + } + data.files = $.each($.makeArray(data.files), this._normalizeFile); + this._onAdd(null, data); + }, + + // This method is exposed to the widget API and allows sending files + // using the fileupload API. The data parameter accepts an object which + // must have a files property and can contain additional options: + // .fileupload('send', {files: filesList}); + // The method returns a Promise object for the file upload call. + send: function (data) { + if (data && !this.options.disabled) { + data.files = $.each($.makeArray(data.files), this._normalizeFile); + if (data.files.length) { + return this._onSend(null, data); + } + } + return this._getXHRPromise(false, data && data.context); + } + + }); + +}(jQuery)); \ No newline at end of file diff --git a/underlays/attachment/ikiwiki/jquery.iframe-transport.js b/underlays/attachment/ikiwiki/jquery.iframe-transport.js new file mode 100644 index 000000000..e859dfe49 --- /dev/null +++ b/underlays/attachment/ikiwiki/jquery.iframe-transport.js @@ -0,0 +1,133 @@ +/* + * jQuery Iframe Transport Plugin 1.1 + * https://github.com/blueimp/jQuery-File-Upload + * + * Copyright 2011, Sebastian Tschan + * https://blueimp.net + * + * Licensed under the MIT license: + * http://creativecommons.org/licenses/MIT/ + */ + +/*jslint unparam: true */ +/*global jQuery */ + +(function ($) { + 'use strict'; + + // Helper variable to create unique names for the transport iframes: + var counter = 0; + + // The iframe transport accepts two additional options: + // options.fileInput: a jQuery collection of file input fields + // options.formData: an array of objects with name and value properties, + // equivalent to the return data of .serializeArray(), e.g.: + // [{name: a, value: 1}, {name: b, value: 2}] + $.ajaxTransport('iframe', function (options, originalOptions, jqXHR) { + if (options.type === 'POST' || options.type === 'GET') { + var form, + iframe; + return { + send: function (headers, completeCallback) { + form = $('
'); + // javascript:false as initial iframe src + // prevents warning popups on HTTPS in IE6. + // IE versions below IE8 cannot set the name property of + // elements that have already been added to the DOM, + // so we set the name along with the iframe HTML markup: + iframe = $( + '' + ).bind('load', function () { + var fileInputClones; + iframe + .unbind('load') + .bind('load', function () { + // The complete callback returns the + // iframe content document as response object: + completeCallback( + 200, + 'success', + {'iframe': iframe.contents()} + ); + // Fix for IE endless progress bar activity bug + // (happens on form submits to iframe targets): + $('') + .appendTo(form); + form.remove(); + }); + form + .prop('target', iframe.prop('name')) + .prop('action', options.url) + .prop('method', options.type); + if (options.formData) { + $.each(options.formData, function (index, field) { + $('') + .prop('name', field.name) + .val(field.value) + .appendTo(form); + }); + } + if (options.fileInput && options.fileInput.length && + options.type === 'POST') { + fileInputClones = options.fileInput.clone(); + // Insert a clone for each file input field: + options.fileInput.after(function (index) { + return fileInputClones[index]; + }); + // Appending the file input fields to the hidden form + // removes them from their original location: + form + .append(options.fileInput) + .prop('enctype', 'multipart/form-data') + // enctype must be set as encoding for IE: + .prop('encoding', 'multipart/form-data'); + } + form.submit(); + // Insert the file input fields at their original location + // by replacing the clones with the originals: + if (fileInputClones && fileInputClones.length) { + options.fileInput.each(function (index, input) { + $(fileInputClones[index]).replaceWith(input); + }); + } + }); + form.append(iframe).appendTo('body'); + }, + abort: function () { + if (iframe) { + // javascript:false as iframe src aborts the request + // and prevents warning popups on HTTPS in IE6. + // concat is used to avoid the "Script URL" JSLint error: + iframe + .unbind('load') + .prop('src', 'javascript'.concat(':false;')); + } + if (form) { + form.remove(); + } + } + }; + } + }); + + // The iframe transport returns the iframe content document as response. + // The following adds converters from iframe to text, json, html, and script: + $.ajaxSetup({ + converters: { + 'iframe text': function (iframe) { + return iframe.text(); + }, + 'iframe json': function (iframe) { + return $.parseJSON(iframe.text()); + }, + 'iframe html': function (iframe) { + return iframe.find('body').html(); + }, + 'iframe script': function (iframe) { + return $.globalEval(iframe.text()); + } + } + }); + +}(jQuery)); \ No newline at end of file diff --git a/underlays/attachment/ikiwiki/pbar-ani.gif b/underlays/attachment/ikiwiki/pbar-ani.gif new file mode 100644 index 000000000..fbcce6bc9 Binary files /dev/null and b/underlays/attachment/ikiwiki/pbar-ani.gif differ diff --git a/underlays/attachments/ikiwiki/jquery.fileupload-ui.css b/underlays/attachments/ikiwiki/jquery.fileupload-ui.css deleted file mode 100644 index d792724b7..000000000 --- a/underlays/attachments/ikiwiki/jquery.fileupload-ui.css +++ /dev/null @@ -1,8 +0,0 @@ -.fileupload-content .ui-progressbar { - width: 200px; - height: 20px; -} - -.fileupload-content .ui-progressbar-value { - background: url(pbar-ani.gif); -} diff --git a/underlays/attachments/ikiwiki/jquery.fileupload-ui.js b/underlays/attachments/ikiwiki/jquery.fileupload-ui.js deleted file mode 100644 index 61897ba55..000000000 --- a/underlays/attachments/ikiwiki/jquery.fileupload-ui.js +++ /dev/null @@ -1,357 +0,0 @@ -/* - * jQuery File Upload User Interface Plugin 5.0.13 - * https://github.com/blueimp/jQuery-File-Upload - * - * Copyright 2010, Sebastian Tschan - * https://blueimp.net - * - * Licensed under the MIT license: - * http://creativecommons.org/licenses/MIT/ - */ - -/*jslint nomen: true, unparam: true, regexp: true */ -/*global window, document, URL, webkitURL, FileReader, jQuery */ - -(function ($) { - 'use strict'; - - // The UI version extends the basic fileupload widget and adds - // a complete user interface based on the given upload/download - // templates. - $.widget('blueimpUI.fileupload', $.blueimp.fileupload, { - - options: { - // By default, files added to the widget are uploaded as soon - // as the user clicks on the start buttons. To enable automatic - // uploads, set the following option to true: - autoUpload: true, - // The file upload template that is given as first argument to the - // jQuery.tmpl method to render the file uploads: - uploadTemplate: $('#template-upload'), - // The file download template, that is given as first argument to the - // jQuery.tmpl method to render the file downloads: - downloadTemplate: $('#template-download'), - // The expected data type of the upload response, sets the dataType - // option of the $.ajax upload requests: - dataType: 'json', - - // The add callback is invoked as soon as files are added to the 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) { - var that = $(this).data('fileupload'); - data.isAdjusted = true; - data.isValidated = that._validate(data.files); - data.context = that._renderUpload(data.files) - .appendTo($(this).find('.files')).fadeIn(function () { - // Fix for IE7 and lower: - $(this).show(); - }).data('data', data); - if ((that.options.autoUpload || data.autoUpload) && - data.isValidated) { - data.jqXHR = data.submit(); - } - }, - // Callback for the start of each file upload request: - send: function (e, data) { - if (!data.isValidated) { - var that = $(this).data('fileupload'); - if (!that._validate(data.files)) { - return false; - } - } - if (data.context && data.dataType && - data.dataType.substr(0, 6) === 'iframe') { - // Iframe Transport does not support progress events. - // In lack of an indeterminate progress bar, we set - // the progress to 100%, showing the full animated bar: - data.context.find('.ui-progressbar').progressbar( - 'value', - parseInt(100, 10) - ); - } - }, - // Callback for successful uploads: - done: function (e, data) { - var that = $(this).data('fileupload'); - if (data.context) { - data.context.each(function (index) { - var file = ($.isArray(data.result) && - data.result[index]) || {error: 'emptyResult'}; - $(this).fadeOut(function () { - that._renderDownload([file]) - .css('display', 'none') - .replaceAll(this) - .fadeIn(function () { - // Fix for IE7 and lower: - $(this).show(); - }); - }); - }); - } else { - that._renderDownload(data.result) - .css('display', 'none') - .appendTo($(this).find('.files')) - .fadeIn(function () { - // Fix for IE7 and lower: - $(this).show(); - }); - } - }, - // Callback for failed (abort or error) uploads: - fail: function (e, data) { - var that = $(this).data('fileupload'); - if (data.context) { - data.context.each(function (index) { - $(this).fadeOut(function () { - if (data.errorThrown !== 'abort') { - var file = data.files[index]; - file.error = file.error || data.errorThrown - || true; - that._renderDownload([file]) - .css('display', 'none') - .replaceAll(this) - .fadeIn(function () { - // Fix for IE7 and lower: - $(this).show(); - }); - } else { - data.context.remove(); - } - }); - }); - } else if (data.errorThrown !== 'abort') { - data.context = that._renderUpload(data.files) - .css('display', 'none') - .appendTo($(this).find('.files')) - .fadeIn(function () { - // Fix for IE7 and lower: - $(this).show(); - }).data('data', data); - } - }, - // Callback for upload progress events: - progress: function (e, data) { - if (data.context) { - data.context.find('.ui-progressbar').progressbar( - 'value', - parseInt(data.loaded / data.total * 100, 10) - ); - } - }, - // Callback for global upload progress events: - progressall: function (e, data) { - $(this).find('.fileupload-progressbar').progressbar( - 'value', - parseInt(data.loaded / data.total * 100, 10) - ); - }, - // Callback for uploads start, equivalent to the global ajaxStart event: - start: function () { - $(this).find('.fileupload-progressbar') - .progressbar('value', 0).fadeIn(); - }, - // Callback for uploads stop, equivalent to the global ajaxStop event: - stop: function () { - $(this).find('.fileupload-progressbar').fadeOut(); - }, - }, - - _createObjectURL: function (file) { - var undef = 'undefined', - urlAPI = (typeof window.createObjectURL !== undef && window) || - (typeof URL !== undef && URL) || - (typeof webkitURL !== undef && webkitURL); - return urlAPI ? urlAPI.createObjectURL(file) : false; - }, - - _revokeObjectURL: function (url) { - var undef = 'undefined', - urlAPI = (typeof window.revokeObjectURL !== undef && window) || - (typeof URL !== undef && URL) || - (typeof webkitURL !== undef && webkitURL); - return urlAPI ? urlAPI.revokeObjectURL(url) : false; - }, - - // Link handler, that allows to download files - // by drag & drop of the links to the desktop: - _enableDragToDesktop: function () { - var link = $(this), - url = link.prop('href'), - name = decodeURIComponent(url.split('/').pop()) - .replace(/:/g, '-'), - type = 'application/octet-stream'; - link.bind('dragstart', function (e) { - try { - e.originalEvent.dataTransfer.setData( - 'DownloadURL', - [type, name, url].join(':') - ); - } catch (err) {} - }); - }, - - _hasError: function (file) { - if (file.error) { - return file.error; - } - return null; - }, - - _validate: function (files) { - var that = this, - valid; - $.each(files, function (index, file) { - file.error = that._hasError(file); - valid = !file.error; - }); - return valid; - }, - - _uploadTemplateHelper: function (file) { - return file; - }, - - _renderUploadTemplate: function (files) { - var that = this; - return $.tmpl( - this.options.uploadTemplate, - $.map(files, function (file) { - return that._uploadTemplateHelper(file); - }) - ); - }, - - _renderUpload: function (files) { - var that = this, - options = this.options, - tmpl = this._renderUploadTemplate(files); - if (!(tmpl instanceof $)) { - return $(); - } - tmpl.css('display', 'none'); - // .slice(1).remove().end().first() removes all but the first - // element and selects only the first for the jQuery collection: - tmpl.find('.progress div').slice(1).remove().end().first() - .progressbar(); - tmpl.find('.start button').slice( - this.options.autoUpload ? 0 : 1 - ).remove().end().first() - .button({ - text: false, - icons: {primary: 'ui-icon-circle-arrow-e'} - }); - tmpl.find('.cancel button').slice(1).remove().end().first() - .button({ - text: false, - icons: {primary: 'ui-icon-cancel'} - }); - return tmpl; - }, - - _downloadTemplateHelper: function (file) { - return file; - }, - - _renderDownloadTemplate: function (files) { - var that = this; - return $.tmpl( - this.options.downloadTemplate, - $.map(files, function (file) { - return that._downloadTemplateHelper(file); - }) - ); - }, - - _renderDownload: function (files) { - var tmpl = this._renderDownloadTemplate(files); - if (!(tmpl instanceof $)) { - return $(); - } - tmpl.css('display', 'none'); - tmpl.find('a').each(this._enableDragToDesktop); - return tmpl; - }, - - _startHandler: function (e) { - e.preventDefault(); - var tmpl = $(this).closest('.template-upload'), - data = tmpl.data('data'); - if (data && data.submit && !data.jqXHR) { - data.jqXHR = data.submit(); - $(this).fadeOut(); - } - }, - - _cancelHandler: function (e) { - e.preventDefault(); - var tmpl = $(this).closest('.template-upload'), - data = tmpl.data('data') || {}; - if (!data.jqXHR) { - data.errorThrown = 'abort'; - e.data.fileupload._trigger('fail', e, data); - } else { - data.jqXHR.abort(); - } - }, - - _initEventHandlers: function () { - $.blueimp.fileupload.prototype._initEventHandlers.call(this); - var filesList = this.element.find('.files'), - eventData = {fileupload: this}; - filesList.find('.start button') - .live( - 'click.' + this.options.namespace, - eventData, - this._startHandler - ); - filesList.find('.cancel button') - .live( - 'click.' + this.options.namespace, - eventData, - this._cancelHandler - ); - }, - - _destroyEventHandlers: function () { - var filesList = this.element.find('.files'); - filesList.find('.start button') - .die('click.' + this.options.namespace); - filesList.find('.cancel button') - .die('click.' + this.options.namespace); - $.blueimp.fileupload.prototype._destroyEventHandlers.call(this); - }, - - _initTemplates: function () { - // Handle cases where the templates are defined - // after the widget library has been included: - if (this.options.uploadTemplate instanceof $ && - !this.options.uploadTemplate.length) { - this.options.uploadTemplate = $( - this.options.uploadTemplate.selector - ); - } - if (this.options.downloadTemplate instanceof $ && - !this.options.downloadTemplate.length) { - this.options.downloadTemplate = $( - this.options.downloadTemplate.selector - ); - } - }, - - _create: function () { - $.blueimp.fileupload.prototype._create.call(this); - this._initTemplates(); - }, - - enable: function () { - $.blueimp.fileupload.prototype.enable.call(this); - }, - - disable: function () { - $.blueimp.fileupload.prototype.disable.call(this); - } - - }); - -}(jQuery)); diff --git a/underlays/attachments/ikiwiki/jquery.fileupload.js b/underlays/attachments/ikiwiki/jquery.fileupload.js deleted file mode 100644 index 1e3c6bf97..000000000 --- a/underlays/attachments/ikiwiki/jquery.fileupload.js +++ /dev/null @@ -1,720 +0,0 @@ -/* - * jQuery File Upload Plugin 5.0.2 - * https://github.com/blueimp/jQuery-File-Upload - * - * Copyright 2010, Sebastian Tschan - * https://blueimp.net - * - * Licensed under the MIT license: - * http://creativecommons.org/licenses/MIT/ - */ - -/*jslint nomen: true, unparam: true, regexp: true */ -/*global document, XMLHttpRequestUpload, Blob, File, FormData, location, jQuery */ - -(function ($) { - 'use strict'; - - // The fileupload widget listens for change events on file input fields - // defined via fileInput setting and drop events of the given dropZone. - // In addition to the default jQuery Widget methods, the fileupload widget - // exposes the "add" and "send" methods, to add or directly send files - // using the fileupload API. - // By default, files added via file input selection, drag & drop or - // "add" method are uploaded immediately, but it is possible to override - // the "add" callback option to queue file uploads. - $.widget('blueimp.fileupload', { - - options: { - // The namespace used for event handler binding on the dropZone and - // fileInput collections. - // If not set, the name of the widget ("fileupload") is used. - namespace: undefined, - // The drop target collection, by the default the complete document. - // Set to null or an empty collection to disable drag & drop support: - dropZone: $(document), - // The file input field collection, that is listened for change events. - // If undefined, it is set to the file input fields inside - // of the widget element on plugin initialization. - // Set to null or an empty collection to disable the change listener. - fileInput: undefined, - // By default, the file input field is replaced with a clone after - // each input field change event. This is required for iframe transport - // queues and allows change events to be fired for the same file - // selection, but can be disabled by setting the following option to false: - replaceFileInput: true, - // The parameter name for the file form data (the request argument name). - // If undefined or empty, the name property of the file input field is - // used, or "files[]" if the file input name property is also empty: - paramName: undefined, - // By default, each file of a selection is uploaded using an individual - // request for XHR type uploads. Set to false to upload file - // selections in one request each: - singleFileUploads: true, - // Set the following option to true to issue all file upload requests - // in a sequential order: - sequentialUploads: false, - // Set the following option to true to force iframe transport uploads: - forceIframeTransport: false, - // By default, XHR file uploads are sent as multipart/form-data. - // The iframe transport is always using multipart/form-data. - // Set to false to enable non-multipart XHR uploads: - multipart: true, - // To upload large files in smaller chunks, set the following option - // to a preferred maximum chunk size. If set to 0, null or undefined, - // or the browser does not support the required Blob API, files will - // be uploaded as a whole. - maxChunkSize: undefined, - // When a non-multipart upload or a chunked multipart upload has been - // aborted, this option can be used to resume the upload by setting - // it to the size of the already uploaded bytes. This option is most - // useful when modifying the options object inside of the "add" or - // "send" callbacks, as the options are cloned for each file upload. - uploadedBytes: undefined, - // By default, failed (abort or error) file uploads are removed from the - // global progress calculation. Set the following option to false to - // prevent recalculating the global progress data: - recalculateProgress: 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 - // value properties, a function returning such an array, a FormData - // object (for XHR file uploads), or a simple object. - // The form of the first fileInput is given as parameter to the function: - formData: function (form) { - return form.serializeArray(); - }, - - // The add callback is invoked as soon as files are added to the fileupload - // widget (via file input selection, drag & drop or add API call). - // If the singleFileUploads option is enabled, this callback will be - // called once for each file in the selection for XHR file uplaods, else - // once for each file selection. - // The upload starts when the submit method is invoked on the data parameter. - // The data object contains a files property holding the added files - // and allows to override plugin options as well as define ajax settings. - // Listeners for this callback can also be bound the following way: - // .bind('fileuploadadd', func); - // data.submit() returns a Promise object and allows to attach additional - // handlers using jQuery's Deferred callbacks: - // data.submit().done(func).fail(func).always(func); - add: function (e, data) { - data.submit(); - }, - - // Other callbacks: - // Callback for the start of each file upload request: - // send: function (e, data) {}, // .bind('fileuploadsend', func); - // Callback for successful uploads: - // done: function (e, data) {}, // .bind('fileuploaddone', func); - // Callback for failed (abort or error) uploads: - // fail: function (e, data) {}, // .bind('fileuploadfail', func); - // Callback for completed (success, abort or error) requests: - // always: function (e, data) {}, // .bind('fileuploadalways', func); - // Callback for upload progress events: - // progress: function (e, data) {}, // .bind('fileuploadprogress', func); - // Callback for global upload progress events: - // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func); - // Callback for uploads start, equivalent to the global ajaxStart event: - // start: function (e) {}, // .bind('fileuploadstart', func); - // Callback for uploads stop, equivalent to the global ajaxStop event: - // stop: function (e) {}, // .bind('fileuploadstop', func); - // Callback for change events of the fileInput collection: - // change: function (e, data) {}, // .bind('fileuploadchange', func); - // Callback for drop events of the dropZone collection: - // drop: function (e, data) {}, // .bind('fileuploaddrop', func); - // Callback for dragover events of the dropZone collection: - // dragover: function (e) {}, // .bind('fileuploaddragover', func); - - // The plugin options are used as settings object for the ajax calls. - // The following are jQuery ajax settings required for the file uploads: - processData: false, - contentType: false, - cache: false - }, - - // A list of options that require a refresh after assigning a new value: - _refreshOptionsList: ['namespace', 'dropZone', 'fileInput'], - - _isXHRUpload: function (options) { - var undef = 'undefined'; - return !options.forceIframeTransport && - typeof XMLHttpRequestUpload !== undef && typeof File !== undef && - (!options.multipart || typeof FormData !== undef); - }, - - _getFormData: function (options) { - var formData; - if (typeof options.formData === 'function') { - return options.formData(options.form); - } else if ($.isArray(options.formData)) { - return options.formData; - } else if (options.formData) { - formData = []; - $.each(options.formData, function (name, value) { - formData.push({name: name, value: value}); - }); - return formData; - } - return []; - }, - - _getTotal: function (files) { - var total = 0; - $.each(files, function (index, file) { - total += file.size || 1; - }); - return total; - }, - - _onProgress: function (e, data) { - if (e.lengthComputable) { - var total = data.total || this._getTotal(data.files), - loaded = parseInt( - e.loaded / e.total * (data.chunkSize || total), - 10 - ) + (data.uploadedBytes || 0); - this._loaded += loaded - (data.loaded || data.uploadedBytes || 0); - data.lengthComputable = true; - data.loaded = loaded; - data.total = total; - // Trigger a custom progress event with a total data property set - // to the file size(s) of the current upload and a loaded data - // property calculated accordingly: - 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 - }); - } - }, - - _initProgressListener: function (options) { - var that = this, - xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr(); - // Accesss to the native XHR object is required to add event listeners - // for the upload progress event: - if (xhr.upload && xhr.upload.addEventListener) { - xhr.upload.addEventListener('progress', function (e) { - that._onProgress(e, options); - }, false); - options.xhr = function () { - return xhr; - }; - } - }, - - _initXHRData: function (options) { - var formData, - file = options.files[0]; - if (!options.multipart || options.blob) { - // For non-multipart uploads and chunked uploads, - // file meta data is not part of the request body, - // so we transmit this data as part of the HTTP headers. - // For cross domain requests, these headers must be allowed - // via Access-Control-Allow-Headers or removed using - // the beforeSend callback: - options.headers = $.extend(options.headers, { - 'X-File-Name': file.name, - 'X-File-Type': file.type, - 'X-File-Size': file.size - }); - if (!options.blob) { - // Non-chunked non-multipart upload: - options.contentType = file.type; - options.data = file; - } else if (!options.multipart) { - // Chunked non-multipart upload: - options.contentType = 'application/octet-stream'; - options.data = options.blob; - } - } - if (options.multipart && typeof FormData !== 'undefined') { - if (options.formData instanceof FormData) { - formData = options.formData; - } else { - formData = new FormData(); - $.each(this._getFormData(options), function (index, field) { - formData.append(field.name, field.value); - }); - } - if (options.blob) { - formData.append(options.paramName, options.blob); - } else { - $.each(options.files, function (index, file) { - // File objects are also Blob instances. - // This check allows the tests to run with - // dummy objects: - if (file instanceof Blob) { - formData.append(options.paramName, file); - } - }); - } - options.data = formData; - } - // Blob reference is not needed anymore, free memory: - options.blob = null; - }, - - _initIframeSettings: function (options) { - // Setting the dataType to iframe enables the iframe transport: - options.dataType = 'iframe ' + (options.dataType || ''); - // The iframe transport accepts a serialized array as form data: - options.formData = this._getFormData(options); - }, - - _initDataSettings: function (options) { - if (this._isXHRUpload(options)) { - if (!this._chunkedUpload(options, true)) { - if (!options.data) { - this._initXHRData(options); - } - this._initProgressListener(options); - } - } else { - this._initIframeSettings(options); - } - }, - - _initFormSettings: function (options) { - // Retrieve missing options from the input field and the - // associated form, if available: - if (!options.form || !options.form.length) { - options.form = $(options.fileInput.prop('form')); - } - if (!options.paramName) { - options.paramName = options.fileInput.prop('name') || - 'files[]'; - } - if (!options.url) { - options.url = options.form.prop('action') || location.href; - } - // The HTTP request method must be "POST" or "PUT": - options.type = (options.type || options.form.prop('method') || '') - .toUpperCase(); - if (options.type !== 'POST' && options.type !== 'PUT') { - options.type = 'POST'; - } - }, - - _getAJAXSettings: function (data) { - var options = $.extend({}, this.options, data); - this._initFormSettings(options); - this._initDataSettings(options); - return options; - }, - - // Maps jqXHR callbacks to the equivalent - // methods of the given Promise object: - _enhancePromise: function (promise) { - promise.success = promise.done; - promise.error = promise.fail; - promise.complete = promise.always; - return promise; - }, - - // Creates and returns a Promise object enhanced with - // the jqXHR methods abort, success, error and complete: - _getXHRPromise: function (resolveOrReject, context, args) { - var dfd = $.Deferred(), - promise = dfd.promise(); - context = context || this.options.context || promise; - if (resolveOrReject === true) { - dfd.resolveWith(context, args); - } else if (resolveOrReject === false) { - dfd.rejectWith(context, args); - } - promise.abort = dfd.promise; - return this._enhancePromise(promise); - }, - - // Uploads a file in multiple, sequential requests - // by splitting the file up in multiple blob chunks. - // If the second parameter is true, only tests if the file - // should be uploaded in chunks, but does not invoke any - // upload requests: - _chunkedUpload: function (options, testOnly) { - var that = this, - file = options.files[0], - fs = file.size, - ub = options.uploadedBytes = options.uploadedBytes || 0, - mcs = options.maxChunkSize || fs, - // Use the Blob methods with the slice implementation - // according to the W3C Blob API specification: - slice = file.webkitSlice || file.mozSlice || file.slice, - upload, - n, - jqXHR, - pipe; - if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) || - options.data) { - return false; - } - if (testOnly) { - return true; - } - if (ub >= fs) { - file.error = 'uploadedBytes'; - return this._getXHRPromise(false); - } - // n is the number of blobs to upload, - // calculated via filesize, uploaded bytes and max chunk size: - n = Math.ceil((fs - ub) / mcs); - // The chunk upload method accepting the chunk number as parameter: - upload = function (i) { - if (!i) { - return that._getXHRPromise(true); - } - // Upload the blobs in sequential order: - return upload(i -= 1).pipe(function () { - // Clone the options object for each chunk upload: - var o = $.extend({}, options); - o.blob = slice.call( - file, - ub + i * mcs, - ub + (i + 1) * mcs - ); - // Store the current chunk size, as the blob itself - // will be dereferenced after data processing: - o.chunkSize = o.blob.size; - // Process the upload data (the blob and potential form data): - that._initXHRData(o); - // Add progress listeners for this chunk upload: - that._initProgressListener(o); - jqXHR = ($.ajax(o) || that._getXHRPromise(false, o.context)) - .done(function () { - // Create a progress event if upload is done and - // no progress event has been invoked for this chunk: - if (!o.loaded) { - that._onProgress($.Event('progress', { - lengthComputable: true, - loaded: o.chunkSize, - total: o.chunkSize - }), o); - } - options.uploadedBytes = o.uploadedBytes - += o.chunkSize; - }); - return jqXHR; - }); - }; - // Return the piped Promise object, enhanced with an abort method, - // which is delegated to the jqXHR object of the current upload, - // and jqXHR callbacks mapped to the equivalent Promise methods: - pipe = upload(n); - pipe.abort = function () { - return jqXHR.abort(); - }; - return this._enhancePromise(pipe); - }, - - _beforeSend: function (e, data) { - if (this._active === 0) { - // the start callback is triggered when an upload starts - // and no other uploads are currently running, - // equivalent to the global ajaxStart event: - this._trigger('start'); - } - this._active += 1; - // Initialize the global progress values: - this._loaded += data.uploadedBytes || 0; - this._total += this._getTotal(data.files); - }, - - _onDone: function (result, textStatus, jqXHR, options) { - if (!this._isXHRUpload(options)) { - // Create a progress event for each iframe load: - this._onProgress($.Event('progress', { - lengthComputable: true, - loaded: 1, - total: 1 - }), options); - } - options.result = result; - options.textStatus = textStatus; - options.jqXHR = jqXHR; - this._trigger('done', null, options); - }, - - _onFail: function (jqXHR, textStatus, errorThrown, options) { - options.jqXHR = jqXHR; - options.textStatus = textStatus; - options.errorThrown = errorThrown; - this._trigger('fail', null, options); - 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); - } - }, - - _onAlways: function (result, textStatus, jqXHR, errorThrown, options) { - this._active -= 1; - options.result = result; - options.textStatus = textStatus; - options.jqXHR = jqXHR; - options.errorThrown = errorThrown; - this._trigger('always', null, options); - if (this._active === 0) { - // 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; - } - }, - - _onSend: function (e, data) { - var that = this, - jqXHR, - pipe, - options = that._getAJAXSettings(data), - send = function (resolve, args) { - jqXHR = jqXHR || ( - (resolve !== false && - that._trigger('send', e, options) !== false && - (that._chunkedUpload(options) || $.ajax(options))) || - that._getXHRPromise(false, options.context, args) - ).done(function (result, textStatus, jqXHR) { - that._onDone(result, textStatus, jqXHR, options); - }).fail(function (jqXHR, textStatus, errorThrown) { - that._onFail(jqXHR, textStatus, errorThrown, options); - }).always(function (a1, a2, a3) { - if (!a3 || typeof a3 === 'string') { - that._onAlways(undefined, a2, a1, a3, options); - } else { - that._onAlways(a1, a2, a3, undefined, options); - } - }); - return jqXHR; - }; - this._beforeSend(e, options); - if (this.options.sequentialUploads) { - // Return the piped Promise object, enhanced with an abort method, - // which is delegated to the jqXHR object of the current upload, - // and jqXHR callbacks mapped to the equivalent Promise methods: - pipe = (this._sequence = this._sequence.pipe(send, send)); - pipe.abort = function () { - if (!jqXHR) { - return send(false, [undefined, 'abort', 'abort']); - } - return jqXHR.abort(); - }; - return this._enhancePromise(pipe); - } - return send(); - }, - - _onAdd: function (e, data) { - var that = this, - result = true, - options = $.extend({}, this.options, data); - if (options.singleFileUploads && this._isXHRUpload(options)) { - $.each(data.files, function (index, file) { - var newData = $.extend({}, data, {files: [file]}); - newData.submit = function () { - return that._onSend(e, newData); - }; - return (result = that._trigger('add', e, newData)); - }); - return result; - } else if (data.files.length) { - data = $.extend({}, data); - data.submit = function () { - return that._onSend(e, data); - }; - return this._trigger('add', e, data); - } - }, - - // File Normalization for Gecko 1.9.1 (Firefox 3.5) support: - _normalizeFile: function (index, file) { - if (file.name === undefined && file.size === undefined) { - file.name = file.fileName; - file.size = file.fileSize; - } - }, - - _replaceFileInput: function (input) { - var inputClone = input.clone(true); - $('
').append(inputClone)[0].reset(); - // Detaching allows to insert the fileInput on another form - // without loosing the file input value: - input.after(inputClone).detach(); - // Replace the original file input element in the fileInput - // collection with the clone, which has been copied including - // event handlers: - this.options.fileInput = this.options.fileInput.map(function (i, el) { - if (el === input[0]) { - return inputClone[0]; - } - return el; - }); - }, - - _onChange: function (e) { - var that = e.data.fileupload, - data = { - files: $.each($.makeArray(e.target.files), that._normalizeFile), - fileInput: $(e.target), - form: $(e.target.form) - }; - if (!data.files.length) { - // If the files property is not available, the browser does not - // support the File API and we add a pseudo File object with - // the input value as name with path information removed: - data.files = [{name: e.target.value.replace(/^.*\\/, '')}]; - } - // Store the form reference as jQuery data for other event handlers, - // as the form property is not available after replacing the file input: - if (data.form.length) { - data.fileInput.data('blueimp.fileupload.form', data.form); - } else { - data.form = data.fileInput.data('blueimp.fileupload.form'); - } - if (that.options.replaceFileInput) { - that._replaceFileInput(data.fileInput); - } - if (that._trigger('change', e, data) === false || - that._onAdd(e, data) === false) { - return false; - } - }, - - _onDrop: function (e) { - var that = e.data.fileupload, - dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer, - data = { - files: $.each( - $.makeArray(dataTransfer && dataTransfer.files), - that._normalizeFile - ) - }; - if (that._trigger('drop', e, data) === false || - that._onAdd(e, data) === false) { - return false; - } - e.preventDefault(); - }, - - _onDragOver: function (e) { - var that = e.data.fileupload, - dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer; - if (that._trigger('dragover', e) === false) { - return false; - } - if (dataTransfer) { - dataTransfer.dropEffect = dataTransfer.effectAllowed = 'copy'; - } - e.preventDefault(); - }, - - _initEventHandlers: function () { - var ns = this.options.namespace || this.name; - this.options.dropZone - .bind('dragover.' + ns, {fileupload: this}, this._onDragOver) - .bind('drop.' + ns, {fileupload: this}, this._onDrop); - this.options.fileInput - .bind('change.' + ns, {fileupload: this}, this._onChange); - }, - - _destroyEventHandlers: function () { - var ns = this.options.namespace || this.name; - this.options.dropZone - .unbind('dragover.' + ns, this._onDragOver) - .unbind('drop.' + ns, this._onDrop); - this.options.fileInput - .unbind('change.' + ns, this._onChange); - }, - - _beforeSetOption: function (key, value) { - this._destroyEventHandlers(); - }, - - _afterSetOption: function (key, value) { - var options = this.options; - if (!options.fileInput) { - options.fileInput = $(); - } - if (!options.dropZone) { - options.dropZone = $(); - } - this._initEventHandlers(); - }, - - _setOption: function (key, value) { - var refresh = $.inArray(key, this._refreshOptionsList) !== -1; - if (refresh) { - this._beforeSetOption(key, value); - } - $.Widget.prototype._setOption.call(this, key, value); - if (refresh) { - this._afterSetOption(key, value); - } - }, - - _create: function () { - var options = this.options; - if (options.fileInput === undefined) { - options.fileInput = this.element.is('input:file') ? - this.element : this.element.find('input:file'); - } else if (!options.fileInput) { - options.fileInput = $(); - } - if (!options.dropZone) { - options.dropZone = $(); - } - this._sequence = this._getXHRPromise(true); - this._active = this._loaded = this._total = 0; - this._initEventHandlers(); - }, - - destroy: function () { - this._destroyEventHandlers(); - $.Widget.prototype.destroy.call(this); - }, - - enable: function () { - $.Widget.prototype.enable.call(this); - this._initEventHandlers(); - }, - - disable: function () { - this._destroyEventHandlers(); - $.Widget.prototype.disable.call(this); - }, - - // This method is exposed to the widget API and allows adding files - // using the fileupload API. The data parameter accepts an object which - // must have a files property and can contain additional options: - // .fileupload('add', {files: filesList}); - add: function (data) { - if (!data || this.options.disabled) { - return; - } - data.files = $.each($.makeArray(data.files), this._normalizeFile); - this._onAdd(null, data); - }, - - // This method is exposed to the widget API and allows sending files - // using the fileupload API. The data parameter accepts an object which - // must have a files property and can contain additional options: - // .fileupload('send', {files: filesList}); - // The method returns a Promise object for the file upload call. - send: function (data) { - if (data && !this.options.disabled) { - data.files = $.each($.makeArray(data.files), this._normalizeFile); - if (data.files.length) { - return this._onSend(null, data); - } - } - return this._getXHRPromise(false, data && data.context); - } - - }); - -}(jQuery)); \ No newline at end of file diff --git a/underlays/attachments/ikiwiki/jquery.iframe-transport.js b/underlays/attachments/ikiwiki/jquery.iframe-transport.js deleted file mode 100644 index e859dfe49..000000000 --- a/underlays/attachments/ikiwiki/jquery.iframe-transport.js +++ /dev/null @@ -1,133 +0,0 @@ -/* - * jQuery Iframe Transport Plugin 1.1 - * https://github.com/blueimp/jQuery-File-Upload - * - * Copyright 2011, Sebastian Tschan - * https://blueimp.net - * - * Licensed under the MIT license: - * http://creativecommons.org/licenses/MIT/ - */ - -/*jslint unparam: true */ -/*global jQuery */ - -(function ($) { - 'use strict'; - - // Helper variable to create unique names for the transport iframes: - var counter = 0; - - // The iframe transport accepts two additional options: - // options.fileInput: a jQuery collection of file input fields - // options.formData: an array of objects with name and value properties, - // equivalent to the return data of .serializeArray(), e.g.: - // [{name: a, value: 1}, {name: b, value: 2}] - $.ajaxTransport('iframe', function (options, originalOptions, jqXHR) { - if (options.type === 'POST' || options.type === 'GET') { - var form, - iframe; - return { - send: function (headers, completeCallback) { - form = $('
'); - // javascript:false as initial iframe src - // prevents warning popups on HTTPS in IE6. - // IE versions below IE8 cannot set the name property of - // elements that have already been added to the DOM, - // so we set the name along with the iframe HTML markup: - iframe = $( - '' - ).bind('load', function () { - var fileInputClones; - iframe - .unbind('load') - .bind('load', function () { - // The complete callback returns the - // iframe content document as response object: - completeCallback( - 200, - 'success', - {'iframe': iframe.contents()} - ); - // Fix for IE endless progress bar activity bug - // (happens on form submits to iframe targets): - $('') - .appendTo(form); - form.remove(); - }); - form - .prop('target', iframe.prop('name')) - .prop('action', options.url) - .prop('method', options.type); - if (options.formData) { - $.each(options.formData, function (index, field) { - $('') - .prop('name', field.name) - .val(field.value) - .appendTo(form); - }); - } - if (options.fileInput && options.fileInput.length && - options.type === 'POST') { - fileInputClones = options.fileInput.clone(); - // Insert a clone for each file input field: - options.fileInput.after(function (index) { - return fileInputClones[index]; - }); - // Appending the file input fields to the hidden form - // removes them from their original location: - form - .append(options.fileInput) - .prop('enctype', 'multipart/form-data') - // enctype must be set as encoding for IE: - .prop('encoding', 'multipart/form-data'); - } - form.submit(); - // Insert the file input fields at their original location - // by replacing the clones with the originals: - if (fileInputClones && fileInputClones.length) { - options.fileInput.each(function (index, input) { - $(fileInputClones[index]).replaceWith(input); - }); - } - }); - form.append(iframe).appendTo('body'); - }, - abort: function () { - if (iframe) { - // javascript:false as iframe src aborts the request - // and prevents warning popups on HTTPS in IE6. - // concat is used to avoid the "Script URL" JSLint error: - iframe - .unbind('load') - .prop('src', 'javascript'.concat(':false;')); - } - if (form) { - form.remove(); - } - } - }; - } - }); - - // The iframe transport returns the iframe content document as response. - // The following adds converters from iframe to text, json, html, and script: - $.ajaxSetup({ - converters: { - 'iframe text': function (iframe) { - return iframe.text(); - }, - 'iframe json': function (iframe) { - return $.parseJSON(iframe.text()); - }, - 'iframe html': function (iframe) { - return iframe.find('body').html(); - }, - 'iframe script': function (iframe) { - return $.globalEval(iframe.text()); - } - } - }); - -}(jQuery)); \ No newline at end of file diff --git a/underlays/attachments/ikiwiki/pbar-ani.gif b/underlays/attachments/ikiwiki/pbar-ani.gif deleted file mode 100644 index fbcce6bc9..000000000 Binary files a/underlays/attachments/ikiwiki/pbar-ani.gif and /dev/null differ -- cgit v1.2.3