forked from Wavyzz/dolibarr
Fix: update jquery libraries
This commit is contained in:
77
htdocs/includes/jquery/plugins/fileupload/README.md
Normal file
77
htdocs/includes/jquery/plugins/fileupload/README.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# jQuery File Upload Plugin
|
||||
|
||||
## Demo
|
||||
[Demo File Upload](http://aquantum-demo.appspot.com/file-upload)
|
||||
|
||||
## Setup instructions
|
||||
[How to setup the plugin on your website](https://github.com/blueimp/jQuery-File-Upload/wiki/Setup)
|
||||
|
||||
## Features
|
||||
* **Multiple file upload:**
|
||||
Allows to select multiple files at once and upload them simultaneously.
|
||||
* **Drag & Drop support:**
|
||||
Allows to upload files by dragging them from your desktop or filemanager and dropping them on your browser window.
|
||||
* **Upload progress bar:**
|
||||
Shows a progress bar indicating the upload progress for individual files and for all uploads combined.
|
||||
* **Cancelable uploads:**
|
||||
Individual file uploads can be canceled to stop the upload progress.
|
||||
* **Resumable uploads:**
|
||||
Aborted uploads can be resumed with browsers supporting the Blob API.
|
||||
* **Chunked uploads:**
|
||||
Large files can be uploaded in smaller chunks with browsers supporting the Blob API.
|
||||
* **Preview images:**
|
||||
A preview of image files can be displayed before uploading with browsers supporting the required HTML5 APIs.
|
||||
* **No browser plugins (e.g. Adobe Flash) required:**
|
||||
The implementation is based on open standards like HTML5 and JavaScript and requires no additional browser plugins.
|
||||
* **Graceful fallback for legacy browsers:**
|
||||
Uploads files via XMLHttpRequests if supported and uses iframes as fallback for legacy browsers.
|
||||
* **HTML file upload form fallback:**
|
||||
Shows a standard HTML file upload form if JavaScript is disabled.
|
||||
* **Cross-site file uploads:**
|
||||
Supports uploading files to a different domain with Cross-site XMLHttpRequests.
|
||||
* **Multiple plugin instances:**
|
||||
Allows to use multiple plugin instances on the same webpage.
|
||||
* **Customizable and extensible:**
|
||||
Provides an API to set individual options and define callBack methods for various upload events.
|
||||
* **Multipart and file contents stream uploads:**
|
||||
Files can be uploaded as standard "multipart/form-data" or file contents stream (HTTP PUT file upload).
|
||||
* **Compatible with any server-side application platform:**
|
||||
Works with Google App Engine (Python, Java), Ruby on Rails, PHP and any other platform that supports HTTP file uploads.
|
||||
|
||||
## Requirements
|
||||
* [jQuery](http://jquery.com/) v. 1.6+
|
||||
* [jQuery UI](http://jqueryui.com/) v. 1.8+ (required: Widget, optional: Progressbar, Button)
|
||||
* jQuery Iframe Transport plugin (included)
|
||||
* [jQuery Templates plugin](http://api.jquery.com/category/plugins/templates/) v. 1.0+ (optional)
|
||||
|
||||
The jQuery UI widget factory is a requirement for the basic File Upload plugin, but very lightweight without any other dependencies.
|
||||
The UI version of the File Upload plugin also requires the jQuery UI Progressbar and Button components as well as the jQuery Templates plugin. These dependencies are marked as optional, as the basic File Upload plugin can be used without them and the UI version of the plugin can be extended to override these dependencies with alternative solutions.
|
||||
|
||||
## Browser Support (tested versions)
|
||||
* Google Chrome - 7.0+
|
||||
* Apple Safari - 4.0+
|
||||
* Mozilla Firefox - 3.0+
|
||||
* Opera - 10.0+
|
||||
* Microsoft Internet Explorer 6.0+
|
||||
|
||||
Drag & Drop is only supported on Google Chrome, Firefox 4.0+ and Safari 5.0+.
|
||||
Microsoft Internet Explorer has no support for multiple file selection or upload progress.
|
||||
[Extended browser support information](https://github.com/blueimp/jQuery-File-Upload/wiki/Browser-support).
|
||||
|
||||
## License
|
||||
Released under the [MIT license](http://creativecommons.org/licenses/MIT/).
|
||||
|
||||
## Source Code & Download
|
||||
* Browse and checkout the [source code](https://github.com/blueimp/jQuery-File-Upload).
|
||||
* [Download](https://github.com/blueimp/jQuery-File-Upload/archives/master) the project to add the plugin to your website.
|
||||
|
||||
## Documentation & Support
|
||||
* Documentation can be found on the [Project Wiki](https://github.com/blueimp/jQuery-File-Upload/wiki).
|
||||
* Support requests and bug reports can be posted to the [Issue Tracker](https://github.com/blueimp/jQuery-File-Upload/issues).
|
||||
|
||||
## Donations
|
||||
jQuery File Upload is free software, but you can donate to support the developer, Sebastian Tschan:
|
||||
|
||||
flattr (€): [](https://flattr.com/thing/286433/jQuery-File-Upload-Plugin)
|
||||
|
||||
PayPal ($): [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PYWYSYP77KL54)
|
||||
@@ -5,6 +5,10 @@ Demo
|
||||
----
|
||||
http://aquantum-demo.appspot.com/file-upload
|
||||
|
||||
Setup instructions
|
||||
------------------
|
||||
https://github.com/blueimp/jQuery-File-Upload/wiki/Setup
|
||||
|
||||
Features
|
||||
--------
|
||||
- Multiple file upload:
|
||||
@@ -12,9 +16,15 @@ Features
|
||||
- Drag & Drop support:
|
||||
Allows to upload files by dragging them from your desktop or filemanager and dropping them on your browser window.
|
||||
- Upload progress bar:
|
||||
Shows a progress bar indicating the upload progress for individual files.
|
||||
Shows a progress bar indicating the upload progress for individual files and for all uploads combined.
|
||||
- Cancelable uploads:
|
||||
Individual file uploads can be canceled to stop the upload progress.
|
||||
- Resumable uploads:
|
||||
Aborted uploads can be resumed with browsers supporting the Blob API.
|
||||
- Chunked uploads:
|
||||
Large files can be uploaded in smaller chunks with browsers supporting the Blob API.
|
||||
- Preview images:
|
||||
A preview of image files can be displayed before uploading with browsers supporting the required HTML5 APIs.
|
||||
- No browser plugins (e.g. Adobe Flash) required:
|
||||
The implementation is based on open standards like HTML5 and JavaScript and requires no additional browser plugins.
|
||||
- Graceful fallback for legacy browsers:
|
||||
@@ -34,18 +44,26 @@ Features
|
||||
|
||||
Requirements
|
||||
------------
|
||||
- jQuery v. 1.4+
|
||||
- jQuery UI v. 1.8+ (optional)
|
||||
- jQuery v. 1.6+
|
||||
- jQuery UI v. 1.8+ (required: Widget, optional: Progressbar, Button)
|
||||
- jQuery Iframe Transport plugin (included)
|
||||
- jQuery Templates plugin v. 1.0+ (optional)
|
||||
|
||||
The jQuery UI widget factory is a requirement for the basic File Upload plugin, but very lightweight without any other dependencies.
|
||||
The UI version of the File Upload plugin also requires the jQuery UI Progressbar and Button components as well as the jQuery Templates plugin. These dependencies are marked as optional, as the basic File Upload plugin can be used without them and the UI version of the plugin can be extended to override these dependencies with alternative solutions.
|
||||
|
||||
Browser Support (tested versions)
|
||||
---------------------------------
|
||||
- Google Chrome - 7.0, 8.0, 9.0
|
||||
- Apple Safari - 5.0 ¹
|
||||
- Mozilla Firefox - 3.6
|
||||
- Opera - 10.60 ², 11.00 ²
|
||||
- Microsoft Internet Explorer 6.0 ², 7.0 ², 8.0 ², 9.0 ²
|
||||
¹ Drag & Drop is not supported on the Windows version of Safari.
|
||||
² MSIE and Opera have no support for Drag & Drop, multiple file selection or upload progress indication.
|
||||
- Google Chrome - 7.0+
|
||||
- Apple Safari - 4.0+
|
||||
- Mozilla Firefox - 3.0+
|
||||
- Opera - 10.0+
|
||||
- Microsoft Internet Explorer 6.0+
|
||||
|
||||
Drag & Drop is only supported on Google Chrome, Firefox 4.0+ and Safari 5.0+.
|
||||
Microsoft Internet Explorer has no support for multiple file selection or upload progress.
|
||||
Extended browser support information:
|
||||
https://github.com/blueimp/jQuery-File-Upload/wiki/Browser-support
|
||||
|
||||
License
|
||||
-------
|
||||
@@ -59,3 +77,13 @@ https://github.com/blueimp/jQuery-File-Upload
|
||||
Documentation
|
||||
-------------
|
||||
https://github.com/blueimp/jQuery-File-Upload/wiki
|
||||
|
||||
Donations
|
||||
---------
|
||||
jQuery File Upload is free software, but you can donate to support the developer, Sebastian Tschan:
|
||||
|
||||
flattr (€):
|
||||
https://flattr.com/thing/286433/jQuery-File-Upload-Plugin
|
||||
|
||||
PayPal ($):
|
||||
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PYWYSYP77KL54
|
||||
|
||||
@@ -1,70 +1,100 @@
|
||||
.file_upload {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
direction: ltr;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
-moz-border-radius: 10px;
|
||||
-webkit-border-radius: 10px;
|
||||
border-radius: 10px;
|
||||
width: 200px;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
background: palegreen;
|
||||
border: 1px solid limegreen;
|
||||
}
|
||||
@charset 'UTF-8';
|
||||
/*
|
||||
* jQuery File Upload UI Plugin CSS 5.0.6
|
||||
* https://github.com/blueimp/jQuery-File-Upload
|
||||
*
|
||||
* Copyright 2010, Sebastian Tschan
|
||||
* https://blueimp.net
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://creativecommons.org/licenses/MIT/
|
||||
*/
|
||||
|
||||
.file_upload_small {
|
||||
width: 200px;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
font-size: auto;
|
||||
background: palegreen;
|
||||
border: 1px solid limegreen;
|
||||
}
|
||||
|
||||
.file_upload_large {
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
line-height: 150px;
|
||||
font-size: 20px;
|
||||
background: palegreen;
|
||||
border: 1px solid limegreen;
|
||||
}
|
||||
|
||||
.file_upload_highlight {
|
||||
background: lawngreen;
|
||||
}
|
||||
|
||||
.file_upload input {
|
||||
.fileupload-buttonbar .ui-button input {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
border: 300px solid transparent;
|
||||
border: solid transparent;
|
||||
border-width: 0 0 100px 200px;
|
||||
opacity: 0;
|
||||
-ms-filter: 'alpha(opacity=0)';
|
||||
filter: alpha(opacity=0);
|
||||
-o-transform: translate(-300px, -300px) scale(10);
|
||||
-moz-transform: translate(-800px, 0) scale(10);
|
||||
-o-transform: translate(250px, -50px) scale(1);
|
||||
-moz-transform: translate(-300px, 0) scale(4);
|
||||
direction: ltr;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.file_upload iframe, .file_upload button {
|
||||
display: none;
|
||||
.fileinput-button {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.file_upload_progress .ui-progressbar-value {
|
||||
/* Fix for IE 6: */
|
||||
*html .fileinput-button {
|
||||
padding: 2px 0;
|
||||
}
|
||||
|
||||
/* Fix for IE 7: */
|
||||
*+html .fileinput-button {
|
||||
padding: 2px 0;
|
||||
}
|
||||
|
||||
.fileupload-buttonbar {
|
||||
padding: 0.2em 0.4em;
|
||||
}
|
||||
|
||||
.fileupload-buttonbar .ui-button {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.fileupload-content {
|
||||
padding: 0.2em 0.4em;
|
||||
border-top-width: 0;
|
||||
}
|
||||
|
||||
.fileupload-content .ui-progressbar {
|
||||
width: 200px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.fileupload-content .ui-progressbar-value {
|
||||
background: url(pbar-ani.gif);
|
||||
}
|
||||
|
||||
.file_upload_progress div {
|
||||
width: 150px;
|
||||
height: 15px;
|
||||
.fileupload-content .fileupload-progressbar {
|
||||
width: 400px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.file_upload_cancel div {
|
||||
cursor: pointer;
|
||||
.files {
|
||||
margin: 10px 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.files td {
|
||||
padding: 5px;
|
||||
border-spacing: 5px;
|
||||
}
|
||||
|
||||
.files img {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.files .name {
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.files .size {
|
||||
padding: 0 10px 0 0;
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.ui-state-disabled .ui-state-disabled {
|
||||
opacity: 1;
|
||||
filter: alpha(opacity=100);
|
||||
}
|
||||
|
||||
.ui-state-disabled input {
|
||||
cursor: default;
|
||||
}
|
||||
@@ -1,259 +1,642 @@
|
||||
/*
|
||||
* jQuery File Upload User Interface Plugin 3.2.2
|
||||
* jQuery File Upload User Interface Plugin 5.0.13
|
||||
* https://github.com/blueimp/jQuery-File-Upload
|
||||
*
|
||||
* Copyright 2010, Sebastian Tschan
|
||||
* https://blueimp.net
|
||||
*
|
||||
* Copyright 2010, Sebastian Tschan, AQUANTUM
|
||||
* Licensed under the MIT license:
|
||||
* http://creativecommons.org/licenses/MIT/
|
||||
*
|
||||
* https://blueimp.net
|
||||
* http://www.aquantum.de
|
||||
*/
|
||||
|
||||
/*jslint browser: true */
|
||||
/*global jQuery */
|
||||
/*jslint nomen: true, unparam: true, regexp: true */
|
||||
/*global window, document, URL, webkitURL, FileReader, jQuery */
|
||||
|
||||
(function ($) {
|
||||
|
||||
var UploadHandler,
|
||||
methods;
|
||||
'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, {
|
||||
|
||||
UploadHandler = function (container, options) {
|
||||
var uploadHandler = this,
|
||||
undef = 'undefined',
|
||||
func = 'function',
|
||||
dragOverTimeout,
|
||||
isDropZoneEnlarged;
|
||||
|
||||
this.dropZone = container;
|
||||
this.progressSelector = '.file_upload_progress div';
|
||||
this.cancelSelector = '.file_upload_cancel div';
|
||||
this.cssClassSmall = 'file_upload_small';
|
||||
this.cssClassLarge = 'file_upload_large';
|
||||
this.cssClassHighlight = 'file_upload_highlight';
|
||||
this.dropEffect = 'highlight';
|
||||
this.uploadTable = this.downloadTable = $();
|
||||
|
||||
this.buildUploadRow = this.buildDownloadRow = function () {
|
||||
return null;
|
||||
};
|
||||
|
||||
this.addNode = function (parentNode, node, callBack) {
|
||||
if (node) {
|
||||
node.css('display', 'none').appendTo(parentNode).fadeIn(function () {
|
||||
if (typeof callBack === func) {
|
||||
try {
|
||||
callBack();
|
||||
} catch (e) {
|
||||
// Fix endless exception loop:
|
||||
$(this).stop();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (typeof callBack === func) {
|
||||
callBack();
|
||||
}
|
||||
};
|
||||
|
||||
this.removeNode = function (node, callBack) {
|
||||
if (node) {
|
||||
node.fadeOut(function () {
|
||||
$(this).remove();
|
||||
if (typeof callBack === func) {
|
||||
try {
|
||||
callBack();
|
||||
} catch (e) {
|
||||
// Fix endless exception loop:
|
||||
$(this).stop();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (typeof callBack === func) {
|
||||
callBack();
|
||||
}
|
||||
};
|
||||
|
||||
this.onAbort = function (event, files, index, xhr, handler) {
|
||||
uploadHandler.removeNode(handler.uploadRow);
|
||||
};
|
||||
|
||||
this.cancelUpload = function (event, files, index, xhr, handler) {
|
||||
var readyState = xhr.readyState;
|
||||
xhr.abort();
|
||||
// If readyState is below 2, abort() has no effect:
|
||||
if (isNaN(readyState) || readyState < 2) {
|
||||
handler.onAbort(event, files, index, xhr, handler);
|
||||
}
|
||||
};
|
||||
|
||||
this.initProgressBar = function (node, value) {
|
||||
if (typeof node.progressbar === func) {
|
||||
return node.progressbar({
|
||||
value: value
|
||||
});
|
||||
} else {
|
||||
var progressbar = $('<progress value="' + value + '" max="100"/>').appendTo(node);
|
||||
progressbar.progressbar = function (key, value) {
|
||||
progressbar.attr('value', value);
|
||||
};
|
||||
return progressbar;
|
||||
}
|
||||
};
|
||||
|
||||
this.initUploadRow = function (event, files, index, xhr, handler, callBack) {
|
||||
var uploadRow = handler.uploadRow = uploadHandler.buildUploadRow(files, index);
|
||||
if (uploadRow) {
|
||||
handler.progressbar = uploadHandler.initProgressBar(
|
||||
uploadRow.find(uploadHandler.progressSelector),
|
||||
(xhr.upload ? 0 : 100)
|
||||
);
|
||||
uploadRow.find(uploadHandler.cancelSelector).click(function (e) {
|
||||
uploadHandler.cancelUpload(e, files, index, xhr, handler);
|
||||
});
|
||||
}
|
||||
uploadHandler.addNode(uploadHandler.uploadTable, uploadRow, callBack);
|
||||
};
|
||||
|
||||
this.initUpload = function (event, files, index, xhr, handler, callBack) {
|
||||
uploadHandler.initUploadRow(event, files, index, xhr, handler, function () {
|
||||
if (typeof uploadHandler.beforeSend === func) {
|
||||
uploadHandler.beforeSend(event, files, index, xhr, handler, callBack);
|
||||
} else {
|
||||
callBack();
|
||||
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: false,
|
||||
// The following option limits the number of files that are
|
||||
// allowed to be uploaded using this widget:
|
||||
maxNumberOfFiles: undefined,
|
||||
// The maximum allowed file size:
|
||||
maxFileSize: undefined,
|
||||
// The minimum allowed file size:
|
||||
minFileSize: 1,
|
||||
// The regular expression for allowed file types, matches
|
||||
// against either file type or file name:
|
||||
acceptFileTypes: /.+$/i,
|
||||
// The regular expression to define for which files a preview
|
||||
// image is shown, matched against the file type:
|
||||
previewFileTypes: /^image\/(gif|jpeg|png)$/,
|
||||
// The maximum width of the preview images:
|
||||
previewMaxWidth: 80,
|
||||
// The maximum height of the preview images:
|
||||
previewMaxHeight: 80,
|
||||
// By default, preview images are displayed as canvas elements
|
||||
// if supported by the browser. Set the following option to false
|
||||
// to always display preview images as img elements:
|
||||
previewAsCanvas: 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');
|
||||
that._adjustMaxNumberOfFiles(-data.files.length);
|
||||
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();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.onProgress = function (event, files, index, xhr, handler) {
|
||||
if (handler.progressbar) {
|
||||
handler.progressbar.progressbar(
|
||||
'value',
|
||||
parseInt(event.loaded / event.total * 100, 10)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
this.parseResponse = function (xhr) {
|
||||
if (typeof xhr.responseText !== undef) {
|
||||
return $.parseJSON(xhr.responseText);
|
||||
} else {
|
||||
// Instead of an XHR object, an iframe is used for legacy browsers:
|
||||
return $.parseJSON(xhr.contents().text());
|
||||
}
|
||||
};
|
||||
|
||||
this.initDownloadRow = function (event, files, index, xhr, handler, callBack) {
|
||||
var json, downloadRow;
|
||||
try {
|
||||
json = handler.response = uploadHandler.parseResponse(xhr);
|
||||
downloadRow = handler.downloadRow = uploadHandler.buildDownloadRow(json);
|
||||
uploadHandler.addNode(uploadHandler.downloadTable, downloadRow, callBack);
|
||||
} catch (e) {
|
||||
if (typeof uploadHandler.onError === func) {
|
||||
handler.originalEvent = event;
|
||||
uploadHandler.onError(e, files, index, xhr, handler);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.onLoad = function (event, files, index, xhr, handler) {
|
||||
uploadHandler.removeNode(handler.uploadRow, function () {
|
||||
uploadHandler.initDownloadRow(event, files, index, xhr, handler, function () {
|
||||
if (typeof uploadHandler.onComplete === func) {
|
||||
uploadHandler.onComplete(event, files, index, xhr, handler);
|
||||
},
|
||||
// Callback for the start of each file upload request:
|
||||
send: function (e, data) {
|
||||
if (!data.isValidated) {
|
||||
var that = $(this).data('fileupload');
|
||||
if (!data.isAdjusted) {
|
||||
that._adjustMaxNumberOfFiles(-data.files.length);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.dropZoneEnlarge = function () {
|
||||
if (!isDropZoneEnlarged) {
|
||||
if (typeof uploadHandler.dropZone.switchClass === func) {
|
||||
uploadHandler.dropZone.switchClass(
|
||||
uploadHandler.cssClassSmall,
|
||||
uploadHandler.cssClassLarge
|
||||
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)
|
||||
);
|
||||
} else {
|
||||
uploadHandler.dropZone.addClass(uploadHandler.cssClassLarge);
|
||||
uploadHandler.dropZone.removeClass(uploadHandler.cssClassSmall);
|
||||
}
|
||||
isDropZoneEnlarged = true;
|
||||
}
|
||||
};
|
||||
|
||||
this.dropZoneReduce = function () {
|
||||
if (typeof uploadHandler.dropZone.switchClass === func) {
|
||||
uploadHandler.dropZone.switchClass(
|
||||
uploadHandler.cssClassLarge,
|
||||
uploadHandler.cssClassSmall
|
||||
},
|
||||
// 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'};
|
||||
if (file.error) {
|
||||
that._adjustMaxNumberOfFiles(1);
|
||||
}
|
||||
$(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');
|
||||
that._adjustMaxNumberOfFiles(data.files.length);
|
||||
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') {
|
||||
that._adjustMaxNumberOfFiles(-data.files.length);
|
||||
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)
|
||||
);
|
||||
} else {
|
||||
uploadHandler.dropZone.addClass(uploadHandler.cssClassSmall);
|
||||
uploadHandler.dropZone.removeClass(uploadHandler.cssClassLarge);
|
||||
},
|
||||
// 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();
|
||||
},
|
||||
// Callback for file deletion:
|
||||
destroy: function (e, data) {
|
||||
var that = $(this).data('fileupload');
|
||||
if (data.url) {
|
||||
$.ajax(data)
|
||||
.success(function () {
|
||||
that._adjustMaxNumberOfFiles(1);
|
||||
$(this).fadeOut(function () {
|
||||
$(this).remove();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
data.context.fadeOut(function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
isDropZoneEnlarged = false;
|
||||
};
|
||||
},
|
||||
|
||||
this.onDocumentDragEnter = function (event) {
|
||||
uploadHandler.dropZoneEnlarge();
|
||||
};
|
||||
|
||||
this.onDocumentDragOver = function (event) {
|
||||
if (dragOverTimeout) {
|
||||
clearTimeout(dragOverTimeout);
|
||||
// Scales the given image (img HTML element)
|
||||
// using the given options.
|
||||
// Returns a canvas object if the canvas option is true
|
||||
// and the browser supports canvas, else the scaled image:
|
||||
_scaleImage: function (img, options) {
|
||||
options = options || {};
|
||||
var canvas = document.createElement('canvas'),
|
||||
scale = Math.min(
|
||||
(options.maxWidth || img.width) / img.width,
|
||||
(options.maxHeight || img.height) / img.height
|
||||
);
|
||||
if (scale >= 1) {
|
||||
scale = Math.max(
|
||||
(options.minWidth || img.width) / img.width,
|
||||
(options.minHeight || img.height) / img.height
|
||||
);
|
||||
}
|
||||
dragOverTimeout = setTimeout(function () {
|
||||
uploadHandler.dropZoneReduce();
|
||||
}, 200);
|
||||
};
|
||||
|
||||
this.onDragEnter = this.onDragLeave = function (event) {
|
||||
uploadHandler.dropZone.toggleClass(uploadHandler.cssClassHighlight);
|
||||
};
|
||||
|
||||
this.onDrop = function (event) {
|
||||
if (dragOverTimeout) {
|
||||
clearTimeout(dragOverTimeout);
|
||||
img.width = parseInt(img.width * scale, 10);
|
||||
img.height = parseInt(img.height * scale, 10);
|
||||
if (!options.canvas || !canvas.getContext) {
|
||||
return img;
|
||||
}
|
||||
if (uploadHandler.dropEffect && typeof uploadHandler.dropZone.effect === func) {
|
||||
uploadHandler.dropZone.effect(uploadHandler.dropEffect, function () {
|
||||
uploadHandler.dropZone.removeClass(uploadHandler.cssClassHighlight);
|
||||
uploadHandler.dropZoneReduce();
|
||||
});
|
||||
} else {
|
||||
uploadHandler.dropZone.removeClass(uploadHandler.cssClassHighlight);
|
||||
uploadHandler.dropZoneReduce();
|
||||
}
|
||||
};
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
canvas.getContext('2d')
|
||||
.drawImage(img, 0, 0, img.width, img.height);
|
||||
return canvas;
|
||||
},
|
||||
|
||||
$.extend(this, options);
|
||||
};
|
||||
_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;
|
||||
},
|
||||
|
||||
methods = {
|
||||
init : function (options) {
|
||||
return this.each(function () {
|
||||
$(this).fileUpload(new UploadHandler($(this), options));
|
||||
// Loads a given File object via FileReader interface,
|
||||
// invokes the callback with a data url:
|
||||
_loadFile: function (file, callback) {
|
||||
if (typeof FileReader !== 'undefined' &&
|
||||
FileReader.prototype.readAsDataURL) {
|
||||
var fileReader = new FileReader();
|
||||
fileReader.onload = function (e) {
|
||||
callback(e.target.result);
|
||||
};
|
||||
fileReader.readAsDataURL(file);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// Loads an image for a given File object.
|
||||
// Invokes the callback with an img or optional canvas
|
||||
// element (if supported by the browser) as parameter:
|
||||
_loadImage: function (file, callback, options) {
|
||||
var that = this,
|
||||
url,
|
||||
img;
|
||||
if (!options || !options.fileTypes ||
|
||||
options.fileTypes.test(file.type)) {
|
||||
url = this._createObjectURL(file);
|
||||
img = $('<img>').bind('load', function () {
|
||||
$(this).unbind('load');
|
||||
that._revokeObjectURL(url);
|
||||
callback(that._scaleImage(img[0], options));
|
||||
}).prop('src', url);
|
||||
if (!url) {
|
||||
this._loadFile(file, function (url) {
|
||||
img.prop('src', url);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 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) {}
|
||||
});
|
||||
},
|
||||
|
||||
destroy : function (namespace) {
|
||||
return this.each(function () {
|
||||
$(this).fileUpload('destroy', namespace);
|
||||
|
||||
_adjustMaxNumberOfFiles: function (operand) {
|
||||
if (typeof this.options.maxNumberOfFiles === 'number') {
|
||||
this.options.maxNumberOfFiles += operand;
|
||||
if (this.options.maxNumberOfFiles < 1) {
|
||||
this._disableFileInputButton();
|
||||
} else {
|
||||
this._enableFileInputButton();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_formatFileSize: function (file) {
|
||||
if (typeof file.size !== 'number') {
|
||||
return '';
|
||||
}
|
||||
if (file.size >= 1000000000) {
|
||||
return (file.size / 1000000000).toFixed(2) + ' GB';
|
||||
}
|
||||
if (file.size >= 1000000) {
|
||||
return (file.size / 1000000).toFixed(2) + ' MB';
|
||||
}
|
||||
return (file.size / 1000).toFixed(2) + ' KB';
|
||||
},
|
||||
|
||||
_hasError: function (file) {
|
||||
if (file.error) {
|
||||
return file.error;
|
||||
}
|
||||
// The number of added files is subtracted from
|
||||
// maxNumberOfFiles before validation, so we check if
|
||||
// maxNumberOfFiles is below 0 (instead of below 1):
|
||||
if (this.options.maxNumberOfFiles < 0) {
|
||||
return 'maxNumberOfFiles';
|
||||
}
|
||||
// Files are accepted if either the file type or the file name
|
||||
// matches against the acceptFileTypes regular expression, as
|
||||
// only browsers with support for the File API report the type:
|
||||
if (!(this.options.acceptFileTypes.test(file.type) ||
|
||||
this.options.acceptFileTypes.test(file.name))) {
|
||||
return 'acceptFileTypes';
|
||||
}
|
||||
if (this.options.maxFileSize &&
|
||||
file.size > this.options.maxFileSize) {
|
||||
return 'maxFileSize';
|
||||
}
|
||||
if (typeof file.size === 'number' &&
|
||||
file.size < this.options.minFileSize) {
|
||||
return 'minFileSize';
|
||||
}
|
||||
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) {
|
||||
file.sizef = this._formatFileSize(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'}
|
||||
});
|
||||
tmpl.find('.preview').each(function (index, node) {
|
||||
that._loadImage(
|
||||
files[index],
|
||||
function (img) {
|
||||
$(img).hide().appendTo(node).fadeIn();
|
||||
},
|
||||
{
|
||||
maxWidth: options.previewMaxWidth,
|
||||
maxHeight: options.previewMaxHeight,
|
||||
fileTypes: options.previewFileTypes,
|
||||
canvas: options.previewAsCanvas
|
||||
}
|
||||
);
|
||||
});
|
||||
return tmpl;
|
||||
},
|
||||
|
||||
_downloadTemplateHelper: function (file) {
|
||||
file.sizef = this._formatFileSize(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('.delete button').button({
|
||||
text: false,
|
||||
icons: {primary: 'ui-icon-trash'}
|
||||
});
|
||||
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();
|
||||
}
|
||||
},
|
||||
|
||||
_deleteHandler: function (e) {
|
||||
e.preventDefault();
|
||||
var button = $(this);
|
||||
e.data.fileupload._trigger('destroy', e, {
|
||||
context: button.closest('.template-download'),
|
||||
url: button.attr('data-url'),
|
||||
type: button.attr('data-type'),
|
||||
dataType: e.data.fileupload.options.dataType
|
||||
});
|
||||
},
|
||||
|
||||
_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
|
||||
);
|
||||
filesList.find('.delete button')
|
||||
.live(
|
||||
'click.' + this.options.namespace,
|
||||
eventData,
|
||||
this._deleteHandler
|
||||
);
|
||||
},
|
||||
|
||||
_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);
|
||||
filesList.find('.delete button')
|
||||
.die('click.' + this.options.namespace);
|
||||
$.blueimp.fileupload.prototype._destroyEventHandlers.call(this);
|
||||
},
|
||||
|
||||
_initFileUploadButtonBar: function () {
|
||||
var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
|
||||
filesList = this.element.find('.files'),
|
||||
ns = this.options.namespace;
|
||||
fileUploadButtonBar
|
||||
.addClass('ui-widget-header ui-corner-top');
|
||||
this.element.find('.fileinput-button').each(function () {
|
||||
var fileInput = $(this).find('input:file').detach();
|
||||
$(this).button({icons: {primary: 'ui-icon-plusthick'}})
|
||||
.append(fileInput);
|
||||
});
|
||||
fileUploadButtonBar.find('.start')
|
||||
.button({icons: {primary: 'ui-icon-circle-arrow-e'}})
|
||||
.bind('click.' + ns, function (e) {
|
||||
e.preventDefault();
|
||||
filesList.find('.start button').click();
|
||||
});
|
||||
fileUploadButtonBar.find('.cancel')
|
||||
.button({icons: {primary: 'ui-icon-cancel'}})
|
||||
.bind('click.' + ns, function (e) {
|
||||
e.preventDefault();
|
||||
filesList.find('.cancel button').click();
|
||||
});
|
||||
fileUploadButtonBar.find('.delete')
|
||||
.button({icons: {primary: 'ui-icon-trash'}})
|
||||
.bind('click.' + ns, function (e) {
|
||||
e.preventDefault();
|
||||
filesList.find('.delete button').click();
|
||||
});
|
||||
},
|
||||
|
||||
_destroyFileUploadButtonBar: function () {
|
||||
this.element.find('.fileupload-buttonbar')
|
||||
.removeClass('ui-widget-header ui-corner-top');
|
||||
this.element.find('.fileinput-button').each(function () {
|
||||
var fileInput = $(this).find('input:file').detach();
|
||||
$(this).button('destroy')
|
||||
.append(fileInput);
|
||||
});
|
||||
this.element.find('.fileupload-buttonbar button')
|
||||
.unbind('click.' + this.options.namespace)
|
||||
.button('destroy');
|
||||
},
|
||||
|
||||
_enableFileInputButton: function () {
|
||||
this.element.find('.fileinput-button input:file:disabled')
|
||||
.each(function () {
|
||||
var fileInput = $(this),
|
||||
button = fileInput.parent();
|
||||
fileInput.detach().prop('disabled', false);
|
||||
button.button('enable').append(fileInput);
|
||||
});
|
||||
},
|
||||
|
||||
_disableFileInputButton: function () {
|
||||
this.element.find('.fileinput-button input:file:enabled')
|
||||
.each(function () {
|
||||
var fileInput = $(this),
|
||||
button = fileInput.parent();
|
||||
fileInput.detach().prop('disabled', true);
|
||||
button.button('disable').append(fileInput);
|
||||
});
|
||||
},
|
||||
|
||||
_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();
|
||||
this.element
|
||||
.addClass('ui-widget');
|
||||
this._initFileUploadButtonBar();
|
||||
this.element.find('.fileupload-content')
|
||||
.addClass('ui-widget-content ui-corner-bottom');
|
||||
this.element.find('.fileupload-progressbar')
|
||||
.hide().progressbar();
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
this.element.find('.fileupload-progressbar')
|
||||
.progressbar('destroy');
|
||||
this.element.find('.fileupload-content')
|
||||
.removeClass('ui-widget-content ui-corner-bottom');
|
||||
this._destroyFileUploadButtonBar();
|
||||
this.element.removeClass('ui-widget');
|
||||
$.blueimp.fileupload.prototype.destroy.call(this);
|
||||
},
|
||||
|
||||
enable: function () {
|
||||
$.blueimp.fileupload.prototype.enable.call(this);
|
||||
this.element.find(':ui-button').not('.fileinput-button')
|
||||
.button('enable');
|
||||
this._enableFileInputButton();
|
||||
},
|
||||
|
||||
disable: function () {
|
||||
this.element.find(':ui-button').not('.fileinput-button')
|
||||
.button('disable');
|
||||
this._disableFileInputButton();
|
||||
$.blueimp.fileupload.prototype.disable.call(this);
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.fileUploadUI = function (method) {
|
||||
if (methods[method]) {
|
||||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
||||
} else if (typeof method === 'object' || !method) {
|
||||
return methods.init.apply(this, arguments);
|
||||
} else {
|
||||
$.error('Method ' + method + ' does not exist on jQuery.fileUploadUI');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
|
||||
}(jQuery));
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* jQuery Iframe Transport Plugin 1.2.2
|
||||
* 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 three additional options:
|
||||
// options.fileInput: a jQuery collection of file input fields
|
||||
// options.paramName: the parameter name for the file form data,
|
||||
// overrides the name property of the file input field(s)
|
||||
// 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 = $('<form style="display:none;"></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 = $(
|
||||
'<iframe src="javascript:false;" name="iframe-transport-' +
|
||||
(counter += 1) + '"></iframe>'
|
||||
).bind('load', function () {
|
||||
var fileInputClones;
|
||||
iframe
|
||||
.unbind('load')
|
||||
.bind('load', function () {
|
||||
var response;
|
||||
// Wrap in a try/catch block to catch exceptions thrown
|
||||
// when trying to access cross-domain iframe contents:
|
||||
try {
|
||||
response = iframe.contents();
|
||||
// Google Chrome and Firefox do not throw an
|
||||
// exception when calling iframe.contents() on
|
||||
// cross-domain requests, so we unify the response:
|
||||
if (!response.length || !response[0].firstChild) {
|
||||
throw new Error();
|
||||
}
|
||||
} catch (e) {
|
||||
response = undefined;
|
||||
}
|
||||
// The complete callback returns the
|
||||
// iframe content document as response object:
|
||||
completeCallback(
|
||||
200,
|
||||
'success',
|
||||
{'iframe': response}
|
||||
);
|
||||
// Fix for IE endless progress bar activity bug
|
||||
// (happens on form submits to iframe targets):
|
||||
$('<iframe src="javascript:false;"></iframe>')
|
||||
.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) {
|
||||
$('<input type="hidden"/>')
|
||||
.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];
|
||||
});
|
||||
if (options.paramName) {
|
||||
options.fileInput.each(function () {
|
||||
$(this).prop('name', options.paramName);
|
||||
});
|
||||
}
|
||||
// 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) {
|
||||
var clone = $(fileInputClones[index]);
|
||||
$(input).prop('name', clone.prop('name'));
|
||||
clone.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));
|
||||
10
htdocs/includes/jquery/plugins/fileupload/jquery.tmpl.min.js
vendored
Normal file
10
htdocs/includes/jquery/plugins/fileupload/jquery.tmpl.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 297 KiB After Width: | Height: | Size: 3.2 KiB |
Reference in New Issue
Block a user