📄 thinkjavascript[1].0.0.2.js
字号:
}); return this; }, setStyle:function(name,value){ this.elements.each(function(el){ switch(name){ case 'opacity': return this.setOpacity(value.toFloat()); break; case 'float': name=ThinkJS.msie?'styleFloat':'cssFloat'; break; } name=name.camelize(); switch(ThinkJS.type(value)){ case 'number': if(!['zIndex','zoom'].contain(name)){value+='px';} break; case 'array': value='rgb('+value.join(',')+')'; break; } el.style[name]=value; },this); return this; }, setCSS:function(key,value){ if(ThinkJS.type(key)=='object'){ this.elements.each(function(el){ for(o in key){this.setStyle(o,key[o]);} },this); }else{ this.setStyle(key,value); } return this; }, getCSS:function(n){ var rs,el=this.elements[parseInt(n).limit(0, this.elements.length)]; var win=(el.ownerDocument||el.documentElement).defaultView; if(win&&(el!==win)&&win.getComputedStyle){ rs=win.getComputedStyle(el,null); }else{ rs=el.style; } return rs; }, hasClass:function(cn,n){ this.elements[parseInt(n).limit(0, this.length)].className.contain(cn,' '); return this; }, addClass:function(cn){ this.elements.each(function(el){ if(!el.className.contain(cn,' ')){el.className=(el.className+' '+cn).clean();} }); return this; }, removeClass:function(cn){ this.elements.each(function(el){ if(el.className.contain(cn,' ')){el.className=el.className.replace(new RegExp('(^|\\s)'+cn+'(?:\\s|$)'),'$1').clean();} }); return this; }, toggleClass:function(cn){ this.elements.each(function(el){ el.className=(el.className.contain(cn,' ')?el.className.replace(new RegExp('(^|\\s)'+cn+'(?:\\s|$)'),'$1'):(el.className+' '+cn)).clean(); }); return this; }, switchClass:function(cn,nc){ this.elements.each(function(el){ if(el.className.contain(cn,' ')){ el.className=(el.className.replace(new RegExp('(^|\\s)'+cn+'(?:\\s|$)'),'$1')+' '+nc).clean(); }else if(el.className.contain(nc,' ')){ el.className=(el.className.replace(new RegExp('(^|\\s)'+nc+'(?:\\s|$)'),'$1')+' '+cn).clean(); }else{ el.className=(el.className+' '+cn).clean(); } }); return this; }, getProperty:function(key,n){ var rs,el=this.elements[parseInt(n).limit(0, this.elements.length)]; if(this._attrs[key]){ rs=el[this._attrs[key]]; }else{ var ig=this._flags[key]||0; if(!ThinkJS.msie||ig){ rs=el.getAttribute(key,ig); }else{ var node=el.attributes[key]; rs=node?node.nodeValue:null; } } return rs; }, setProperty:function(key,value){ this.elements.each(function(el){ if(this._attrs[key]){ el[this._attrs[key]]=value; }else{ el.setAttribute(key,value); } },this); return this; }, removeProperty:function(key){ this.elements.each(function(el){ if(this._attrs[key]){ el[this._attrs[key]]=''; }else{ el.removeAttribute(key); } },this); return this; }, getWidth:function(n){ var rs=0,el=this.elements[parseInt(n).limit(0, this.elements.length)]; if(el.style.visibility=='hidden'){ el.style.visibility='visible'; rs=Math.max(parseInt(el.offsetWidth),parseInt(el.style.width)); el.style.visibility='hidden'; }else{ rs=Math.max(parseInt(el.offsetWidth),parseInt(el.style.width)); } return rs; }, setWidth:function(width,n){ if(ThinkJS.is(n)){ this.elements[parseInt(n).limit(0, this.elements.length)].style.width=width+'px'; }else{ this.elements.each(function(el){ el.style.width=width+'px'; }); } return this; }, getHeight:function(n){ var rs=0,el=this.elements[parseInt(n).limit(0, this.elements.length)]; if(el.style.visibility=='hidden'){ el.style.visibility='visible'; rs=Math.max(parseInt(el.offsetHeight),parseInt(el.style.height)); el.style.visibility='hidden'; }else{ rs=Math.max(parseInt(el.offsetHeight),parseInt(el.style.height)); } return rs; }, setHeight:function(height,n){ if(ThinkJS.is(n)){ this.elements[parseInt(n).limit(0, this.elements.length)].style.height=height+'px'; }else{ this.elements.each(function(el){ el.style.height=height+'px'; }); } return this; }, getXY:function(n,off){ var el=this.elements[parseInt(n).limit(0, this.elements.length)],left=0,top=0; do{ left+=el.offsetLeft||0; top+=el.offsetTop||0; }while(el=el.offsetParent); if(off){ ThinkJS.merge(off).each(function(e){ left-=e.scrollLeft||0; top-=e.scrollTop||0; }); } return {'x':left,'y':top}; }, setXY:function(x,y){ this.elements.each(function(el){ el.style.position='absolute'; el.style.left=x+'px'; el.style.top=y+'px'; }); return this; }, setHTML:function(where,html){ where=where.toLowerCase(); this.elements.each(function(el){ if(el.insertAdjacentHTML){ switch(where){ case 'beforbegin': el.insertAdjacentHTML('BeforeBegin',html); break; case 'afterbegin': el.insertAdjacentHTML('AfterBegin',html); break; case 'beforeend': el.insertAdjacentHTML('BeforeEnd',html); break; case 'afterend': el.insertAdjacentHTML('AfterEnd',html); break; } }else{ var frag,range=el.ownerDocument.createRange(); switch(where){ case 'beforbegin': range.setStartBefore(el); frag=range.createContextualFragment(html); el.parentNode.insertBefore(frag,el); break; case 'afterbegin': if(el.firstChild){ range.setStartBefore(el.firstChild); frag=range.createContextualFragment(html); el.insertBefore(frag,el.firstChild); }else{ el.innerHTML=html; } break; case 'beforeend': if(el.lastChild){ range.setStartAfter(el.lastChild); frag=range.createContextualFragment(html); el.appendChild(frag); }else{ el.innerHTML=html; } break; case 'afterend': range.setStartAfter(el); frag=range.createContextualFragment(html); el.parentNode.insertBefore(frag,el.nextSibling); break; } } }); return this; }, getHTML:function(n){ var rs,el=this.elements[parseInt(n).limit(0, this.elements.length)]; if(el.outerHTML){ rs=el.outerHTML; }else{ var attr,i=0,attrs=el.attributes; rs='<'+el.tagName; while(attr=attrs[i++]){ if(attr.specified){ rs+=' '+attr.name+'="'+attr.value+'"'; } } rs+='>'+(el.innerHTML||'')+'</'+el.tagName+'>'; } return rs; }, getValue:function(n){ var rs,el=this.elements[parseInt(n).limit(0, this.elements.length)]; switch(el.tagName.toLowerCase()){ case 'select': ThinkJS.foreach(el.options,function(opt){ if(opt.selected){rs=ThinkJS.pick(opt.value,opt.text);return;} }); break; case 'input': if(!(el.checked&&['checkbox','radio'].contain(el.type))&&!['hidden','text','password'].contain(el.type)){break;} case 'textarea': rs=el.value; break; } return rs; }}); ThinkJS.Event=new ThinkJS.SimpleObject({ initialize:function(e){ e=e||window.event; this.type=e.type; this.altKey=e.altKey; this.ctrlKey=e.ctrlKey; this.shiftKey=e.shiftKey; if(ThinkJS.is(e.button)){ this.button=(typeof(e.which)!=='undefined')?e.button:((e.button===4)?1:((e.button===2)?2:0)); } if(e.type==='keypress'){ this.charCode=e.charCode||e.keyCode; }else if(e.keyCode&&(e.keyCode===46)){ this.keyCode=127; }else{ this.keyCode=e.keyCode; } this.clientX=e.clientX; this.clientY=e.clientY; this.screenX=e.screenX; this.screenY=e.screenY; this.target=e.target?e.target:e.srcElement; while(this.target&&this.target.nodeType==3){this.target=this.target.parentNode;} if(this.target){ this.offsetX=(e.offsetX||(window.pageXOffset + (e.clientX||0) - this.target.offsetLeft)); this.offsetY=(e.offsetY||(window.pageYOffset + (e.clientY||0) - this.target.offsetTop)); } return this; } });ThinkJS.Dom.extend({ addHandler:function(type,fn){ this.elements.each(function(el){ if(el.FNS==undefined){el.FNS={};} var BH,FNC=el.FNS[type]; if(FNC==undefined){el.FNS[type]=FNC=[];} if(el.addEventListener){ BH=function(e){return fn.call(el,new ThinkJS.Event(e));}; el.addEventListener(type,BH,false); }else if(el.attachEvent){ BH=function(){return fn.call(el,new ThinkJS.Event(window.event));}; el.attachEvent(('on'+type),BH); } FNC[FNC.length]={fn:fn,BH:BH}; }); return this; }, removeHandler:function(type,fn){ this.elements.each(function(el){ if((ThinkJS.type(el.FNS)!=='object')||(el.FNS==null)){return;} var BH,FNC=el.FNS[type]; for(var i=0,l=FNC.length;i<l;i++){if(FNC[i].fn===fn){BH=FNC[i].BH;break;}} if(ThinkJS.type(BH)!=='function'){return;} if(el.removeEventListener){ el.removeEventListener(type,BH,false); }else if(el.detachEvent){ el.detachEvent(('on' + type),BH); } FNC.splice(i,1); }); return this; }, on:function(type,fn){ return this.addHandler(type,fn); }, off:function(type,fn){ return this.removeHandler(type,fn); }, clone:function(el,type){ el=this._Selector(el)[0]; if(el.FNS){ if(type!=undefined&&el.FNS[type]){ el.FNS[type].each(function(fn){ this.addHandler(type,fn); },this); }else{ for(var type in el.FNS){this.clone(el,type);} } } return this; }, fire:function(type,args,delay){ this.elements.each(function(el){ if(el.FNS&&el.FNS[type]){ el.FNS[type].each(function(FNC){FNC.fn.create({'bind':el,'delay':delay,'arguments':args})();}); } }); return this; } });ThinkJS.DD=new ThinkJS.SimpleObject({ initialize:function(el,root,minX,maxX,minY,maxY,x,y){ el=(typeof el=='string')?(new ThinkJS.Dom(el)).elements[0]:el; this.el=el; el.cache={ cursor:el.style.cursor }; el.onmousedown=this.start(); el.x=x?false:true; el.y=y?false:true; el.root=((typeof root=='string')?(new ThinkJS.Dom(root)).elements[0]:root)||el; if(el.x&&isNaN(parseInt(el.root.style.left))){ el.root.style.left='0px'; } if(el.y&&isNaN(parseInt(el.root.style.top))){ el.root.style.top='0px'; } if(!el.x&&isNaN(parseInt(el.root.style.right))){ el.root.style.right='0px'; } if(!el.y&&isNaN(parseInt(el.root.style.bottom))){ el.root.style.bottom='0px'; } el.minX=typeof minX!='undefined'?minX:null; el.maxX=typeof maxX!='undefined'?maxX:null; el.minY=typeof minY!='undefined'?minY:null; el.maxY=typeof maxY!='undefined'?maxY:null; el.root.onStart=new Function(); el.root.onDrag=new Function(); el.root.onDrop=new Function(); }, start:function(){ var that=this,el=this.el; return function(e){ el.style.cursor='move'; e=new ThinkJS.Event(e); var x=parseInt(el.x?el.root.style.left:el.root.style.right), y=parseInt(el.y?el.root.style.top:el.root.style.bottom); el.root.onStart(x,y); el.lastMX=e.clientX; el.lastMY=e.clientY; if(el.x){ if(el.minX!=null){el.minMX=e.clientX-x+el.minX;} if(el.maxX!=null){el.maxMX=el.minMX+el.maxX-el.minX;} }else{ if(el.minX!=null){el.maxMX=e.clientX+x-el.minX;} if(el.maxX!=null){el.minMX=e.clientX+x-el.maxX;} } if(el.y){ if(el.minY!=null){el.minMY=e.clientY-y+el.minY;} if(el.maxY!=null){el.maxMY=el.minMY+el.maxY-el.minY;} }else{ if(el.minY!=null){el.maxMY=e.clientY+y-el.minY;} if(el.maxY!=null){el.minMY=e.clientY+y-el.maxY;} } document.onmousemove=that.drag(); document.onmouseup=that.drop(); return false; }; }, drag:function(){ var that=this,el=this.el; return function(e){ e=new ThinkJS.Event(e); var ex=e.clientX,ey=e.clientY; var x=parseInt(el.x?el.root.style.left:el.root.style.right), y=parseInt(el.y?el.root.style.top:el.root.style.bottom); var nx,ny; if(el.minX!=null){ex=el.x?Math.max(ex,el.minMX):Math.min(ex,el.maxMX);} if(el.maxX!=null){ex=el.x?Math.min(ex,el.maxMX):Math.max(ex,el.minMX);} if(el.minY!=null){ey=el.y?Math.max(ey,el.minMY):Math.min(ey,el.maxMY);} if(el.maxY!=null){ey=el.y?Math.min(ey,el.maxMY):Math.max(ey,el.minMY);} nx=x+((ex-el.lastMX)*(el.x?1:-1)); ny=y+((ey-el.lastMY)*(el.y?1:-1)); el.root.style[el.x?'left':'right']=nx+'px'; el.root.style[el.y?'top':'bottom']=ny+'px'; el.lastMX=ex; el.lastMY=ey; el.root.onDrag(nx,ny); return false; }; }, drop:function(){ var that=this,el=this.el; return function(){ el.style.cursor=el.cache.cursor; document.onmousemove=null; document.onmouseup=null; el.root.onDrop(parseInt(el.root.style[el.x?'left':'right']),parseInt(el.root.style[el.y?'top':'bottom'])); } }});ThinkJS.Dom.extend({ dragable:function(root,minX,maxX,minY,maxY,x,y){ this.elements.each(function(el){ new ThinkJS.DD(el,root,minX,maxX,minY,maxY,x,y); }); return this; }});ThinkJS.XHR=new ThinkJS.SimpleObject({ initialize:function(){ this.flag=false; this.etag={}; this.XHR=(function(){ var xhr; if(window.XMLHttpRequest){ xhr=new XMLHttpRequest(); }else{ var MS=[ 'MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ]; for(var i=0;MS[i];i++){ try{xhr=new ActiveXObject(MS[i]);break;}catch(e){} } } return xhr; })(); return this; }, AJAX:function(opts){ this._cfg=ThinkJS.apply({ url:location.href, data:'', async:true, method:'POST', charset:'UTF-8', etag:false, course:function(){},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -