?? mootools.svn.js
字號:
/*Script: Core.js Mootools - My Object Oriented javascript.License: MIT-style license.MooTools Copyright: copyright (c) 2007 Valerio Proietti, <http://mad4milk.net>MooTools Credits: - Class is slightly based on Base.js <http://dean.edwards.name/weblog/2006/03/base/> (c) 2006 Dean Edwards, License <http://creativecommons.org/licenses/LGPL/2.1/> - Some functions are inspired by those found in prototype.js <http://prototype.conio.net/> (c) 2005 Sam Stephenson sam [at] conio [dot] net, MIT-style license - Documentation by Aaron Newton (aaron.newton [at] cnet [dot] com) and Valerio Proietti.*/var MooTools = { version: '1.11' };/* Section: Core Functions *//*Function: $defined Returns true if the passed in value/object is defined, that means is not null or undefined.Arguments: obj - object to inspect*/function $defined(obj){ return (obj != undefined);};/*Function: $type Returns the type of object that matches the element passed in.Arguments: obj - the object to inspect.Example: >var myString = 'hello'; >$type(myString); //returns "string"Returns: 'element' - if obj is a DOM element node 'textnode' - if obj is a DOM text node 'whitespace' - if obj is a DOM whitespace node 'arguments' - if obj is an arguments object 'object' - if obj is an object 'string' - if obj is a string 'number' - if obj is a number 'boolean' - if obj is a boolean 'function' - if obj is a function 'regexp' - if obj is a regular expression 'class' - if obj is a Class. (created with new Class, or the extend of another class). 'collection' - if obj is a native htmlelements collection, such as childNodes, getElementsByTagName .. etc. false - (boolean) if the object is not defined or none of the above.*/function $type(obj){ if (!$defined(obj)) return false; if (obj.htmlElement) return 'element'; var type = typeof obj; if (type == 'object' && obj.nodeName){ switch(obj.nodeType){ case 1: return 'element'; case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace'; } } if (type == 'object' || type == 'function'){ switch(obj.constructor){ case Array: return 'array'; case RegExp: return 'regexp'; case Class: return 'class'; } if (typeof obj.length == 'number'){ if (obj.item) return 'collection'; if (obj.callee) return 'arguments'; } } return type;};/*Function: $merge merges a number of objects recursively without referencing them or their sub-objects.Arguments: any number of objects.Example: >var mergedObj = $merge(obj1, obj2, obj3); >//obj1, obj2, and obj3 are unaltered*/function $merge(){ var mix = {}; for (var i = 0; i < arguments.length; i++){ for (var property in arguments[i]){ var ap = arguments[i][property]; var mp = mix[property]; if (mp && $type(ap) == 'object' && $type(mp) == 'object') mix[property] = $merge(mp, ap); else mix[property] = ap; } } return mix;};/*Function: $extend Copies all the properties from the second passed object to the first passed Object. If you do myWhatever.extend = $extend the first parameter will become myWhatever, and your extend function will only need one parameter.Example: (start code) var firstOb = { 'name': 'John', 'lastName': 'Doe' }; var secondOb = { 'age': '20', 'sex': 'male', 'lastName': 'Dorian' }; $extend(firstOb, secondOb); //firstOb will become: { 'name': 'John', 'lastName': 'Dorian', 'age': '20', 'sex': 'male' }; (end)Returns: The first object, extended.*/var $extend = function(){ var args = arguments; if (!args[1]) args = [this, args[0]]; for (var property in args[1]) args[0][property] = args[1][property]; return args[0];};/*Function: $native Will add a .extend method to the objects passed as a parameter, but the property passed in will be copied to the object's prototype only if non previously existent. Its handy if you dont want the .extend method of an object to overwrite existing methods. Used automatically in MooTools to implement Array/String/Function/Number methods to browser that dont support them whitout manual checking.Arguments: a number of classes/native javascript objects*/var $native = function(){ for (var i = 0, l = arguments.length; i < l; i++){ arguments[i].extend = function(props){ for (var prop in props){ if (!this.prototype[prop]) this.prototype[prop] = props[prop]; if (!this[prop]) this[prop] = $native.generic(prop); } }; }};$native.generic = function(prop){ return function(bind){ return this.prototype[prop].apply(bind, Array.prototype.slice.call(arguments, 1)); };};$native(Function, Array, String, Number);/*Function: $chk Returns true if the passed in value/object exists or is 0, otherwise returns false. Useful to accept zeroes.Arguments: obj - object to inspect*/function $chk(obj){ return !!(obj || obj === 0);};/*Function: $pick Returns the first object if defined, otherwise returns the second.Arguments: obj - object to test picked - the default to returnExample: (start code) function say(msg){ alert($pick(msg, 'no meessage supplied')); } (end)*/function $pick(obj, picked){ return $defined(obj) ? obj : picked;};/*Function: $random Returns a random integer number between the two passed in values.Arguments: min - integer, the minimum value (inclusive). max - integer, the maximum value (inclusive).Returns: a random integer between min and max.*/function $random(min, max){ return Math.floor(Math.random() * (max - min + 1) + min);};/*Function: $time Returns the current timestampReturns: a timestamp integer.*/function $time(){ return new Date().getTime();};/*Function: $clear clears a timeout or an Interval.Returns: nullArguments: timer - the setInterval or setTimeout to clear.Example: >var myTimer = myFunction.delay(5000); //wait 5 seconds and execute my function. >myTimer = $clear(myTimer); //nevermindSee also: <Function.delay>, <Function.periodical>*/function $clear(timer){ clearTimeout(timer); clearInterval(timer); return null;};/*Class: Abstract Abstract class, to be used as singleton. Will add .extend to any objectArguments: an objectReturns: the object with an .extend property, equivalent to <$extend>.*/var Abstract = function(obj){ obj = obj || {}; obj.extend = $extend; return obj;};//window, documentvar Window = new Abstract(window);var Document = new Abstract(document);document.head = document.getElementsByTagName('head')[0];/*Class: window Some properties are attached to the window object by the browser detection. Note: browser detection is entirely object-based. We dont sniff.Properties: window.ie - will be set to true if the current browser is internet explorer (any). window.ie6 - will be set to true if the current browser is internet explorer 6. window.ie7 - will be set to true if the current browser is internet explorer 7. window.gecko - will be set to true if the current browser is Mozilla/Gecko. window.webkit - will be set to true if the current browser is Safari/Konqueror. window.webkit419 - will be set to true if the current browser is Safari2 / webkit till version 419. window.webkit420 - will be set to true if the current browser is Safari3 (Webkit SVN Build) / webkit over version 419. window.opera - is set to true by opera itself.*/window.xpath = !!(document.evaluate);if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;else if (document.childNodes && !document.all && !navigator.taintEnabled) window.webkit = window[window.xpath ? 'webkit420' : 'webkit419'] = true;else if (document.getBoxObjectFor != null) window.gecko = true;/*compatibility*/window.khtml = window.webkit;Object.extend = $extend;/*end compatibility*///htmlelementif (typeof HTMLElement == 'undefined'){ var HTMLElement = function(){}; if (window.webkit) document.createElement("iframe"); //fixes safari HTMLElement.prototype = (window.webkit) ? window["[[DOMElement.prototype]]"] : {};}HTMLElement.prototype.htmlElement = function(){};//enables background image cache for internet explorer 6if (window.ie6) try {document.execCommand("BackgroundImageCache", false, true);} catch(e){};/*Script: Class.js Contains the Class Function, aims to ease the creation of reusable Classes.License: MIT-style license.*//*Class: Class The base class object of the <http://mootools.net> framework. Creates a new class, its initialize method will fire upon class instantiation. Initialize wont fire on instantiation when you pass *null*.Arguments: properties - the collection of properties that apply to the class.Example: (start code) var Cat = new Class({ initialize: function(name){ this.name = name; } }); var myCat = new Cat('Micia'); alert(myCat.name); //alerts 'Micia' (end)*/var Class = function(properties){ var klass = function(){ return (arguments[0] !== null && this.initialize && $type(this.initialize) == 'function') ? this.initialize.apply(this, arguments) : this; }; $extend(klass, this); klass.prototype = properties; klass.constructor = Class; return klass;};/*Property: empty Returns an empty function*/Class.empty = function(){};Class.prototype = { /* Property: extend Returns the copy of the Class extended with the passed in properties. Arguments: properties - the properties to add to the base class in this new Class. Example: (start code) var Animal = new Class({ initialize: function(age){ this.age = age; } }); var Cat = Animal.extend({ initialize: function(name, age){ this.parent(age); //will call the previous initialize; this.name = name; } }); var myCat = new Cat('Micia', 20); alert(myCat.name); //alerts 'Micia' alert(myCat.age); //alerts 20 (end) */ extend: function(properties){ var proto = new this(null); for (var property in properties){ var pp = proto[property]; proto[property] = Class.Merge(pp, properties[property]); } return new Class(proto); }, /* Property: implement Implements the passed in properties to the base Class prototypes, altering the base class, unlike <Class.extend>. Arguments: properties - the properties to add to the base class. Example: (start code) var Animal = new Class({ initialize: function(age){ this.age = age; } }); Animal.implement({ setName: function(name){ this.name = name } }); var myAnimal = new Animal(20); myAnimal.setName('Micia'); alert(myAnimal.name); //alerts 'Micia' (end) */ implement: function(){ for (var i = 0, l = arguments.length; i < l; i++) $extend(this.prototype, arguments[i]); }};//internalClass.Merge = function(previous, current){ if (previous && previous != current){ var type = $type(current); if (type != $type(previous)) return current; switch(type){ case 'function': var merged = function(){ this.parent = arguments.callee.parent; return current.apply(this, arguments); }; merged.parent = previous; return merged; case 'object': return $merge(previous, current); } } return current;};/*Script: Class.Extras.js Contains common implementations for custom classes. In Mootools is implemented in <Ajax>, <XHR> and <Fx.Base> and many more.License: MIT-style license.*//*Class: Chain An "Utility" Class. Its methods can be implemented with <Class.implement> into any <Class>. Currently implemented in <Fx.Base>, <XHR> and <Ajax>. In <Fx.Base> for example, is used to execute a list of function, one after another, once the effect is completed. The functions will not be fired all togheter, but one every completion, to create custom complex animations.Example: (start code) var myFx = new Fx.Style('element', 'opacity'); myFx.start(1,0).chain(function(){ myFx.start(0,1); }).chain(function(){ myFx.start(1,0); }).chain(function(){ myFx.start(0,1); }); //the element will appear and disappear three times (end)*/var Chain = new Class({ /* Property: chain adds a function to the Chain instance stack. Arguments: fn - the function to append. */ chain: function(fn){ this.chains = this.chains || []; this.chains.push(fn); return this; },
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -