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

📄 thinkjavascript[1].0.0.2.js

📁 自己写的javascript框架 类似jquery prototypy 希望对大家学习有帮助
💻 JS
📖 第 1 页 / 共 4 页
字号:
	 * @params {Integer} The base to use (default to 10).	 * @return {Integer}	 * @member String	 */	toInt:function(base){		return parseInt(this,base||10);	},	/**	 * @method toFloat	 * Parse a string to an float.	 * @params {Void}	 * @return {Float}	 * @member String	 */	toFloat:function(){		return parseFloat(this);	},	/**	 * @method template	 * Allow you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens.	 * Each token must be unique,and must increment in the format {0},{1},etc.	 * Example usage:		<code>			var cls='my-class',text='Some text';			var s="";			var s=s.template('<div class="{0}">{1}</div>',cls,text);			// s now contains the string: '<div class="my-class">Some text</div>'		</code>	 * @params {String} Bouth the template and replace args	 * @return {String}	 * @member ThinkJS	 */	template:function(/*arguments*/){		var args=ThinkJS.merge(arguments);		return this.replace(/\{(\d+)\}/g,function(k,v){			return args[v];		});	},	/**	 * @method rgbToHex	 * Convert an RGB value to hexidecimal.	 * The string must be in the format of "rgb(255,255,255)" or "rgba(255,255,255,1)";	 * @params {Boolean} True is return an array,and false for the string	 * @return {String}	 * @member String	 */	rgbToHex: function(bool){		var rgb=this.match(new RegExp('([\\d]{1,3})','g'));		if (rgb[3]==0){return 'transparent';}		var hex=[];		for (var i=0;i<3;i++){			var bit=(rgb[i]-0).toString(16);			hex.push(bit.length==1?'0'+bit:bit);		}		return bool?hex:('#'+hex.join(''));	},	/**	 * @method hexToRgb	 * Convert a hexidecimal color value to RGB.	 * Input string must be the hex color value (with or without the hash). Also accepts triplets ('333');	 * @params {Boolean} True is return an array,and false for the string	 * @return {String}	 * @member String	 */	hexToRgb: function(bool){		var hex=this.match(new RegExp('^[#]{0,1}([\\w]{1,2})([\\w]{1,2})([\\w]{1,2})$'));		var rgb=[];		for (var i=1;i<hex.length;i++){			if (hex[i].length==1) hex[i]+=hex[i];			rgb.push(parseInt(hex[i],16));		}		return bool?rgb:('rbg('+rgb.join(',')+')');	}	});Array.extend({	/**	 * @method origin	 * Create a copy of an array,optionally from a specific range.	 * Useful for applying the array prototypes to iterable objects such as a DOM Node collection or the arguments object.	 * @param {Integer} The starting index.	 * @param {Integer} The length of the resulting copied array.	 * @return {Array}	 * @member Array	 */	origin:function(offset,length){		offset=offset||0;		if(offset<0){offset+=this.length;}		length=length||this.length-offset;		length+=offset;		return Array.prototype.slice.call(this,offset,length);	},	/**	 * @method repeat	 * Padding an array to give length with the template array	 * @param {Array} The template array	 * @return {Array}	 * @member Array	 */	repeat:function(tpl){		var rs=[];		if(ThinkJS.type(tpl)=='array'){			var al=tpl.length,TMP=a.slice(0,this.length%al);			for(var i=0,l=this.length/al;i<l;i++){rs=rs.concat(a);}			rs=rs.concat(TMP);		}		return rs;	},	/**	 * @method merge	 * Merge an array in another array,without duplicates. (case- and type-sensitive)	 * @params {Array} The array list	 * @return {Array}	 * @member Array	 */	merge:function(){		for (var i=0,l=arguments.length;i<l;i++){			for(var ii=0,jj=arguments[i].length;ii<jj;ii++){				if (!this.contain(arguments[i][ii])){this.push(arguments[i][ii]);}			}		}		return this;	},	/**	 * @method contain	 * Test an array for the presence of an item.	 * @param {Object} The item to search for in the array.	 * @param {Integer} The index of the array at which to begin the search.	 * @return {Boolean}	 * @member Array	 */	contain:function(item,offset){		var l=this.length;		offset=((offset<0)?Math.max(0,l+offset):offset)||0;		for(var i=offset;i<l;i++){			if(this[i]===item){return true;}		}		return false;	},	/**	 * @method remove	 * Remove all occurrences of an item from the array.	 * @param {Object} The item to delete from the array.	 * @return {Array}	 * @member Array	 */	remove: function(item){		var i=0,l=this.length;		while (i<l){			if (this[i]===item){				this.splice(i,1);				l--;			} else {				i++;			}		}		return this;	},	/**	 * @method each	 * Call a function for each item in the array.	 * This function is passed the item and its index in the array.	 * @param {Function} The function which should be executed on each item in the array.	 * @param {Object} The object to use as 'this' in the function.		[code]			var arr=["one","two","three"];			arr.each(function(item,index){				alert(index+"="+item);			});			// will alerts "0=one" etc		[/code]	 * @return {Array}	 * @member Array	 */	each: function(fn,bind){		for (var i=0,l=this.length;i<l;i++){			fn.call(bind,this[i],i,this);		}	},	/**	 * @method map	 * Create a new array with the results of calling a provided function on every item in the array.	 * @param {Function} The function to produce an item of the new Array from an item of the current one.	 * @param {Object} The object to use as 'this' in the function.		[code]			var timesTwo=[1,2,3].map(function(item,index){				return item * 2;			});			//now timesTwo=[2,4,6];		[/code]	 * @return {Array}	 * @member Array	 */	map:function(fn,bind){		var rs=[];		for(var i=0,l=this.length;i<l;i++){			rs[i]=fn.call(bind,this[i],i,this);		}		return rs;	},	/**	 * @method filter	 * Call a provided callback function once for each item in an array,and constructs a new array of all the values for which callback returns a true value.	 * @param {Function} The function to produce an item of the new Array from an item of the current one.	 * @param {Object} The object to use as 'this' in the function.		[code]			var timesTwo=[1,2,3].filter(function(item,index){				return ite >= 2;			});			//now timesTwo=[2,3];		[/code]	 * @return {Array}	 * @member Array	 */	filter:function(fn,bind){		var rs=[];		for(var i=0,l=this.length;i<l;i++){			if(fn.call(bind,this[i],i,this)){				rs.push(this[i]);			}		}		return rs;	},	/**	 * @method include	 * Include the passed in item in the array,only if its not already present. 	 * @param {Object} The item that should be added to this array.	 * @return {Array}	 * @member Array	 */	include: function(item){		if (!this.contain(item)){this.push(item);}		return this;	}});Number.extend({	/**	 * @method limit	 * Return integer number between the two passed in values.	 * @param {Integer} The min value	 * @param {Integer} The max value	 * @return {Integer}	 * @member Number	 */	limit:function(min,max){		return Math.min(max,Math.max(min,this));	}});ThinkJS.Ready=new ThinkJS.SimpleObject({	initialize:function(){},	onReady:function(){		if(ThinkJS.isReady){return;}		ThinkJS.isReady=true;		if(this._timer){clearInterval(this._timer);}		this._callee.each(function(fn){fn();});		this._callee=null;	},	onDomReady:function(fn){		if(!this._callee){			var domReady=this.onReady.bind(this);			if(document.addEventListener){				document.addEventListener('DOMContentLoaded',domReady,false);			}			if(ThinkJS.msie){				document.write('<script id=_ie_on_load defer src=javascript:void(0)><\/script>');				document.getElementById('_ie_on_load').onreadystatechange=function() {if (this.readyState=='complete'){domReady();}};			}			if(ThinkJS.safari){				this._timer=setInterval(function(){if(['loaded','complete'].contain(document.readyState)){domReady();}},10);			}			if (window.addEventListener) {				window.addEventListener('load',domReady,false);			} else {				if (window.attachEvent) {window.attachEvent('onload',domReady);}			}			this._callee=[];		}		this._callee.push(fn);	}}); ThinkJS.Dom=new ThinkJS.SimpleObject({	_attrs:{		'class':'className','for':'htmlFor','colspan':'colSpan',		'rowspan':'rowSpan',	'accesskey':'accessKey','value':'value',		'tabindex':'tabIndex','maxlength':'maxLength','selected':'selected',		'readonly':'readOnly','frameborder':'frameBorder',		'disabled':'disabled','checked':'checked','multiple':'multiple' 	},	_flags:{'href':2,'src':2},	_walk:function(el,brother,start){		brother+='Sibling';		var el=start?el[start]:el[brother];		while(el&&ThinkJS.type(el)!='element'){			el=el[brother];		}		return el;	},	initialize:function(args,o){		this.length=0;		this.elements=[];		if(typeof args=='string'){			this.elements.merge(this._Selector(args,o));		}else{			for(var i=0;args[i];i++){				this.elements.merge(this._Selector(args[i],o));			}		}		this.length=this.elements.length;		return this;	},	_Selector:function(el,o){		// @tag,tag		// #id,id		// .class,tag.class		// tag[attribute(=|!=|^=|$=|*=|~=)value]		// [tag|id|class|tag[*]]>[tag|id|class|tag[*]]>....		var els=[];		if(typeof el=='string'){			el=el.replace(/\s+/g,''); // remove all whiteSpace			if(el.contain('>')){				this._Selector(el.split('>')[0],o).each(function(io){					els.merge(this._Selector(el.replace(/[^>]*?>/i,''),io));				},this);			}else if(el.contain(',')){				el.split(',').each(function(ie){					els.merge(this._Selector(ie,o));				},this);			}else if(el.contain('#')){				els.merge(this._idSelector(el.split('#')[1],o));			}else if(el.contain('.')){				var tc=el.split('.');				els.merge(this._cssSelector(tc[1],tc[0],o));			}else if(el.contain('@')){				els.merge(this._tagSelector(el.split('@')[1],o));			}else if(/\[.*?\]/g.test(el)){				var ta=[];				els.merge(this._pptSelector(el.replace(/\[.*?\]/gi,function($1){ta.push($1.replace(/\[|\]/g,''));return '';}),ta,o));			}else{				var rs=this._tagSelector(el,o);				if(rs.length){					els.merge(rs);				}else{					els.merge(this._idSelector(el,o));				}			}		}else{			els.push(el);		}		return els;	},	_idSelector:function(id){		return [document.getElementById(id)];	},	_tagSelector:function(tag,o){		var els=[],i=0,el,rs=(o||document).getElementsByTagName(tag||'*');		if(ThinkJS.msie){			while(el=rs[i]){				if(el&&el.nodeType!=8){els[i]=el;}				++i;			}		}else{			while(el=rs[i]){els[i++]=el;}		}		return els;	},	_cssSelector:function(css,tag,o){		var els=[],css=' '+css+' ';		this._tagSelector(tag,o).each(function(el){			if(el&&((' '+el.className+' ').indexOf(css)>-1)){els.push(el);}		});		return els;	},	_pptSelector:function(tag,ppt,o){		var els=[],i=0,reg=/^ *([\w-]+) *([~!$^*=]*) *('?"?)(.*)\3 */,rs=this._tagSelector(tag,o);		while(el=rs[i++]){			ppt.each(function(p){				var m=reg.exec(p);				if(m){					var attr=ThinkJS.msie?el.attributes[m[1]].nodeValue:el.getAttribute(m[1]);					if(m[2]==''&&!!attr||						m[2]=='='&&attr==m[4]||						m[2]=='!='&&attr!=m[4]||						m[2]=='^='&&attr&&attr.indexOf(m[4])==0||						m[2]=='$='&&attr.substr(attr.length-m[4].length)==m[4]||						m[2]=='*='&&attr.indexOf(m[4])>=0||						m[2]=='~='&&attr.indexOf(m[4])<0){						els.push(el);					}				}			});		}		return els;	} });ThinkJS.Dom.extend({	parent:function(){		var els=[];		this.elements.each(function(el){			if(el.parentNode){els.push(el.parentNode);}		});		this.elements=els;		return this;	},	child:function(){		var els=[];		this.elements.each(function(el){			if(el.hasChildNodes()){				el.childNodes.each(function(node){					if(node.nodeType==1){els.push(node);}				});			}		});		this.elements=els;		return this;	},	prev:function(){		var els=[];		this.elements.each(function(el){			els.push(this._walk(el,'previous'));		});		this.elements=els;		return this;	},	next:function(){		var els=[];		this.elements.each(function(el){			els.push(this._walk(el,'next'));		});		this.elements=els;		return this;	},	first:function(){		var els=[];		this.elements.each(function(el){			els.push(this._walk(el,'next','firstChild'));		});		this.elements=els;		return this;	},	last:function(){		var els=[];		this.elements.each(function(el){			els.push(this._walk(el,'previous','lastChild'));		});		this.elements=els;		return this;	},	odd:function(){		this.elements=this.elements.filter(function(e,i){return (i+1)%2;});		return this;	},	even:function(){		this.elements=this.elements.filter(function(e,i){return i%2;});		return this;	},	replace:function(ie){		if(typeof ie=='string'){			ie=this._Selector(ie)[0];		}		this.elements.each(function(el){			if(el.parentNode){el.parentNode.replaceChild(ie,el);}		});		return this;	},	remove:function(){		this.elements.each(function(el){			if(el.parentNode){el.parentNode.removeChild(el);}		});		return this;	},	empty:function(){		this.elements.each(function(el){			if(el.hasChildNodes()){				ThinkJS.merge(el.childNodes).each(function(ie){					if(ie.parentNode){ie.parentNode.removeChild(ie);}				});			}		});		return this;	},	setOpacity:function(opt){		this.elements.each(function(el){			if(opt==0){				if(el.style.visibility!='hidden'){el.style.visibility='hidden';}			}else{				if(el.style.visibility!='visible'){el.style.visibility='visible';}			}			if(!el.currentStyle||el.currentStyle.hasLayout){el.style.zoom=1;}			if(ThinkJS.msie){el.style.filter=(opt==1)?'':'alpha(opacity='+opt*100+')';}			el.style.opacity=opt;

⌨️ 快捷键说明

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