创建版本
This commit is contained in:
+592
@@ -0,0 +1,592 @@
|
||||
(function ($) {
|
||||
|
||||
function _getstyles(){
|
||||
var s='<style>.changeuserlist div.listsss{padding:10px; background:white;border-bottom:1px #eeeeee solid;cursor:default}.changeuserlist div:active{ background:#f1f1f1}.changeuserbotton{height:30px;width:50px; background:#3a3f51;color:white;font-size:14px;border:none;padding:0px;margin:0px;line-height:20px;cursor:default;opacity:1;outline:none;border-radius:3px}.changeuserbotton:active{color:white;border:none;opacity:0.8}</style>';
|
||||
return s;
|
||||
}
|
||||
|
||||
function chnageuser(sobj, options) {
|
||||
var obj = sobj;
|
||||
var rand = '' + parseInt(Math.random() * 9999999);
|
||||
var me = this;
|
||||
this.rand = rand;
|
||||
this.changesel = '';
|
||||
this.firstpid = 0;
|
||||
|
||||
this._init = function() {
|
||||
for (var i in options) this[i] = options[i];
|
||||
this.oveob = false;
|
||||
if (this.showview !='' && get(this.showview)) this.oveob = true;
|
||||
|
||||
if (!this.oveob) {
|
||||
window.onhashchange = function() {
|
||||
var has = location.hash;
|
||||
if (has.indexOf('#changeuser') == -1) me.hide();
|
||||
}
|
||||
js.location('#changeuser');
|
||||
}
|
||||
|
||||
this.userarr = [];
|
||||
this.deptarr = [];
|
||||
this.grouparr = [];
|
||||
if (isempt(this.changerange) && isempt(this.changerangeno)) {
|
||||
|
||||
var us = js.getoption('userjson');
|
||||
if (us) this.userarr = js.decode(us);
|
||||
|
||||
us = js.getoption('deptjson');
|
||||
if (us) this.deptarr = js.decode(us);
|
||||
us = js.getoption('groupjson');
|
||||
if (us) this.grouparr = js.decode(us);
|
||||
}
|
||||
this.show();
|
||||
};
|
||||
|
||||
this.creatediv = function() {
|
||||
var type='checkbox';
|
||||
if (this.changetype.indexOf('check') == -1) type='radio';
|
||||
this.inputtype = type;
|
||||
$('#changeuser_' + rand).remove();
|
||||
var hei = $(window).height(), jhei=50, atts='position:fixed;';
|
||||
if (this.oveob) {
|
||||
hei = $('#'+this.showview+'').height();
|
||||
atts='';
|
||||
}
|
||||
var s='<div style="' + atts + 'z-index:100;width:100%;height:100%;overflow:hidden;left:0px;top:0px; background:white" id="changeuser_'+rand+'">';
|
||||
if (this.titlebool) {
|
||||
s += '<div style="height:50px;line-height:50px;text-align:center; background:white;border-bottom:1px #cccccc solid"><b>'+this.title+'</b></div>';
|
||||
jhei += 50;
|
||||
}
|
||||
if (this.changetype.indexOf('user') >= 0) {
|
||||
s += '<div style="height:50px;overflow:hidden;border-bottom:1px #cccccc solid"><table width="100%"><tr><td width="100%" height="50"><input id="changekey_'+this.rand+'" placeholder="部门/姓名/职位" style="height:30px;border:none;background:none;width:100%;margin:0px 10px;outline:none"></td><td><button style="background:none;border:none;color:#666666" class="changeuserbotton" id="changesoubtn_'+this.rand+'" type="button" >查找</button></td></tr></table></div>';
|
||||
jhei += 50;
|
||||
}
|
||||
s += '<div style="-webkit-overflow-scrolling:touch;height:'+(hei-jhei)+'px;overflow:auto; background:#f1f1f1" class="changeuserlist">';
|
||||
s += '<span id="showdiv'+rand+'_0"></span>';
|
||||
s += '<span id="showdiv'+rand+'_search"></span>';
|
||||
s += '</div>';
|
||||
var s3= '<input id="changeboxs_'+rand+'" style="width:18px;height:18px;" align="absmiddle" type="checkbox" >';
|
||||
if (type != 'checkbox1') s3 = '';
|
||||
if (1==1) {
|
||||
s3='<select id="changesel_'+rand+'" style="height:30px;border:none;background:none;outline:none">';
|
||||
s3+='<option value="">默认显示</option>';
|
||||
if (this.changetype.indexOf('user') >= 0) s3+='<option value="1">仅限显示人员</option>';
|
||||
if (this.changetype.indexOf('dept') >= 0) s3+='<option value="2">仅限显示部门</option>';
|
||||
if (this.changetype.indexOf('user') >= 0) s3+='<option value="3">显示组</option>';
|
||||
s3 += '</select>';
|
||||
}
|
||||
s += '<div style="height:50px;line-height:50px;border-top:1px #cccccc solid" align="right"><table width="100%"><tr><td width="10" nowrap> </td><td width="80%">'+s3+'</td><td><button style="width:70px;border:none" type="button" id="changereload_'+rand+'" class="changeuserbotton" >刷新数据</button></td><td width="10" nowrap> </td><td><button class="changeuserbotton" type="button" id="changecancl_'+rand+'" >取消</button></td><td width="10" nowrap> </td><td height="50"><button style="background:#1890ff;" id="changeok_'+rand+'" type="button" class="changeuserbotton">确定</button></td><td width="10" nowrap> </td></tr></table></div>';
|
||||
s += _getstyles();
|
||||
s += '</div>';
|
||||
if (atts=='') {
|
||||
$('#'+this.showview+'').html(s);
|
||||
} else {
|
||||
obj.append(s);
|
||||
}
|
||||
|
||||
$('#changecancl_'+this.rand+'').click(function(){
|
||||
me._clickcancel();
|
||||
});
|
||||
$('#changereload_'+this.rand+'').click(function(){
|
||||
me._loaddata();
|
||||
});
|
||||
$('#changeok_'+this.rand+'').click(function(){
|
||||
me.queding();
|
||||
});
|
||||
$('#changesoubtn_'+this.rand+'').click(function(){
|
||||
me._searchkey(true);
|
||||
});
|
||||
$('#changekey_'+this.rand+'').keydown(function(e){
|
||||
me._searchkeys(e)
|
||||
});
|
||||
$('#changeboxs_'+this.rand+'').click(function(){
|
||||
me._changboxxuan(this)
|
||||
});
|
||||
$('#changesel_'+this.rand+'').change(function(){
|
||||
me._changesel(this)
|
||||
});
|
||||
};
|
||||
this.showlist=function(pid,oi){
|
||||
var type=this.inputtype,hw=24;
|
||||
var s='',ssu='',s1='';
|
||||
var sel = this.changesel;
|
||||
var dob = this.changetype.indexOf('dept')==-1;
|
||||
var uob = this.changetype.indexOf('user')>=0;
|
||||
this.fid = 1;
|
||||
|
||||
if(sel=='1'){
|
||||
ssu = this._showuser(0,'',type,sel);
|
||||
}else if(sel=='2'){
|
||||
s = this._showdept(pid,oi,s1,type,sel,dob,uob);
|
||||
}else if(sel=='3'){
|
||||
s = this._showgorup(type);
|
||||
}else{
|
||||
s1='<div style="width:'+(hw*oi)+'px"></div>';
|
||||
s = this._showdept(pid,oi,s1,type,sel,dob,uob);
|
||||
if(uob){
|
||||
ssu+=this._showuser(pid,s1,type,sel);
|
||||
}
|
||||
}
|
||||
var xud = (oi==0)?'0' : pid;
|
||||
$('#showdiv'+rand+'_'+xud+'').html(ssu+s).attr('show','true');
|
||||
if(sel==''){
|
||||
if(oi==0)this.showlist(this.fid, 1);
|
||||
$('#showdiv'+rand+'_0 [deptxu]').unbind('click').click(function(){
|
||||
me._deptclicks(this);
|
||||
});
|
||||
}
|
||||
if(sel=='3'){
|
||||
$('#showdiv'+rand+'_0 [groupxu]').unbind('click').click(function(){
|
||||
me._groupclicks(this);
|
||||
});
|
||||
}
|
||||
};
|
||||
this._showuser=function(pid,s1,type,sel){
|
||||
var a,len,i,ssu='',dids,zoi=0,ids;
|
||||
a=this.userarr;
|
||||
len=a.length;
|
||||
for(i=0;i<len;i++){
|
||||
dids = ','+a[i].deptids+',';
|
||||
if(
|
||||
((a[i].deptid==pid || dids.indexOf(','+pid+',')>-1 || sel=='1') && sel!='3')
|
||||
||
|
||||
(sel=='3' && (','+a[i].groupname+',').indexOf(','+pid+',')>-1)//显示组下人员
|
||||
){
|
||||
ssu+='<div class="listsss">';
|
||||
ssu+='<table width="100%"><tr><td>'+s1+'</td><td width="100%"><img align="absmiddle" height="24" height="24" src="'+a[i].face+'"> '+a[i].name+'<span style="font-size:12px;color:#888888">('+a[i].ranking+')</span></td><td><input name="changeuserinput_'+rand+'" xxu="'+i+'" xls="u" xname="'+a[i].name+'" value="'+a[i].id+'" style="/*width:18px;height:18px;*/" type="'+type+'"></td></tr></table>';
|
||||
ssu+='</div>';
|
||||
zoi++;
|
||||
if(zoi>=200)break;//最多显示200人,其他用搜索
|
||||
}
|
||||
}
|
||||
return ssu;
|
||||
};
|
||||
this._showdept=function(pid,oi,s1,type,sel,dob,uob){
|
||||
var a,len,i,wwj,s2='',s='';
|
||||
a=this.deptarr;
|
||||
len=a.length;
|
||||
for(i=0;i<len;i++){
|
||||
if(a[i].pid==pid || sel=='2'){
|
||||
this.fid = a[i].id;
|
||||
wjj= '/assets/chat/images/files.png';
|
||||
if(a[i].ntotal=='0' && uob)wjj= '/assets/chat/images/file.png';
|
||||
s2 = '<input name="changeuserinput_'+rand+'" xls="d" xname="'+a[i].name+'" xu="'+i+'" value="'+a[i].id+'" style="/*width:18px;height:18px;*/" type="'+type+'">';
|
||||
if(dob)s2='';
|
||||
if(s2!='' && !this._isdeptcheck(a[i]))s2='';
|
||||
s+='<div class="listsss">';
|
||||
s+='<table width="100%"><tr><td>'+s1+'</td><td deptxu="'+i+'_'+oi+'" width="100%"><img align="absmiddle" height="20" height="20" src="'+wjj+'"> '+a[i].name+'</td><td>'+s2+'</td></tr></table>';
|
||||
s+='</div>';
|
||||
s+='<span show="false" id="showdiv'+rand+'_'+a[i].id+'"></span>';
|
||||
}
|
||||
}
|
||||
return s;
|
||||
};
|
||||
this._showgorup=function(type){
|
||||
var a,len,i,ssu='',s1;
|
||||
a=this.grouparr;
|
||||
len=a.length;
|
||||
for(i=0;i<len;i++){
|
||||
s1 = '<input name="changeuserinput_'+rand+'" xls="g" xname="'+a[i].name+'" value="'+a[i].id+'" style="/*width:18px;height:18px;*/" type="'+type+'">';
|
||||
if(this.changetype.indexOf('deptuser')==-1)s1='';
|
||||
ssu+='<div class="listsss">';
|
||||
ssu+='<table width="100%"><tr><td></td><td groupxu="'+i+'" width="100%"><img align="absmiddle" height="24" height="24" src="/assets/chat/images/group.png"> '+a[i].name+' <span style="font-size:12px;color:#888888">('+a[i].usershu+'人)</span></td><td>'+s1+'</td></tr></table>';
|
||||
ssu+='</div>';
|
||||
ssu+='<span show="false" id="showgroup'+rand+'_'+a[i].id+'"></span>';
|
||||
}
|
||||
return ssu;
|
||||
};
|
||||
this._groupclicks = function(o) {
|
||||
if (this.changetype.indexOf('user')==-1)return;
|
||||
var sxu = $(o).attr('groupxu');
|
||||
var a = this.grouparr[sxu];
|
||||
var o1 = $('#showgroup'+rand+'_'+a.id+'');
|
||||
var lx = o1.attr('show');
|
||||
if (lx=='false') {
|
||||
var s1='<div style="width:24px"></div>';
|
||||
var s = this._showuser(a.id,s1,this.inputtype, this.changesel);
|
||||
o1.html(s).attr('show','true');
|
||||
} else {
|
||||
o1.toggle();
|
||||
}
|
||||
};
|
||||
this._changesel = function(o1) {
|
||||
var val = o1.value;
|
||||
this.changesel = val;
|
||||
this.showlist(this.firstpid, 0);
|
||||
};
|
||||
this._searchkeys=function(e){
|
||||
clearTimeout(this._searchkeystime);
|
||||
this._searchkeystime=setTimeout(function(){
|
||||
me._searchkey(false);
|
||||
},500);
|
||||
};
|
||||
this._isdeptcheck=function(a){
|
||||
if(this.inputtype=='checkbox' && this.changetype.indexOf('user')>=0 && this.changetype.indexOf('dept')>=0){
|
||||
var stotal,i,nstotal=0,len=this.userarr.length,spath;
|
||||
stotal = parseFloat(a.stotal);
|
||||
for(i=0;i<len;i++){
|
||||
spath = this.userarr[i].deptpath;
|
||||
if(spath.indexOf('['+a.id+']')>=0)nstotal++;
|
||||
}
|
||||
return nstotal>=stotal;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
},
|
||||
this._clickcheckbox=function(o1) {
|
||||
var o = $(o1),xu,a,stotal,i,nstotal=0,len=this.userarr.length,spath;
|
||||
if (o.attr('xls') != 'd') return;
|
||||
xu = parseFloat(o.attr('xu'));
|
||||
a = this.deptarr[xu];
|
||||
stotal = parseFloat(a.stotal);
|
||||
for (i=0; i < len; i++) {
|
||||
spath = this.userarr[i].deptpath;
|
||||
if (spath.indexOf('['+a.id+']')>=0)nstotal++;
|
||||
}
|
||||
if (nstotal < stotal) {
|
||||
o1.checked=false;
|
||||
o1.disabled=true;
|
||||
js.msg('msg','无权选择部门['+a.name+']');
|
||||
}
|
||||
},
|
||||
this._searchkey = function(bo){
|
||||
var key = $('#changekey_'+this.rand+'').val(),s='',a=[],d=[],len,i;
|
||||
a=this.userarr;
|
||||
len=a.length;
|
||||
if(key!='')for(i=0;i<len;i++)if(a[i].name.indexOf(key)>-1 || a[i].pingyin.indexOf(key)==0 || a[i].deptname.indexOf(key)>-1 || a[i].ranking.indexOf(key)>-1){a[i].xu=i;d.push(a[i])};
|
||||
len = d.length;
|
||||
for(i=0;i<len;i++){
|
||||
s+='<div class="listsss">';
|
||||
s+='<table width="100%"><tr><td></td><td width="100%"><img align="absmiddle" height="24" height="24" src="'+d[i].face+'"> '+d[i].name+'<span style="font-size:12px;color:#888888">('+d[i].ranking+')</span></td><td><input name="changeuserinput_'+rand+'_soukey" xxu="'+d[i].xu+'" xls="u" xname="'+d[i].name+'" value="'+d[i].id+'" style="/*width:18px;height:18px;*/" type="'+this.inputtype+'"></td></tr></table>';
|
||||
s+='</div>';
|
||||
}
|
||||
if(bo && s=='' && key!='')js.msg('msg','无相关['+key+']的记录', 2);
|
||||
$('#showdiv'+rand+'_search').html(s);
|
||||
var o1 = $('#showdiv'+rand+'_0');
|
||||
if(s==''){o1.show();}else{o1.hide();}
|
||||
};
|
||||
this._clickcancel=function(){
|
||||
if(!this.oveob)history.back();
|
||||
this.hide();
|
||||
};
|
||||
this.hide=function(){
|
||||
$('#changeuser_'+rand+'').remove();
|
||||
this.oncancel();
|
||||
};
|
||||
this.show=function() {
|
||||
this.creatediv();
|
||||
if (this.deptarr.length > 0) {
|
||||
this.firstpid = this.deptarr[0].pid;
|
||||
this.showlist(this.firstpid, 0);
|
||||
} else {
|
||||
this._loaddata();
|
||||
}
|
||||
};
|
||||
this._deptclicks=function(o){
|
||||
var sxu = $(o).attr('deptxu').split('_');
|
||||
var a = this.deptarr[sxu[0]];
|
||||
var o1 = $('#showdiv' + rand + '_' + a.id);
|
||||
var lx = o1.attr('show');
|
||||
if (lx=='false') {
|
||||
this.showlist(a.id, parseFloat(sxu[1]) + 1);
|
||||
} else {
|
||||
o1.toggle();
|
||||
}
|
||||
};
|
||||
|
||||
this._loaddata = function() {
|
||||
var o1 = $('#showdiv'+rand+'_0'),url;
|
||||
o1.html('<div align="center" style="padding:30px"><img src="/assets/chat/images/mloading.gif"></div>');
|
||||
|
||||
// var url = 'index.php?a=deptuserjson&m=dept&d=system&ajaxbool=true&changerange='+this.changerange+'&changerangeno='+this.changerangeno+'>ype=change';
|
||||
var url = '/chat/chat/getDepartmentUserData?changerange='+this.changerange+'&changerangeno='+this.changerangeno+'>ype=change';
|
||||
$.getJSON(url, function(ret) {
|
||||
if (ret.code == 200) {
|
||||
ret = ret.data;
|
||||
me._loaddatashow(ret);
|
||||
} else {
|
||||
o1.html(ret.msg);
|
||||
}
|
||||
});
|
||||
};
|
||||
this._loaddatashow = function(ret) {
|
||||
if (isempt(this.changerange) && isempt(this.changerangeno)) {
|
||||
js.setoption('deptjson', ret.deptjson);
|
||||
js.setoption('userjson', ret.userjson);
|
||||
js.setoption('groupjson', ret.groupjson);
|
||||
}
|
||||
this.userarr = ret.userjson;
|
||||
this.deptarr = ret.deptjson;
|
||||
this.grouparr = ret.groupjson;
|
||||
this.firstpid = 0;
|
||||
if (this.deptarr[0]) {
|
||||
this.firstpid = this.deptarr[0].pid;
|
||||
}
|
||||
this.showlist(this.firstpid, 0);
|
||||
};
|
||||
this._changboxxuan=function(os) {
|
||||
var ns= 'changeuserinput_' + rand;
|
||||
if($('#showdiv'+rand+'_search').html()!='')ns+='_soukey';
|
||||
var ob = os.checked,o=$("input[name='"+ns+"']"),i;
|
||||
for(i=0;i<o.length;i++)o[i].checked=ob;
|
||||
};
|
||||
this.queding=function(){
|
||||
var ns= 'changeuserinput_'+rand+'';
|
||||
if($('#showdiv'+rand+'_search').html()!='')ns+='_soukey';
|
||||
var o = $("input[name='"+ns+"']");
|
||||
var i,len=o.length,o1,xls,xna,xal,xxu,sid='',sna='',ob1=this.changetype.indexOf('dept')==-1,ob2=this.changetype.indexOf('user')==-1,xzarr=[];
|
||||
var ob3=ob1 || ob2;
|
||||
for(i=0;i<len;i++){
|
||||
o1 = $(o[i]);
|
||||
if(o[i].checked){
|
||||
xls= o1.attr('xls');
|
||||
xna= o1.attr('xname');
|
||||
xxu= o1.attr('xxu');
|
||||
xal= o1.val();
|
||||
if(ob3)xls='';
|
||||
sid+=','+xls+''+xal+'';
|
||||
sna+=','+xna+'';
|
||||
if(!isempt(xxu))xzarr.push(this.userarr[parseFloat(xxu)]);
|
||||
}
|
||||
}
|
||||
if(sid!=''){
|
||||
sid=sid.substr(1);
|
||||
sna=sna.substr(1);
|
||||
}
|
||||
if(this.idobj)this.idobj.value=sid;
|
||||
if(this.nameobj){
|
||||
this.nameobj.value=sna;
|
||||
this.nameobj.focus();
|
||||
}
|
||||
if(!this.oveob)history.back();
|
||||
this.onselect(sna, sid, xzarr);
|
||||
this.hide();
|
||||
}
|
||||
}
|
||||
|
||||
function selectdata(sobj, options){
|
||||
var obj = sobj;
|
||||
var rand = ''+parseInt(Math.random()*9999999)+'';
|
||||
var me = this;
|
||||
this.rand = rand;
|
||||
this.ismobile = false;
|
||||
|
||||
this._init = function(){
|
||||
for(var i in options)this[i]=options[i];
|
||||
if(typeof(ismobile) && ismobile==1)this.ismobile = true;
|
||||
this._showcreate();
|
||||
};
|
||||
this._showcreate = function(){
|
||||
var ws = '350px';
|
||||
if(this.ismobile)ws='90%';
|
||||
var s='<div style="z-index:1;width:100%;height:100%;overflow:hidden;left:0px;top:0px; background:rgba(0,0,0,0.3);position:fixed;z-index:9" id="selectdata_'+rand+'">';
|
||||
s+='<div tsid="main" id="mints_'+rand+'" style="position:absolute;top:30%; background:white;width:'+ws+';box-shadow:0px 0px 5px rgba(0,0,0,0.3)">';
|
||||
s+=' <div onmousedown="js.move(\'mints_'+rand+'\')" style="line-height:40px; background:#2c3e50;color:white;font-size:16px"> '+this.title+'</div>';
|
||||
s+=' <div style="height:40px;overflow:hidden;border-bottom:1px #cccccc solid;"><table width="100%"><tr><td><select id="selxuan_'+this.rand+'" style="width:120px;border:none;background:none;display:none"><option value="">选择所有</option></select></td><td width="100%" height="40"><input id="changekey_'+this.rand+'" placeholder="搜索关键词" style="height:30px;border:none;background:none;width:100%;margin:0px 10px;outline:none"></td><td><button style="background:none;color:#666666;" class="changeuserbotton" id="changesoubtn_'+this.rand+'" type="button" >查找</button></td></tr></table></div>';
|
||||
s+=' <div style="-webkit-overflow-scrolling:touch;height:300px;overflow:auto; background:#f1f1f1" id="selectlist_'+rand+'" class="changeuserlist"></div>';
|
||||
s+=' <div style="height:50px;line-height:50px;border-top:1px #cccccc solid" align="right"><table width="100%"><tr><td width="10" nowrap> </td><td width="80%"><font color="#888888" tsid="count"></font></td><td><button type="button" id="changereload_'+rand+'" class="changeuserbotton">刷新</button></td><td width="10" nowrap> </td><td><button class="changeuserbotton" type="button" id="changecancl_'+rand+'">取消</button></td><td width="10" nowrap> </td><td height="50"><button style="background:#1890ff;" id="changeok_'+rand+'" type="button" class="changeuserbotton">确定</button></td><td width="10" nowrap> </td></tr></table></div>';
|
||||
s+='</div>';
|
||||
s+='</div>';
|
||||
s+=_getstyles();
|
||||
$('body').append(s);
|
||||
this.showdata(this.data);
|
||||
var o = this._getobj('main');
|
||||
var l = ($(window).width()-o.width())*0.5,t = ($(window).height()-o.height())*0.5;
|
||||
o.css({'left':''+l+'px','top':''+t+'px'});
|
||||
$('#changecancl_'+this.rand+'').click(function(){
|
||||
me._clickcancel();
|
||||
});
|
||||
$('#changeok_'+this.rand+'').click(function(){
|
||||
me.queding();
|
||||
});
|
||||
$('#changereload_'+this.rand+'').click(function(){
|
||||
me.loaddata();
|
||||
});
|
||||
$('#changesoubtn_'+this.rand+'').click(function(){
|
||||
me._searchkey(true);
|
||||
});
|
||||
$('#changekey_'+this.rand+'').keydown(function(e){
|
||||
me._searchkeys(e)
|
||||
});
|
||||
$('#changekey_'+this.rand+'').keyup(function(e){
|
||||
me._searchkeys(e)
|
||||
});
|
||||
};
|
||||
this._getobj=function(lx){
|
||||
var o = $('#selectdata_'+rand+'').find("[tsid='"+lx+"']");
|
||||
return o;
|
||||
};
|
||||
this._clickcancel=function(){
|
||||
this.hide();
|
||||
};
|
||||
this.hide=function(){
|
||||
$('#selectdata_'+rand+'').remove();
|
||||
this.oncancel();
|
||||
};
|
||||
this.queding=function(){
|
||||
var ns= 'changeuserinput_'+rand+'';
|
||||
var o = $("input[name='"+ns+"']");
|
||||
var i,len=o.length,o1,xna,xu,xal,sid='',sna='',seld=[];
|
||||
for(i=0;i<len;i++){
|
||||
o1 = $(o[i]);
|
||||
if(o[i].checked){
|
||||
xna= o1.attr('xname');
|
||||
xu = parseFloat(o1.attr('xu'));
|
||||
if(this.checked){
|
||||
seld.push(this.nowdata[xu]);
|
||||
}else{
|
||||
seld=this.nowdata[xu];
|
||||
}
|
||||
xal= o1.val();
|
||||
sid+=','+xal+'';
|
||||
sna+=','+xna+'';
|
||||
}
|
||||
}
|
||||
if(sid!=''){
|
||||
sid=sid.substr(1);
|
||||
sna=sna.substr(1);
|
||||
}
|
||||
if(this.idobj)this.idobj.value=sid;
|
||||
if(this.nameobj){
|
||||
this.nameobj.value=sna;
|
||||
this.nameobj.focus();
|
||||
}
|
||||
this.onselect(seld,sna, sid);
|
||||
this.hide();
|
||||
};
|
||||
this.showdata=function(a,inb){
|
||||
if(!a)a=[];
|
||||
this.showselectdata(a.selectdata);
|
||||
if(a.rows)a = a.rows;
|
||||
var s='',len=a.length,s1='';
|
||||
if(len==0){
|
||||
s='<div align="center" style="margin-top:30px;color:#cccccc;font-size:16px">无记录</div>';
|
||||
}else{
|
||||
s = this.showhtml(a);
|
||||
s1='共'+len+'条';
|
||||
}
|
||||
this._getobj('count').html(s1);
|
||||
var o = $('#selectlist_'+rand+'');
|
||||
o.html(s);
|
||||
if(!inb && len==0)this.loaddata();
|
||||
};
|
||||
this.seldatsse = [];
|
||||
this.showselectdata=function(da) {
|
||||
if (this.showselbo || !da) return;
|
||||
var o = get('selxuan_' + this.rand);
|
||||
js.setselectdata(o,da,'value');
|
||||
if (da.length > 0) {
|
||||
this.showselbo=true;
|
||||
}
|
||||
$(o).change(function() {
|
||||
me._changeselval(this);
|
||||
}).show();
|
||||
};
|
||||
this._changeselval = function(o) {
|
||||
this.loaddata(o.value);
|
||||
};
|
||||
this.showhtml=function(a){
|
||||
this.nowdata = a;
|
||||
var i,len=a.length,s='',s2,s1='',atr,oldvel='',d;
|
||||
if(this.nameobj)oldvel=this.nameobj.value;
|
||||
if(this.idobj)oldvel=this.idobj.value;
|
||||
var type='checkbox',ched='';
|
||||
if(!this.checked)type='radio';
|
||||
oldvel = ','+oldvel+',';
|
||||
for(i=0;i<len && i<this.maxshow;i++){
|
||||
ched='';
|
||||
d = a[i];
|
||||
if(!isempt(d.value) && oldvel.indexOf(','+d.value+',')>-1)ched='checked';
|
||||
if(d.disabled)ched+=' disabled';
|
||||
s2 = '<input xu="'+i+'" '+ched+' name="changeuserinput_'+rand+'" xname="'+d.name+'" value="'+d.value+'" style="/*width:18px;height:18px;*/" align="absmiddle" type="'+type+'">';
|
||||
atr = '';
|
||||
if(d.padding)atr='style="padding-left:'+d.padding+'px"';
|
||||
if(!d.iconswidth)d.iconswidth=18;
|
||||
if(d.iconsimg)s2+=' <img align="absmiddle" src="'+d.iconsimg+'" height="'+d.iconswidth+'" width="'+d.iconswidth+'">';
|
||||
s+='<div class="listsss" '+atr+'><label>'+s2+' '+d.name+'';
|
||||
if(d.subname)s+=' <span style="font-size:12px;color:#888888">('+d.subname+')</span>';
|
||||
s+='</label></div>';
|
||||
}
|
||||
return s;
|
||||
};
|
||||
this.loaddata=function(svel){
|
||||
var url = this.url;
|
||||
if(svel)url+='&selvalue='+svel+'';
|
||||
if(url=='')return;
|
||||
$('#selectlist_'+rand+'').html('<div align="center" style="margin-top:30px"><img src="/assets/chat/images/mloading.gif"></div>');
|
||||
$.getJSON(url, function(a){
|
||||
me.data = a;
|
||||
me.onloaddata(a);
|
||||
me.showdata(a, true);
|
||||
});
|
||||
};
|
||||
this._searchkeys=function(e){
|
||||
clearTimeout(this._searchkeystime);
|
||||
this._searchkeystime=setTimeout(function(){
|
||||
me._searchkey(false);
|
||||
},500);
|
||||
};
|
||||
this._searchkey = function(bo){
|
||||
var key = $('#changekey_'+this.rand+'').val(),a=[],d=[],d1,len,i,oi=0,s;
|
||||
a=this.data;
|
||||
if(a.rows)a=a.rows;
|
||||
len=a.length;if(len==0)return;
|
||||
if(key!='')for(i=0;i<len;i++){
|
||||
d1 = a[i];
|
||||
if(d1.name.indexOf(key)>-1 || d1.value==key || (d1.subname && d1.subname.indexOf(key)>-1)){
|
||||
d.push(d1);
|
||||
oi++;
|
||||
if(oi>20)break;//最多显示搜索
|
||||
}
|
||||
}
|
||||
len = d.length;
|
||||
if(len==0){
|
||||
s=this.showhtml(a);
|
||||
}else{
|
||||
s=this.showhtml(d);
|
||||
}
|
||||
$('#selectlist_'+rand+'').html(s);
|
||||
if(bo && len==0 && key!='')js.msg('msg','无相关['+key+']的记录', 2);
|
||||
};
|
||||
}
|
||||
|
||||
$.fn.chnageuser = function(options) {
|
||||
var defaultVal = {
|
||||
'title': '请选择...',
|
||||
'titlebool': true,
|
||||
'showview': '',
|
||||
'changerange': '', //从哪些人员中选择
|
||||
'changerangeno': '', //不从哪些人选择
|
||||
'changetype' : 'user',
|
||||
'idobj': false,
|
||||
'nameobj': false,
|
||||
'onselect': function() {},
|
||||
'oncancel': function() {}
|
||||
};
|
||||
var can = $.extend({}, defaultVal, options);
|
||||
var funcls = new chnageuser($(this), can);
|
||||
funcls._init();
|
||||
return funcls;
|
||||
};
|
||||
|
||||
$.selectdata = function(options) {
|
||||
var defaultVal = {
|
||||
'showview': '',
|
||||
'title': '请选择...',
|
||||
'maxshow': 100, // 最多显示防止卡死浏览器
|
||||
'data': [],
|
||||
'url' : '',
|
||||
'checked': false,
|
||||
'idobj': false,
|
||||
'nameobj': false,
|
||||
'onselect': function() {},
|
||||
'oncancel': function() {},
|
||||
'onloaddata': function() {}
|
||||
};
|
||||
var can = $.extend({}, defaultVal, options);
|
||||
var funcls = new selectdata(false, can);
|
||||
funcls._init();
|
||||
return funcls;
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
(function ($) {
|
||||
|
||||
function get(id){return document.getElementById(id)};
|
||||
|
||||
function funclass(opts, obj){
|
||||
if(!opts)opts={};
|
||||
var me = this;
|
||||
this.ismobile = false;
|
||||
this.downbool = true;
|
||||
this.dushu = 0;
|
||||
this.init=function(){
|
||||
for(var i in opts)this[i]=opts[i];
|
||||
if(obj)this.url=obj.attr('src');
|
||||
this.mheiht = document.body.scrollHeight,sed=$(window).height();
|
||||
if(this.mheiht<sed)this.mheiht=sed;
|
||||
this.showview();
|
||||
};
|
||||
this.remove=function(){
|
||||
$('#imgview_main').remove();
|
||||
};
|
||||
this.showview=function(){
|
||||
var s='<div id="imgview_main" style="position:absolute;left:0px;top:0px;width:100%;height:100%;z-index:800">';
|
||||
s+='<div style="position:absolute;z-index:0;left:0px;top:0px;width:100%;height:'+this.mheiht+'px;background-color:rgba(0,0,0,0.6)" id="imgview_mask"></div>';
|
||||
s+='<span onclick="$(this).parent().remove()" style="position:fixed;z-index:2;top:2px;right:5px;color:white"><i class="fa fa-remove"></i></span>';
|
||||
s+='<div id="imgview_span" style="position:fixed;z-index:1;left:47%;top:47%;overflow:hidden;color:white">';
|
||||
s+=' <div id="imgview_spanmask" style="position:absolute;z-index:1;left:0px;top:0px;background-color:rgba(0,0,0,0);width:100%;height:100%;cursor:move;user-select:none;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;-khtml-user-select:none;"></div>';
|
||||
s+=' <img style="position:absolute;z-index:0;left:0px;top:0px" id="imgview_spanimg" width="100%" height="100%" src="/assets/chat/images/mloading.gif" >';
|
||||
s+='</div>';
|
||||
s+='<div style="position:fixed;z-index:2;left:0px;bottom:0px;text-align:center;color:white;width:100%;font-size:20px;background-color:rgba(0,0,0,0.2);height:40px;line-height:40px;overflow:hidden"><i style="cursor:pointer" id="imgview_zoom-out" class="fa fa-search-minus" title="缩小"></i> <span id="imgview_nowbili" style="font-size:14px">100%</span> <i style="cursor:pointer" class="fa fa-search-plus" title="放大" id="imgview_zoom-in"></i>';
|
||||
s+=' <i style="cursor:pointer" class="fa fa-arrows" title="原始大小" id="imgview_zoom-move"></i>';
|
||||
if(!this.ismobile && this.downbool)s+=' <a target="_blank" download="" style="color:white;font-size:20px" href="'+this.url+'"><i style="cursor:pointer" class="fa fa-download" title="下载"></i></a>';
|
||||
s+=' <i style="cursor:pointer" class="fa fa-refresh" title="旋转90度" id="imgview_zoom-refresh"></i>';
|
||||
s+='</div>';
|
||||
s+='</div>';
|
||||
$('body').append(s);
|
||||
$('#imgview_mask').click(function(){
|
||||
$('#imgview_main').remove();
|
||||
});
|
||||
this.showez(32,32,0);
|
||||
var img = new Image();
|
||||
img.src = this.url;
|
||||
img.onload = function(){
|
||||
me.showez(this.width,this.height, 1);
|
||||
try{
|
||||
$('#imgview_span').mousewheel(function(e){
|
||||
me.bilixxx(e.deltaY*0.1);
|
||||
});}catch(e){}
|
||||
me.rotate(me.dushu);
|
||||
me.initmove();
|
||||
}
|
||||
img.onerror=function(e){
|
||||
$('#imgview_span').html('无图');
|
||||
}
|
||||
$('#imgview_zoom-out').click(function(){
|
||||
me.bilixxx(-0.1);
|
||||
});
|
||||
$('#imgview_zoom-in').click(function(){
|
||||
me.bilixxx(0.1);
|
||||
});
|
||||
$('#imgview_zoom-refresh').click(function(){
|
||||
me.clickrotate();
|
||||
});
|
||||
$('#imgview_zoom-move').click(function(){
|
||||
me.bl=1;
|
||||
me.rotate(0);
|
||||
me.bilixxx(0);
|
||||
});
|
||||
};
|
||||
this.showez=function(w, h, lx){
|
||||
this.width = w;
|
||||
this.height = h;
|
||||
var zw = $(window).width(),zh=$(window).height();
|
||||
var wm = zw-50,wh = zh-50;
|
||||
var bl= 1,nw=w,nh=h;
|
||||
if(w>wm){
|
||||
bl=wm/w;
|
||||
nh = h*bl;
|
||||
}
|
||||
if(nh>wh){
|
||||
bl= wh/h;
|
||||
}
|
||||
this.showbl(bl,lx);
|
||||
};
|
||||
this.showbl=function(bl,lx){
|
||||
this.bl = bl;
|
||||
$('#imgview_nowbili').html(''+parseInt(bl*100)+'%');
|
||||
var zw = $(window).width(),zh=$(window).height();
|
||||
var nw = this.width*this.bl,nh=this.height*this.bl;
|
||||
var l = (zw-nw)*0.5,t = (zh-nh)*0.5;
|
||||
var arr = {left:''+l+'px',top:''+t+'px',width:''+nw+'px',height:''+nh+'px'};
|
||||
var o1 = $('#imgview_span');
|
||||
if(lx!=2){
|
||||
if(lx==1)get('imgview_spanimg').src=this.url;
|
||||
o1.css(arr);
|
||||
}else{
|
||||
o1.stop();
|
||||
o1.animate(arr,300);
|
||||
}
|
||||
};
|
||||
this.bilixxx=function(lx){
|
||||
var bl = this.bl+lx;
|
||||
if(bl<0)bl=0.05;
|
||||
if(bl>3)bl=3;
|
||||
this.showbl(bl,2);
|
||||
};
|
||||
this.initmove=function(){
|
||||
if(this.ismobile){
|
||||
this.movehammer();
|
||||
return;
|
||||
}
|
||||
var o = $('#imgview_spanmask');
|
||||
var x=0,y=0,oldl,oldt;
|
||||
o.mousedown(function(e){
|
||||
x=e.clientX;
|
||||
y=e.clientY;
|
||||
var o1=get('imgview_span');
|
||||
oldl = parseInt(o1.style.left);
|
||||
oldt = parseInt(o1.style.top);
|
||||
me.movebo=true;
|
||||
});
|
||||
o.mousemove(function(e){
|
||||
if(!me.movebo)return;
|
||||
var _x = e.clientX-x,_y=e.clientY-y;
|
||||
$('#imgview_span').css({left:''+(oldl+_x)+'px',top:''+(oldt+_y)+'px'});
|
||||
});
|
||||
o.mouseup(function(e){
|
||||
me.movebo=false;
|
||||
});
|
||||
};
|
||||
this.rotate=function(ds){
|
||||
var o = get('imgview_span');
|
||||
var val= "rotate("+ds+"deg)";
|
||||
o.style.transform=val;
|
||||
o.style.webkitTransform=val;
|
||||
o.style.msTransform=val;
|
||||
o.style.MozTransform=val;
|
||||
o.style.OTransform=val;
|
||||
};
|
||||
this.clickrotate=function(){
|
||||
this.dushu+=90;
|
||||
if(this.dushu>=360)this.dushu=0;
|
||||
this.rotate(this.dushu);
|
||||
};
|
||||
this.movehammer=function(){
|
||||
var o = get('imgview_spanmask');
|
||||
var x=0,y=0,oldl,oldt;
|
||||
this.touchci = 0;
|
||||
o.addEventListener('touchstart',function(e){
|
||||
me.touchci++;
|
||||
x=e.touches[0].clientX;
|
||||
y=e.touches[0].clientY;
|
||||
var o1=get('imgview_span');
|
||||
oldl = parseInt(o1.style.left);
|
||||
oldt = parseInt(o1.style.top);
|
||||
me.movebo=true;
|
||||
clearTimeout(me.touctimes);
|
||||
me.touctimes = setTimeout(function(){me.touchci=0},200);
|
||||
});
|
||||
o.addEventListener('touchmove',function(e){
|
||||
e.preventDefault();
|
||||
if(!me.movebo)return;
|
||||
var _x = e.touches[0].clientX-x,_y=e.touches[0].clientY-y;
|
||||
$('#imgview_span').css({left:''+(oldl+_x)+'px',top:''+(oldt+_y)+'px'});
|
||||
});
|
||||
o.addEventListener('touchend',function(e){
|
||||
me.movebo=false;
|
||||
if(me.touchci==2){
|
||||
me.bilixxx(0.1);
|
||||
me.touchci=0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$.imgview = function(options){
|
||||
var cls = new funclass(options,false);
|
||||
cls.init();
|
||||
return cls;
|
||||
}
|
||||
|
||||
$.fn.imgview = function(options){
|
||||
var cls = new funclass(options, $(this));
|
||||
cls.init();
|
||||
return cls;
|
||||
}
|
||||
|
||||
$.imgviewclose= function(){
|
||||
var bo = get('imgview_main');
|
||||
$('#imgview_main').remove();
|
||||
return bo;
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
(function ($) {
|
||||
// 模式提示
|
||||
$.rockmodelmsg = function (lx, txt, sj, fun) {
|
||||
clearTimeout($.rockmodelmsgtime);
|
||||
$('#rockmodelmsg').remove();
|
||||
js.msg('none');
|
||||
if (!fun) fun = function () { };
|
||||
if (lx == 'none') return;
|
||||
var s = '<div id="rockmodelmsg" onclick="$(this).remove()" align="center" style="position:fixed;left:45%;top:30%;z-index:9999;border-radius:10px;padding:30px; background:rgba(0,0,0,0.7);color:white;font-size:18px">';
|
||||
if (lx == 'wait') {
|
||||
if (!txt) txt = '处理中...';
|
||||
s += '<div><img src="/assets/chat/images/mloading.gif"></div>';
|
||||
s += '<div style="padding-top:5px">' + txt + '</div>';
|
||||
if (!sj) sj = 60;
|
||||
}
|
||||
if (lx == 'ok') {
|
||||
if (!txt) txt = '处理成功';
|
||||
s += '<div style="font-size:40px">✔</div>';
|
||||
s += '<div>' + txt + '</div>';
|
||||
}
|
||||
if (lx == 'msg' || !lx) {
|
||||
if (!txt) txt = '提示';
|
||||
s += '<div style="font-size:40px;color:red">☹</div>';
|
||||
s += '<div style="color:red">' + txt + '</div>';
|
||||
}
|
||||
s += '</div>';
|
||||
$('body').append(s);
|
||||
if (!sj) sj = 3;
|
||||
var le = (winWb() - $('#rockmodelmsg').width()) * 0.5 - 20;
|
||||
$('#rockmodelmsg').css('left', '' + le + 'px');
|
||||
$.rockmodelmsgtime = setTimeout(function () {
|
||||
$('#rockmodelmsg').remove();
|
||||
fun();
|
||||
}, sj * 1000);
|
||||
}
|
||||
js.msgok = function (msg, fun, sj) {
|
||||
$.rockmodelmsg('ok', msg, sj, fun);
|
||||
};
|
||||
js.msgerror = function (msg, fun, sj) {
|
||||
$.rockmodelmsg('msg', msg, sj, fun);
|
||||
};
|
||||
js.loading = function (msg, sj) {
|
||||
$.rockmodelmsg('wait', msg, sj);
|
||||
};
|
||||
js.unloading = function () {
|
||||
$.rockmodelmsg('none');
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
+321
@@ -0,0 +1,321 @@
|
||||
(function ($) {
|
||||
maxupgloble = 0;
|
||||
function rockupload(opts) {
|
||||
var me = this;
|
||||
var opts = js.apply({
|
||||
inputfile: '', initpdbool: false, initremove: true, uptype: '*', maxsize: 5, onchange: function () { }, onprogress: function () { }, urlparams: {}, updir: '', onsuccess: function () { }, quality: 0.7, xu: 0, fileallarr: [], autoup: true, oldids: '',
|
||||
onerror: function () { }, fileidinput: 'fileid',
|
||||
onabort: function () { },
|
||||
allsuccess: function () { }
|
||||
}, opts);
|
||||
this._init = function () {
|
||||
for (var a in opts) this[a] = opts[a];
|
||||
// 加载最大可上传大小
|
||||
if (maxupgloble == 0) $.getJSON(js.apiurl('/chat/chat/getMaxUpload'), function (res) {
|
||||
try {
|
||||
if (res.code == 200) {
|
||||
var maxUpload = parseFloat(res.data.maxUpload);
|
||||
me.maxsize = maxUpload;
|
||||
maxupgloble = maxUpload;
|
||||
}
|
||||
} catch (e) { }
|
||||
});
|
||||
|
||||
if (maxupgloble > 0) this.maxsize = maxupgloble;
|
||||
|
||||
if (!this.autoup) return;
|
||||
if (this.initremove) {
|
||||
$('#' + this.inputfile + '').parent().remove();
|
||||
var s = '<form style="display:none;height:0px;width:0px" name="form_' + this.inputfile + '"><input type="file" id="' + this.inputfile + '"></form>';
|
||||
$('body').append(s);
|
||||
}
|
||||
$('#' + this.inputfile + '').change(function () {
|
||||
me.change(this);
|
||||
});
|
||||
};
|
||||
this.reset = function () {
|
||||
if (!this.autoup) return;
|
||||
var fids = 'form_' + this.inputfile + '';
|
||||
if (document[fids]) document[fids].reset();
|
||||
};
|
||||
this.setparams = function (ars) {
|
||||
this.oparams = js.apply({ uptype: this.uptype }, ars);
|
||||
this.uptype = this.oparams.uptype;
|
||||
};
|
||||
this.setuptype = function (lx) {
|
||||
this.uptype = lx;
|
||||
},
|
||||
this.click = function (ars) {
|
||||
if (this.upbool) return;
|
||||
this.setparams(ars);
|
||||
get(this.inputfile).click();
|
||||
};
|
||||
this.clear = function () {
|
||||
this.fileallarr = [];
|
||||
this.filearr = {};
|
||||
this.xu = 0;
|
||||
$('#' + this.fileview + '').html('');
|
||||
};
|
||||
this.change = function (o1) {
|
||||
if (!o1.files) {
|
||||
js.msg('msg', '当前浏览器不支持上传1');
|
||||
return;
|
||||
}
|
||||
|
||||
var f = o1.files[0];
|
||||
if (!f || f.name == '/') return;
|
||||
var a = { filename: f.name, filesize: f.size, filesizecn: js.formatsize(f.size) };
|
||||
if (a.filesize <= 0) {
|
||||
js.msg('msg', '' + f.name + '不存在');
|
||||
return;
|
||||
}
|
||||
if (this.isfields(a)) return;
|
||||
if (f.size > this.maxsize * 1024 * 1024) {
|
||||
this.reset();
|
||||
js.msg('msg', '文件不能超过' + this.maxsize + 'MB,当前文件' + a.filesizecn + '');
|
||||
return;
|
||||
}
|
||||
var filename = f.name;
|
||||
var fileext = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase();
|
||||
if (!this.uptype) this.uptype = '*';
|
||||
if (this.uptype == 'image') this.uptype = 'jpg,gif,png,bmp,jpeg';
|
||||
if (this.uptype == 'word') this.uptype = 'doc,docx,pdf,xls,xlsx,ppt,pptx,txt';
|
||||
if (this.uptype != '*') {
|
||||
var upss = ',' + this.uptype + ',';
|
||||
if (upss.indexOf(',' + fileext + ',') < 0) {
|
||||
js.msg('msg', '禁止文件类型,请选择' + this.uptype + '');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
a.fileext = fileext;
|
||||
a.isimg = js.isimg(fileext);
|
||||
if (a.isimg) a.imgviewurl = this.getimgview(o1);
|
||||
a.xu = this.xu;
|
||||
a.f = f;
|
||||
for (var i in this.oparams) a[i] = this.oparams[i];
|
||||
this.filearr = a;
|
||||
var zc = this.fileallarr.push(a);
|
||||
|
||||
//如果是图片压缩一下超过1M
|
||||
if (f.size > 1024 * 1024 && a.isimg && this.quality < 1) {
|
||||
this.compressimg(a.imgviewurl, f, function (nf) {
|
||||
a.filesize = nf.size;
|
||||
a.filesizecn = js.formatsize(nf.size);
|
||||
me.fileallarr[zc - 1].f = nf;
|
||||
me.nnonchagn(a, nf, zc);
|
||||
});
|
||||
} else {
|
||||
this.nnonchagn(a, f, zc);
|
||||
}
|
||||
};
|
||||
this.nnonchagn = function (a, f, zc) {
|
||||
this.xu++;
|
||||
this.onchange(a);
|
||||
this.reset();
|
||||
if (!this.autoup) {
|
||||
var s = '<div style="padding:3px;font-size:14px;border-bottom:1px #dddddd solid"><font>' + a.filename + '</font>(' + a.filesizecn + ') <span style="color:#ff6600" id="' + this.fileview + '_' + a.xu + '"></span> <a oi="' + (zc - 1) + '" id="gm' + this.fileview + '_' + a.xu + '" href="javascript:;">改名</a> <a onclick="$(this).parent().remove()" href="javascript:;">×</a></div>';
|
||||
$('#' + this.fileview + '').append(s);
|
||||
$('#gm' + this.fileview + '_' + a.xu + '').click(function () {
|
||||
me.s_gaiming(this);
|
||||
});
|
||||
return;
|
||||
}
|
||||
this._startup(f);
|
||||
};
|
||||
this.s_gaiming = function (o1) {
|
||||
var o, oi, one, fa;
|
||||
o = $(o1);
|
||||
oi = parseFloat($(o1).attr('oi'));
|
||||
fa = this.fileallarr[oi];
|
||||
one = o.parent().find('font').html().replace('.' + fa.fileext + '', '');
|
||||
if (get('confirm_main')) {
|
||||
var nr = prompt('新文件名', one);
|
||||
if (nr) {
|
||||
var newfie = nr + '.' + fa.fileext;
|
||||
o.parent().find('font').html(newfie);
|
||||
me.fileallarr[oi].filename = newfie;
|
||||
}
|
||||
} else {
|
||||
js.prompt('修改文件名', '新文件名', function (jg, nr) {
|
||||
if (jg == 'yes' && nr) {
|
||||
var newfie = nr + '.' + fa.fileext;
|
||||
o.parent().find('font').html(newfie);
|
||||
me.fileallarr[oi].filename = newfie;
|
||||
}
|
||||
}, one);
|
||||
}
|
||||
};
|
||||
this.compressimg = function (path, fobj, call) {
|
||||
var img = new Image();
|
||||
img.src = path;
|
||||
if (!call) call = function () { };
|
||||
img.onload = function () {
|
||||
var that = this;
|
||||
var w = that.width,
|
||||
h = that.height,
|
||||
scale = w / h;
|
||||
var quality = me.quality;//压缩图片质量
|
||||
var canvas = document.createElement('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
var anw = document.createAttribute("width");
|
||||
anw.nodeValue = w;
|
||||
var anh = document.createAttribute("height");
|
||||
anh.nodeValue = h;
|
||||
canvas.setAttributeNode(anw);
|
||||
canvas.setAttributeNode(anh);
|
||||
ctx.drawImage(that, 0, 0, w, h);
|
||||
var base64 = canvas.toDataURL(fobj.type, quality);
|
||||
var nfobj = me.base64toblob(base64);
|
||||
call(nfobj);
|
||||
}
|
||||
};
|
||||
this.base64toblob = function (urlData) {
|
||||
var arr = urlData.split(','), mime = arr[0].match(/:(.*?);/)[1],
|
||||
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
|
||||
while (n--) {
|
||||
u8arr[n] = bstr.charCodeAt(n);
|
||||
}
|
||||
return new Blob([u8arr], { type: mime });
|
||||
};
|
||||
this.getimgview = function (o1) {
|
||||
try {
|
||||
return URL.createObjectURL(o1.files.item(0));
|
||||
} catch (e) { return false; }
|
||||
};
|
||||
this.isfields = function (a) {
|
||||
var bo = false, i, d = this.fileallarr;
|
||||
for (i = 0; i < d.length; i++) {
|
||||
if (this.fileviewxu(d[i].xu) && d[i].filename == a.filename && d[i].filesize == a.filesize) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return bo;
|
||||
};
|
||||
this.sendbase64 = function (nr, ocs) {
|
||||
this.filearr = js.apply({ filename: '截图.png', filesize: 0, filesizecn: '', isimg: true, fileext: 'png' }, ocs);
|
||||
this._startup(false, nr);
|
||||
};
|
||||
this.start = function () {
|
||||
return this.startss(0);
|
||||
};
|
||||
this.startss = function (oi) {
|
||||
if (oi >= this.xu) {
|
||||
var ids = '' + this.oldids + '';
|
||||
var a = this.fileallarr;
|
||||
for (var i = 0; i < a.length; i++)if (a[i].id) ids += ',' + a[i].id + '';
|
||||
if (ids != '' && ids.substr(0, 1) == ',') ids = ids.substr(1);
|
||||
try { if (form(this.fileidinput)) form(this.fileidinput).value = ids; } catch (e) { };
|
||||
this.allsuccess(this.fileallarr, ids); //必须全部才触发
|
||||
return false;
|
||||
}
|
||||
this.nowoi = oi;
|
||||
var f = this.fileallarr[oi];
|
||||
if (!f || !this.fileviewxu(f.xu)) {
|
||||
return this.startss(this.nowoi + 1);
|
||||
}
|
||||
this.filearr = f;
|
||||
this.onsuccessa = function (f, str) {
|
||||
var dst = js.decode(str);
|
||||
if (dst.id) {
|
||||
this.fileallarr[this.nowoi].id = dst.id;
|
||||
this.fileallarr[this.nowoi].filepath = dst.filepath;
|
||||
} else {
|
||||
js.msg('msg', str);
|
||||
this.fileviewxu(this.nowoi, '<font color=red>失败1</font>');
|
||||
}
|
||||
this.startss(this.nowoi + 1);
|
||||
}
|
||||
this.onprogressa = function (f, bil) {
|
||||
this.fileviewxu(this.nowoi, '' + bil + '%');
|
||||
}
|
||||
this.onerror = function () {
|
||||
this.fileviewxu(this.nowoi, '<font color=red>失败0</font>');
|
||||
this.startss(this.nowoi + 1);
|
||||
}
|
||||
this._startup(f.f);
|
||||
return true;
|
||||
};
|
||||
this.fileviewxu = function (oi, st) {
|
||||
if (typeof (st) == 'string') $('#' + this.fileview + '_' + oi + '').html(st);
|
||||
return get('' + this.fileview + '_' + oi + '');
|
||||
};
|
||||
//初始化文件防止重复上传
|
||||
this._initfile = function (f) {
|
||||
var a = this.filearr, d = { 'filesize': a.filesize, 'fileext': a.fileext };
|
||||
if (!a.isimg) d.filename = a.filename;
|
||||
var url = js.apiurl('upload', 'initfile', d);
|
||||
$.getJSON(url, function (ret) {
|
||||
if (ret.success) {
|
||||
var bstr = ret.data;
|
||||
me.upbool = false;
|
||||
me.onsuccess(a, bstr);
|
||||
} else {
|
||||
me._startup(f, false, true);
|
||||
}
|
||||
});
|
||||
};
|
||||
this._startup = function (fs, nr, bos) {
|
||||
this.upbool = true;
|
||||
if (this.initpdbool && fs && !bos) { this._initfile(fs); return; }
|
||||
try { var xhr = new XMLHttpRequest(); } catch (e) { js.msg('msg', '当前浏览器不支持2'); return; }
|
||||
this.urlparams.maxsize = this.maxsize;
|
||||
if (this.updir) this.urlparams.updir = this.updir;
|
||||
var url = js.apiurl('upload', 'upfile', this.urlparams);
|
||||
xhr.open('POST', url, true);
|
||||
xhr.onreadystatechange = function () { me._statechange(this); };
|
||||
xhr.upload.addEventListener("progress", function (evt) { me._onprogress(evt, this); }, false);
|
||||
xhr.addEventListener("load", function () { me._onsuccess(this); }, false);
|
||||
xhr.addEventListener("error", function () { me._error(false, this); }, false);
|
||||
if (nr) fs = this.base64toblob(nr);
|
||||
var fd = new FormData();
|
||||
fd.append('file', fs, this.filearr.filename);
|
||||
xhr.send(fd);
|
||||
this.xhr = xhr;
|
||||
};
|
||||
this.onsuccessa = function () {
|
||||
|
||||
};
|
||||
this._onsuccess = function (o) {
|
||||
this.upbool = false;
|
||||
var bstr = o.response;
|
||||
if (bstr.indexOf('id') < 0 || o.status != 200) {
|
||||
this._error(bstr);
|
||||
} else {
|
||||
this.onsuccessa(this.filearr, bstr, o);
|
||||
this.onsuccess(this.filearr, bstr, o);
|
||||
}
|
||||
};
|
||||
this._error = function (ts, xr) {
|
||||
this.upbool = false;
|
||||
if (!ts) ts = '上传内部错误';
|
||||
this.onerror(ts);
|
||||
};
|
||||
this._statechange = function (o) {
|
||||
|
||||
};
|
||||
this.onprogressa = function () {
|
||||
|
||||
};
|
||||
this._onprogress = function (evt) {
|
||||
var loaded = evt.loaded;
|
||||
var tot = evt.total;
|
||||
var per = Math.floor(100 * loaded / tot);
|
||||
this.onprogressa(this.filearr, per, evt);
|
||||
this.onprogress(this.filearr, per, evt);
|
||||
};
|
||||
this.abort = function () {
|
||||
this.xhr.abort();
|
||||
this.upbool = false;
|
||||
this.onabort();
|
||||
};
|
||||
this._init();
|
||||
}
|
||||
|
||||
|
||||
$.rockupload = function (options) {
|
||||
var cls = new rockupload(options, false);
|
||||
return cls;
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,22 @@
|
||||
.rockmenu{ position:absolute;display:none; z-index:9999}
|
||||
.rockmenuli{border:1px #eeeeee solid;
|
||||
background-color:#ffffff; left:0px; top:0px; background:rgba(255,255,255,0.9);
|
||||
box-shadow:0px 0px 5px rgba(0,0,0,0.3);color:#555555
|
||||
}
|
||||
.rockmenulijt{ padding:0px; text-align:center}
|
||||
.rockmenu ul{padding:0px;margin:0px}
|
||||
.rockmenu li{ list-style-type:none; padding:8px 12px; cursor:pointer; text-align:left; border-bottom:1px #eeeeee dotted;}
|
||||
.rockmenu li.li01{ background-color:#eeeeee;}
|
||||
.rockmenu li span{ font-size:10px; }
|
||||
.rockmenu li.li01 span{}
|
||||
.rockmenuli li img.iconsa{ vertical-align:middle; width:16px; height:16px; margin-right:8px}
|
||||
|
||||
.rockmenu .arrow-up{
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-left: 10px solid transparent; /* 左边框的宽 */
|
||||
border-right: 10px solid transparent; /* 右边框的宽 */
|
||||
border-bottom: 10px solid #cccccc; /* 下边框的长度|高,以及背景色 */
|
||||
font-size: 0;
|
||||
line-height: 0;
|
||||
}
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
var rockmenuobj = null;
|
||||
(function ($) {
|
||||
|
||||
function rockmenu(element, options){
|
||||
var obj = element;
|
||||
var can = options;
|
||||
var json = can.data;
|
||||
var rand = js.getrand();
|
||||
var me = this;
|
||||
this.obj = obj;
|
||||
|
||||
//初始化
|
||||
this.init = function(){
|
||||
if(!obj)return;
|
||||
obj[can.trigger](function(){
|
||||
me.setcontent();
|
||||
return false;
|
||||
});
|
||||
};
|
||||
this.hide = function(){
|
||||
var o = this.mdivobj;
|
||||
if(!o)return;
|
||||
o.hide();
|
||||
if(can.bgcolor!='')obj.css('background','');
|
||||
if(can.autoremove)o.remove();
|
||||
};
|
||||
this.setcontent = function(){
|
||||
$('.rockmenu').remove();
|
||||
rockmenuobj = this;
|
||||
can.beforeshow(this);
|
||||
if(json.length<=0)return false;
|
||||
if(can.bgcolor!='')obj.css('background',can.bgcolor);
|
||||
if(can.autoremove)$('#rockmenu_'+rand+'').remove();
|
||||
if(document.getElementById('rockmenu_'+rand+'')) {
|
||||
this.setweizhi();
|
||||
return false;
|
||||
}
|
||||
var len = json.length;
|
||||
var str = '<div class="rockmenu" id="rockmenu_'+rand+'">';
|
||||
if(can.arrowup)str+='<div class="arrow-up"></div>';
|
||||
str+='<div style="background:'+can.background+';" id="rockmenuli_'+rand+'" class="rockmenuli '+can.maincls+'"><ul>';
|
||||
var s = '',ys='',col,va;
|
||||
for(var i=0; i<len; i++){
|
||||
ys= '',
|
||||
va= json[i][can.display];
|
||||
if(i==len-1)ys+='border:none;';
|
||||
col = '';
|
||||
if(json[i].color)ys+='color:'+json[i].color+';';
|
||||
if(va==can.value)col='#e1e1e1';
|
||||
if(json[i].background)col=json[i].background;
|
||||
if(col)ys+='background:'+col+';';
|
||||
s = '<li temp="'+i+'" style="'+ys+'">';
|
||||
var s1 = can.resultbody(json[i], this, i);
|
||||
if(!s1){
|
||||
if(json[i].icons)s+='<img src="'+json[i].icons+'" width="'+can.iconswh+'" height="'+can.iconswh+'" align="absmiddle"> ';
|
||||
s+=va;
|
||||
}else{
|
||||
s+=s1;
|
||||
}
|
||||
s+='</li>';
|
||||
str+=s;
|
||||
}
|
||||
str+='</ul></div></div>';
|
||||
$('body').prepend(str);
|
||||
var oac = $('#rockmenu_'+rand+'');
|
||||
can.aftershow(this);
|
||||
oac.find('li').mouseover(function(){this.className=can.overcls;});
|
||||
oac.find('li').mouseout(function(){this.className='';});
|
||||
oac.find('li').click(function(){me.itemsclick(this);});
|
||||
if(can.width!=0){
|
||||
$('#rockmenuli_'+rand+'').css('width',''+can.width+'px');
|
||||
};
|
||||
js.addbody(rand, 'remove', 'rockmenu_'+rand+'');
|
||||
this.mdivobj = oac;
|
||||
this.setweizhi();
|
||||
};
|
||||
this.showAt = function(l, t, w){
|
||||
this.setcontent();
|
||||
var oac = this.mdivobj;
|
||||
if(!oac)return;
|
||||
if(w)this.setWidth(w);
|
||||
this._reshewhere(l,t);
|
||||
};
|
||||
this.offset=function(l,t){
|
||||
this._reshewhere(l,t);
|
||||
};
|
||||
this.getHeight = function(){
|
||||
return get('rockmenu_'+rand+'').scrollHeight;
|
||||
};
|
||||
this._reshewhere=function(l,t){
|
||||
var oac = this.mdivobj;
|
||||
var jg = (l+oac.width()+5 - winWb()),jg1=0;
|
||||
if(jg>0)l=l-jg;
|
||||
jg1 = t+get('rockmenu_'+rand+'').scrollHeight+10-winHb();
|
||||
if(jg1>0)t=t-jg1;
|
||||
if(t<5)t=5;
|
||||
oac.css({'left':''+l+'px','top':''+t+'px'});
|
||||
};
|
||||
this.setValue = function(v){
|
||||
can.value = v;
|
||||
};
|
||||
this.removeItems = function(oi){
|
||||
$('#rockmenu_'+rand+'').find("li[temp='"+oi+"']").remove();
|
||||
};
|
||||
this.setWidth = function(w){
|
||||
var oac = this.mdivobj;
|
||||
if(!oac)return;
|
||||
oac.css({'width':''+w+'px'});
|
||||
};
|
||||
this.setweizhi = function(){
|
||||
var oac = this.mdivobj;
|
||||
if(can.donghua)oac.slideDown(100);
|
||||
oac.show();
|
||||
if(!obj)return;
|
||||
var off = obj.offset(),
|
||||
l = off.left+ can.left,
|
||||
t = off.top+can.top;
|
||||
this._reshewhere(l,t);
|
||||
};
|
||||
//项目单击
|
||||
this.itemsclick = function(o){
|
||||
var oi = parseInt($(o).attr('temp'));
|
||||
can.itemsclick(json[oi],oi,me);
|
||||
if(can.autohide)this.hide();
|
||||
};
|
||||
this.setData = function(da){
|
||||
can.data= da;
|
||||
json = da;
|
||||
can.autoremove = true;
|
||||
};
|
||||
this.remove = function(){
|
||||
this.hide();
|
||||
}
|
||||
};
|
||||
|
||||
$.rockmenu = function(options, dxo){
|
||||
var defaultVal = {
|
||||
data:[],
|
||||
display:'name',//显示的名称
|
||||
left:0,
|
||||
overcls:'li01',
|
||||
maincls:'',
|
||||
top:0,
|
||||
width:0,value:'',
|
||||
iconswh:16,
|
||||
itemsclick:function(){},
|
||||
beforeshow:function(){},
|
||||
aftershow:function(){},
|
||||
autoremove:true,
|
||||
trigger:'click',
|
||||
autohide:true,
|
||||
arrowup:false, //是否有箭头
|
||||
background:'#ffffff',//背景颜色
|
||||
bgcolor:'',
|
||||
resultbody:function(){
|
||||
return '';
|
||||
},
|
||||
donghua:false
|
||||
};
|
||||
var can = $.extend({}, defaultVal, options);
|
||||
var menu = new rockmenu(dxo, can);
|
||||
menu.init();
|
||||
return menu;
|
||||
}
|
||||
|
||||
$.fn.rockmenu = function(options){
|
||||
return $.rockmenu(options, $(this));
|
||||
};
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,201 @@
|
||||
/*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh)
|
||||
* Licensed under the MIT License (LICENSE.txt).
|
||||
*
|
||||
* Version: 3.1.9
|
||||
*
|
||||
* Requires: jQuery 1.2.2+
|
||||
*/
|
||||
|
||||
(function (factory) {
|
||||
if ( typeof define === 'function' && define.amd ) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery'], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node/CommonJS style for Browserify
|
||||
module.exports = factory;
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
|
||||
var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
|
||||
toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
|
||||
['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
|
||||
slice = Array.prototype.slice,
|
||||
nullLowestDeltaTimeout, lowestDelta;
|
||||
|
||||
if ( $.event.fixHooks ) {
|
||||
for ( var i = toFix.length; i; ) {
|
||||
$.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
|
||||
}
|
||||
}
|
||||
|
||||
var special = $.event.special.mousewheel = {
|
||||
version: '3.1.9',
|
||||
|
||||
setup: function() {
|
||||
if ( this.addEventListener ) {
|
||||
for ( var i = toBind.length; i; ) {
|
||||
this.addEventListener( toBind[--i], handler, false );
|
||||
}
|
||||
} else {
|
||||
this.onmousewheel = handler;
|
||||
}
|
||||
// Store the line height and page height for this particular element
|
||||
$.data(this, 'mousewheel-line-height', special.getLineHeight(this));
|
||||
$.data(this, 'mousewheel-page-height', special.getPageHeight(this));
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
if ( this.removeEventListener ) {
|
||||
for ( var i = toBind.length; i; ) {
|
||||
this.removeEventListener( toBind[--i], handler, false );
|
||||
}
|
||||
} else {
|
||||
this.onmousewheel = null;
|
||||
}
|
||||
},
|
||||
|
||||
getLineHeight: function(elem) {
|
||||
return parseInt($(elem)['offsetParent' in $.fn ? 'offsetParent' : 'parent']().css('fontSize'), 10);
|
||||
},
|
||||
|
||||
getPageHeight: function(elem) {
|
||||
return $(elem).height();
|
||||
},
|
||||
|
||||
settings: {
|
||||
adjustOldDeltas: true
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.extend({
|
||||
mousewheel: function(fn) {
|
||||
return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');
|
||||
},
|
||||
|
||||
unmousewheel: function(fn) {
|
||||
return this.unbind('mousewheel', fn);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function handler(event) {
|
||||
var orgEvent = event || window.event,
|
||||
args = slice.call(arguments, 1),
|
||||
delta = 0,
|
||||
deltaX = 0,
|
||||
deltaY = 0,
|
||||
absDelta = 0;
|
||||
event = $.event.fix(orgEvent);
|
||||
event.type = 'mousewheel';
|
||||
|
||||
// Old school scrollwheel delta
|
||||
if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
|
||||
if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
|
||||
if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
|
||||
if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
|
||||
|
||||
// Firefox < 17 horizontal scrolling related to DOMMouseScroll event
|
||||
if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
|
||||
deltaX = deltaY * -1;
|
||||
deltaY = 0;
|
||||
}
|
||||
|
||||
// Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
|
||||
delta = deltaY === 0 ? deltaX : deltaY;
|
||||
|
||||
// New school wheel delta (wheel event)
|
||||
if ( 'deltaY' in orgEvent ) {
|
||||
deltaY = orgEvent.deltaY * -1;
|
||||
delta = deltaY;
|
||||
}
|
||||
if ( 'deltaX' in orgEvent ) {
|
||||
deltaX = orgEvent.deltaX;
|
||||
if ( deltaY === 0 ) { delta = deltaX * -1; }
|
||||
}
|
||||
|
||||
// No change actually happened, no reason to go any further
|
||||
if ( deltaY === 0 && deltaX === 0 ) { return; }
|
||||
|
||||
// Need to convert lines and pages to pixels if we aren't already in pixels
|
||||
// There are three delta modes:
|
||||
// * deltaMode 0 is by pixels, nothing to do
|
||||
// * deltaMode 1 is by lines
|
||||
// * deltaMode 2 is by pages
|
||||
if ( orgEvent.deltaMode === 1 ) {
|
||||
var lineHeight = $.data(this, 'mousewheel-line-height');
|
||||
delta *= lineHeight;
|
||||
deltaY *= lineHeight;
|
||||
deltaX *= lineHeight;
|
||||
} else if ( orgEvent.deltaMode === 2 ) {
|
||||
var pageHeight = $.data(this, 'mousewheel-page-height');
|
||||
delta *= pageHeight;
|
||||
deltaY *= pageHeight;
|
||||
deltaX *= pageHeight;
|
||||
}
|
||||
|
||||
// Store lowest absolute delta to normalize the delta values
|
||||
absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
|
||||
|
||||
if ( !lowestDelta || absDelta < lowestDelta ) {
|
||||
lowestDelta = absDelta;
|
||||
|
||||
// Adjust older deltas if necessary
|
||||
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
|
||||
lowestDelta /= 40;
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust older deltas if necessary
|
||||
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
|
||||
// Divide all the things by 40!
|
||||
delta /= 40;
|
||||
deltaX /= 40;
|
||||
deltaY /= 40;
|
||||
}
|
||||
|
||||
// Get a whole, normalized value for the deltas
|
||||
delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
|
||||
deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
|
||||
deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
|
||||
|
||||
// Add information to the event object
|
||||
event.deltaX = deltaX;
|
||||
event.deltaY = deltaY;
|
||||
event.deltaFactor = lowestDelta;
|
||||
// Go ahead and set deltaMode to 0 since we converted to pixels
|
||||
// Although this is a little odd since we overwrite the deltaX/Y
|
||||
// properties with normalized deltas.
|
||||
event.deltaMode = 0;
|
||||
|
||||
// Add event and delta to the front of the arguments
|
||||
args.unshift(event, delta, deltaX, deltaY);
|
||||
|
||||
// Clearout lowestDelta after sometime to better
|
||||
// handle multiple device types that give different
|
||||
// a different lowestDelta
|
||||
// Ex: trackpad = 3 and mouse wheel = 120
|
||||
if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
|
||||
nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
|
||||
|
||||
return ($.event.dispatch || $.event.handle).apply(this, args);
|
||||
}
|
||||
|
||||
function nullLowestDelta() {
|
||||
lowestDelta = null;
|
||||
}
|
||||
|
||||
function shouldAdjustOldDeltas(orgEvent, absDelta) {
|
||||
// If this is an older event and the delta is divisable by 120,
|
||||
// then we are assuming that the browser is treating this as an
|
||||
// older mouse wheel event and that we should divide the deltas
|
||||
// by 40 to try and get a more usable deltaFactor.
|
||||
// Side note, this actually impacts the reported scroll distance
|
||||
// in older browsers and can cause scrolling to be slower than native.
|
||||
// Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
|
||||
return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
|
||||
}
|
||||
|
||||
}));
|
||||
@@ -0,0 +1,127 @@
|
||||
.ps-container .ps-scrollbar-x-rail {
|
||||
position: absolute; /* please don't change 'position' */
|
||||
bottom: 3px; /* there must be 'bottom' for ps-scrollbar-x-rail */
|
||||
height: 5px;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
opacity: 0;
|
||||
filter: alpha(opacity = 0);
|
||||
-o-transition: background-color .2s linear, opacity .2s linear;
|
||||
-webkit-transition: background-color .2s linear, opacity .2s linear;
|
||||
-moz-transition: background-color .2s linear, opacity .2s linear;
|
||||
transition: background-color .2s linear, opacity .2s linear;
|
||||
z-index:10;
|
||||
}
|
||||
|
||||
.ps-container:hover .ps-scrollbar-x-rail,
|
||||
.ps-container.hover .ps-scrollbar-x-rail {
|
||||
opacity: 0.6;
|
||||
filter: alpha(opacity = 60);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-x-rail:hover,
|
||||
.ps-container .ps-scrollbar-x-rail.hover {
|
||||
background-color: #eee;
|
||||
opacity: 0.9;
|
||||
filter: alpha(opacity = 90);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-x-rail.in-scrolling {
|
||||
background-color: #eee;
|
||||
opacity: 0.9;
|
||||
filter: alpha(opacity = 90);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-y-rail {
|
||||
position: absolute; /* please don't change 'position' */
|
||||
right: 3px; /* there must be 'right' for ps-scrollbar-y-rail */
|
||||
width: 5px;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
opacity: 0;
|
||||
filter: alpha(opacity = 0);
|
||||
-o-transition: background-color .2s linear, opacity .2s linear;
|
||||
-webkit-transition: background-color .2s linear, opacity .2s linear;
|
||||
-moz-transition: background-color .2s linear, opacity .2s linear;
|
||||
transition: background-color .2s linear, opacity .2s linear;
|
||||
z-index:10;
|
||||
}
|
||||
|
||||
.ps-container:hover .ps-scrollbar-y-rail,
|
||||
.ps-container.hover .ps-scrollbar-y-rail {
|
||||
opacity: 0.6;
|
||||
filter: alpha(opacity = 60);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-y-rail:hover,
|
||||
.ps-container .ps-scrollbar-y-rail.hover {
|
||||
background-color: #eee;
|
||||
opacity: 0.9;
|
||||
filter: alpha(opacity = 90);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-y-rail.in-scrolling {
|
||||
background-color: #eee;
|
||||
opacity: 0.9;
|
||||
filter: alpha(opacity = 90);
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-x {
|
||||
position: absolute; /* please don't change 'position' */
|
||||
bottom: 0; /* there must be 'bottom' for ps-scrollbar-x */
|
||||
height: 5px;
|
||||
background-color: #aaa;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
-o-transition: background-color .2s linear;
|
||||
-webkit-transition: background-color.2s linear;
|
||||
-moz-transition: background-color .2s linear;
|
||||
transition: background-color .2s linear;
|
||||
}
|
||||
|
||||
.ps-container.ie6 .ps-scrollbar-x {
|
||||
font-size: 0; /* fixed scrollbar height in xp sp3 ie6 */
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-x-rail:hover .ps-scrollbar-x,
|
||||
.ps-container .ps-scrollbar-x-rail.hover .ps-scrollbar-x {
|
||||
background-color: #999;
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-y {
|
||||
position: absolute; /* please don't change 'position' */
|
||||
right: 0; /* there must be 'right' for ps-scrollbar-y */
|
||||
width: 5px;
|
||||
background-color: #aaa;
|
||||
-webkit-border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
-o-transition: background-color .2s linear;
|
||||
-webkit-transition: background-color.2s linear;
|
||||
-moz-transition: background-color .2s linear;
|
||||
transition: background-color .2s linear;
|
||||
}
|
||||
|
||||
.ps-container.ie6 .ps-scrollbar-y {
|
||||
font-size: 0; /* fixed scrollbar height in xp sp3 ie6 */
|
||||
}
|
||||
|
||||
.ps-container .ps-scrollbar-y-rail:hover .ps-scrollbar-y,
|
||||
.ps-container .ps-scrollbar-y-rail.hover .ps-scrollbar-y {
|
||||
background-color: #999;
|
||||
}
|
||||
|
||||
.ps-container.ie .ps-scrollbar-x,
|
||||
.ps-container.ie .ps-scrollbar-y {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.ps-container.ie:hover .ps-scrollbar-x,
|
||||
.ps-container.ie:hover .ps-scrollbar-y,
|
||||
.ps-container.ie.hover .ps-scrollbar-x,
|
||||
.ps-container.ie.hover .ps-scrollbar-y {
|
||||
visibility: visible;
|
||||
}
|
||||
@@ -0,0 +1,878 @@
|
||||
/*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh)
|
||||
* Licensed under the MIT License (LICENSE.txt).
|
||||
*
|
||||
* Version: 3.1.9
|
||||
*
|
||||
* Requires: jQuery 1.2.2+
|
||||
*/
|
||||
|
||||
(function (factory) {
|
||||
if ( typeof define === 'function' && define.amd ) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery'], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node/CommonJS style for Browserify
|
||||
module.exports = factory;
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
|
||||
var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
|
||||
toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
|
||||
['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
|
||||
slice = Array.prototype.slice,
|
||||
nullLowestDeltaTimeout, lowestDelta;
|
||||
|
||||
if ( $.event.fixHooks ) {
|
||||
for ( var i = toFix.length; i; ) {
|
||||
$.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
|
||||
}
|
||||
}
|
||||
|
||||
var special = $.event.special.mousewheel = {
|
||||
version: '3.1.9',
|
||||
|
||||
setup: function() {
|
||||
if ( this.addEventListener ) {
|
||||
for ( var i = toBind.length; i; ) {
|
||||
this.addEventListener( toBind[--i], handler, false );
|
||||
}
|
||||
} else {
|
||||
this.onmousewheel = handler;
|
||||
}
|
||||
// Store the line height and page height for this particular element
|
||||
$.data(this, 'mousewheel-line-height', special.getLineHeight(this));
|
||||
$.data(this, 'mousewheel-page-height', special.getPageHeight(this));
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
if ( this.removeEventListener ) {
|
||||
for ( var i = toBind.length; i; ) {
|
||||
this.removeEventListener( toBind[--i], handler, false );
|
||||
}
|
||||
} else {
|
||||
this.onmousewheel = null;
|
||||
}
|
||||
},
|
||||
|
||||
getLineHeight: function(elem) {
|
||||
return parseInt($(elem)['offsetParent' in $.fn ? 'offsetParent' : 'parent']().css('fontSize'), 10);
|
||||
},
|
||||
|
||||
getPageHeight: function(elem) {
|
||||
return $(elem).height();
|
||||
},
|
||||
|
||||
settings: {
|
||||
adjustOldDeltas: true
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.extend({
|
||||
mousewheel: function(fn) {
|
||||
return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');
|
||||
},
|
||||
|
||||
unmousewheel: function(fn) {
|
||||
return this.unbind('mousewheel', fn);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function handler(event) {
|
||||
var orgEvent = event || window.event,
|
||||
args = slice.call(arguments, 1),
|
||||
delta = 0,
|
||||
deltaX = 0,
|
||||
deltaY = 0,
|
||||
absDelta = 0;
|
||||
event = $.event.fix(orgEvent);
|
||||
event.type = 'mousewheel';
|
||||
|
||||
// Old school scrollwheel delta
|
||||
if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
|
||||
if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
|
||||
if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
|
||||
if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
|
||||
|
||||
// Firefox < 17 horizontal scrolling related to DOMMouseScroll event
|
||||
if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
|
||||
deltaX = deltaY * -1;
|
||||
deltaY = 0;
|
||||
}
|
||||
|
||||
// Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
|
||||
delta = deltaY === 0 ? deltaX : deltaY;
|
||||
|
||||
// New school wheel delta (wheel event)
|
||||
if ( 'deltaY' in orgEvent ) {
|
||||
deltaY = orgEvent.deltaY * -1;
|
||||
delta = deltaY;
|
||||
}
|
||||
if ( 'deltaX' in orgEvent ) {
|
||||
deltaX = orgEvent.deltaX;
|
||||
if ( deltaY === 0 ) { delta = deltaX * -1; }
|
||||
}
|
||||
|
||||
// No change actually happened, no reason to go any further
|
||||
if ( deltaY === 0 && deltaX === 0 ) { return; }
|
||||
|
||||
// Need to convert lines and pages to pixels if we aren't already in pixels
|
||||
// There are three delta modes:
|
||||
// * deltaMode 0 is by pixels, nothing to do
|
||||
// * deltaMode 1 is by lines
|
||||
// * deltaMode 2 is by pages
|
||||
if ( orgEvent.deltaMode === 1 ) {
|
||||
var lineHeight = $.data(this, 'mousewheel-line-height');
|
||||
delta *= lineHeight;
|
||||
deltaY *= lineHeight;
|
||||
deltaX *= lineHeight;
|
||||
} else if ( orgEvent.deltaMode === 2 ) {
|
||||
var pageHeight = $.data(this, 'mousewheel-page-height');
|
||||
delta *= pageHeight;
|
||||
deltaY *= pageHeight;
|
||||
deltaX *= pageHeight;
|
||||
}
|
||||
|
||||
// Store lowest absolute delta to normalize the delta values
|
||||
absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
|
||||
|
||||
if ( !lowestDelta || absDelta < lowestDelta ) {
|
||||
lowestDelta = absDelta;
|
||||
|
||||
// Adjust older deltas if necessary
|
||||
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
|
||||
lowestDelta /= 40;
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust older deltas if necessary
|
||||
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
|
||||
// Divide all the things by 40!
|
||||
delta /= 40;
|
||||
deltaX /= 40;
|
||||
deltaY /= 40;
|
||||
}
|
||||
|
||||
// Get a whole, normalized value for the deltas
|
||||
delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
|
||||
deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
|
||||
deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
|
||||
|
||||
// Add information to the event object
|
||||
event.deltaX = deltaX;
|
||||
event.deltaY = deltaY;
|
||||
event.deltaFactor = lowestDelta;
|
||||
// Go ahead and set deltaMode to 0 since we converted to pixels
|
||||
// Although this is a little odd since we overwrite the deltaX/Y
|
||||
// properties with normalized deltas.
|
||||
event.deltaMode = 0;
|
||||
|
||||
// Add event and delta to the front of the arguments
|
||||
args.unshift(event, delta, deltaX, deltaY);
|
||||
|
||||
// Clearout lowestDelta after sometime to better
|
||||
// handle multiple device types that give different
|
||||
// a different lowestDelta
|
||||
// Ex: trackpad = 3 and mouse wheel = 120
|
||||
if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
|
||||
nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
|
||||
|
||||
return ($.event.dispatch || $.event.handle).apply(this, args);
|
||||
}
|
||||
|
||||
function nullLowestDelta() {
|
||||
lowestDelta = null;
|
||||
}
|
||||
|
||||
function shouldAdjustOldDeltas(orgEvent, absDelta) {
|
||||
// If this is an older event and the delta is divisable by 120,
|
||||
// then we are assuming that the browser is treating this as an
|
||||
// older mouse wheel event and that we should divide the deltas
|
||||
// by 40 to try and get a more usable deltaFactor.
|
||||
// Side note, this actually impacts the reported scroll distance
|
||||
// in older browsers and can cause scrolling to be slower than native.
|
||||
// Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
|
||||
return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
|
||||
|
||||
/* Copyright (c) 2012, 2014 Hyeonje Alex Jun and other contributors
|
||||
* Licensed under the MIT License
|
||||
*/
|
||||
(function (factory) {
|
||||
'use strict';
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery'], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node/CommonJS
|
||||
factory(require('jquery'));
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
'use strict';
|
||||
|
||||
// The default settings for the plugin
|
||||
var defaultSettings = {
|
||||
wheelSpeed: 10,
|
||||
wheelPropagation: false,
|
||||
minScrollbarLength: null,
|
||||
useBothWheelAxes: false,
|
||||
useKeyboard: true,
|
||||
suppressScrollX: false,
|
||||
suppressScrollY: false,
|
||||
scrollXMarginOffset: 0,
|
||||
scrollYMarginOffset: 0,
|
||||
includePadding: false
|
||||
};
|
||||
|
||||
var getEventClassName = (function () {
|
||||
var incrementingId = 0;
|
||||
return function () {
|
||||
var id = incrementingId;
|
||||
incrementingId += 1;
|
||||
return '.perfect-scrollbar-' + id;
|
||||
};
|
||||
}());
|
||||
|
||||
$.fn.perfectScrollbar = function (suppliedSettings, option) {
|
||||
|
||||
return this.each(function () {
|
||||
// Use the default settings
|
||||
var settings = $.extend(true, {}, defaultSettings),
|
||||
$this = $(this);
|
||||
|
||||
if (typeof suppliedSettings === "object") {
|
||||
// But over-ride any supplied
|
||||
$.extend(true, settings, suppliedSettings);
|
||||
} else {
|
||||
// If no settings were supplied, then the first param must be the option
|
||||
option = suppliedSettings;
|
||||
}
|
||||
|
||||
// Catch options
|
||||
|
||||
if (option === 'update') {
|
||||
if ($this.data('perfect-scrollbar-update')) {
|
||||
$this.data('perfect-scrollbar-update')();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
else if (option === 'destroy') {
|
||||
if ($this.data('perfect-scrollbar-destroy')) {
|
||||
$this.data('perfect-scrollbar-destroy')();
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($this.data('perfect-scrollbar')) {
|
||||
// if there's already perfect-scrollbar
|
||||
return $this.data('perfect-scrollbar');
|
||||
}
|
||||
|
||||
|
||||
// Or generate new perfectScrollbar
|
||||
|
||||
// Set class to the container
|
||||
$this.addClass('ps-container');
|
||||
|
||||
var $scrollbarXRail = $("<div class='ps-scrollbar-x-rail'></div>").appendTo($this),
|
||||
$scrollbarYRail = $("<div class='ps-scrollbar-y-rail'></div>").appendTo($this),
|
||||
$scrollbarX = $("<div class='ps-scrollbar-x'></div>").appendTo($scrollbarXRail),
|
||||
$scrollbarY = $("<div class='ps-scrollbar-y'></div>").appendTo($scrollbarYRail),
|
||||
scrollbarXActive,
|
||||
scrollbarYActive,
|
||||
containerWidth,
|
||||
containerHeight,
|
||||
contentWidth,
|
||||
contentHeight,
|
||||
scrollbarXWidth,
|
||||
scrollbarXLeft,
|
||||
scrollbarXBottom = parseInt($scrollbarXRail.css('bottom'), 10),
|
||||
isScrollbarXUsingBottom = scrollbarXBottom === scrollbarXBottom, // !isNaN
|
||||
scrollbarXTop = isScrollbarXUsingBottom ? null : parseInt($scrollbarXRail.css('top'), 10),
|
||||
scrollbarYHeight,
|
||||
scrollbarYTop,
|
||||
scrollbarYRight = parseInt($scrollbarYRail.css('right'), 10),
|
||||
isScrollbarYUsingRight = scrollbarYRight === scrollbarYRight, // !isNaN
|
||||
scrollbarYLeft = isScrollbarYUsingRight ? null: parseInt($scrollbarYRail.css('left'), 10),
|
||||
isRtl = $this.css('direction') === "rtl",
|
||||
eventClassName = getEventClassName();
|
||||
|
||||
var updateContentScrollTop = function (currentTop, deltaY) {
|
||||
var newTop = currentTop + deltaY,
|
||||
maxTop = containerHeight - scrollbarYHeight;
|
||||
|
||||
if (newTop < 0) {
|
||||
scrollbarYTop = 0;
|
||||
}
|
||||
else if (newTop > maxTop) {
|
||||
scrollbarYTop = maxTop;
|
||||
}
|
||||
else {
|
||||
scrollbarYTop = newTop;
|
||||
}
|
||||
|
||||
var scrollTop = parseInt(scrollbarYTop * (contentHeight - containerHeight) / (containerHeight - scrollbarYHeight), 10);
|
||||
$this.scrollTop(scrollTop);
|
||||
|
||||
if (isScrollbarXUsingBottom) {
|
||||
$scrollbarXRail.css({bottom: scrollbarXBottom - scrollTop});
|
||||
} else {
|
||||
$scrollbarXRail.css({top: scrollbarXTop + scrollTop});
|
||||
}
|
||||
};
|
||||
|
||||
var updateContentScrollLeft = function (currentLeft, deltaX) {
|
||||
var newLeft = currentLeft + deltaX,
|
||||
maxLeft = containerWidth - scrollbarXWidth;
|
||||
|
||||
if (newLeft < 0) {
|
||||
scrollbarXLeft = 0;
|
||||
}
|
||||
else if (newLeft > maxLeft) {
|
||||
scrollbarXLeft = maxLeft;
|
||||
}
|
||||
else {
|
||||
scrollbarXLeft = newLeft;
|
||||
}
|
||||
|
||||
var scrollLeft = parseInt(scrollbarXLeft * (contentWidth - containerWidth) / (containerWidth - scrollbarXWidth), 10);
|
||||
$this.scrollLeft(scrollLeft);
|
||||
|
||||
if (isScrollbarYUsingRight) {
|
||||
$scrollbarYRail.css({right: scrollbarYRight - scrollLeft});
|
||||
} else {
|
||||
$scrollbarYRail.css({left: scrollbarYLeft + scrollLeft});
|
||||
}
|
||||
};
|
||||
|
||||
var getSettingsAdjustedThumbSize = function (thumbSize) {
|
||||
if (settings.minScrollbarLength) {
|
||||
thumbSize = Math.max(thumbSize, settings.minScrollbarLength);
|
||||
}
|
||||
return thumbSize;
|
||||
};
|
||||
|
||||
var updateScrollbarCss = function () {
|
||||
var scrollbarXStyles = {width: containerWidth, display: scrollbarXActive ? "inherit": "none"};
|
||||
if (isRtl) {
|
||||
scrollbarXStyles.left = $this.scrollLeft() + containerWidth - contentWidth;
|
||||
} else {
|
||||
scrollbarXStyles.left = $this.scrollLeft();
|
||||
}
|
||||
if (isScrollbarXUsingBottom) {
|
||||
scrollbarXStyles.bottom = scrollbarXBottom - $this.scrollTop();
|
||||
} else {
|
||||
scrollbarXStyles.top = scrollbarXTop + $this.scrollTop();
|
||||
}
|
||||
$scrollbarXRail.css(scrollbarXStyles);
|
||||
|
||||
var scrollbarYStyles = {top: $this.scrollTop(), height: containerHeight, display: scrollbarYActive ? "inherit": "none"};
|
||||
|
||||
if (isScrollbarYUsingRight) {
|
||||
if (isRtl) {
|
||||
scrollbarYStyles.right = contentWidth - $this.scrollLeft() - scrollbarYRight - $scrollbarY.outerWidth();
|
||||
} else {
|
||||
scrollbarYStyles.right = scrollbarYRight - $this.scrollLeft();
|
||||
}
|
||||
} else {
|
||||
if (isRtl) {
|
||||
scrollbarYStyles.left = $this.scrollLeft() + containerWidth * 2 - contentWidth - scrollbarYLeft - $scrollbarY.outerWidth();
|
||||
} else {
|
||||
scrollbarYStyles.left = scrollbarYLeft + $this.scrollLeft();
|
||||
}
|
||||
}
|
||||
$scrollbarYRail.css(scrollbarYStyles);
|
||||
|
||||
$scrollbarX.css({left: scrollbarXLeft, width: scrollbarXWidth});
|
||||
$scrollbarY.css({top: scrollbarYTop, height: scrollbarYHeight});
|
||||
};
|
||||
|
||||
var updateBarSizeAndPosition = function () {
|
||||
containerWidth = settings.includePadding ? $this.innerWidth() : $this.width();
|
||||
containerHeight = settings.includePadding ? $this.innerHeight() : $this.height();
|
||||
contentWidth = $this.prop('scrollWidth');
|
||||
contentHeight = $this.prop('scrollHeight');
|
||||
|
||||
if (!settings.suppressScrollX && containerWidth + settings.scrollXMarginOffset < contentWidth) {
|
||||
scrollbarXActive = true;
|
||||
scrollbarXWidth = getSettingsAdjustedThumbSize(parseInt(containerWidth * containerWidth / contentWidth, 10));
|
||||
scrollbarXLeft = parseInt($this.scrollLeft() * (containerWidth - scrollbarXWidth) / (contentWidth - containerWidth), 10);
|
||||
}
|
||||
else {
|
||||
scrollbarXActive = false;
|
||||
scrollbarXWidth = 0;
|
||||
scrollbarXLeft = 0;
|
||||
$this.scrollLeft(0);
|
||||
}
|
||||
|
||||
if (!settings.suppressScrollY && containerHeight + settings.scrollYMarginOffset < contentHeight) {
|
||||
scrollbarYActive = true;
|
||||
scrollbarYHeight = getSettingsAdjustedThumbSize(parseInt(containerHeight * containerHeight / contentHeight, 10));
|
||||
scrollbarYTop = parseInt($this.scrollTop() * (containerHeight - scrollbarYHeight) / (contentHeight - containerHeight), 10);
|
||||
}
|
||||
else {
|
||||
scrollbarYActive = false;
|
||||
scrollbarYHeight = 0;
|
||||
scrollbarYTop = 0;
|
||||
$this.scrollTop(0);
|
||||
}
|
||||
|
||||
if (scrollbarYTop >= containerHeight - scrollbarYHeight) {
|
||||
scrollbarYTop = containerHeight - scrollbarYHeight;
|
||||
}
|
||||
if (scrollbarXLeft >= containerWidth - scrollbarXWidth) {
|
||||
scrollbarXLeft = containerWidth - scrollbarXWidth;
|
||||
}
|
||||
|
||||
updateScrollbarCss();
|
||||
};
|
||||
|
||||
var bindMouseScrollXHandler = function () {
|
||||
var currentLeft,
|
||||
currentPageX;
|
||||
|
||||
$scrollbarX.bind('mousedown' + eventClassName, function (e) {
|
||||
currentPageX = e.pageX;
|
||||
currentLeft = $scrollbarX.position().left;
|
||||
$scrollbarXRail.addClass('in-scrolling');
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind('mousemove' + eventClassName, function (e) {
|
||||
if ($scrollbarXRail.hasClass('in-scrolling')) {
|
||||
updateContentScrollLeft(currentLeft, e.pageX - currentPageX);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).bind('mouseup' + eventClassName, function (e) {
|
||||
if ($scrollbarXRail.hasClass('in-scrolling')) {
|
||||
$scrollbarXRail.removeClass('in-scrolling');
|
||||
}
|
||||
});
|
||||
|
||||
currentLeft =
|
||||
currentPageX = null;
|
||||
};
|
||||
|
||||
var bindMouseScrollYHandler = function () {
|
||||
var currentTop,
|
||||
currentPageY;
|
||||
|
||||
$scrollbarY.bind('mousedown' + eventClassName, function (e) {
|
||||
currentPageY = e.pageY;
|
||||
currentTop = $scrollbarY.position().top;
|
||||
$scrollbarYRail.addClass('in-scrolling');
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind('mousemove' + eventClassName, function (e) {
|
||||
if ($scrollbarYRail.hasClass('in-scrolling')) {
|
||||
updateContentScrollTop(currentTop, e.pageY - currentPageY);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).bind('mouseup' + eventClassName, function (e) {
|
||||
if ($scrollbarYRail.hasClass('in-scrolling')) {
|
||||
$scrollbarYRail.removeClass('in-scrolling');
|
||||
}
|
||||
});
|
||||
|
||||
currentTop =
|
||||
currentPageY = null;
|
||||
};
|
||||
|
||||
// check if the default scrolling should be prevented.
|
||||
var shouldPreventDefault = function (deltaX, deltaY) {
|
||||
var scrollTop = $this.scrollTop();
|
||||
if (deltaX === 0) {
|
||||
if (!scrollbarYActive) {
|
||||
return false;
|
||||
}
|
||||
if ((scrollTop === 0 && deltaY > 0) || (scrollTop >= contentHeight - containerHeight && deltaY < 0)) {
|
||||
return !settings.wheelPropagation;
|
||||
}
|
||||
}
|
||||
|
||||
var scrollLeft = $this.scrollLeft();
|
||||
if (deltaY === 0) {
|
||||
if (!scrollbarXActive) {
|
||||
return false;
|
||||
}
|
||||
if ((scrollLeft === 0 && deltaX < 0) || (scrollLeft >= contentWidth - containerWidth && deltaX > 0)) {
|
||||
return !settings.wheelPropagation;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// bind handlers
|
||||
var bindMouseWheelHandler = function () {
|
||||
// FIXME: Backward compatibility.
|
||||
// After e.deltaFactor applied, wheelSpeed should have smaller value.
|
||||
// Currently, there's no way to change the settings after the scrollbar initialized.
|
||||
// But if the way is implemented in the future, wheelSpeed should be reset.
|
||||
settings.wheelSpeed /= 10;
|
||||
|
||||
var shouldPrevent = false;
|
||||
$this.bind('mousewheel' + eventClassName, function (e, deprecatedDelta, deprecatedDeltaX, deprecatedDeltaY) {
|
||||
var deltaX = e.deltaX * e.deltaFactor || deprecatedDeltaX,
|
||||
deltaY = e.deltaY * e.deltaFactor || deprecatedDeltaY;
|
||||
|
||||
shouldPrevent = false;
|
||||
if (!settings.useBothWheelAxes) {
|
||||
// deltaX will only be used for horizontal scrolling and deltaY will
|
||||
// only be used for vertical scrolling - this is the default
|
||||
$this.scrollTop($this.scrollTop() - (deltaY * settings.wheelSpeed));
|
||||
$this.scrollLeft($this.scrollLeft() + (deltaX * settings.wheelSpeed));
|
||||
} else if (scrollbarYActive && !scrollbarXActive) {
|
||||
// only vertical scrollbar is active and useBothWheelAxes option is
|
||||
// active, so let's scroll vertical bar using both mouse wheel axes
|
||||
if (deltaY) {
|
||||
$this.scrollTop($this.scrollTop() - (deltaY * settings.wheelSpeed));
|
||||
} else {
|
||||
$this.scrollTop($this.scrollTop() + (deltaX * settings.wheelSpeed));
|
||||
}
|
||||
shouldPrevent = true;
|
||||
} else if (scrollbarXActive && !scrollbarYActive) {
|
||||
// useBothWheelAxes and only horizontal bar is active, so use both
|
||||
// wheel axes for horizontal bar
|
||||
if (deltaX) {
|
||||
$this.scrollLeft($this.scrollLeft() + (deltaX * settings.wheelSpeed));
|
||||
} else {
|
||||
$this.scrollLeft($this.scrollLeft() - (deltaY * settings.wheelSpeed));
|
||||
}
|
||||
shouldPrevent = true;
|
||||
}
|
||||
|
||||
// update bar position
|
||||
updateBarSizeAndPosition();
|
||||
|
||||
shouldPrevent = (shouldPrevent || shouldPreventDefault(deltaX, deltaY));
|
||||
if (shouldPrevent) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
// fix Firefox scroll problem
|
||||
$this.bind('MozMousePixelScroll' + eventClassName, function (e) {
|
||||
if (shouldPrevent) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var bindKeyboardHandler = function () {
|
||||
var hovered = false;
|
||||
$this.bind('mouseenter' + eventClassName, function (e) {
|
||||
hovered = true;
|
||||
});
|
||||
$this.bind('mouseleave' + eventClassName, function (e) {
|
||||
hovered = false;
|
||||
});
|
||||
|
||||
var shouldPrevent = false;
|
||||
$(document).bind('keydown' + eventClassName, function (e) {
|
||||
if (!hovered || $(document.activeElement).is(":input,[contenteditable]")) {
|
||||
return;
|
||||
}
|
||||
|
||||
var deltaX = 0,
|
||||
deltaY = 0;
|
||||
|
||||
switch (e.which) {
|
||||
case 37: // left
|
||||
deltaX = -30;
|
||||
break;
|
||||
case 38: // up
|
||||
deltaY = 30;
|
||||
break;
|
||||
case 39: // right
|
||||
deltaX = 30;
|
||||
break;
|
||||
case 40: // down
|
||||
deltaY = -30;
|
||||
break;
|
||||
case 33: // page up
|
||||
deltaY = 90;
|
||||
break;
|
||||
case 32: // space bar
|
||||
case 34: // page down
|
||||
deltaY = -90;
|
||||
break;
|
||||
case 35: // end
|
||||
deltaY = -containerHeight;
|
||||
break;
|
||||
case 36: // home
|
||||
deltaY = containerHeight;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
$this.scrollTop($this.scrollTop() - deltaY);
|
||||
$this.scrollLeft($this.scrollLeft() + deltaX);
|
||||
|
||||
shouldPrevent = shouldPreventDefault(deltaX, deltaY);
|
||||
if (shouldPrevent) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var bindRailClickHandler = function () {
|
||||
var stopPropagation = function (e) { e.stopPropagation(); };
|
||||
|
||||
$scrollbarY.bind('click' + eventClassName, stopPropagation);
|
||||
$scrollbarYRail.bind('click' + eventClassName, function (e) {
|
||||
var halfOfScrollbarLength = parseInt(scrollbarYHeight / 2, 10),
|
||||
positionTop = e.pageY - $scrollbarYRail.offset().top - halfOfScrollbarLength,
|
||||
maxPositionTop = containerHeight - scrollbarYHeight,
|
||||
positionRatio = positionTop / maxPositionTop;
|
||||
|
||||
if (positionRatio < 0) {
|
||||
positionRatio = 0;
|
||||
} else if (positionRatio > 1) {
|
||||
positionRatio = 1;
|
||||
}
|
||||
|
||||
$this.scrollTop((contentHeight - containerHeight) * positionRatio);
|
||||
});
|
||||
|
||||
$scrollbarX.bind('click' + eventClassName, stopPropagation);
|
||||
$scrollbarXRail.bind('click' + eventClassName, function (e) {
|
||||
var halfOfScrollbarLength = parseInt(scrollbarXWidth / 2, 10),
|
||||
positionLeft = e.pageX - $scrollbarXRail.offset().left - halfOfScrollbarLength,
|
||||
maxPositionLeft = containerWidth - scrollbarXWidth,
|
||||
positionRatio = positionLeft / maxPositionLeft;
|
||||
|
||||
if (positionRatio < 0) {
|
||||
positionRatio = 0;
|
||||
} else if (positionRatio > 1) {
|
||||
positionRatio = 1;
|
||||
}
|
||||
|
||||
$this.scrollLeft((contentWidth - containerWidth) * positionRatio);
|
||||
});
|
||||
};
|
||||
|
||||
// bind mobile touch handler
|
||||
var bindMobileTouchHandler = function () {
|
||||
var applyTouchMove = function (differenceX, differenceY) {
|
||||
$this.scrollTop($this.scrollTop() - differenceY);
|
||||
$this.scrollLeft($this.scrollLeft() - differenceX);
|
||||
|
||||
// update bar position
|
||||
updateBarSizeAndPosition();
|
||||
};
|
||||
|
||||
var startCoords = {},
|
||||
startTime = 0,
|
||||
speed = {},
|
||||
breakingProcess = null,
|
||||
inGlobalTouch = false;
|
||||
|
||||
$(window).bind("touchstart" + eventClassName, function (e) {
|
||||
inGlobalTouch = true;
|
||||
});
|
||||
$(window).bind("touchend" + eventClassName, function (e) {
|
||||
inGlobalTouch = false;
|
||||
});
|
||||
|
||||
$this.bind("touchstart" + eventClassName, function (e) {
|
||||
var touch = e.originalEvent.targetTouches[0];
|
||||
|
||||
startCoords.pageX = touch.pageX;
|
||||
startCoords.pageY = touch.pageY;
|
||||
|
||||
startTime = (new Date()).getTime();
|
||||
|
||||
if (breakingProcess !== null) {
|
||||
clearInterval(breakingProcess);
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
});
|
||||
$this.bind("touchmove" + eventClassName, function (e) {
|
||||
if (!inGlobalTouch && e.originalEvent.targetTouches.length === 1) {
|
||||
var touch = e.originalEvent.targetTouches[0];
|
||||
|
||||
var currentCoords = {};
|
||||
currentCoords.pageX = touch.pageX;
|
||||
currentCoords.pageY = touch.pageY;
|
||||
|
||||
var differenceX = currentCoords.pageX - startCoords.pageX,
|
||||
differenceY = currentCoords.pageY - startCoords.pageY;
|
||||
|
||||
applyTouchMove(differenceX, differenceY);
|
||||
startCoords = currentCoords;
|
||||
|
||||
var currentTime = (new Date()).getTime();
|
||||
|
||||
var timeGap = currentTime - startTime;
|
||||
if (timeGap > 0) {
|
||||
speed.x = differenceX / timeGap;
|
||||
speed.y = differenceY / timeGap;
|
||||
startTime = currentTime;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
$this.bind("touchend" + eventClassName, function (e) {
|
||||
clearInterval(breakingProcess);
|
||||
breakingProcess = setInterval(function () {
|
||||
if (Math.abs(speed.x) < 0.01 && Math.abs(speed.y) < 0.01) {
|
||||
clearInterval(breakingProcess);
|
||||
return;
|
||||
}
|
||||
|
||||
applyTouchMove(speed.x * 30, speed.y * 30);
|
||||
|
||||
speed.x *= 0.8;
|
||||
speed.y *= 0.8;
|
||||
}, 10);
|
||||
});
|
||||
};
|
||||
|
||||
var bindScrollHandler = function () {
|
||||
$this.bind('scroll' + eventClassName, function (e) {
|
||||
updateBarSizeAndPosition();
|
||||
});
|
||||
};
|
||||
|
||||
var destroy = function () {
|
||||
$this.unbind(eventClassName);
|
||||
$(window).unbind(eventClassName);
|
||||
$(document).unbind(eventClassName);
|
||||
$this.data('perfect-scrollbar', null);
|
||||
$this.data('perfect-scrollbar-update', null);
|
||||
$this.data('perfect-scrollbar-destroy', null);
|
||||
$scrollbarX.remove();
|
||||
$scrollbarY.remove();
|
||||
$scrollbarXRail.remove();
|
||||
$scrollbarYRail.remove();
|
||||
|
||||
// clean all variables
|
||||
$scrollbarXRail =
|
||||
$scrollbarYRail =
|
||||
$scrollbarX =
|
||||
$scrollbarY =
|
||||
scrollbarXActive =
|
||||
scrollbarYActive =
|
||||
containerWidth =
|
||||
containerHeight =
|
||||
contentWidth =
|
||||
contentHeight =
|
||||
scrollbarXWidth =
|
||||
scrollbarXLeft =
|
||||
scrollbarXBottom =
|
||||
isScrollbarXUsingBottom =
|
||||
scrollbarXTop =
|
||||
scrollbarYHeight =
|
||||
scrollbarYTop =
|
||||
scrollbarYRight =
|
||||
isScrollbarYUsingRight =
|
||||
scrollbarYLeft =
|
||||
isRtl =
|
||||
eventClassName = null;
|
||||
};
|
||||
|
||||
var ieSupport = function (version) {
|
||||
$this.addClass('ie').addClass('ie' + version);
|
||||
|
||||
var bindHoverHandlers = function () {
|
||||
var mouseenter = function () {
|
||||
$(this).addClass('hover');
|
||||
};
|
||||
var mouseleave = function () {
|
||||
$(this).removeClass('hover');
|
||||
};
|
||||
$this.bind('mouseenter' + eventClassName, mouseenter).bind('mouseleave' + eventClassName, mouseleave);
|
||||
$scrollbarXRail.bind('mouseenter' + eventClassName, mouseenter).bind('mouseleave' + eventClassName, mouseleave);
|
||||
$scrollbarYRail.bind('mouseenter' + eventClassName, mouseenter).bind('mouseleave' + eventClassName, mouseleave);
|
||||
$scrollbarX.bind('mouseenter' + eventClassName, mouseenter).bind('mouseleave' + eventClassName, mouseleave);
|
||||
$scrollbarY.bind('mouseenter' + eventClassName, mouseenter).bind('mouseleave' + eventClassName, mouseleave);
|
||||
};
|
||||
|
||||
var fixIe6ScrollbarPosition = function () {
|
||||
updateScrollbarCss = function () {
|
||||
var scrollbarXStyles = {left: scrollbarXLeft + $this.scrollLeft(), width: scrollbarXWidth};
|
||||
if (isScrollbarXUsingBottom) {
|
||||
scrollbarXStyles.bottom = scrollbarXBottom;
|
||||
} else {
|
||||
scrollbarXStyles.top = scrollbarXTop;
|
||||
}
|
||||
$scrollbarX.css(scrollbarXStyles);
|
||||
|
||||
var scrollbarYStyles = {top: scrollbarYTop + $this.scrollTop(), height: scrollbarYHeight};
|
||||
if (isScrollbarYUsingRight) {
|
||||
scrollbarYStyles.right = scrollbarYRight;
|
||||
} else {
|
||||
scrollbarYStyles.left = scrollbarYLeft;
|
||||
}
|
||||
|
||||
$scrollbarY.css(scrollbarYStyles);
|
||||
$scrollbarX.hide().show();
|
||||
$scrollbarY.hide().show();
|
||||
};
|
||||
};
|
||||
|
||||
if (version === 6) {
|
||||
bindHoverHandlers();
|
||||
fixIe6ScrollbarPosition();
|
||||
}
|
||||
};
|
||||
|
||||
var supportsTouch = (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch);
|
||||
|
||||
var initialize = function () {
|
||||
var ieMatch = navigator.userAgent.toLowerCase().match(/(msie) ([\w.]+)/);
|
||||
if (ieMatch && ieMatch[1] === 'msie') {
|
||||
// must be executed at first, because 'ieSupport' may addClass to the container
|
||||
ieSupport(parseInt(ieMatch[2], 10));
|
||||
}
|
||||
|
||||
updateBarSizeAndPosition();
|
||||
bindScrollHandler();
|
||||
bindMouseScrollXHandler();
|
||||
bindMouseScrollYHandler();
|
||||
bindRailClickHandler();
|
||||
if (supportsTouch) {
|
||||
bindMobileTouchHandler();
|
||||
}
|
||||
if ($this.mousewheel) {
|
||||
bindMouseWheelHandler();
|
||||
}
|
||||
if (settings.useKeyboard) {
|
||||
bindKeyboardHandler();
|
||||
}
|
||||
$this.data('perfect-scrollbar', $this);
|
||||
$this.data('perfect-scrollbar-update', updateBarSizeAndPosition);
|
||||
$this.data('perfect-scrollbar-destroy', destroy);
|
||||
};
|
||||
|
||||
// initialize
|
||||
initialize();
|
||||
|
||||
return $this;
|
||||
});
|
||||
};
|
||||
}));
|
||||
Reference in New Issue
Block a user