|
@@ -979,6 +979,7 @@ var _Dever_Upload =
|
|
var id = e.attr('id');
|
|
var id = e.attr('id');
|
|
var value = e.attr('dever-upload-value');
|
|
var value = e.attr('dever-upload-value');
|
|
var key = e.attr('dever-upload-key');
|
|
var key = e.attr('dever-upload-key');
|
|
|
|
+ var pic = e.attr('dever-upload-pic');
|
|
var type = e.attr('dever-upload-type');
|
|
var type = e.attr('dever-upload-type');
|
|
var callback = e.attr('dever-upload-callback');
|
|
var callback = e.attr('dever-upload-callback');
|
|
var input = $("#" + value);
|
|
var input = $("#" + value);
|
|
@@ -1013,13 +1014,14 @@ var _Dever_Upload =
|
|
,field: 'file'
|
|
,field: 'file'
|
|
,url: url
|
|
,url: url
|
|
,multiple: true
|
|
,multiple: true
|
|
|
|
+ ,xhr:xhrOnProgress
|
|
,before: function(obj) {
|
|
,before: function(obj) {
|
|
layer.load();
|
|
layer.load();
|
|
}
|
|
}
|
|
,done: function(data) {
|
|
,done: function(data) {
|
|
layer.closeAll('loading');
|
|
layer.closeAll('loading');
|
|
if (data.status == 1) {
|
|
if (data.status == 1) {
|
|
- self.Set(type, e, input, value, callback, data.url);
|
|
|
|
|
|
+ self.Set(type, e, input, value, callback, data.url, pic);
|
|
} else {
|
|
} else {
|
|
layer.msg(data.msg, {icon: 4});
|
|
layer.msg(data.msg, {icon: 4});
|
|
return false;
|
|
return false;
|
|
@@ -1034,22 +1036,27 @@ var _Dever_Upload =
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- ,Set : function(type, e, input, value, callback, url)
|
|
|
|
|
|
+ ,Set : function(type, e, input, value, callback, url, pic)
|
|
{
|
|
{
|
|
if (type == 'mul') {
|
|
if (type == 'mul') {
|
|
this.SetMul(e, input, value, callback, url);
|
|
this.SetMul(e, input, value, callback, url);
|
|
} else {
|
|
} else {
|
|
- this.SetOne(e, input, value, callback, url);
|
|
|
|
|
|
+ this.SetOne(e, input, value, callback, url, pic);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- ,SetOne : function(e, input, value, callback, url)
|
|
|
|
|
|
+ ,SetOne : function(e, input, value, callback, url, pic)
|
|
{
|
|
{
|
|
var html = '';
|
|
var html = '';
|
|
if (this.callback && this.callback[callback]) {
|
|
if (this.callback && this.callback[callback]) {
|
|
html = this.callback[callback].call(this, e, url, 'dever-upload-close');
|
|
html = this.callback[callback].call(this, e, url, 'dever-upload-close');
|
|
} else {
|
|
} else {
|
|
- html = '<img src="'+url+'" class="pics">';
|
|
|
|
|
|
+ pic = $("#" + pic);
|
|
|
|
+ if (pic.length) {
|
|
|
|
+ pic.attr('src', url).show();
|
|
|
|
+ } else {
|
|
|
|
+ html = '<img src="'+url+'" class="dever-upload-pic">';
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if (html) {
|
|
if (html) {
|
|
@@ -1073,7 +1080,7 @@ var _Dever_Upload =
|
|
if (this.callback && this.callback[callback]) {
|
|
if (this.callback && this.callback[callback]) {
|
|
html += this.callback[callback].call(this, e, url, 'dever-upload-close');
|
|
html += this.callback[callback].call(this, e, url, 'dever-upload-close');
|
|
} else {
|
|
} else {
|
|
- html += '<li><img src="'+url+'" class="pics"><em class="dever-upload-close"></em></li>';
|
|
|
|
|
|
+ html += '<li><img src="'+url+'" class="dever-upload-pics"><em class="dever-upload-close"></em></li>';
|
|
}
|
|
}
|
|
|
|
|
|
if (html) {
|
|
if (html) {
|
|
@@ -1109,4 +1116,21 @@ var _Dever_Upload =
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//创建监听函数
|
|
|
|
+var xhrOnProgress=function(fun) {
|
|
|
|
+ xhrOnProgress.onprogress = fun; //绑定监听
|
|
|
|
+ //使用闭包实现监听绑
|
|
|
|
+ return function() {
|
|
|
|
+ //通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
|
|
|
|
+ var xhr = $.ajaxSettings.xhr();
|
|
|
|
+ //判断监听函数是否为函数
|
|
|
|
+ if (typeof xhrOnProgress.onprogress !== 'function') return xhr;
|
|
|
|
+ //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
|
|
|
|
+ if (xhrOnProgress.onprogress && xhr.upload) {
|
|
|
|
+ xhr.upload.onprogress = xhrOnProgress.onprogress;
|
|
|
|
+ }
|
|
|
|
+ return xhr;
|
|
|
|
+ }
|
|
}
|
|
}
|