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

📄 mootools.svn.js

📁 基于MOOnTOOLs所开发的一个导航拦仅供参考
💻 JS
📖 第 1 页 / 共 5 页
字号:
	/*	Property: callChain		Executes the first function of the Chain instance stack, then removes it. The first function will then become the second.	*/	callChain: function(){		if (this.chains && this.chains.length) this.chains.shift().delay(10, this);	},	/*	Property: clearChain		Clears the stack of a Chain instance.	*/	clearChain: function(){		this.chains = [];	}});/*Class: Events	An "Utility" Class. Its methods can be implemented with <Class.implement> into any <Class>.	In <Fx.Base> Class, for example, is used to give the possibility add any number of functions to the Effects events, like onComplete, onStart, onCancel.	Events in a Class that implements <Events> can be either added as an option, or with addEvent. Never with .options.onEventName.Example:	(start code)	var myFx = new Fx.Style('element', 'opacity').addEvent('onComplete', function(){		alert('the effect is completed');	}).addEvent('onComplete', function(){		alert('I told you the effect is completed');	});	myFx.start(0,1);	//upon completion it will display the 2 alerts, in order.	(end)Implementing:	This class can be implemented into other classes to add the functionality to them.	Goes well with the <Options> class.Example:	(start code)	var Widget = new Class({		initialize: function(){},		finish: function(){			this.fireEvent('onComplete');		}	});	Widget.implement(new Events);	//later...	var myWidget = new Widget();	myWidget.addEvent('onComplete', myfunction);	(end)*/var Events = new Class({	/*	Property: addEvent		adds an event to the stack of events of the Class instance.	Arguments:		type - string; the event name (e.g. 'onComplete')		fn - function to execute	*/	addEvent: function(type, fn){		if (fn != Class.empty){			this.$events = this.$events || {};			this.$events[type] = this.$events[type] || [];			this.$events[type].include(fn);		}		return this;	},	/*	Property: fireEvent		fires all events of the specified type in the Class instance.	Arguments:		type - string; the event name (e.g. 'onComplete')		args - array or single object; arguments to pass to the function; if more than one argument, must be an array		delay - (integer) delay (in ms) to wait to execute the event	Example:	(start code)	var Widget = new Class({		initialize: function(arg1, arg2){			...			this.fireEvent("onInitialize", [arg1, arg2], 50);		}	});	Widget.implement(new Events);	(end)	*/	fireEvent: function(type, args, delay){		if (this.$events && this.$events[type]){			this.$events[type].each(function(fn){				fn.create({'bind': this, 'delay': delay, 'arguments': args})();			}, this);		}		return this;	},	/*	Property: removeEvent		removes an event from the stack of events of the Class instance.	Arguments:		type - string; the event name (e.g. 'onComplete')		fn - function that was added	*/	removeEvent: function(type, fn){		if (this.$events && this.$events[type]) this.$events[type].remove(fn);		return this;	}});/*Class: Options	An "Utility" Class. Its methods can be implemented with <Class.implement> into any <Class>.	Used to automate the options settings, also adding Class <Events> when the option begins with on.	Example:		(start code)		var Widget = new Class({			options: {				color: '#fff',				size: {					width: 100					height: 100				}			},			initialize: function(options){				this.setOptions(options);			}		});		Widget.implement(new Options);		//later...		var myWidget = new Widget({			color: '#f00',			size: {				width: 200			}		});		//myWidget.options = {color: #f00, size: {width: 200, height: 100}}		(end)*/var Options = new Class({	/*	Property: setOptions		sets this.options	Arguments:		defaults - object; the default set of options		options - object; the user entered options. can be empty too.	Note:		if your Class has <Events> implemented, every option beginning with on, followed by a capital letter (onComplete) becomes an Class instance event.	*/	setOptions: function(){		this.options = $merge.apply(null, [this.options].extend(arguments));		if (this.addEvent){			for (var option in this.options){				if ($type(this.options[option] == 'function') && (/^on[A-Z]/).test(option)) this.addEvent(option, this.options[option]);			}		}		return this;	}});/*Script: Array.js	Contains Array prototypes, <$A>, <$each>License:	MIT-style license.*//*Class: Array	A collection of The Array Object prototype methods.*///custom methodsArray.extend({	/*	Property: forEach		Iterates through an array; This method is only available for browsers without native *forEach* support.		For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:forEach>		*forEach* executes the provided function (callback) once for each element present in the array. callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values.	Arguments:		fn - function to execute with each item in the array; passed the item and the index of that item in the array		bind - the object to bind "this" to (see <Function.bind>)	Example:		>['apple','banana','lemon'].each(function(item, index){		>	alert(index + " = " + item); //alerts "0 = apple" etc.		>}, bindObj); //optional second arg for binding, not used here	*/	forEach: function(fn, bind){		for (var i = 0, j = this.length; i < j; i++) fn.call(bind, this[i], i, this);	},	/*	Property: filter		This method is provided only for browsers without native *filter* support.		For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:filter>		*filter* calls a provided callback function once for each element in an array, and constructs a new array of all the values for which callback returns a true value. callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values. Array elements which do not pass the callback test are simply skipped, and are not included in the new array.	Arguments:		fn - function to execute with each item in the array; passed the item and the index of that item in the array		bind - the object to bind "this" to (see <Function.bind>)	Example:		>var biggerThanTwenty = [10,3,25,100].filter(function(item, index){		> return item > 20;		>});		>//biggerThanTwenty = [25,100]	*/	filter: function(fn, bind){		var results = [];		for (var i = 0, j = this.length; i < j; i++){			if (fn.call(bind, this[i], i, this)) results.push(this[i]);		}		return results;	},	/*	Property: map		This method is provided only for browsers without native *map* support.		For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:map>		*map* calls a provided callback function once for each element in an array, in order, and constructs a new array from the results. callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values.	Arguments:		fn - function to execute with each item in the array; passed the item and the index of that item in the array		bind - the object to bind "this" to (see <Function.bind>)	Example:		>var timesTwo = [1,2,3].map(function(item, index){		> return item*2;		>});		>//timesTwo = [2,4,6];	*/	map: function(fn, bind){		var results = [];		for (var i = 0, j = this.length; i < j; i++) results[i] = fn.call(bind, this[i], i, this);		return results;	},	/*	Property: every		This method is provided only for browsers without native *every* support.		For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:every>		*every* executes the provided callback function once for each element present in the array until it finds one where callback returns a false value. If such an element is found, the every method immediately returns false. Otherwise, if callback returned a true value for all elements, every will return true. callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values.	Arguments:		fn - function to execute with each item in the array; passed the item and the index of that item in the array		bind - the object to bind "this" to (see <Function.bind>)	Example:		>var areAllBigEnough = [10,4,25,100].every(function(item, index){		> return item > 20;		>});		>//areAllBigEnough = false	*/	every: function(fn, bind){		for (var i = 0, j = this.length; i < j; i++){			if (!fn.call(bind, this[i], i, this)) return false;		}		return true;	},	/*	Property: some		This method is provided only for browsers without native *some* support.		For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:some>		*some* executes the callback function once for each element present in the array until it finds one where callback returns a true value. If such an element is found, some immediately returns true. Otherwise, some returns false. callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values.	Arguments:		fn - function to execute with each item in the array; passed the item and the index of that item in the array		bind - the object to bind "this" to (see <Function.bind>)	Example:		>var isAnyBigEnough = [10,4,25,100].some(function(item, index){		> return item > 20;		>});		>//isAnyBigEnough = true	*/	some: function(fn, bind){		for (var i = 0, j = this.length; i < j; i++){			if (fn.call(bind, this[i], i, this)) return true;		}		return false;	},	/*	Property: indexOf		This method is provided only for browsers without native *indexOf* support.		For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:indexOf>		*indexOf* compares a search element to elements of the Array using strict equality (the same method used by the ===, or triple-equals, operator).	Arguments:		item - any type of object; element to locate in the array		from - integer; optional; the index of the array at which to begin the search (defaults to 0)	Example:		>['apple','lemon','banana'].indexOf('lemon'); //returns 1		>['apple','lemon'].indexOf('banana'); //returns -1	*/	indexOf: function(item, from){		var len = this.length;		for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){			if (this[i] === item) return i;		}		return -1;	},	/*	Property: each		Same as <Array.forEach>.	Arguments:		fn - function to execute with each item in the array; passed the item and the index of that item in the array		bind - optional, the object that the "this" of the function will refer to.	Example:		>var Animals = ['Cat', 'Dog', 'Coala'];		>Animals.each(function(animal){		>	document.write(animal)		>});	*/	/*	Property: copy		returns a copy of the array.	Returns:		a new array which is a copy of the current one.	Arguments:		start - integer; optional; the index where to start the copy, default is 0. If negative, it is taken as the offset from the end of the array.		length - integer; optional; the number of elements to copy. By default, copies all elements from start to the end of the array.	Example:		>var letters = ["a","b","c"];		>var copy = letters.copy();		// ["a","b","c"] (new instance)	*/	copy: function(start, length){		start = start || 0;		if (start < 0) start = this.length + start;		length = length || (this.length - start);		var newArray = [];		for (var i = 0; i < length; i++) newArray[i] = this[start++];		return newArray;	},	/*	Property: remove		Removes all occurrences of an item from the array.	Arguments:		item - the item to remove	Returns:		the Array with all occurrences of the item removed.	Example:		>["1","2","3","2"].remove("2") // ["1","3"];	*/	remove: function(item){		var i = 0;		var len = this.length;		while (i < len){			if (this[i] === item){				this.splice(i, 1);				len--;			} else {				i++;			}		}		return this;	},	/*	Property: contains		Tests an array for the presence of an item.	Arguments:		item - the item to search for in the array.		from - integer; optional; the index at which to begin the search, default is 0. If negative, it is taken as the offset from the end of the array.	Returns:		true - the item was found		false - it wasn't	Example:		>["a","b","c"].contains("a"); // true		>["a","b","c"].contains("d"); // false	*/	contains: function(item, from){		return this.indexOf(item, from) != -1;	},	/*	Property: associate		Creates an object with key-value pairs based on the array of keywords passed in		and the current content of the array.	Arguments:		keys - the array of keywords.	Example:		(start code)		var Animals = ['Cat', 'Dog', 'Coala', 'Lizard'];		var Speech = ['Miao', 'Bau', 'Fruuu', 'Mute'];		var Speeches = Animals.associate(Speech);		//Speeches['Miao'] is now Cat.		//Speeches['Bau'] is now Dog.		//...		(end)	*/	associate: function(keys){		var obj = {}, length = Math.min(this.length, keys.length);		for (var i = 0; i < length; i++) obj[keys[i]] = this[i];		return obj;	},	/*	Property: extend		Extends an array with another one.	Arguments:		array - the array to extend ours with	Example:		>var Animals = ['Cat', 'Dog', 'Coala'];		>Animals.extend(['Lizard']);		>//Animals is now: ['Cat', 'Dog', 'Coala', 'Lizard'];	*/	extend: function(array){		for (var i = 0, j = array.length; i < j; i++) this.push(array[i]);		return this;	},	/*	Property: merge		merges an array in another array, without duplicates. (case- and type-sensitive)	Arguments:		array - the array to merge from.	Example:		>['Cat','Dog'].merge(['Dog','Coala']); //returns ['Cat','Dog','Coala']	*/	merge: function(array){		for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);		return this;	},	/*	Property: include		includes the passed in element in the array, only if its not already present. (case- and type-sensitive)	Arguments:		item - item to add to the array (if not present)	Example:		>['Cat','Dog'].include('Dog'); //returns ['Cat','Dog']		>['Cat','Dog'].include('Coala'); //returns ['Cat','Dog','Coala']	*/	include: function(item){		if (!this.contains(item)) this.push(item);		return this;	},	/*

⌨️ 快捷键说明

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