|
|
@ -6,24 +6,24 @@ |
|
|
|
* @extends BI.Single |
|
|
|
* @extends BI.Single |
|
|
|
* @abstract |
|
|
|
* @abstract |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
(function (document) { |
|
|
|
((function (document) { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @description normalize input.files. create if not present, add item method if not present |
|
|
|
* @description normalize input.files. create if not present, add item method if not present |
|
|
|
* @param Object generated wrap object |
|
|
|
* @param Object generated wrap object |
|
|
|
* @return Object the wrap object itself |
|
|
|
* @return Object the wrap object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
var F = (function (item) { |
|
|
|
var F = ((function (item) { |
|
|
|
return function (input) { |
|
|
|
return function (input) { |
|
|
|
var files = input.files || [input]; |
|
|
|
var files = input.files || [input]; |
|
|
|
if (!files.item) { |
|
|
|
if (!files.item) { |
|
|
|
files.item = item; |
|
|
|
files.item = item; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return files; |
|
|
|
return files; |
|
|
|
}; |
|
|
|
}; |
|
|
|
})(function (i) { |
|
|
|
})(function (i) { |
|
|
|
return this[i]; |
|
|
|
return this[i]; |
|
|
|
}); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
var event = { |
|
|
|
var event = { |
|
|
|
|
|
|
|
|
|
|
@ -37,10 +37,12 @@ |
|
|
|
add: document.addEventListener ? |
|
|
|
add: document.addEventListener ? |
|
|
|
function (node, name, callback) { |
|
|
|
function (node, name, callback) { |
|
|
|
node.addEventListener(name, callback, false); |
|
|
|
node.addEventListener(name, callback, false); |
|
|
|
|
|
|
|
|
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} : |
|
|
|
} : |
|
|
|
function (node, name, callback) { |
|
|
|
function (node, name, callback) { |
|
|
|
node.attachEvent("on" + name, callback); |
|
|
|
node.attachEvent("on" + name, callback); |
|
|
|
|
|
|
|
|
|
|
|
return this; |
|
|
|
return this; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -54,10 +56,12 @@ |
|
|
|
del: document.removeEventListener ? |
|
|
|
del: document.removeEventListener ? |
|
|
|
function (node, name, callback) { |
|
|
|
function (node, name, callback) { |
|
|
|
node.removeEventListener(name, callback, false); |
|
|
|
node.removeEventListener(name, callback, false); |
|
|
|
|
|
|
|
|
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} : |
|
|
|
} : |
|
|
|
function (node, name, callback) { |
|
|
|
function (node, name, callback) { |
|
|
|
node.detachEvent("on" + name, callback); |
|
|
|
node.detachEvent("on" + name, callback); |
|
|
|
|
|
|
|
|
|
|
|
return this; |
|
|
|
return this; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -77,11 +81,16 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var sendFile = (function (toString) { |
|
|
|
var sendFile = (function (toString) { |
|
|
|
var multipart = function (boundary, name, file) { |
|
|
|
var split = "onabort.onerror.onloadstart.onprogress".split("."), |
|
|
|
|
|
|
|
length = split.length, |
|
|
|
|
|
|
|
CRLF = "\r\n", |
|
|
|
|
|
|
|
xhr = XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"), |
|
|
|
|
|
|
|
sendFile; |
|
|
|
|
|
|
|
function multipart(boundary, name, file) { |
|
|
|
return "--".concat( |
|
|
|
return "--".concat( |
|
|
|
boundary, CRLF, |
|
|
|
boundary, CRLF, |
|
|
|
"Content-Disposition: form-data; name=\"", name, "\"; filename=\"", _global.encodeURIComponent(file.fileName), "\"", CRLF, |
|
|
|
"Content-Disposition: form-data; name=\"", name, "\"; filename=\"", _global.encodeURIComponent(file.fileName), "\"", CRLF, |
|
|
@ -90,15 +99,11 @@ |
|
|
|
file.getAsBinary(), CRLF, |
|
|
|
file.getAsBinary(), CRLF, |
|
|
|
"--", boundary, "--", CRLF |
|
|
|
"--", boundary, "--", CRLF |
|
|
|
); |
|
|
|
); |
|
|
|
}, |
|
|
|
} |
|
|
|
isFunction = function (Function) { |
|
|
|
function isFunction (Function) { |
|
|
|
return toString.call(Function) === "[object Function]"; |
|
|
|
return toString.call(Function) === "[object Function]"; |
|
|
|
}, |
|
|
|
} |
|
|
|
split = "onabort.onerror.onloadstart.onprogress".split("."), |
|
|
|
|
|
|
|
length = split.length, |
|
|
|
|
|
|
|
CRLF = "\r\n", |
|
|
|
|
|
|
|
xhr = XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"), |
|
|
|
|
|
|
|
sendFile; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FireFox 3+, Safari 4 beta (Chrome 2 beta file is buggy and will not work)
|
|
|
|
// FireFox 3+, Safari 4 beta (Chrome 2 beta file is buggy and will not work)
|
|
|
|
if (xhr.upload || xhr.sendAsBinary) { |
|
|
|
if (xhr.upload || xhr.sendAsBinary) { |
|
|
@ -108,14 +113,15 @@ |
|
|
|
if (isFunction(handler.onerror)) { |
|
|
|
if (isFunction(handler.onerror)) { |
|
|
|
handler.onerror(); |
|
|
|
handler.onerror(); |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
for (var |
|
|
|
for (var |
|
|
|
xhr = new XMLHttpRequest, |
|
|
|
xhr = new XMLHttpRequest, |
|
|
|
upload = xhr.upload || { |
|
|
|
upload = xhr.upload || { |
|
|
|
addEventListener: function (event, callback) { |
|
|
|
addEventListener: function (event, callback) { |
|
|
|
this["on" + event] = callback; |
|
|
|
this["on" + event] = callback; |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
i = 0; |
|
|
|
i = 0; |
|
|
|
i < length; |
|
|
|
i < length; |
|
|
@ -129,7 +135,7 @@ |
|
|
|
handler[event](rpe, xhr); |
|
|
|
handler[event](rpe, xhr); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
})(split[i]), |
|
|
|
}(split[i])), |
|
|
|
false |
|
|
|
false |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
@ -174,49 +180,53 @@ |
|
|
|
}; |
|
|
|
}; |
|
|
|
xhr.onreadystatechange = function () { |
|
|
|
xhr.onreadystatechange = function () { |
|
|
|
switch (xhr.readyState) { |
|
|
|
switch (xhr.readyState) { |
|
|
|
case 2: |
|
|
|
case 2: |
|
|
|
case 3: |
|
|
|
case 3: |
|
|
|
if (rpe.total <= rpe.loaded) { |
|
|
|
if (rpe.total <= rpe.loaded) { |
|
|
|
rpe.loaded = rpe.total; |
|
|
|
rpe.loaded = rpe.total; |
|
|
|
} |
|
|
|
} |
|
|
|
upload.onprogress(rpe); |
|
|
|
upload.onprogress(rpe); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
case 4: |
|
|
|
clearInterval(rpe.interval); |
|
|
|
clearInterval(rpe.interval); |
|
|
|
rpe.interval = 0; |
|
|
|
rpe.interval = 0; |
|
|
|
rpe.loaded = rpe.total; |
|
|
|
rpe.loaded = rpe.total; |
|
|
|
upload.onprogress(rpe); |
|
|
|
upload.onprogress(rpe); |
|
|
|
if (199 < xhr.status && xhr.status < 400) { |
|
|
|
if (199 < xhr.status && xhr.status < 400) { |
|
|
|
upload["onload"]({}); |
|
|
|
upload.onload({}); |
|
|
|
var attachO = BI.jsonDecode(xhr.responseText); |
|
|
|
var attachO = BI.jsonDecode(xhr.responseText); |
|
|
|
attachO.filename = handler.file.fileName; |
|
|
|
attachO.filename = handler.file.fileName; |
|
|
|
if (handler.file.type.indexOf("image") != -1) { |
|
|
|
if (handler.file.type.indexOf("image") !== -1) { |
|
|
|
attachO.attach_type = "image"; |
|
|
|
attachO.attach_type = "image"; |
|
|
|
} |
|
|
|
} |
|
|
|
handler.attach_array[current] = attachO; |
|
|
|
handler.attach_array[current] = attachO; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
upload["onerror"]({}); |
|
|
|
upload.onerror({}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
upload.onloadstart(rpe); |
|
|
|
upload.onloadstart(rpe); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
xhr.onreadystatechange = function () { |
|
|
|
xhr.onreadystatechange = function () { |
|
|
|
switch (xhr.readyState) { |
|
|
|
switch (xhr.readyState) { |
|
|
|
case 4: |
|
|
|
case 4: |
|
|
|
var attachO = BI.jsonDecode(xhr.responseText); |
|
|
|
var attachO = BI.jsonDecode(xhr.responseText); |
|
|
|
if (handler.file.type.indexOf("image") != -1) { |
|
|
|
if (handler.file.type.indexOf("image") !== -1) { |
|
|
|
attachO.attach_type = "image"; |
|
|
|
attachO.attach_type = "image"; |
|
|
|
} |
|
|
|
} |
|
|
|
attachO.filename = handler.file.fileName; |
|
|
|
attachO.filename = handler.file.fileName; |
|
|
|
if (handler.maxLength == 1) { |
|
|
|
if (handler.maxLength === 1) { |
|
|
|
handler.attach_array[0] = attachO; |
|
|
|
handler.attach_array[0] = attachO; |
|
|
|
// handler.attach_array.push(attachO);
|
|
|
|
// handler.attach_array.push(attachO);
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
handler.attach_array[current] = attachO; |
|
|
|
handler.attach_array[current] = attachO; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
if (isFunction(upload.onloadstart)) { |
|
|
|
if (isFunction(upload.onloadstart)) { |
|
|
@ -235,11 +245,11 @@ |
|
|
|
form.append("FileData", handler.file); |
|
|
|
form.append("FileData", handler.file); |
|
|
|
xhr.send(form); |
|
|
|
xhr.send(form); |
|
|
|
} |
|
|
|
} |
|
|
|
return handler; |
|
|
|
|
|
|
|
|
|
|
|
return handler; |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} else { |
|
|
|
// Internet Explorer, Opera, others
|
|
|
|
// Internet Explorer, Opera, others
|
|
|
|
else { |
|
|
|
|
|
|
|
sendFile = function (handler, maxSize, width, height) { |
|
|
|
sendFile = function (handler, maxSize, width, height) { |
|
|
|
var current = handler.current; |
|
|
|
var current = handler.current; |
|
|
|
var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"), |
|
|
|
var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"), |
|
|
@ -251,9 +261,10 @@ |
|
|
|
if (isFunction(handler.onprogress)) { |
|
|
|
if (isFunction(handler.onprogress)) { |
|
|
|
handler.onprogress(rpe, {}); |
|
|
|
handler.onprogress(rpe, {}); |
|
|
|
} |
|
|
|
} |
|
|
|
}, 100) |
|
|
|
}, 100), |
|
|
|
}, |
|
|
|
}, |
|
|
|
onload = function () { |
|
|
|
target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_"); |
|
|
|
|
|
|
|
function onload() { |
|
|
|
iframe.onreadystatechange = iframe.onload = iframe.onerror = null; |
|
|
|
iframe.onreadystatechange = iframe.onload = iframe.onerror = null; |
|
|
|
form.parentNode.removeChild(form); |
|
|
|
form.parentNode.removeChild(form); |
|
|
|
form = null; |
|
|
|
form = null; |
|
|
@ -262,7 +273,7 @@ |
|
|
|
try { |
|
|
|
try { |
|
|
|
var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML; |
|
|
|
var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML; |
|
|
|
var attachO = BI.jsonDecode(responseText); |
|
|
|
var attachO = BI.jsonDecode(responseText); |
|
|
|
if (handler.file.type.indexOf("image") != -1) { |
|
|
|
if (handler.file.type.indexOf("image") !== -1) { |
|
|
|
attachO.attach_type = "image"; |
|
|
|
attachO.attach_type = "image"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -273,7 +284,7 @@ |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
attachO.filename = handler.file.fileName; |
|
|
|
attachO.filename = handler.file.fileName; |
|
|
|
} |
|
|
|
} |
|
|
|
if (handler.maxLength == 1) { |
|
|
|
if (handler.maxLength === 1) { |
|
|
|
handler.attach_array[0] = attachO; |
|
|
|
handler.attach_array[0] = attachO; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
handler.attach_array[current] = attachO; |
|
|
|
handler.attach_array[current] = attachO; |
|
|
@ -286,8 +297,8 @@ |
|
|
|
if (isFunction(handler.onload)) { |
|
|
|
if (isFunction(handler.onload)) { |
|
|
|
handler.onload(rpe, { responseText: responseText }); |
|
|
|
handler.onload(rpe, { responseText: responseText }); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_"); |
|
|
|
|
|
|
|
try { // IE < 8 does not accept enctype attribute ...
|
|
|
|
try { // IE < 8 does not accept enctype attribute ...
|
|
|
|
var form = document.createElement("<form enctype=\"multipart/form-data\"></form>"), |
|
|
|
var form = document.createElement("<form enctype=\"multipart/form-data\"></form>"), |
|
|
|
iframe = handler.iframe || (handler.iframe = document.createElement("<iframe id=\"" + target + "\" name=\"" + target + "\" src=\"" + url + "\"></iframe>")); |
|
|
|
iframe = handler.iframe || (handler.iframe = document.createElement("<iframe id=\"" + target + "\" name=\"" + target + "\" src=\"" + url + "\"></iframe>")); |
|
|
@ -320,8 +331,8 @@ |
|
|
|
loading: 2, |
|
|
|
loading: 2, |
|
|
|
interactive: 3, |
|
|
|
interactive: 3, |
|
|
|
loaded: 4, |
|
|
|
loaded: 4, |
|
|
|
complete: 4 |
|
|
|
complete: 4, |
|
|
|
}[iframe.readyState] || 1 |
|
|
|
}[iframe.readyState] || 1, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
@ -342,13 +353,12 @@ |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
xhr = null; |
|
|
|
xhr = null; |
|
|
|
return sendFile; |
|
|
|
|
|
|
|
})(Object.prototype.toString); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sendFiles = function (handler, maxSize, width, height) { |
|
|
|
return sendFile; |
|
|
|
|
|
|
|
}(Object.prototype.toString)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sendFiles(handler, maxSize, width, height) { |
|
|
|
var length = handler.files.length, |
|
|
|
var length = handler.files.length, |
|
|
|
i = 0, |
|
|
|
|
|
|
|
onload = handler.onload, |
|
|
|
onload = handler.onload, |
|
|
|
onloadstart = handler.onloadstart; |
|
|
|
onloadstart = handler.onloadstart; |
|
|
|
handler.current = 0; |
|
|
|
handler.current = 0; |
|
|
@ -401,11 +411,12 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return handler; |
|
|
|
return handler; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var r1 = /\.([^.]+)$/; // .png
|
|
|
|
var r1 = /\.([^.]+)$/; // .png
|
|
|
|
var r2 = /\/([^/]+)$/; // image/png
|
|
|
|
var r2 = /\/([^/]+)$/; // image/png
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 校验文件类型是否合法,同时兼容旧版形式 |
|
|
|
* 校验文件类型是否合法,同时兼容旧版形式 |
|
|
@ -413,7 +424,7 @@ |
|
|
|
* @param fileType |
|
|
|
* @param fileType |
|
|
|
* @returns {boolean} |
|
|
|
* @returns {boolean} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
var fileTypeValidate = function (fileName, fileType) { |
|
|
|
function fileTypeValidate(fileName, fileType) { |
|
|
|
if (!fileType) { |
|
|
|
if (!fileType) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -421,25 +432,29 @@ |
|
|
|
if (mimes[0] === fileType) { |
|
|
|
if (mimes[0] === fileType) { |
|
|
|
mimes = (fileType + "").split(";"); |
|
|
|
mimes = (fileType + "").split(";"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return BI.some(mimes, function (index, mime) { |
|
|
|
return BI.some(mimes, function (index, mime) { |
|
|
|
var matches; |
|
|
|
var matches; |
|
|
|
if (matches = mime.match(r1)) { |
|
|
|
matches = mime.match(r1); |
|
|
|
|
|
|
|
if (matches) { |
|
|
|
return fileName.toLowerCase().indexOf(matches[1]) > -1; |
|
|
|
return fileName.toLowerCase().indexOf(matches[1]) > -1; |
|
|
|
} |
|
|
|
} |
|
|
|
if (matches = mime.match(r2)) { |
|
|
|
matches = mime.match(r2); |
|
|
|
|
|
|
|
if (matches) { |
|
|
|
return matches[1] === "*" ? true : fileName.toLowerCase().indexOf(matches[1]) > -1; |
|
|
|
return matches[1] === "*" ? true : fileName.toLowerCase().indexOf(matches[1]) > -1; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BI.File = BI.inherit(BI.Widget, { |
|
|
|
BI.File = BI.inherit(BI.Widget, { |
|
|
|
_defaultConfig: function () { |
|
|
|
_defaultConfig: function () { |
|
|
|
var conf = BI.File.superclass._defaultConfig.apply(this, arguments); |
|
|
|
var conf = BI.File.superclass._defaultConfig.apply(this, arguments); |
|
|
|
|
|
|
|
|
|
|
|
return BI.extend(conf, { |
|
|
|
return BI.extend(conf, { |
|
|
|
baseCls: (conf.baseCls || "") + " bi-file display-block", |
|
|
|
baseCls: (conf.baseCls || "") + " bi-file display-block", |
|
|
|
tagName: "input", |
|
|
|
tagName: "input", |
|
|
|
attributes: { |
|
|
|
attributes: { |
|
|
|
type: "file" |
|
|
|
type: "file", |
|
|
|
}, |
|
|
|
}, |
|
|
|
name: "", |
|
|
|
name: "", |
|
|
|
url: "", |
|
|
|
url: "", |
|
|
@ -452,7 +467,7 @@ |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
render: function () { |
|
|
|
render: function () { |
|
|
|
var self = this, o = this.options; |
|
|
|
var o = this.options; |
|
|
|
if (o.multiple === true) { |
|
|
|
if (o.multiple === true) { |
|
|
|
this.element.attr("multiple", "multiple"); |
|
|
|
this.element.attr("multiple", "multiple"); |
|
|
|
} |
|
|
|
} |
|
|
@ -498,7 +513,7 @@ |
|
|
|
file: this.file, |
|
|
|
file: this.file, |
|
|
|
total: rpe.total, |
|
|
|
total: rpe.total, |
|
|
|
loaded: rpe.loaded, |
|
|
|
loaded: rpe.loaded, |
|
|
|
simulation: rpe.simulation |
|
|
|
simulation: rpe.simulation, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -522,19 +537,21 @@ |
|
|
|
if (200 > xhr.status || xhr.status > 399) { |
|
|
|
if (200 > xhr.status || xhr.status > 399) { |
|
|
|
BI.Msg.toast(BI.i18nText("BI-Upload_File_Error"), { level: "error" }); |
|
|
|
BI.Msg.toast(BI.i18nText("BI-Upload_File_Error"), { level: "error" }); |
|
|
|
self.fireEvent(BI.File.EVENT_ERROR); |
|
|
|
self.fireEvent(BI.File.EVENT_ERROR); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var error = BI.some(_wrap.attach_array, function (index, attach) { |
|
|
|
var error = BI.some(_wrap.attach_array, function (index, attach) { |
|
|
|
if (attach.errorCode) { |
|
|
|
if (attach.errorCode) { |
|
|
|
BI.Msg.toast(BI.i18nText(attach.errorMsg), { level: "error" }); |
|
|
|
BI.Msg.toast(BI.i18nText(attach.errorMsg), { level: "error" }); |
|
|
|
self.fireEvent(BI.File.EVENT_ERROR, attach); |
|
|
|
self.fireEvent(BI.File.EVENT_ERROR, attach); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
!error && self.fireEvent(BI.File.EVENT_UPLOADED); |
|
|
|
!error && self.fireEvent(BI.File.EVENT_UPLOADED); |
|
|
|
}; |
|
|
|
}; |
|
|
|
_wrap.url = o.url; |
|
|
|
_wrap.url = o.url; |
|
|
|
_wrap.fileType = o.accept; // 文件类型限制
|
|
|
|
_wrap.fileType = o.accept; // 文件类型限制
|
|
|
|
_wrap.attach_array = []; |
|
|
|
_wrap.attach_array = []; |
|
|
|
_wrap.attach_names = []; |
|
|
|
_wrap.attach_names = []; |
|
|
|
_wrap.attachNum = 0; |
|
|
|
_wrap.attachNum = 0; |
|
|
@ -548,35 +565,34 @@ |
|
|
|
var files = F(wrap.dom.input); |
|
|
|
var files = F(wrap.dom.input); |
|
|
|
if (o.maxLength !== -1 && o.maxLength < files.length) { |
|
|
|
if (o.maxLength !== -1 && o.maxLength < files.length) { |
|
|
|
self.fireEvent(BI.File.EVENT_ERROR, { |
|
|
|
self.fireEvent(BI.File.EVENT_ERROR, { |
|
|
|
errorType: 2 |
|
|
|
errorType: 2, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
for (var i = 0; i < files.length; i++) { |
|
|
|
for (var i = 0; i < files.length; i++) { |
|
|
|
var item = files.item(i); |
|
|
|
var item = files.item(i); |
|
|
|
var tempFile = item.value || item.name; |
|
|
|
var tempFile = item.value || item.name; |
|
|
|
var value = item.fileName || (item.fileName = tempFile.split("\\").pop()), |
|
|
|
var value = item.fileName || (item.fileName = tempFile.split("\\").pop()), |
|
|
|
ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown", |
|
|
|
|
|
|
|
size = item.fileSize || item.size; |
|
|
|
size = item.fileSize || item.size; |
|
|
|
var validateFileType = fileTypeValidate(value, wrap.fileType); |
|
|
|
var validateFileType = fileTypeValidate(value, wrap.fileType); |
|
|
|
if (!validateFileType) { |
|
|
|
if (!validateFileType) { |
|
|
|
// 文件类型不支持
|
|
|
|
// 文件类型不支持
|
|
|
|
BI.Msg.toast(o.errorText({ |
|
|
|
BI.Msg.toast(o.errorText({ |
|
|
|
errorType: 0, |
|
|
|
errorType: 0, |
|
|
|
file: item |
|
|
|
file: item, |
|
|
|
}) || BI.i18nText("BI-Upload_File_Type_Error", wrap.fileType), { level: "error" }); |
|
|
|
}) || BI.i18nText("BI-Upload_File_Type_Error", wrap.fileType), { level: "error" }); |
|
|
|
self.fireEvent(BI.File.EVENT_ERROR, { |
|
|
|
self.fireEvent(BI.File.EVENT_ERROR, { |
|
|
|
errorType: 0, |
|
|
|
errorType: 0, |
|
|
|
file: item |
|
|
|
file: item, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) { |
|
|
|
} else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) { |
|
|
|
// 文件大小不支持
|
|
|
|
// 文件大小不支持
|
|
|
|
BI.Msg.toast(o.errorText({ |
|
|
|
BI.Msg.toast(o.errorText({ |
|
|
|
errorType: 1, |
|
|
|
errorType: 1, |
|
|
|
file: item |
|
|
|
file: item, |
|
|
|
}) || BI.i18nText("BI-Upload_File_Size_Error", Math.ceil(wrap.maxSize / 1024 / 1024)), { level: "error" }); |
|
|
|
}) || BI.i18nText("BI-Upload_File_Size_Error", Math.ceil(wrap.maxSize / 1024 / 1024)), { level: "error" }); |
|
|
|
self.fireEvent(BI.File.EVENT_ERROR, { |
|
|
|
self.fireEvent(BI.File.EVENT_ERROR, { |
|
|
|
errorType: 1, |
|
|
|
errorType: 1, |
|
|
|
file: item |
|
|
|
file: item, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
wrap.files.unshift(item); |
|
|
|
wrap.files.unshift(item); |
|
|
@ -584,18 +600,19 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
wrap.files.length > 0 && self.fireEvent(BI.File.EVENT_CHANGE, { |
|
|
|
wrap.files.length > 0 && self.fireEvent(BI.File.EVENT_CHANGE, { |
|
|
|
files: wrap.files |
|
|
|
files: wrap.files, |
|
|
|
}); |
|
|
|
}); |
|
|
|
input.value = ""; |
|
|
|
input.value = ""; |
|
|
|
wrap.dom.input.parentNode.replaceChild(input, wrap.dom.input); |
|
|
|
wrap.dom.input.parentNode.replaceChild(input, wrap.dom.input); |
|
|
|
wrap.dom.input = input; |
|
|
|
wrap.dom.input = input; |
|
|
|
event.add(wrap.dom.input, "change", arguments.callee); |
|
|
|
event.add(wrap.dom.input, "change", arguments.callee); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return wrap; |
|
|
|
return wrap; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
_wrap: function () { |
|
|
|
_wrap: function () { |
|
|
|
var self = this, o = this.options; |
|
|
|
var o = this.options; |
|
|
|
// be sure input accept multiple files
|
|
|
|
// be sure input accept multiple files
|
|
|
|
var input = this.element[0]; |
|
|
|
var input = this.element[0]; |
|
|
|
if (o.multiple === true) { |
|
|
|
if (o.multiple === true) { |
|
|
@ -608,14 +625,14 @@ |
|
|
|
|
|
|
|
|
|
|
|
// DOM namespace
|
|
|
|
// DOM namespace
|
|
|
|
dom: { |
|
|
|
dom: { |
|
|
|
input: input, // input file
|
|
|
|
input: input, // input file
|
|
|
|
disabled: false // internal use, checks input file state
|
|
|
|
disabled: false, // internal use, checks input file state
|
|
|
|
}, |
|
|
|
}, |
|
|
|
name: input.name, // name to send for each file ($_FILES[{name}] in the server)
|
|
|
|
name: input.name, // name to send for each file ($_FILES[{name}] in the server)
|
|
|
|
// maxSize is the maximum amount of bytes for each file
|
|
|
|
// maxSize is the maximum amount of bytes for each file
|
|
|
|
maxSize: o.maxSize ? o.maxSize >> 0 : -1, |
|
|
|
maxSize: o.maxSize ? o.maxSize >> 0 : -1, |
|
|
|
maxLength: o.maxLength, |
|
|
|
maxLength: o.maxLength, |
|
|
|
files: [], // file list
|
|
|
|
files: [], // file list
|
|
|
|
|
|
|
|
|
|
|
|
// remove every file from the noswfupload component
|
|
|
|
// remove every file from the noswfupload component
|
|
|
|
clean: function () { |
|
|
|
clean: function () { |
|
|
@ -632,6 +649,7 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
sendFiles(this, this.maxSize); |
|
|
|
sendFiles(this, this.maxSize); |
|
|
|
|
|
|
|
|
|
|
|
return this; |
|
|
|
return this; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -651,7 +669,7 @@ |
|
|
|
this.dom.disabled = true; |
|
|
|
this.dom.disabled = true; |
|
|
|
this.dom.input.setAttribute("disabled", "disabled"); |
|
|
|
this.dom.input.setAttribute("disabled", "disabled"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -710,7 +728,7 @@ |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.element.attr("disabled", "disabled"); |
|
|
|
this.element.attr("disabled", "disabled"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
BI.File.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
BI.File.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
BI.File.EVENT_UPLOADSTART = "EVENT_UPLOADSTART"; |
|
|
|
BI.File.EVENT_UPLOADSTART = "EVENT_UPLOADSTART"; |
|
|
@ -718,4 +736,4 @@ |
|
|
|
BI.File.EVENT_PROGRESS = "EVENT_PROGRESS"; |
|
|
|
BI.File.EVENT_PROGRESS = "EVENT_PROGRESS"; |
|
|
|
BI.File.EVENT_UPLOADED = "EVENT_UPLOADED"; |
|
|
|
BI.File.EVENT_UPLOADED = "EVENT_UPLOADED"; |
|
|
|
BI.shortcut("bi.file", BI.File); |
|
|
|
BI.shortcut("bi.file", BI.File); |
|
|
|
})(_global.document || {}); |
|
|
|
})(_global.document || {})); |
|
|
|