Skip to content

Commit

Permalink
更新框架
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Apr 18, 2013
1 parent 2813dda commit dc02597
Show file tree
Hide file tree
Showing 7 changed files with 2,036 additions and 2,119 deletions.
213 changes: 89 additions & 124 deletions ajax.js

Large diffs are not rendered by default.

59 changes: 27 additions & 32 deletions ajax_fix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

define(!!this.FormData, ["flow"], function($) {
var str = 'Function BinaryToArray(binary)\r\n\
var str = 'Function BinaryToArray(binary)\r\n\
Dim oDic\r\n\
Set oDic = CreateObject("scripting.dictionary")\r\n\
length = LenB(binary) - 1\r\n\
Expand All @@ -10,13 +10,13 @@ define(!!this.FormData, ["flow"], function($) {
BinaryToArray = oDic.Items\r\n\
End Function'
execScript(str, "VBScript");
$.ajaxConverters.arraybuffer = function() {
var body = this.tranport && this.tranport.responseBody
if (body) {
return new VBArray(BinaryToArray(body)).toArray();
}
};
$.fixAjax = function() {
$.ajaxConverters.arraybuffer = function() {
var body = this.tranport && this.tranport.responseBody
if (body) {
return new VBArray(BinaryToArray(body)).toArray();
}
};
function createIframe(ID) {
var iframe = $.parseHTML("<iframe " + " id='" + ID + "'" +
" name='" + ID + "'" + " style='position:absolute;left:-9999px;top:-9999px;/>").firstChild;
Expand All @@ -40,7 +40,8 @@ define(!!this.FormData, ["flow"], function($) {
}
return ret;
}
$.AjaxTransports.upload = {
//https://github.com/codenothing/Pure-Javascript-Upload/blob/master/src/upload.js
$.ajaxTransports.upload = {
request: function() {
var self = this;
var opts = this.options;
Expand All @@ -51,61 +52,55 @@ define(!!this.FormData, ["flow"], function($) {
//1:application/x-www-form-urlencoded 在发送前编码所有字符(默认)
//2:multipart/form-data 不对字符编码。在使用包含文件上传控件的表单时,必须使用该值。
//3:text/plain 空格转换为 "+" 加号,但不对特殊字符编码。
this.backups = {
var backups = {
target: form.target || "",
action: form.action || "",
enctype: form.enctype,
method: form.method
};
var fields = opts.data ? addDataToForm(form, opts.data) : [];
//必须指定method与enctype,要不在FF报错
//“表单包含了一个文件输入元素,但是其中缺少 method=POST 以及 enctype=multipart/form-data,所以文件将不会被发送。”
//表单包含文件域时,如果缺少 method=POST 以及 enctype=multipart/form-data,
// 设置target到隐藏iframe,避免整页刷新
form.target = ID;
form.action = opts.url;
form.method = "POST";
form.enctype = "multipart/form-data";
this.fields = opts.data ? addDataToForm(form, opts.data) : [];
this.form = form; //一个表单元素
$.log("iframe transport...");
this.uploadcallback = $.bind(iframe, "load", function(event) {
self.respond(event);
});
setTimeout(function() {
form.submit();
form.submit();
//还原form的属性
for (var i in backups) {
form[i] = backups[i];
}
//移除之前动态添加的节点
fields.forEach(function(input) {
form.removeChild(input);
});
},
respond: function(event, forceAbort) {
var node = this.transport;
respond: function(event) {
var node = this.transport, child
// 防止重复调用,成功后 abort
if (!node) {
return;
}
if (event && event.type === "load") {
var doc = node.contentWindow.document;
this.responseXML = doc;
if (doc.body) {
// response is html document or plain text
if (doc.body) {//如果存在body属性,说明不是返回XML
this.responseText = doc.body.innerHTML;
//当,MIME为"text/plain",浏览器会把文本放到一个PRE标签中
if (doc.body.firstChild && doc.body.firstChild.nodeName === 'PRE') {
this.responseText = doc.body.firstChild.firstChild.nodeValue;
//当MIME为'application/javascript' 'text/javascript",浏览器会把内容放到一个PRE标签中
if ((child = doc.body.firstChild) && child.nodeName.toUpperCase() === 'PRE' && child.firstChild) {
this.responseText = child.firstChild.nodeValue;
}
}
this.dispatch(200, "success");
}
//还原form的属性
var form = this.options.form;
for (var i in transport.backups) {
form[i] = transport.backups[i];
}
//移除之前动态添加的节点
transport.fields.forEach(function(input) {
form.removeChild(input);
});
this.uploadcallback = $.unbind(node, "load", this.uploadcallback);
delete this.uploadcallback;
setTimeout(function() {
// Fix busy state in FF3
setTimeout(function() { // Fix busy state in FF3
node.parentNode.removeChild(node);
$.log("iframe.parentNode.removeChild(iframe)");
});
Expand Down
3 changes: 2 additions & 1 deletion lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define("lang", Array.isArray ? ["mass"] : ["lang_fix"], function($) {
get: function() {
}
});
$.supportDefineProperty = true;
} catch (e) {
method = function(obj, name, method) {
if (!obj[name]) {
Expand Down Expand Up @@ -93,7 +94,7 @@ define("lang", Array.isArray ? ["mass"] : ["lang_fix"], function($) {
}
if (type === "Object") {
var i = obj.length;
return i >= 0 && parseInt(i) === i; //非负整数
return i >= 0 && i % 1 === 0; //非负整数
}
return false;
},
Expand Down
Loading

0 comments on commit dc02597

Please sign in to comment.