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

📄 thinkjavascript[1].0.0.2.js

📁 自己写的javascript框架 类似jquery prototypy 希望对大家学习有帮助
💻 JS
📖 第 1 页 / 共 4 页
字号:
/** +------------------------------------------------------------------------------------------- * @project ThinkJS * @package src * @author Mc@Spring <Heresy.Mc@gmail.com> * @version $ID: Think.js Created on 2008-03-28 by Mc@Spring at 22:47:28 $ * @todo TODO * @update Modified on 2008-03-28 by Mc@Spring at 22:47:28 * @link http://groups.google.com/group/mspring * @copyright Copyright (C) 2008-2009 MC@Spring Team. All rights reserved. * @declare These are inspired by those found in *		prototype.js <http://prototypejs.org/>, * 	mootools.js <http://mootools.net/>, * 	jquery.js <http://jquery.com/>, * 	ext.js <http://extjs.com/> * *                                Licensed under The Apache License * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License +------------------------------------------------------------------------------------------- */window['undefined']=window['undefined'];/** * @class ThinkJS * ThinkJS core object * @singleton */ThinkJS={version:'0.0.2'};/** * @method apply * Copy all the properties of servant to main. * If defaults is provide that will also be applied for default values * @param {Object} The receiver of the properties * @param {Object} The source of the properties * @param {Object} The default of the properties * @return {Object} * @member ThinkJS */ThinkJS.apply=function(main,servant,defaults){	if(defaults){ThinkJS.apply(main,defaults);}    if(servant && typeof servant=='object'){		for(var ppt in servant){			main[ppt]=servant[ppt];		}	}    return main;};/** * @closure Void * ThinkJS core utilties and methods * Initialize and extend ThinkJS object properties * @param {Void} * @return {Void} * @singleton */(function(){	var ua=navigator.userAgent.toLowerCase();	var opera=/opera/.test(ua),		safari=/(webkid|khtml)/.test(ua),		msie=(!opera&&/msie/.test(ua)),		msie7=(!opera&&/msie 7/.test(ua)),		mozilla=(!safari&&/mozilla/.test(ua)),		strict=(document.compatMode=='CSS1Compat'),		isBB=msie&&!strict;	if(msie&&!msie7){ // remove IE6 css image flicker        try{document.execCommand('BackgroundImageCache',false,true);}catch(e){}    }	ThinkJS.apply(ThinkJS,{		isReady:false,		opera:opera,		safari:safari,		msie:msie,		msie7:msie7,		mozilla:mozilla,		strict:strict,		isBB:isBB,		debug:true,		/**		 * @method is		 * Return true if the passed in object exists or is 0,otherwise return false.		 * @param {Mixed} Object to inspect		 * @return {Boolean}		 * @member ThinkJS		 */		is:function(o){return !!(o||o===0);},		/**		 * @method def		 * Return true if the passed in object is defined,that means is not null or undefined.		 * @param {Mixed} Object to inspect		 * @return {Boolean}		 * @member ThinkJS		 */		def:function(o){return (o!=undefined);},		/**		 * @method type		 * Return the type of object that is passed in.		 * If the object passed in is null or undefined it return *null*.		 * @param {Mixed} Object to inspect		 * @return {String}			[Returns]				'boolean','number','string','array','regexp','function','object',				'collection','element','textnode','whitespace',				'class',				null			[/Returns]		 * @member ThinkJS		 */		type:function(o){			if(o==undefined){return;}			if(o.htmlElement){return 'element';}			var T=typeof o;			if(T=='object'&&o.nodeName){				switch(o.nodeType){					case 1:	return 'element';					case 3:	return (/\S/).test(o.nodeValue)?'textnode':'whitespace';				}			}			if(T=='object'||T=='function'){				switch(o.constructor){					case Array:return 'array';					case RegExp:return 'regexp';					case this.SimpleObject:return 'class';				}				if(typeof o.length=='number'){					if(o.item){						return 'collection';					}else if(o.callee){						return 'arguments';					}				}			}			return T;		},		/**		 * @method self		 * Retrieve script self src string		 * @param {Void}		 * @return {String}		 * @member ThinkJS		 */		self:function(){			var scripts=document.getElementsByTagName('script'),length=scripts.length;			do{if(scripts[length-1].src!=''){return scripts[length-1].src;}}while(length--);		},		/**		 * @method exec		 * Eval script string in global enviroment		 * @param {String} The current script string		 * @return {Void}		 * @member ThinkJS		 */		exec:function(text){			var head=document.getElementsByTagName('head')[0]||document.documentElement,script=document.createElement('script');			script.type='text/javascript';			if (ThinkJS.msie){				script.text=text;			}else{				script.appendChild(document.createTextNode(text));			}			head.insertBefore(script,head.firstChild);			head.removeChild(script);		}	},{		/**		 * @method time		 * Return current unix timestamp		 * @params {Void}		 * @return {Integer}		 * @member ThinkJS		 */		time:function(){return +new Date;},		/**		 * @method rand		 * Return a random integer number between the two passed in.		 * @param {Integer} The min value		 * @param {Integer} The max value		 * @return {Integer}		 * @member ThinkJS		 */		rand:function(min,max){return Math.floor(Math.random()*(max-min+1)+min);},		/**		 * @method random		 * Return a seed under the passed in argument		 * @param {Integer} The base seed		 * @return {Integer}		 * @member ThinkJS		 */		random:function(i){return Math.ceil((((+new Date)*9301+49297)%233280)/(233280.0)*i);},		/**		 * @method pick		 * Return the first object defined.		 * If none is selected it will return null.		 * @params {Mixed} The list of value		 * @return {Mixed}		 * @member ThinkJS		 */		pick:function(/*arguments*/){			for(var i=0,l=arguments.length;i<l;i++){				if(arguments[i]!=undefined){return arguments[i];}			}			return null;		},		/**		 * @method splat		 * Return an array base the argument passed in.		 * @param {Mixed} Object to inspect		 * @return {Array}		 * @member ThinkJS		 */		splat:function(o){			var type=this.type(o);			return (type)?((type!='array'&&type!='arguments')?[o]:o):[];		},		/**		 * @method merge		 * Merge any number of objects recursively into a new array,with its sub-object.		 * @params {Mixed} The list of object		 * @return {Array}		 * @member ThinkJS		 */		merge:function(/*arguments*/){			var mix=[],i=0,arg;			while(arg=arguments[i++]){				var T=this.type(arg);				if(T=='array'){					mix=mix.concat(arg);				}else if(T=='object'){					var j=arg.length;					if(j){						for(var x=0;x<j;x++){mix=this.merge(mix,arg[x]);}					}else{						for(o in arg){mix=this.merge(mix,arg[o]);}					}				}else if(T=='collection'){					for(var x=0,j=arg.length;x<j;x++){mix=this.merge(mix,arg[x]);}				}else if(arg!=undefined){					mix.push(arg);				}			}			return mix;		},		/**		 * @method attempt		 * Tries to execute a function,return false if it fails.		 * @param {Object} The object bind to		 * @param {Object} The bind function		 * @param {Array} The args for function		 * @return {Object}		 * @member ThinkJS		 */		attempt:function(bind,fn,args){			try {				return fn.apply((bind||fn),this.splat(args));			} catch(e){}			return false;		},		/**		 * @method foreach		 * Iterates an array calling the passed function with each,stopping if it return false.		 * If the passed is not an array,the function is called once with it.		 * @param {Array} The object list to bind		 * @param {Object} The bind function		 * @param {Object} The object that bind to		 * @return {Object}		 * @member ThinkJS		 */		foreach:function(args,fn,bind){			var i=0,j=args.length;			if(j){				for(var o=args[0];i<j&&fn.apply((bind||o),this.splat(o))!==false;o=args[++i]){}			}else{				for(o in args){if(fn.apply((bind||args[o]),this.splat(args[0]))===false){break;}}			}		},		/**		 * @method Native		 * Append .extend method to the objects passed in by prototype mode.		 * Its handy if you don't wanna the .extend method of an object to overwrite existing methods.		 * @params {Object} The objects to extend		 * @return {Object} The object with .extend method		 * @member ThinkJS		 */		Native:function(/*arguments*/){			var i=0;			while(arguments[i]){				arguments[i].extend=function(ppts){					for(var ppt in ppts){						if(!this.prototype[ppt]){this.prototype[ppt]=ppts[ppt];}						if(!this[ppt]){							this[ppt]=(function(){								return function(bind){									return this.prototype[ppt].apply(bind,Array.prototype.slice.call(arguments,1));								};							})(ppt);						}					}				};				++i;			}		},		/**		 * @method SimpleObject		 * The base class object of the Think JavaScript framework.		 * Create a new class,its initialize method will fire upon when class instantiation.		 * This will adds the .extend method to the class that can be used to override members on an instance.		 * Initialize wont fire on instantiation when pass *null*.		 * @params {Object} The extend properties		 * @return {Object}		 * @member ThinkJS		 */		SimpleObject:function(property){			var cls=function(){				return (arguments[0]!==null&&this.initialize&&ThinkJS.type(this.initialize)=='function')?this.initialize.apply(this,arguments):this;			};			for(var ppt in this){cls[ppt]=this[ppt];}			cls.prototype=property||{};			cls.extend=function(ppts){				for(var ppt in ppts){					this.prototype[ppt]=ppts[ppt];					if(!this[ppt]){						this[ppt]=(function(){							return function(bind){								return this.prototype[ppt].apply(bind,Array.prototype.slice.call(arguments,1));							};						})(ppt);					}				}			};			cls.constructor=ThinkJS.SimpleObject;			return cls;		}	});	window.onerror=function(){return !ThinkJS.debug;};	ThinkJS.Native(Function,String,Array,Number);})();Function.extend({	/**	 * @method create	 * Main function to create closure.	 * @params {Object} The options passed to closure	 * @return {Function}	 * @member Function	 */	create:function(opts){		var that=this;		this.options=ThinkJS.apply({			'bind':this,			'event':false,			'arguments':null,			'delay':false,			'periodical':false,			'attempt':false		},opts);		return function(event){			var args=ThinkJS.pick(that.options.arguments,arguments);			if(that.options.event){args=ThinkJS.apply([event||window.event],args);}			var rs=function(){return that.call(ThinkJS.pick(that.options.bind,that),args);};			if(that.options.delay){return setTimeout(rs,that.options.delay);}			if(that.options.periodical){return setInterval(rs,that.options.periodical);}			if(that.options.attempt){return ThinkJS.attempt(rs);}			return rs();		};	},	/**	 * @method bind	 * Create closure with "this" easily.	 * @params {Object} The closure bind to	 * @return {Function}	 * @member Function	 */	bind:function(bind){		var that = this;		return function(){return that.apply(bind, Array.prototype.slice.call(arguments, 1));};	}});String.extend({	/**	 * @method test	 * Search for a match between the string and a regular expression.	 * @param {Mixed} The string or regular expression to match with.	 * @param {String} If first parameter is a regular,any parameters you want to pass to the regular expression ('g' has no effect).	 * @return {Boolean} If a match for the regular expression is found in this string return true,otherwise return false.	 * @member String	 */	test:function(reg,sym){		return ((typeof reg=='string')?new RegExp(reg,sym):reg).test(this);	},	/**	 * @method contain	 * Check if it the segment is exist in the string.	 * @param {String} The string to search for.	 * @param {String} The string that separates the values in this string (eg. Element classNames are separated by a ' ').	 * @return {Boolean} If the string is contained in this string return true,otherwise return false.	 * @member String	 */	contain:function(string,s){		return (s?(s+this+s):this).indexOf(s?(s+string+s):string)>-1;	},	/**	 * @method trim	 * Trim the leading or trailing or both leading and trailing spaces of a string.	 * @param {Integer} Which type to trim [eg. 1=>left,-1=>right,others are both]	 * @return {String}	 * @member String	 */	trim:function(){		var reg=/^\s+|\s+$/g;		switch(arguments[0]){			case 1:				reg=/^\s+/g;			break;			case -1:				reg=/\s+$/g;			break;			default:			break;		}		return this.replace(reg,'');	},	/**	 * @method clean	 * Trim (<String.trim>) a string AND remove all the double spaces in a string.	 * @params {Void}	 * @return {String}	 * @member String	 */	clean:function(){		return this.replace(/\s{2,}/g,' ').trim();	},	/**	 * @method stripTags	 * Remove all HTML tags in a string AND clean (<String.clean>) it	 * @params {Void}	 * @return {String}	 * @member String	 */	stripTags:function(){		return this.replace(/<\/?[^>]+>/gi,'').clean();	},	/**	 * @method capitalize	 * Convert the first letter in each word of a string to uppercase.	 * @params {Void}	 * @return {String}	 * @member String	 */	capitalize:function(){		return this.replace(/\b[a-z]/g,function(match){			return match.toUpperCase();		});	},	/**	 * @method camelize	 * Convert a hiphenated string to a camelcase string.	 * @params {Void}	 * @return {String}	 * @member String	 */	camelize:function(){		return this.replace(/-\D/g,function(match){			return match.charAt(1).toUpperCase();		});	},	/**	 * @method hyphenate	 * Convert a camelCased string to a hyphen-ated string.	 * @params {Void}	 * @return {String}	 * @member String	 */	hyphenate: function(){		return this.replace(/\w[A-Z]/g,function(match){			return (match.charAt(0)+'-'+match.charAt(1).toLowerCase());		});	},	/**	 * @mehtod escapeRegExp	 * Filter a string for RegExp	 * @params {Void}	 * @return {String}	 * @member String	 */	escapeRegExp:function(){		return this.replace(/([.*+?^${}()|[\]\/\\])/g,'\\$1');	},	/**	 * @method toInt	 * Parse a string to an integer.

⌨️ 快捷键说明

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