jQuery.fn.fileUploadUIX = function(method) {
'use strict';
// under windows, if wps is installed, word file will be taken as application/kswps or application/kset for excel
var docTypes = /^application\/(msword|excel|x-excel|x-msexcel|vnd\.ms-excel|vnd\.openxmlformats-officedocument\.wordprocessingml\.document|vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet|pdf|x-mht|kswps|kset)|vnd.oasis.opendocument.text|vnd.oasis.opendocument.spreadsheet|text\/richtext|text\/plain|text\/html|multipart\/related|message\/rfc822/i;
var imageTypes = /^image\/(gif|bmp|jpeg|png|svg+xml)$/i;
var docImageTypes = /^application\/(msword|vnd\.ms-office|pdf|vnd\.openxmlformats-officedocument\.wordprocessingml\.document|vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet|vnd\.oasis\.opendocument\.text|vnd\.oasis\.opendocument\.spreadsheet|kswps|kset)|image\/(jpeg|png)/i;
var officeTypes = /^application\/(msword|vnd\.ms-office|pdf|vnd\.openxmlformats-officedocument\.wordprocessingml\.document|vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet|vnd\.oasis\.opendocument\.text|vnd\.oasis\.opendocument\.spreadsheet|kswps|kset)|image\/(jpeg)/i;
var compressTypes = /^application\/(zip|octet-stream)$/i;
//for IE only
var validImageFileExts = ["bmp","gif","png","jpg","jpeg"];
var validDocFileExts = ["docx","doc","pdf","odf","rtf","mht","txt","htm","html"];
var validDocImageFileExts = ["png","jpg","jpeg","docx","doc","pdf"];
var validOfficeFileExts = ["jpg","jpeg","docx","doc","pdf"];
var validCompressFileExts = ["zip"];
// map from type => ext
var mimeTypeExtMap = {
imageTypes: [imageTypes, validImageFileExts],
docTypes: [docTypes, validDocFileExts],
docImageTypes: [docImageTypes, validDocImageFileExts],
officeTypes: [officeTypes, validOfficeFileExts],
compressTypes: [compressTypes, validCompressFileExts]
};
// Emulate jQuery UI button (without states) if not available:
if (typeof jQuery().button !== 'function') {
jQuery.fn.button = function (options) {
return this.each(function () {
if (options === 'destroy') {
jQuery(this).removeClass(
'ui-button ui-widget ui-state-default ui-corner-all' +
' ui-button-icon-only ui-button-text-icon-primary'
).html(jQuery(this).text());
} else {
jQuery(this)
.addClass('ui-button ui-widget ui-state-default ui-corner-all')
.addClass(
options.text === false ? 'ui-button-icon-only' :
'ui-button-text-icon-primary'
)
.html(jQuery('<span class="ui-button-text"/>').text(jQuery(this).text()))
.prepend(
jQuery('<span class="ui-button-icon-primary ui-icon"/>')
.addClass(options.icons.primary)
);
}
});
};
}
var UploadHandler = function (container, options) {
var uploadHandler = this;
this.locale = {};
this.sequentialUploads = true;
this.maxFileSize = null;
this.minFileSize = 1;
this.maxNumberOfFiles = null;
this.acceptFileTypes = /.+$/i;
this.acceptFileExts = jQuery.merge(jQuery.merge([], validImageFileExts), validDocFileExts),
this.autoUpload = false;
this.url = container.find('form:first').attr('action');
this.dropZone = container.find('form:first');
this.uploadTable = container.find('.files:first');
this.progressAllNode = container.find('.file_upload_overall_progress div:first');
this.uploadTemplate = this.uploadTable.find('.file_upload_template:first');
this.multiButtons = container.find('.file_upload_buttons:first');
/* based on option, change allow type */
if(options.allowDocType) {
this.acceptFileTypes = docTypes;
this.acceptFileExts = validDocFileExts;
} else if(options.allowImageType) {
this.acceptFileTypes = imageTypes;
this.acceptFileExts = validImageFileExts;
} else if (options.allowDocImageType) {
this.acceptFileTypes = docImageTypes;
this.acceptFileExts = validDocImageFileExts;
} else if (options.allowOfficeTypes) {
this.acceptFileTypes = officeTypes;
this.acceptFileExts = validOfficeFileExts;
};
if(options.mixedFileTypes) {
var self = this;
this.acceptFileExts = [];
this.acceptFileTypes = [];
// allow mixed types is array
$.each(options.mixedFileTypes, function(i, t) {
var typeExt = mimeTypeExtMap[t];
self.acceptFileTypes[self.acceptFileTypes.length++] = typeExt.shift();
$.merge(self.acceptFileExts, typeExt.shift());
});
}
this.adjustMaxNumberOfFiles = function (operand) {
var number = container.fileUploadUIX('option', 'maxNumberOfFiles');
if (typeof number === 'number') {
container.fileUploadUIX('option', 'maxNumberOfFiles', number + operand);
}
};
this.formatFileSize = function (bytes) {
if (typeof bytes !== 'number' || bytes === null) {
return '';
}
if (bytes >= 1000000000) {
return (bytes / 1000000000).toFixed(2) + ' GB';
}
if (bytes >= 1000000) {
return (bytes / 1000000).toFixed(2) + ' MB';
}
return (bytes / 1000).toFixed(2) + ' KB';
};
this.formatFileName = function (name) {
return name.replace(/^.*[\/\\]/, '');
};
this.enableDragToDesktop = function () {
var link = jQuery(this),
url = link.get(0).href,
name = decodeURIComponent(url.split('/').pop()).replace(/:/g, '-'),
type = 'application/octet-stream';
link.bind('dragstart', function (event) {
try {
event.originalEvent.dataTransfer
.setData('DownloadURL', [type, name, url].join(':'));
} catch (e) {}
});
};
this.buildMultiUploadRow = function (files, handler) {
var rows = jQuery('<tbody style="display:none;"/>');
jQuery.each(files, function (index, file) {
var row = handler.buildUploadRow(files, index, handler).show(),
cells = row.find(
'.file_upload_progress, .file_upload_start, .file_upload_cancel'
);
if (index) {
cells.remove();
} else {
cells.attr('rowspan', files.length);
}
rows.append(row);
});
return rows;
};
this.buildUploadRow = function (files, index, handler) {
if (typeof index !== 'number') {
return handler.buildMultiUploadRow(files, handler);
}
var file = files[index],
fileName = handler.formatFileName(file.name),
uploadRow = handler.uploadTemplate
.clone().removeAttr('id');
uploadRow.find('.file_name')
.text(fileName);
uploadRow.find('.file_size')
.text(handler.formatFileSize(file.size));
uploadRow.find('.file_upload_start').addClass('active');
if (handler.autoUpload) {
uploadRow.find('.file_upload_start button').hide();
} else {
uploadRow.find('.file_upload_start button')
.button();
}
uploadRow.find('.file_upload_cancel button')
.button();
return uploadRow;
};
this.getFileUrl = function (file, handler) {
return file.url;
};
this.getThumbnailUrl = function (file, handler) {
return file.thumbnail;
};
this.onError = function (event, files, index, xhr, handler) {
handler.uploadRow.addClass('file_upload_error')
.find('.file_upload_progress').append(jQuery('<div class="error"/>').append(
handler.locale[event] || event
));
// for autoUpload case the uploadRow has already been removed. re-added again
if(handler.autoUpload) {
var p = handler.uploadRow.appendTo(handler.uploadTable).fadeIn();
p.find('.file_upload_cancel button').button()
.bind('click', function() { handler.removeNode(p, null);});
p.find('.file_upload_progress div:first').hide();
}
};
this.validate = function (event, files, index, xhr, handler) {
var isValid = true,
file;
if (typeof index !== 'number') {
jQuery.each(files, function (index, file) {
isValid = handler.validate(event, files, index, xhr, handler);
});
} else {
file = files[index];
if (handler.maxFileSize && file.size > handler.maxFileSize) {
handler.onError('文件太大。', files, index, xhr, handler);
return false;
} else if (typeof file.size === 'number' && file.size < handler.minFileSize) {
handler.onError('文件太小。', files, index, xhr, handler);
return false;
}
if (jQuery.browser.msie && jQuery.browser.version <= 9) {
var ext=file.name.substring(file.name.lastIndexOf(".")+1,file.name.length).toLowerCase();
if(jQuery.inArray(ext, handler.acceptFileExts) < 0) {
handler.onError('不正确的文件格式。', files, index, xhr, handler);
return false;
}
}
else if (file.type.length <= 0) {
var ext=file.name.substring(file.name.lastIndexOf(".")+1,file.name.length).toLowerCase();
if(jQuery.inArray(ext, handler.acceptFileExts) < 0) {
handler.onError('不正确的文件格式。', files, index, xhr, handler);
return false;
}
}
else {
if($.isArray(handler.acceptFileTypes)) {
var accepted = true;
$.each(handler.acceptFileTypes, function(i, r) {
if(r.test(file.type))
isValid = true;
return isValid;
});
if(!isValid){
handler.onError('不正确的文件格式。', files, index, xhr, handler);
return false;
}
} else if ( !handler.acceptFileTypes.test(file.type) ) {
handler.onError('不正确的文件格式。', files, index, xhr, handler);
return false;
}
}
if (typeof handler.maxNumberOfFiles === 'number' &&
handler.maxNumberOfFiles < index + 1) {
handler.onError('上传太多,已达上限。', files, index, xhr, handler);
return false;
}
}
return isValid;
};
this.uploadCallBack = function (event, files, index, xhr, handler, callBack) {
callBack();
};
this.beforeSend = function (event, files, index, xhr, handler, callBack) {
if (!handler.validate(event, files, index, xhr, handler)) {
handler.uploadRow.find(handler.cancelSelector).click(function (e) {
handler.uploadRow.fadeOut().remove();
});
return;
}
uploadHandler.multiButtons.show();
if(options.captcha) {
jQuery(options.captcha.form).find(".error").html('');
jQuery(options.captcha.form).find("#captcha_code").val('');
jQuery(options.captcha.form).fadeIn();
if(uploadHandler.captcha_checked == true) {
uploadHandler.captcha_checked = null;
jQuery(options.captcha.form).find("#reload").trigger("click");
}
}
if(options.beforeSendCallback && jQuery.isFunction(options.beforeSendCallback)) {
options.beforeSendCallback(this, handler, options);
}
var number = typeof index === 'number' ? 1 : files.length;
handler.adjustMaxNumberOfFiles(-number);
handler.uploadRow.find(handler.cancelSelector).click(function (e) {
handler.adjustMaxNumberOfFiles(number);
});
if (handler.autoUpload) {
handler.uploadCallBack(event, files, index, xhr, handler, callBack);
} else {
handler.uploadRow.find('.file_upload_start button').click(function (e) {
var uploadCB = function(button) {
jQuery(button).fadeOut().parent().removeClass("active");
handler.uploadCallBack(event, files, index, xhr, handler, callBack);
/* schedule another one. The reason of doing this to avoid multiple captcha check */
uploadHandler.uploadTable.find('.file_upload_start.active button').triggerHandler('click');
e.preventDefault();
};
/* validate captcha for every upload if it's enabled */
var button = this;
if(options.captcha && uploadHandler.captcha_checked == null) {
handler.validateCaptcha(files, index, xhr, handler, function() {
uploadCB(button);
});
}
else if(!options.captcha || uploadHandler.captcha_checked == true) {
uploadCB(button);
};
});
}
};
this.removeNode = function(node, callBack) {
if (node && node.length) {
var sentBefore = node.find(".file_upload_start.active").length <= 0;
node.find('.file_upload_start.active').removeClass("active");
// if node has no upload error and sentBefore (which active class has been removed from previous xhr check),
// don't remove the node(the case when server returns some errors, and we want to tell browser why it fails)
if(!node.hasClass("file_upload_error") && sentBefore) {
if (typeof callBack === "function") {
callBack();
}
}
else
node.fadeOut(function () {
node.remove();
if (typeof callBack === "function") {
try {
callBack();
} catch (e) {
node.stop();
throw e;
}
}
});
} else if (typeof callBack === "function") {
callBack();
}
};
this.deleteHandler = function (e) {
var row = jQuery(this).closest('tr');
jQuery.ajax({
url: getUrlQuery(uploadHandler.url, 'file=' + encodeURIComponent(
row.attr('data-id')
)),
type: 'DELETE',
success: function () {
uploadHandler.adjustMaxNumberOfFiles(1);
row.fadeOut(function () {
row.remove();
});
}
});
e.preventDefault();
};
this.multiButtonHandler = function (e) {
if(e.data.selector == '.file_upload_start.active') {
if(options.captcha) {
/* we need to revalidate for any click */
if(uploadHandler.captcha_checked == false) {
uploadHandler.captcha_checked = null;
}
}
uploadHandler.uploadTable.find(e.data.selector + ' button').triggerHandler('click');
}
else
uploadHandler.uploadTable.find(e.data.selector + ' button').trigger('click');
e.preventDefault();
};
this.initMultiButtons = function () {
if (uploadHandler.autoUpload) {
uploadHandler.multiButtons.find('.file_upload_start:first').hide();
} else {
uploadHandler.multiButtons.find('.file_upload_start:first')
.button()
.bind('click', {selector: '.file_upload_start.active'}, uploadHandler.multiButtonHandler);
}
uploadHandler.multiButtons.find('.file_upload_cancel:first')
.button()
.bind('click', {selector: '.file_upload_cancel'}, uploadHandler.multiButtonHandler);
};
this.destroyMultiButtons = function () {
uploadHandler.multiButtons.find(
'.file_upload_start:first, .file_upload_cancel:first'
).unbind('click', uploadHandler.multiButtonHandler).button('reset').show();
};
this.initExtended = function () {
uploadHandler.initMultiButtons();
};
this.destroyExtended = function () {
uploadHandler.destroyMultiButtons();
};
this.cancelUpload = function (event, files, index, xhr, handler) {
var readyState = xhr.readyState;
xhr.abort();
// If readyState is below 2, abort() has no effect:
if (typeof readyState !== 'number' || readyState < 2) {
handler.onAbort(event, files, index, xhr, handler);
}
/* check whether we need to disable buttons and captcha */
if(uploadHandler.uploadTable.find('.file_upload_start.active').length <= 0) {
this.completeAll();
}
};
this.validateCaptcha = function(files, index, xhr, handler, cb) {
if(options.captcha) {
jQuery(options.captcha.form).find(".error").html('');
var captcha_code = jQuery(options.captcha.form).find("#captcha_code").val();
jQuery.ajax({
type: 'POST',
dataType: 'json',
url: options.captcha.validate,
data: {'captcha_code': captcha_code},
success: function(data) {
try {
if(data.error) {
jQuery(options.captcha.form).find(".error").html(data.error);
uploadHandler.captcha_checked = false;
return;
}
/* set to be captcha checked */
uploadHandler.captcha_checked = true;
container.find('form:first').find('input[name="captcha_code"]').val(captcha_code);
cb.apply(handler);
}
catch(e) { }
}
});
}
else
cb.apply(handler);
};
options.onComplete = function (event, files, index, xhr, handler) {
var response = handler.parseResponse(xhr, handler);
if(response.error && response.error.length > 0) {
handler.onError(response.error, files, index, xhr, handler);
}
else {
handler.completeOne(event, files, index, xhr, handler);
handler.uploadRow.addClass('file_upload_error').addClass(options.keepList ? "keeprow" : "");
if(options.onSuccess && $.isFunction(options.onSuccess)) {
options.onSuccess(this, handler, options);
}
else
handler.uploadRow.find('.file_upload_progress').append(jQuery('<div class="success"/>').append("成功上传"));
}
};
this.completeOne = function(event, files, index, xhr, handler) {
handler.uploadRow.find('.file_upload_cancel').fadeOut();
};
this.completeAll = function(list) {
if(options.captcha) {
jQuery(options.captcha.form).find(".error").html('');
jQuery(options.captcha.form).fadeOut();
jQuery(options.captcha.form).find("#captcha_code").val('');
}
uploadHandler.multiButtons.fadeOut();
};
if(!options.onCompleteAll) {
options.onCompleteAll = function(list) {
this.completeAll(list);
};
}
jQuery.extend(this, options);
};
var methods = {
init : function (options) {
return this.each(function () {
jQuery(this).fileUploadUI(new UploadHandler(jQuery(this), options));
});
},
option: function (option, value, namespace) {
if (!option || (typeof option === 'string' && typeof value === 'undefined')) {
return jQuery(this).fileUpload('option', option, value, namespace);
}
return this.each(function () {
jQuery(this).fileUploadUI('option', option, value, namespace);
});
},
destroy : function (namespace) {
return this.each(function () {
jQuery(this).fileUploadUI('destroy', namespace);
});
},
upload: function (files, namespace) {
return this.each(function () {
jQuery(this).fileUploadUI('upload', files, namespace);
});
}
};
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 {
jQuery.error('Method "' + method + '" does not exist on jQuery.fileUploadUIX');
}
};
相关推荐
Umi-OCR-main.zip
基于springboot+Web的毕业设计选题系统源码数据库文档.zip
基于springboot校外兼职教师考勤管理系统源码数据库文档.zip
58商铺全新UI试客试用平台网站源码
基于springboot大学生就业信息管理系统源码数据库文档.zip
基于SpringBoot的口腔诊所系统源码数据库文档.zip
数据存放网盘,txt文件内包含下载链接及提取码,永久有效。失效会第一时间进行补充。样例数据及详细介绍参见文章:https://blog.csdn.net/T0620514/article/details/143956923
3-240P2162218.zip
网络安全 基于Qt创建的Linux系统下的浏览器.zip
C++ 类和对象:多态-练习题目2(制作咖啡和茶叶)
基于springboot+J2EE在线项目管理与任务分配中的应用源码数据库文档.zip
简介本项目提供了一个在51单片机上运行的简单操作系统,旨在帮助学习者深入理解操作系统的基本原理和任务调度机制。该操作系统通过汇编和C语言编写,实现了任务调度、中断处理等核心功能,并提供了详细的源代码和注释,方便学习和实践。
本文将深度卷积神经网络(CNN)设计实现一个复杂结构的生成模型,旨在通过多阶段的编码器-解码器结构,能够有效地将灰度图像转换为彩色图像。最后,本文将实现一个简单的Web应用,用户可以通过上传灰度图像,应用会使用预训练的Caffe模型对其进行颜色化,并将结果返回给用户。 1.模型设计:模型由多个卷积层、ReLU激活函数和批归一化层组成,通过前向传播函数将输入的灰度图像(L通道)转换为彩色图像(ab通道)。如果指定了 pretrained=True,则会自动下载并加载预训练的模型权重。 2. 系统通过Flask框架提供了一个Web应用,用户可以上传灰度图像,系统会自动将其转换为彩色图像,并在网页上显示结果。整个过程包括文件验证、图像处理、颜色化预测和结果展示,具有较高的实用性和用户体验。
一个JAVA图形化的、联网的五子棋游戏.zip javaweb
KWDB 是一款面向 【AIoT 场景】的【分布式多模数据库】,支持在同一实例同时建立时序库和关系库并融合处理多模数据,具备千万级设备接入、百万级数据秒级写入、亿级数据秒级读取等时序数据高效处理能力,具有稳定安全、高可用、易运维等特点。
页面数量:7页 网页主题:网站模板、酒店网站模板、官方网站模板 网页页面:首页、关于我们、相关服务、服务详情、在线博客、博客详情、在线留言 页面实现元素:加载动画、滚动加载、主题切换、导航栏 、轮播图、图文列表、图片切换、 文字列表、 按钮悬停、图片悬停、表单 实现技术:HTML、CSS 、JQuery 源码样式及js文件均分开存放,所有内容仅供初学者学习参考
内容概要:本文档提供了详细的 Neo4j 安装与配置指南,涵盖 Windows、Linux 和 Mac 系统的安装步骤。具体包括下载、安装、启动服务、修改配置文件(如端口配置、远程访问和内存限制)、设置管理员密码以及基本的 Cypher 查询语言使用方法。同时,还提供了一些常见问题及其解决方案。 适合人群:数据库管理员、软件开发人员、系统管理员。 使用场景及目标:①帮助初学者快速掌握 Neo4j 的安装与配置;②适用于需要搭建和使用图数据库的项目;③为已有用户解决常见问题。 其他说明:本文档不仅包含了基础的安装和配置流程,还提供了实际操作中可能遇到的问题及其解决方法,有助于提高使用者的实际操作能力。
基于SpringBoot+Vue的软件产品展示销售系统源码数据库文档.zip
《书戴嵩画牛》教学课件.pptx
20届智能车 【项目资源】:包含前端、后端、移动开发、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源,毕业设计等各种技术项目的源码。包括C++、Java、python、web、C#、EDA等项目的源码。 【适用人群】:适用于希望学习不同技术领域的初学者或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【附加价值】:项目具有较高的学习借鉴价值,也可直接拿来修改复刻。对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。 【沟通交流】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。鼓励下载和使用,并欢迎大家互相学习,共同进步。