⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thinkjavascript[1].0.0.2.js

📁 自己写的javascript框架 类似jquery prototypy 希望对大家学习有帮助
💻 JS
📖 第 1 页 / 共 4 页
字号:
			success:function(){},			failure:function(){},			filter:null,			type:'text'		},opts);		this._cfg.url+=(this._cfg.url.contain('?')?'&':'?')+'mc='+(+new Date());		this._cfg.method=this._cfg.method.toUpperCase();		this._cfg.type=this._cfg.type.toLowerCase();		if(this.XHR||this.initialize()){			this.flag=true;			this.XHR.onreadystatechange=function(){};			this.XHR.abort();			try{				this.XHR.open(this._cfg.method,this._cfg.url,this._cfg.async);				if(this._cfg.method=='POST'){					this.XHR.setRequestHeader('Content-Type',('application/x-www-form-urlencoded;charset='+this._cfg.charset));				}				if(this._cfg.etag){					this.XHR.setRequestHeader('If-Modified-Since', this.etag[this._cfg.url]||'Thu, 01 Jan 1970 00:00:00 GMT');				}				this.XHR.setRequestHeader('X-Requested-With', 'XMLHttpRequest');				this.XHR.onreadystatechange=this.handle.bind(this);				this.XHR.send(this._cfg.data);				if(!this._cfg.async){this.handle.bing(this);}			}catch(e){				if(ThinkJS.type(this._cfg.failure)=='function'){					this._cfg.failure(e);				}			}		}		return this;	},	handle:function(){		if(this.XHR.readyState==4){			try{				this.flag=(this.XHR.status>=200&&this.XHR.status<300)||this.XHR.status==304||this.XHR.getResponseHeader('Last-Modified')==this.etag[this._cfg.url]||(!this.XHR.status&&location.protocol=='file:')||this.XHR.status==1223||(ThinkJS.safari&&this.XHR.status==undefined);			}catch(e){}			if(this.flag){				if(this._cfg.etag){					try{						var rs=this.XHR.getResponseHeader('Last-Modified');						if(rs){this.etag[this._cfg.url]=rs;}					}catch(e){}				}				if(ThinkJS.type(this._cfg.success)=='function'){					this._cfg.success(this.data({						text:this.XHR.responseText,						xml:this.XHR.responseXML					}),this.XHR.status);				}			}else{				if(ThinkJS.type(this._cfg.failure)=='function'){					this._cfg.failure(this.XHR.status);				}			}		}else{			if(ThinkJS.type(this._cfg.course)=='function'){				this._cfg.course(this.XHR.status);			}		}	},	data:function(data){		switch(this._cfg.type){			case 'xml':				data=data.xml;				break;			case 'text':			case 'json':			case 'script':			default:				data=data.text;				break;		}		if(ThinkJS.type(this._cfg.filter)=='function'){			data=this._cfg.filter(data);		}		if(this._cfg.type=='script'){			ThinkJS.exec(data);		}		if(this._cfg.type=='json'){			data=eval('('+data+')');		}		return data;	},	set:function(url,data,ok,no,ing,filter,type){		if(ThinkJS.type(data)=='function'){			ok=data;			data=null;		}		return this.AJAX({			url:url,			data:data,			async:true,			method:'POST',			charset:'UTF-8',			etag:false,			course:ing,			success:ok,			failure:no,			filter:filter,			type:type		});	},	get:function(url,data,ok,no,ing,filter,type){		if(ThinkJS.type(data)=='function'){			ok=data;			data=null;		}		return this.AJAX({			url:url,			data:data,			async:true,			method:'GET',			charset:'UTF-8',			etag:true,			course:ing,			success:ok,			failure:no,			filter:filter,			type:type		});	}});ThinkJS.Dom.extend({	refresh:function(url,where,ing,filter){		var that=this,where=(['beforebegin','afterbegin','beforeend','afterend'].contain(where)?where:null);		var ok=function(data,status){			if(where){				that.elements.each(function(el){$(el).setHTML(where,data);});			}else{				that.elements.each(function(el){$(el).empty().setHTML('afterbegin',data);});			}		};		(new ThinkJS.XHR).get(url,null,ok,null,ing,filter,'text');		return this;	},	submit:function(url,ok,no,ing){		var QS=[];		var toQS=function(K,V){			return (V!=undefined)?QS.push(K+'='+encodeURIComponent(V)):'';		};		this.elements.filter(function(tag){			return (tag.tagName==='FORM');		}).each(function(el){			var els=[];			el.setAttribute('onsubmit', 'return false;');			els.merge(el.getElementsByTagName('input'));			els.merge(el.getElementsByTagName('select'));			els.merge(el.getElementsByTagName('textarea'));			els.each(function(e){				var eK=e.name,eV=(new ThinkJS.Dom(el)).getValue(0);				if(ThinkJS.type(eV)=='array'){eV.each(toQS);}else{toQS(eK,eV);}			});		});		(new ThinkJS.XHR).set(url,QS.join('&'),ok,no,ing,null,'text');		return this;	},	reset:function(){		this.elements.each(function(el){			if(['input', 'textarea'].contain(el.tagName.toLowerCase())){el.value='';}		});	}});var Fx=fx={};Fx.Transitions={	linear:function(t,b,c,d) { return c*t/d + b;},	sineInOut:function(t,b,c,d){return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;}};Fx.Effect=new ThinkJS.SimpleObject({	initialize:function(el,ppt,opts){		this.el=el;		this.ppt=ppt;		this.options=ThinkJS.apply({			fps:50,			unit:'px',			duration:500,			transition:Fx.Transitions.sineInOut,			wait:true,			start:function(){},			stop:function(){}		},opts);	},	run:function(from,to){		if (!this.options.wait){this.clear();}		if (this.timer){return;}		setTimeout(this.options.start.bind(this,this.el),10);		this.from=from;		this.to=to;		this.time=+new Date();		this.timer=setInterval(this.step.bind(this),Math.round(1000/this.options.fps));		return this;	},	ing:function(){		this.now=this.compute(this.from,this.to);	},	step:function(){		var time=+new Date();		if(time<(this.time+this.options.duration)){			this._time=time-this.time;			this.ing();		}else{			setTimeout(this.options.stop.bind(this,this.el),10);			this.clear();			this.now=this.to;		}		this.increase();	},	compute:function(from,to){		return this.options.transition(this._time,from,(to-from),this.options.duration);	},	clear:function(){		clearInterval(this.timer);		this.timer=null;		return this;	},	custom:function(from,to){		return this.run(from,to);	},	set:function(to){		this.now=to;		this.increase();		return this;	},	show:function(){		return this.set(1);	},	hide:function(){		return this.set(0);	},	increase:function(){		this.setStyle(this.el,this.ppt,this.now);	},	setStyle:function(el,ppt,value){		if (ppt=='opacity'){			if (value==0&&el.style.visibility!='hidden'){				el.style.visibility='hidden';			}else if(el.style.visibility!='visible'){				el.style.visibility='visible';			}			if (window.ActiveXObject){el.style.filter='alpha(opacity='+value*100+')';}			el.style.opacity=value;		}else{			el.style[ppt]=value+this.options.unit;		}	}});Fx.Opacity=ThinkJS.SimpleObject(new Fx.Effect);Fx.Opacity.extend({	initialize:function(el,opts){		this.el=el;		this.options=ThinkJS.apply(this.options,opts);		this.now=1;	},	toggle:function(){		if (this.now>0){			return this.custom(1,0);		}else{			return this.custom(0,1);		}	},	increase:function(){		this.setStyle(this.el,'opacity',this.now);	}});Fx.Color=ThinkJS.SimpleObject(new Fx.Effect);Fx.Color.extend({	initialize:function(el,ppt,hex,opts){		this.el=el;		this.ppt=ppt.camelize();		this.hex=hex;		this.options=ThinkJS.apply(this.options,opts);		this.now=[];	},	blink:function(){		return this.custom(this.hex.start,this.hex.end);	},	ing:function(){		[0,1,2].each(function(i){			this.now[i]=Math.round(this.compute(this.from[i],this.to[i]));		},this);	},	custom:function(from,to){		return this.run(from.hexToRgb(true),to.hexToRgb(true));	},	increase:function(){		this.el.style[this.ppt]='rgb('+this.now[0]+','+this.now[1]+','+this.now[2]+')';	}});Fx.Scroll=ThinkJS.SimpleObject(new Fx.Effect);Fx.Scroll.extend({	initialize:function(el,opts){		this.el=el;		this.options=ThinkJS.apply(this.options,opts);		this.el.style.overflow='hidden';	},	up:function(){		return this.custom(this.el.scrollTop,0);	},	down:function(){		return this.custom(this.el.scrollTop,this.el.scrollHeight-this.el.offsetHeight);	},	increase:function(){		this.el.scrollTop=this.now;	}});Fx.Width=ThinkJS.SimpleObject(new Fx.Effect);Fx.Width.extend({	initialize:function(el,opts){		this.el=el;		this.options=ThinkJS.apply(this.options,opts);		this.el.style.overflow='hidden';		this.iniWidth=this.el.offsetWidth;	},	toggle:function(){		if (this.el.offsetWidth>0){			return this.custom(this.el.offsetWidth,0);		}else{			return this.custom(0,this.iniWidth);		}	},	show:function(){		return this.set(this.iniWidth);	},	increase:function(){		this.setStyle(this.el,'width',this.now);	}});Fx.Height=ThinkJS.SimpleObject(new Fx.Effect);Fx.Height.extend({	initialize:function(el,opts){		this.el=el;		this.options=ThinkJS.apply(this.options,opts);		this.el.style.overflow='hidden';		this.iniHeight=this.el.offsetHeight;	},	toggle:function(){		if(this.el.offsetHeight>0){			return this.custom(this.el.offsetHeight,0);		}else{			return this.custom(0,this.el.scrollHeight);		}	},	show:function(){		return this.set(this.el.scrollHeight);	},	increase:function(){		this.setStyle(this.el,'height',this.now);	}});ThinkJS.Dom.extend({	FxOpacity:function(fn,opts,n){		var n=parseInt(n).limit(0,(this.elements.length - 1)),FO=[];		this.elements.each(function(el){			if(el.FNS==undefined){el.FNS={FX:{O:{}}};}			if(el.FNS.FX.O[fn]==undefined){el.FNS.FX.O[fn]=new Fx.Opacity(el,opts);}			FO.push(el.FNS.FX.O[fn]);		});		if(ThinkJS.is(n)&&(ThinkJS.type(FO[n][fn])=='function')){			FO[n][fn]();		}else{			FO.each(function(o){if(ThinkJS.type(o[fn])=='function'){o[fn]();}});		}		return this;	},	FxColor:function(fn,ppt,hex,opts,n){		var n=parseInt(n).limit(0,(this.elements.length - 1)),FC=[];		this.elements.each(function(el){			if(el.FNS==undefined){el.FNS={FX:{C:{}}};}			if(el.FNS.FX.C[fn]==undefined){el.FNS.FX.C[fn]=new Fx.Color(el,ppt,hex,opts);}			FC.push(el.FNS.FX.C[fn]);		});		if(ThinkJS.is(n)&&(ThinkJS.type(FC[n][fn])=='function')){			FC[n][fn]();		}else{			FC.each(function(o){if(ThinkJS.type(o[fn])=='function'){o[fn]();}});		}		return this;	},	FxScroll:function(fn,opts,n){		var n=parseInt(n).limit(0,(this.elements.length - 1)),FS=[];		this.elements.each(function(el){			if(el.FNS==undefined){el.FNS={FX:{S:{}}};}			if(el.FNS.FX.S[fn]==undefined){el.FNS.FX.S[fn]=new Fx.Scroll(el,opts);}			FS.push(el.FNS.FX.S[fn]);		});		if(ThinkJS.is(n)&&(ThinkJS.type(FS[n][fn])=='function')){			FS[n][fn]();		}else{			FS.each(function(o){if(ThinkJS.type(o[fn])=='function'){o[fn]();}});		}		return this;	},	FxWidth:function(fn,opts,n){		var n=parseInt(n).limit(0,(this.elements.length - 1)),FW=[];		this.elements.each(function(el){			if(el.FNS==undefined){el.FNS={FX:{W:{}}};}			if(el.FNS.FX.W[fn]==undefined){el.FNS.FX.W[fn]=new Fx.Width(el,opts);}			FW.push(el.FNS.FX.W[fn]);		});		if(ThinkJS.is(n)&&(ThinkJS.type(FW[n][fn])=='function')){			FW[n][fn]();		}else{			FW.each(function(o){if(ThinkJS.type(o[fn])=='function'){o[fn]();}});		}		return this;	},	FxHeight:function(fn,opts,n){		var n=parseInt(n).limit(0,(this.elements.length - 1)),FH=[];		this.elements.each(function(el){			if(el.FNS==undefined){el.FNS={FX:{H:{}}};}			if(el.FNS.FX.H[fn]==undefined){el.FNS.FX.H[fn]=new Fx.Height(el,opts);}			FH.push(el.FNS.FX.H[fn]);		});		if(ThinkJS.is(n)&&(ThinkJS.type(FH[n][fn])=='function')){			FH[n][fn]();		}else{			FH.each(function(o){if(ThinkJS.type(o[fn])=='function'){o[fn]();}});		}		return this;	}});ThinkJS.apply(window,{	$:function(/*arguments*/){		return new ThinkJS.Dom(arguments);	},	$$:function(s,o){		return new ThinkJS.Dom(s,o);	},	onReady:function(fn){		return (new ThinkJS.Ready()).onDomReady(fn);	},	getWidth:function(){		var x=0;		if(ThinkJS.safari){			x=this.innerWidth;		}else if(ThinkJS.opera){			x=document.body.clientWidth;		}else{			x=ThinkJS.strict?document.documentElement.clientWidth:document.body.clientWidth;		}		return x;	},	getHeight:function(){		var y=0;		if(ThinkJS.safari){			y=this.innerHeight;		}else if(ThinkJS.opera){			y=document.body.clientHeight;		}else{			y=ThinkJS.strict?document.documentElement.clientHeight:document.body.clientHeight;		}		return y;	},	getScrollWidth:function(){		var x=0;		if (ThinkJS.msie){			x=Math.max(document.documentElement.offsetWidth,document.documentElement.scrollWidth);		}else if(ThinkJS.safari){			x=document.body.scrollWidth;		}else{			x=document.documentElement.scrollWidth;		}		return x;	},	getScrollHeight:function(){		var y=0;		if (ThinkJS.msie){				y=Math.max(document.documentElement.offsetHeight,document.documentElement.scrollHeight);		}else if(ThinkJS.safari){			y=document.body.scrollHeight;		}else{			y=document.documentElement.scrollHeight;		}		return y;	},	getScrollX:function(){		return this.pageXOffset||document.documentElement.scrollLeft;	},	getScrollY:function(){		return this.pageYOffset||document.documentElement.scrollTop;	},	getSize:function(){		return {			'size':{'x':this.getWidth(),'y':this.getHeight()},			'scrollSize':{'x':this.getScrollWidth(),'y':this.getScrollHeight()},			'scroll':{'x':this.getScrollX(),'y':this.getScrollY()}		};	}});

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -