jQuery modernization : updated libraries to a version compatible with jquery 1.12.4

SVN:trunk[5357]
This commit is contained in:
Stephen Abello
2018-02-22 09:21:05 +00:00
parent e05d780bec
commit ebb541e4f5
3 changed files with 2288 additions and 2181 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* jQuery Autocomplete plugin 1.1 * jQuery Autocomplete plugin 1.2.3
* *
* Copyright (c) 2009 Jörn Zaefferer * Copyright (c) 2009 Jörn Zaefferer
* *
@@ -7,19 +7,25 @@
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html * http://www.gnu.org/licenses/gpl.html
* *
* Revision: $Id: jquery.autocomplete.js 15 2009-08-22 10:30:27Z joern.zaefferer $ * With small modifications by Alfonso Gómez-Arzola.
* See changelog for details.
*
* patched by sabello to : replace .size() to length
* set the row response split to "\t"
*
*/ */
;(function($) { ;(function($) {
$.fn.extend({ $.fn.extend({
autocomplete: function(urlOrData, options) { autocomplete: function(urlOrData, options) {
var isUrl = typeof urlOrData == "string"; var isUrl = typeof urlOrData == "string";
options = $.extend({}, $.Autocompleter.defaults, { options = $.extend({}, $.Autocompleter.defaults, {
url: isUrl ? urlOrData : null, url: isUrl ? urlOrData : null,
data: isUrl ? null : urlOrData, data: isUrl ? null : urlOrData,
delay: isUrl ? $.Autocompleter.defaults.delay : 10, delay: isUrl ? $.Autocompleter.defaults.delay : 10,
max: options && !options.scroll ? 10 : 150 max: options && !options.scroll ? 10 : 150,
noRecord: "No Records."
}, options); }, options);
// if highlight is set to false, replace it with a do-nothing function // if highlight is set to false, replace it with a do-nothing function
@@ -47,9 +53,9 @@ $.fn.extend({
unautocomplete: function() { unautocomplete: function() {
return this.trigger("unautocomplete"); return this.trigger("unautocomplete");
} }
}); });
$.Autocompleter = function(input, options) { $.Autocompleter = function(input, options) {
var KEY = { var KEY = {
UP: 38, UP: 38,
@@ -64,6 +70,11 @@ $.Autocompleter = function(input, options) {
BACKSPACE: 8 BACKSPACE: 8
}; };
var globalFailure = null;
if(options.failure != null && typeof options.failure == "function") {
globalFailure = options.failure;
}
// Create $ object for input element // Create $ object for input element
var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass); var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass);
@@ -80,15 +91,15 @@ $.Autocompleter = function(input, options) {
var blockSubmit; var blockSubmit;
// prevent form submit in opera when selecting with return key // prevent form submit in opera when selecting with return key
$.browser.opera && $(input.form).bind("submit.autocomplete", function() { navigator.userAgent.indexOf("Opera") != -1 && $(input.form).bind("submit.autocomplete", function() {
if (blockSubmit) { if (blockSubmit) {
blockSubmit = false; blockSubmit = false;
return false; return false;
} }
}); });
// only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all // older versions of opera don't trigger keydown multiple times while pressed, others don't work with keypress at all
$input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) { $input.bind((navigator.userAgent.indexOf("Opera") != -1 && !'KeyboardEvent' in window ? "keypress" : "keydown") + ".autocomplete", function(event) {
// a keypress means the input has focus // a keypress means the input has focus
// avoids issue where input had focus before the autocomplete was applied // avoids issue where input had focus before the autocomplete was applied
hasFocus = 1; hasFocus = 1;
@@ -97,8 +108,8 @@ $.Autocompleter = function(input, options) {
switch(event.keyCode) { switch(event.keyCode) {
case KEY.UP: case KEY.UP:
event.preventDefault();
if ( select.visible() ) { if ( select.visible() ) {
event.preventDefault();
select.prev(); select.prev();
} else { } else {
onChange(0, true); onChange(0, true);
@@ -106,8 +117,8 @@ $.Autocompleter = function(input, options) {
break; break;
case KEY.DOWN: case KEY.DOWN:
event.preventDefault();
if ( select.visible() ) { if ( select.visible() ) {
event.preventDefault();
select.next(); select.next();
} else { } else {
onChange(0, true); onChange(0, true);
@@ -115,8 +126,8 @@ $.Autocompleter = function(input, options) {
break; break;
case KEY.PAGEUP: case KEY.PAGEUP:
event.preventDefault();
if ( select.visible() ) { if ( select.visible() ) {
event.preventDefault();
select.pageUp(); select.pageUp();
} else { } else {
onChange(0, true); onChange(0, true);
@@ -124,8 +135,8 @@ $.Autocompleter = function(input, options) {
break; break;
case KEY.PAGEDOWN: case KEY.PAGEDOWN:
event.preventDefault();
if ( select.visible() ) { if ( select.visible() ) {
event.preventDefault();
select.pageDown(); select.pageDown();
} else { } else {
onChange(0, true); onChange(0, true);
@@ -164,9 +175,17 @@ $.Autocompleter = function(input, options) {
} }
}).click(function() { }).click(function() {
// show select when clicking in a focused field // show select when clicking in a focused field
// but if clickFire is true, don't require field
// to be focused to begin with; just show select
if( options.clickFire ) {
if ( !select.visible() ) {
onChange(0, true);
}
} else {
if ( hasFocus++ > 1 && !select.visible() ) { if ( hasFocus++ > 1 && !select.visible() ) {
onChange(0, true); onChange(0, true);
} }
}
}).bind("search", function() { }).bind("search", function() {
// TODO why not just specifying both arguments? // TODO why not just specifying both arguments?
var fn = (arguments.length > 1) ? arguments[1] : null; var fn = (arguments.length > 1) ? arguments[1] : null;
@@ -189,7 +208,7 @@ $.Autocompleter = function(input, options) {
}).bind("flushCache", function() { }).bind("flushCache", function() {
cache.flush(); cache.flush();
}).bind("setOptions", function() { }).bind("setOptions", function() {
$.extend(options, arguments[1]); $.extend(true, options, arguments[1]);
// if we've updated the data, repopulate // if we've updated the data, repopulate
if ( "data" in arguments[1] ) if ( "data" in arguments[1] )
cache.populate(); cache.populate();
@@ -321,7 +340,7 @@ $.Autocompleter = function(input, options) {
$input.val( words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : "") ); $input.val( words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : "") );
} }
else { else {
//$input.val( "" ); $input.val( "" );
$input.trigger("result", null); $input.trigger("result", null);
} }
} }
@@ -346,8 +365,14 @@ $.Autocompleter = function(input, options) {
term = term.toLowerCase(); term = term.toLowerCase();
var data = cache.load(term); var data = cache.load(term);
// recieve the cached data // recieve the cached data
if (data && data.length) { if (data) {
if(data.length) {
success(term, data); success(term, data);
}
else{
var parsed = options.parse && options.parse(options.noRecord) || parse(options.noRecord);
success(term,parsed);
}
// if an AJAX url has been supplied, try loading the data now // if an AJAX url has been supplied, try loading the data now
} else if( (typeof options.url == "string") && (options.url.length > 0) ){ } else if( (typeof options.url == "string") && (options.url.length > 0) ){
@@ -361,7 +386,6 @@ $.Autocompleter = function(input, options) {
$.ajax({ $.ajax({
// try to leverage ajaxQueue plugin to abort previous requests // try to leverage ajaxQueue plugin to abort previous requests
mode: "abort", mode: "abort",
type: "POST",
// limit abortion to this input // limit abortion to this input
port: "autocomplete" + input.name, port: "autocomplete" + input.name,
dataType: options.dataType, dataType: options.dataType,
@@ -379,8 +403,13 @@ $.Autocompleter = function(input, options) {
} else { } else {
// if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match // if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
select.emptyList(); select.emptyList();
if(globalFailure != null) {
globalFailure();
}
else {
failure(term); failure(term);
} }
}
}; };
function parse(data) { function parse(data) {
@@ -404,9 +433,9 @@ $.Autocompleter = function(input, options) {
$input.removeClass(options.loadingClass); $input.removeClass(options.loadingClass);
}; };
}; };
$.Autocompleter.defaults = { $.Autocompleter.defaults = {
inputClass: "ac_input", inputClass: "ac_input",
resultsClass: "ac_results", resultsClass: "ac_results",
loadingClass: "ac_loading", loadingClass: "ac_loading",
@@ -415,8 +444,8 @@ $.Autocompleter.defaults = {
matchCase: false, matchCase: false,
matchSubset: true, matchSubset: true,
matchContains: false, matchContains: false,
cacheLength: 10, cacheLength: 100,
max: 100, max: 1000,
mustMatch: false, mustMatch: false,
extraParams: {}, extraParams: {},
selectFirst: true, selectFirst: true,
@@ -425,15 +454,18 @@ $.Autocompleter.defaults = {
autoFill: false, autoFill: false,
width: 0, width: 0,
multiple: false, multiple: false,
multipleSeparator: ", ", multipleSeparator: " ",
inputFocus: true,
clickFire: false,
highlight: function(value, term) { highlight: function(value, term) {
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"); return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
}, },
scroll: true, scroll: true,
scrollHeight: 180 scrollHeight: 180,
}; scrollJumpPosition: true
};
$.Autocompleter.Cache = function(options) { $.Autocompleter.Cache = function(options) {
var data = {}; var data = {};
var length = 0; var length = 0;
@@ -478,7 +510,7 @@ $.Autocompleter.Cache = function(options) {
rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue; rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue;
var value = options.formatMatch(rawValue, i+1, options.data.length); var value = options.formatMatch(rawValue, i+1, options.data.length);
if ( value === false ) if ( typeof(value) === 'undefined' || value === false )
continue; continue;
var firstChar = value.charAt(0).toLowerCase(); var firstChar = value.charAt(0).toLowerCase();
@@ -570,9 +602,9 @@ $.Autocompleter.Cache = function(options) {
return null; return null;
} }
}; };
}; };
$.Autocompleter.Select = function (options, input, select, config) { $.Autocompleter.Select = function (options, input, select, config) {
var CLASSES = { var CLASSES = {
ACTIVE: "ac_over" ACTIVE: "ac_over"
}; };
@@ -593,7 +625,14 @@ $.Autocompleter.Select = function (options, input, select, config) {
.hide() .hide()
.addClass(options.resultsClass) .addClass(options.resultsClass)
.css("position", "absolute") .css("position", "absolute")
.appendTo(document.body); .appendTo(document.body)
.hover(function(event) {
// Browsers except FF do not fire mouseup event on scrollbars, resulting in mouseDownOnSelect remaining true, and results list not always hiding.
if($(this).is(":visible")) {
input.focus();
}
config.mouseDownOnSelect = false;
});
list = $("<ul/>").appendTo(element).mouseover( function(event) { list = $("<ul/>").appendTo(element).mouseover( function(event) {
if(target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') { if(target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') {
@@ -603,7 +642,7 @@ $.Autocompleter.Select = function (options, input, select, config) {
}).click(function(event) { }).click(function(event) {
$(target(event)).addClass(CLASSES.ACTIVE); $(target(event)).addClass(CLASSES.ACTIVE);
select(); select();
// TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus if( options.inputFocus )
input.focus(); input.focus();
return false; return false;
}).mousedown(function() { }).mousedown(function() {
@@ -646,13 +685,16 @@ $.Autocompleter.Select = function (options, input, select, config) {
}; };
function movePosition(step) { function movePosition(step) {
if (options.scrollJumpPosition || (!options.scrollJumpPosition && !((step < 0 && active == 0) || (step > 0 && active == listItems.length - 1)) )) {
active += step; active += step;
if (active < 0) { if (active < 0) {
active = listItems.size() - 1; active = listItems.length - 1;
} else if (active >= listItems.size()) { } else if (active >= listItems.length) {
active = 0; active = 0;
} }
} }
}
function limitNumberOfItems(available) { function limitNumberOfItems(available) {
return options.max && options.max < available return options.max && options.max < available
@@ -669,9 +711,7 @@ $.Autocompleter.Select = function (options, input, select, config) {
var formatted = options.formatItem(data[i].data, i+1, max, data[i].value, term); var formatted = options.formatItem(data[i].data, i+1, max, data[i].value, term);
if ( formatted === false ) if ( formatted === false )
continue; continue;
// Escape dangerous characters to prevent XSS vulnerabilities var li = $("<li/>").html( options.highlight(formatted, term) ).addClass(i%2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
formatted = formatted.replace('&', '&amp;').replace('"', '&quot;').replace('>', '&gt;').replace('<', '&lt;');
var li = $("<li/>").html( options.highlight(formatted, term) ).addClass('ac_item').addClass(i%2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
$.data(li, "ac_data", data[i]); $.data(li, "ac_data", data[i]);
} }
listItems = list.find("li"); listItems = list.find("li");
@@ -705,8 +745,8 @@ $.Autocompleter.Select = function (options, input, select, config) {
} }
}, },
pageDown: function() { pageDown: function() {
if (active != listItems.size() - 1 && active + 8 > listItems.size()) { if (active != listItems.length - 1 && active + 8 > listItems.length) {
moveSelect( listItems.size() - 1 - active ); moveSelect( listItems.length - 1 - active );
} else { } else {
moveSelect(8); moveSelect(8);
} }
@@ -725,7 +765,7 @@ $.Autocompleter.Select = function (options, input, select, config) {
show: function() { show: function() {
var offset = $(input).offset(); var offset = $(input).offset();
element.css({ element.css({
'min-width': typeof options.width == "string" || options.width > 0 ? options.width : $(input).width(), width: typeof options.width == "string" || options.width > 0 ? options.width : $(input).width(),
top: offset.top + input.offsetHeight, top: offset.top + input.offsetHeight,
left: offset.left left: offset.left
}).show(); }).show();
@@ -736,7 +776,7 @@ $.Autocompleter.Select = function (options, input, select, config) {
overflow: 'auto' overflow: 'auto'
}); });
if($.browser.msie && typeof document.body.style.maxHeight === "undefined") { if(navigator.userAgent.indexOf("MSIE") != -1 && typeof document.body.style.maxHeight === "undefined") {
var listHeight = 0; var listHeight = 0;
listItems.each(function() { listItems.each(function() {
listHeight += this.offsetHeight; listHeight += this.offsetHeight;
@@ -762,9 +802,9 @@ $.Autocompleter.Select = function (options, input, select, config) {
element && element.remove(); element && element.remove();
} }
}; };
}; };
$.fn.selection = function(start, end) { $.fn.selection = function(start, end) {
if (start !== undefined) { if (start !== undefined) {
return this.each(function() { return this.each(function() {
if( this.createTextRange ){ if( this.createTextRange ){
@@ -806,6 +846,6 @@ $.fn.selection = function(start, end) {
end: field.selectionEnd end: field.selectionEnd
} }
} }
}; };
})(jQuery); })(jQuery);

View File

@@ -1,25 +1,31 @@
/* /*
* jQuery File Upload Plugin 5.40.1 * jQuery File Upload Plugin
* https://github.com/blueimp/jQuery-File-Upload * https://github.com/blueimp/jQuery-File-Upload
* *
* Copyright 2010, Sebastian Tschan * Copyright 2010, Sebastian Tschan
* https://blueimp.net * https://blueimp.net
* *
* Licensed under the MIT license: * Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
/* jshint nomen:false */ /* jshint nomen:false */
/* global define, window, document, location, Blob, FormData */ /* global define, require, window, document, location, Blob, FormData */
(function (factory) { ;(function (factory) {
'use strict'; 'use strict';
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module: // Register as an anonymous AMD module:
define([ define([
'jquery', 'jquery',
'jquery.ui.widget' 'jquery-ui/ui/widget'
], factory); ], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS:
factory(
require('jquery'),
require('./vendor/jquery.ui.widget')
);
} else { } else {
// Browser globals: // Browser globals:
factory(window.jQuery); factory(window.jQuery);
@@ -37,7 +43,7 @@
'|(Kindle/(1\\.0|2\\.[05]|3\\.0))' '|(Kindle/(1\\.0|2\\.[05]|3\\.0))'
).test(window.navigator.userAgent) || ).test(window.navigator.userAgent) ||
// Feature detection for all other devices: // Feature detection for all other devices:
$('<input type="file">').prop('disabled')); $('<input type="file"/>').prop('disabled'));
// The FileReader API is not actually used, but works as feature detection, // The FileReader API is not actually used, but works as feature detection,
// as some Safari versions (5?) support XHR file uploads via the FormData API, // as some Safari versions (5?) support XHR file uploads via the FormData API,
@@ -51,6 +57,25 @@
$.support.blobSlice = window.Blob && (Blob.prototype.slice || $.support.blobSlice = window.Blob && (Blob.prototype.slice ||
Blob.prototype.webkitSlice || Blob.prototype.mozSlice); Blob.prototype.webkitSlice || Blob.prototype.mozSlice);
// Helper function to create drag handlers for dragover/dragenter/dragleave:
function getDragHandler(type) {
var isDragOver = type === 'dragover';
return function (e) {
e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer;
var dataTransfer = e.dataTransfer;
if (dataTransfer && $.inArray('Files', dataTransfer.types) !== -1 &&
this._trigger(
type,
$.Event(type, {delegatedEvent: e})
) !== false) {
e.preventDefault();
if (isDragOver) {
dataTransfer.dropEffect = 'copy';
}
}
};
}
// The fileupload widget listens for change events on file input fields defined // The fileupload widget listens for change events on file input fields defined
// via fileInput setting and paste or drop events of the given dropZone. // via fileInput setting and paste or drop events of the given dropZone.
// In addition to the default jQuery Widget methods, the fileupload widget // In addition to the default jQuery Widget methods, the fileupload widget
@@ -65,9 +90,9 @@
// The drop target element(s), by the default the complete document. // The drop target element(s), by the default the complete document.
// Set to null to disable drag & drop support: // Set to null to disable drag & drop support:
dropZone: $(document), dropZone: $(document),
// The paste target element(s), by the default the complete document. // The paste target element(s), by the default undefined.
// Set to null to disable paste support: // Set to a DOM node or jQuery object to enable file pasting:
pasteZone: $(document), pasteZone: undefined,
// The file input field(s), that are listened to for change events. // The file input field(s), that are listened to for change events.
// If undefined, it is set to the file input fields inside // If undefined, it is set to the file input fields inside
// of the widget element on plugin initialization. // of the widget element on plugin initialization.
@@ -252,7 +277,8 @@
// The following are jQuery ajax settings required for the file uploads: // The following are jQuery ajax settings required for the file uploads:
processData: false, processData: false,
contentType: false, contentType: false,
cache: false cache: false,
timeout: 0
}, },
// A list of options that require reinitializing event listeners and/or // A list of options that require reinitializing event listeners and/or
@@ -427,7 +453,7 @@
} }
if (!multipart || options.blob || !this._isInstanceOf('File', file)) { if (!multipart || options.blob || !this._isInstanceOf('File', file)) {
options.headers['Content-Disposition'] = 'attachment; filename="' + options.headers['Content-Disposition'] = 'attachment; filename="' +
encodeURI(file.name) + '"'; encodeURI(file.uploadName || file.name) + '"';
} }
if (!multipart) { if (!multipart) {
options.contentType = file.type || 'application/octet-stream'; options.contentType = file.type || 'application/octet-stream';
@@ -463,7 +489,11 @@
}); });
} }
if (options.blob) { if (options.blob) {
formData.append(paramName, options.blob, file.name); formData.append(
paramName,
options.blob,
file.uploadName || file.name
);
} else { } else {
$.each(options.files, function (index, file) { $.each(options.files, function (index, file) {
// This check allows the tests to run with // This check allows the tests to run with
@@ -626,7 +656,7 @@
data.process = function (resolveFunc, rejectFunc) { data.process = function (resolveFunc, rejectFunc) {
if (resolveFunc || rejectFunc) { if (resolveFunc || rejectFunc) {
data._processQueue = this._processQueue = data._processQueue = this._processQueue =
(this._processQueue || getPromise([this])).pipe( (this._processQueue || getPromise([this])).then(
function () { function () {
if (data.errorThrown) { if (data.errorThrown) {
return $.Deferred() return $.Deferred()
@@ -634,7 +664,7 @@
} }
return getPromise(arguments); return getPromise(arguments);
} }
).pipe(resolveFunc, rejectFunc); ).then(resolveFunc, rejectFunc);
} }
return this._processQueue || getPromise([this]); return this._processQueue || getPromise([this]);
}; };
@@ -704,7 +734,7 @@
promise = dfd.promise(), promise = dfd.promise(),
jqXHR, jqXHR,
upload; upload;
if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) || if (!(this._isXHRUpload(options) && slice && (ub || ($.type(mcs) === 'function' ? mcs(options) : mcs) < fs)) ||
options.data) { options.data) {
return false; return false;
} }
@@ -727,7 +757,7 @@
o.blob = slice.call( o.blob = slice.call(
file, file,
ub, ub,
ub + mcs, ub + ($.type(mcs) === 'function' ? mcs(o) : mcs),
file.type file.type
); );
// Store the current chunk size, as the blob itself // Store the current chunk size, as the blob itself
@@ -919,9 +949,9 @@
if (this.options.limitConcurrentUploads > 1) { if (this.options.limitConcurrentUploads > 1) {
slot = $.Deferred(); slot = $.Deferred();
this._slots.push(slot); this._slots.push(slot);
pipe = slot.pipe(send); pipe = slot.then(send);
} else { } else {
this._sequence = this._sequence.pipe(send, send); this._sequence = this._sequence.then(send, send);
pipe = this._sequence; pipe = this._sequence;
} }
// Return the piped Promise object, enhanced with an abort method, // Return the piped Promise object, enhanced with an abort method,
@@ -958,7 +988,10 @@
fileSet, fileSet,
i, i,
j = 0; j = 0;
if (limitSize && (!filesLength || files[0].size === undefined)) { if (!filesLength) {
return false;
}
if (limitSize && files[0].size === undefined) {
limitSize = undefined; limitSize = undefined;
} }
if (!(options.singleFileUploads || limit || limitSize) || if (!(options.singleFileUploads || limit || limitSize) ||
@@ -1015,12 +1048,21 @@
return result; return result;
}, },
_replaceFileInput: function (input) { _replaceFileInput: function (data) {
var inputClone = input.clone(true); var input = data.fileInput,
inputClone = input.clone(true),
restoreFocus = input.is(document.activeElement);
// Add a reference for the new cloned file input to the data argument:
data.fileInputClone = inputClone;
$('<form></form>').append(inputClone)[0].reset(); $('<form></form>').append(inputClone)[0].reset();
// Detaching allows to insert the fileInput on another form // Detaching allows to insert the fileInput on another form
// without loosing the file input value: // without loosing the file input value:
input.after(inputClone).detach(); input.after(inputClone).detach();
// If the fileInput had focus before it was detached,
// restore focus to the inputClone.
if (restoreFocus) {
inputClone.focus();
}
// Avoid memory leaks with the detached file input: // Avoid memory leaks with the detached file input:
$.cleanData(input.unbind('remove')); $.cleanData(input.unbind('remove'));
// Replace the original file input element in the fileInput // Replace the original file input element in the fileInput
@@ -1042,6 +1084,8 @@
_handleFileTreeEntry: function (entry, path) { _handleFileTreeEntry: function (entry, path) {
var that = this, var that = this,
dfd = $.Deferred(), dfd = $.Deferred(),
entries = [],
dirReader,
errorHandler = function (e) { errorHandler = function (e) {
if (e && !e.entry) { if (e && !e.entry) {
e.entry = entry; e.entry = entry;
@@ -1052,7 +1096,24 @@
// to be returned together in one set: // to be returned together in one set:
dfd.resolve([e]); dfd.resolve([e]);
}, },
dirReader; successHandler = function (entries) {
that._handleFileTreeEntries(
entries,
path + entry.name + '/'
).done(function (files) {
dfd.resolve(files);
}).fail(errorHandler);
},
readEntries = function () {
dirReader.readEntries(function (results) {
if (!results.length) {
successHandler(entries);
} else {
entries = entries.concat(results);
readEntries();
}
}, errorHandler);
};
path = path || ''; path = path || '';
if (entry.isFile) { if (entry.isFile) {
if (entry._file) { if (entry._file) {
@@ -1067,14 +1128,7 @@
} }
} else if (entry.isDirectory) { } else if (entry.isDirectory) {
dirReader = entry.createReader(); dirReader = entry.createReader();
dirReader.readEntries(function (entries) { readEntries();
that._handleFileTreeEntries(
entries,
path + entry.name + '/'
).done(function (files) {
dfd.resolve(files);
}).fail(errorHandler);
}, errorHandler);
} else { } else {
// Return an empy list for file system items // Return an empy list for file system items
// other than files or directories: // other than files or directories:
@@ -1090,7 +1144,7 @@
$.map(entries, function (entry) { $.map(entries, function (entry) {
return that._handleFileTreeEntry(entry, path); return that._handleFileTreeEntry(entry, path);
}) })
).pipe(function () { ).then(function () {
return Array.prototype.concat.apply( return Array.prototype.concat.apply(
[], [],
arguments arguments
@@ -1159,7 +1213,7 @@
return $.when.apply( return $.when.apply(
$, $,
$.map(fileInput, this._getSingleFileInputFiles) $.map(fileInput, this._getSingleFileInputFiles)
).pipe(function () { ).then(function () {
return Array.prototype.concat.apply( return Array.prototype.concat.apply(
[], [],
arguments arguments
@@ -1176,7 +1230,7 @@
this._getFileInputFiles(data.fileInput).always(function (files) { this._getFileInputFiles(data.fileInput).always(function (files) {
data.files = files; data.files = files;
if (that.options.replaceFileInput) { if (that.options.replaceFileInput) {
that._replaceFileInput(data.fileInput); that._replaceFileInput(data);
} }
if (that._trigger( if (that._trigger(
'change', 'change',
@@ -1229,24 +1283,21 @@
} }
}, },
_onDragOver: function (e) { _onDragOver: getDragHandler('dragover'),
e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer;
var dataTransfer = e.dataTransfer; _onDragEnter: getDragHandler('dragenter'),
if (dataTransfer && $.inArray('Files', dataTransfer.types) !== -1 &&
this._trigger( _onDragLeave: getDragHandler('dragleave'),
'dragover',
$.Event('dragover', {delegatedEvent: e})
) !== false) {
e.preventDefault();
dataTransfer.dropEffect = 'copy';
}
},
_initEventHandlers: function () { _initEventHandlers: function () {
if (this._isXHRUpload(this.options)) { if (this._isXHRUpload(this.options)) {
this._on(this.options.dropZone, { this._on(this.options.dropZone, {
dragover: this._onDragOver, dragover: this._onDragOver,
drop: this._onDrop drop: this._onDrop,
// event.preventDefault() on dragenter is required for IE10+:
dragenter: this._onDragEnter,
// dragleave is not required, but added for completeness:
dragleave: this._onDragLeave
}); });
this._on(this.options.pasteZone, { this._on(this.options.pasteZone, {
paste: this._onPaste paste: this._onPaste
@@ -1260,11 +1311,15 @@
}, },
_destroyEventHandlers: function () { _destroyEventHandlers: function () {
this._off(this.options.dropZone, 'dragover drop'); this._off(this.options.dropZone, 'dragenter dragleave dragover drop');
this._off(this.options.pasteZone, 'paste'); this._off(this.options.pasteZone, 'paste');
this._off(this.options.fileInput, 'change'); this._off(this.options.fileInput, 'change');
}, },
_destroy: function () {
this._destroyEventHandlers();
},
_setOption: function (key, value) { _setOption: function (key, value) {
var reinit = $.inArray(key, this._specialOptions) !== -1; var reinit = $.inArray(key, this._specialOptions) !== -1;
if (reinit) { if (reinit) {
@@ -1308,15 +1363,19 @@
_initDataAttributes: function () { _initDataAttributes: function () {
var that = this, var that = this,
options = this.options, options = this.options,
clone = $(this.element[0].cloneNode(false)); data = this.element.data();
// Initialize options set via HTML5 data-attributes: // Initialize options set via HTML5 data-attributes:
$.each( $.each(
clone.data(), this.element[0].attributes,
function (key, value) { function (index, attr) {
var dataAttributeName = 'data-' + var key = attr.name.toLowerCase(),
// Convert camelCase to hyphen-ated key: value;
key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); if (/^data-/.test(key)) {
if (clone.attr(dataAttributeName)) { // Convert hyphen-ated key to camelCase:
key = key.slice(5).replace(/-[a-z]/g, function (str) {
return str.charAt(1).toUpperCase();
});
value = data[key];
if (that._isRegExpOption(key, value)) { if (that._isRegExpOption(key, value)) {
value = that._getRegExp(value); value = that._getRegExp(value);
} }
@@ -1401,7 +1460,8 @@
return; return;
} }
data.files = files; data.files = files;
jqXHR = that._onSend(null, data).then( jqXHR = that._onSend(null, data);
jqXHR.then(
function (result, textStatus, jqXHR) { function (result, textStatus, jqXHR) {
dfd.resolve(result, textStatus, jqXHR); dfd.resolve(result, textStatus, jqXHR);
}, },

File diff suppressed because one or more lines are too long