File: /www/wwwroot/bs.kntsleep.com/system/web/common/js/member/config.js
$(document).ready(function(){
$('input[type="file"][name="avatar"]').change(function(e){
var files = e.target.files;
if(files.length>0){
var reader = new FileReader();
reader.onload = function(){
$('input[type="file"][name="avatar"]').parent('ins').parent('div').find('img').attr('src',this.result);
}
reader.readAsDataURL(files[0]);
}
});
sc = '<a><i>+</i><b>上传文件</b><u>可拖动文件至此处</u></a>',
pl = function(src){
return String(src).replace(/(\.\.\/)+upload\//g,'\.\.\/\/upload\/');
}
$('input[type="file"]:not([name="avatar"])').each(function(){
h = '<div upfile="file"><ul>';
if(vl = $(this).attr('value')){
vl = vl.replace(/\"|\'/,'');
if(vl.match(/\.(jpg|jpeg|gif|png|webp|ico)(\?|$)/)){
h += '<li><ins>+</ins><img src="'+vl+'" /></li>';
}else{
if(type = vl.match(/member\/\d+\/(\w+)\//) || vl.match(/upload\/(\w+)\//)){
type = type[1];
}else{
type = 'file';
}
h += '<li><ins>+</ins><span class="'+type+'"></span></li>';
}
}else{
h += '<li>'+sc+'<input type="file" accept="'+$(this).attr('accept')+'"></li>';
}
h += '</ul><textarea '+($(this)[0].hasAttribute('required')?'required="required"':'')+' name="'+$(this).attr('name')+'" accept="'+$(this).attr('accept')+'" file>'+pl(vl?vl:'')+'</textarea></div>';
$(this).before(h);
$(this).remove();
});
$(document)
.on('change','div[upfile]>ul>li>input[type="file"]',function(e){
var files = e.target.files,
the = $(this);
upfile = the.parents('div[upfile]');
for(f in files){
if(typeof(files[f])=='object'){
formData = new FormData();
formData.append("upfile", files[f]);
$.ajax({
url: $G['relative']+"system/extend/ueditor/php/controller.php?web=true&action=uploadfile&referer="+encodeURIComponent(window.location.href),
type: 'POST',
cache: false,
data: formData,
processData: false,
contentType: false,
dataType: "json",
success: function(data) {
if(data.state == 'SUCCESS'){
if(data.url.match(/\.(jpg|jpeg|gif|png|webp|ico)(\?|$)/)){
upfile.find('ul').html('<li><ins>+</ins><img src="'+data.url+'" /></li>');
}else{
if(type = data.url.match(/member\/\d+\/(\w+)\//) || data.url.match(/upload\/(\w+)\//)){
type = type[1];
}else{
type = 'file';
}
upfile.find('ul').html('<li><ins>+</ins><span class="'+type+'"></span></li>');
}
upfile.find('textarea').html(pl(data.url));
}else{
_alert(data.state);
}
}
});
}
}
})
.on('click','div[upfile]>ul>li>ins',function(){
upfile = $(this).parents('div[upfile]');
accept = upfile.find('textarea').html('').attr('accept');
upfile.find('ul').html('<li>'+sc+'<input type="file" accept="'+accept+'"></li>');
});
});