qc.ifish7.com/Public/webuploader/kinderfile.js

101 lines
3.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var fileFun=function(){
//定义成员
this.listtype="img";//分别为img file video默认为img
this.file_checkbox=0;//默认为00为选择一个文件1可选择多个文件
this.callback;//回调函数(当选择好文件后触发的)
this.pubid;//关联信息的id
this.file_data;//选择文件后赋给的变量
this.input_id;//把变量填写到input里
this.win_width=window.screen.availWidth*0.8; //浏览器时下窗口可视区域高度
this.win_height=window.screen.availHeight*0.8; //浏览器时下窗口文档的高度
this.left=window.screen.availWidth*0.2/2;
this.top=window.screen.availHeight*0.2/2;
this.imgwidth=0;//上传图片前js自动压缩
this.imgheight=0;//上传图片前js自动压缩
//打开文件上传窗口
this.open_window=function(){
window.open('/index.php?m=Admin&c=File&a=index&listtype='+this.listtype+'&file_checkbox='+this.file_checkbox+'&pubid='+this.pubid+'&imgwidth='+this.imgwidth+'&imgheight='+this.imgheight,'','width='+this.win_width+',height='+this.win_height+',top='+this.top+',left='+this.left+',scrollbars=yes');
};
this.window_focus=function(){
window.onfocus = function(){
if(file.file_data){
file.callback(file.file_data,file.input_id);
file.file_data=null;
}
window.onfocus=null;//用完后一定要清空掉否则可能和其它js冲突
};
}
}
var file=new fileFun();
//单个文件选择
function selectfile(input_id,callback,listtype,imgwidth,imgheight){
if(listtype){
file.listtype=listtype;
}
file.input_id=input_id;
file.imgwidth=imgwidth;
file.imgheight=imgheight;
//关联信息的id
file.pubid=$("input[name='pubid']").val();
if(!file.pubid){
file.pubid=parent.$("input[name='pubid']").val();//这里主要用于编辑器里或特殊页面中需要加载框架的
}
file.file_checkbox=0;
//回调函数(如果有回调函数则调用给的回调函数,没有的话用默认的)
if(callback){
file.callback=callback;
}else{
file.callback=function(){
$("#"+input_id).val(file.file_data[1].file_path);
};
}
//打开上传窗口
file.open_window();
//聚焦窗口后调用回调函数
file.window_focus();
}
//多个文件选择
function selectfiles(input_id,callback,listtype,imgwidth,imgheight){
if(listtype){
file.listtype=listtype;
}
file.input_id=input_id;
file.imgwidth=imgwidth;
file.imgheight=imgheight;
//关联信息的id
file.pubid=$("input[name='pubid']").val();
if(!file.pubid){
file.pubid=parent.$("input[name='pubid']").val();//这里主要用于编辑器里或特殊页面中需要加载框架的
}
file.file_checkbox=1;
//回调函数(如果有回调函数则调用给的回调函数,没有的话用默认的)
if(callback){
file.callback=callback;
}else{
file.callback=function(){
var str="";
for(var i=0;i<file.file_data.length;i++){
var file_name=file.file_data[i]['file_name'];
var file_path=file.file_data[i]['file_path'];
str=str+"\r\n"+file_path;
}
$("#"+input_id).val(str);
};
}
//打开上传窗口
file.open_window();
//聚焦窗口后调用回调函数
file.window_focus();
}
//获取json长度
function getJsonLength(jsonData){
var jsonLength = 0;
for(var item in jsonData){
jsonLength++;
}
return jsonLength;
}