PageRenderTime 251ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ festos/admin/includes/tiny_mce/plugins/kfm/j/mootools.v1.11/mootools.v1.11.js

http://festos.googlecode.com/
JavaScript | 4352 lines | 2256 code | 370 blank | 1726 comment | 324 complexity | 4d168e16ae2cb3985021405dc85ccc47 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. /*
  2. Script: Core.js
  3. Mootools - My Object Oriented javascript.
  4. License:
  5. MIT-style license.
  6. MooTools Copyright:
  7. copyright (c) 2007 Valerio Proietti, <http://mad4milk.net>
  8. MooTools Credits:
  9. - 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/>
  10. - 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
  11. - Documentation by Aaron Newton (aaron.newton [at] cnet [dot] com) and Valerio Proietti.
  12. */
  13. var MooTools = {
  14. version: '1.11'
  15. };
  16. /* Section: Core Functions */
  17. /*
  18. Function: $defined
  19. Returns true if the passed in value/object is defined, that means is not null or undefined.
  20. Arguments:
  21. obj - object to inspect
  22. */
  23. function $defined(obj){
  24. return (obj != undefined);
  25. };
  26. /*
  27. Function: $type
  28. Returns the type of object that matches the element passed in.
  29. Arguments:
  30. obj - the object to inspect.
  31. Example:
  32. >var myString = 'hello';
  33. >$type(myString); //returns "string"
  34. Returns:
  35. 'element' - if obj is a DOM element node
  36. 'textnode' - if obj is a DOM text node
  37. 'whitespace' - if obj is a DOM whitespace node
  38. 'arguments' - if obj is an arguments object
  39. 'object' - if obj is an object
  40. 'string' - if obj is a string
  41. 'number' - if obj is a number
  42. 'boolean' - if obj is a boolean
  43. 'function' - if obj is a function
  44. 'regexp' - if obj is a regular expression
  45. 'class' - if obj is a Class. (created with new Class, or the extend of another class).
  46. 'collection' - if obj is a native htmlelements collection, such as childNodes, getElementsByTagName .. etc.
  47. false - (boolean) if the object is not defined or none of the above.
  48. */
  49. function $type(obj){
  50. if (!$defined(obj)) return false;
  51. if (obj.htmlElement) return 'element';
  52. var type = typeof obj;
  53. if (type == 'object' && obj.nodeName){
  54. switch(obj.nodeType){
  55. case 1: return 'element';
  56. case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace';
  57. }
  58. }
  59. if (type == 'object' || type == 'function'){
  60. switch(obj.constructor){
  61. case Array: return 'array';
  62. case RegExp: return 'regexp';
  63. case Class: return 'class';
  64. }
  65. if (typeof obj.length == 'number'){
  66. if (obj.item) return 'collection';
  67. if (obj.callee) return 'arguments';
  68. }
  69. }
  70. return type;
  71. };
  72. /*
  73. Function: $merge
  74. merges a number of objects recursively without referencing them or their sub-objects.
  75. Arguments:
  76. any number of objects.
  77. Example:
  78. >var mergedObj = $merge(obj1, obj2, obj3);
  79. >//obj1, obj2, and obj3 are unaltered
  80. */
  81. function $merge(){
  82. var mix = {};
  83. for (var i = 0; i < arguments.length; i++){
  84. for (var property in arguments[i]){
  85. var ap = arguments[i][property];
  86. var mp = mix[property];
  87. if (mp && $type(ap) == 'object' && $type(mp) == 'object') mix[property] = $merge(mp, ap);
  88. else mix[property] = ap;
  89. }
  90. }
  91. return mix;
  92. };
  93. /*
  94. Function: $extend
  95. Copies all the properties from the second passed object to the first passed Object.
  96. If you do myWhatever.extend = $extend the first parameter will become myWhatever, and your extend function will only need one parameter.
  97. Example:
  98. (start code)
  99. var firstOb = {
  100. 'name': 'John',
  101. 'lastName': 'Doe'
  102. };
  103. var secondOb = {
  104. 'age': '20',
  105. 'sex': 'male',
  106. 'lastName': 'Dorian'
  107. };
  108. $extend(firstOb, secondOb);
  109. //firstOb will become:
  110. {
  111. 'name': 'John',
  112. 'lastName': 'Dorian',
  113. 'age': '20',
  114. 'sex': 'male'
  115. };
  116. (end)
  117. Returns:
  118. The first object, extended.
  119. */
  120. var $extend = function(){
  121. var args = arguments;
  122. if (!args[1]) args = [this, args[0]];
  123. for (var property in args[1]) args[0][property] = args[1][property];
  124. return args[0];
  125. };
  126. /*
  127. Function: $native
  128. 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.
  129. Its handy if you dont want the .extend method of an object to overwrite existing methods.
  130. Used automatically in MooTools to implement Array/String/Function/Number methods to browser that dont support them whitout manual checking.
  131. Arguments:
  132. a number of classes/native javascript objects
  133. */
  134. var $native = function(){
  135. for (var i = 0, l = arguments.length; i < l; i++){
  136. arguments[i].extend = function(props){
  137. for (var prop in props){
  138. if (!this.prototype[prop]) this.prototype[prop] = props[prop];
  139. if (!this[prop]) this[prop] = $native.generic(prop);
  140. }
  141. };
  142. }
  143. };
  144. $native.generic = function(prop){
  145. return function(bind){
  146. return this.prototype[prop].apply(bind, Array.prototype.slice.call(arguments, 1));
  147. };
  148. };
  149. $native(Function, Array, String, Number);
  150. /*
  151. Function: $chk
  152. Returns true if the passed in value/object exists or is 0, otherwise returns false.
  153. Useful to accept zeroes.
  154. Arguments:
  155. obj - object to inspect
  156. */
  157. function $chk(obj){
  158. return !!(obj || obj === 0);
  159. };
  160. /*
  161. Function: $pick
  162. Returns the first object if defined, otherwise returns the second.
  163. Arguments:
  164. obj - object to test
  165. picked - the default to return
  166. Example:
  167. (start code)
  168. function say(msg){
  169. alert($pick(msg, 'no meessage supplied'));
  170. }
  171. (end)
  172. */
  173. function $pick(obj, picked){
  174. return $defined(obj) ? obj : picked;
  175. };
  176. /*
  177. Function: $random
  178. Returns a random integer number between the two passed in values.
  179. Arguments:
  180. min - integer, the minimum value (inclusive).
  181. max - integer, the maximum value (inclusive).
  182. Returns:
  183. a random integer between min and max.
  184. */
  185. function $random(min, max){
  186. return Math.floor(Math.random() * (max - min + 1) + min);
  187. };
  188. /*
  189. Function: $time
  190. Returns the current timestamp
  191. Returns:
  192. a timestamp integer.
  193. */
  194. function $time(){
  195. return new Date().getTime();
  196. };
  197. /*
  198. Function: $clear
  199. clears a timeout or an Interval.
  200. Returns:
  201. null
  202. Arguments:
  203. timer - the setInterval or setTimeout to clear.
  204. Example:
  205. >var myTimer = myFunction.delay(5000); //wait 5 seconds and execute my function.
  206. >myTimer = $clear(myTimer); //nevermind
  207. See also:
  208. <Function.delay>, <Function.periodical>
  209. */
  210. function $clear(timer){
  211. clearTimeout(timer);
  212. clearInterval(timer);
  213. return null;
  214. };
  215. /*
  216. Class: Abstract
  217. Abstract class, to be used as singleton. Will add .extend to any object
  218. Arguments:
  219. an object
  220. Returns:
  221. the object with an .extend property, equivalent to <$extend>.
  222. */
  223. var Abstract = function(obj){
  224. obj = obj || {};
  225. obj.extend = $extend;
  226. return obj;
  227. };
  228. //window, document
  229. var Window = new Abstract(window);
  230. var Document = new Abstract(document);
  231. document.head = document.getElementsByTagName('head')[0];
  232. /*
  233. Class: window
  234. Some properties are attached to the window object by the browser detection.
  235. Note:
  236. browser detection is entirely object-based. We dont sniff.
  237. Properties:
  238. window.ie - will be set to true if the current browser is internet explorer (any).
  239. window.ie6 - will be set to true if the current browser is internet explorer 6.
  240. window.ie7 - will be set to true if the current browser is internet explorer 7.
  241. window.gecko - will be set to true if the current browser is Mozilla/Gecko.
  242. window.webkit - will be set to true if the current browser is Safari/Konqueror.
  243. window.webkit419 - will be set to true if the current browser is Safari2 / webkit till version 419.
  244. window.webkit420 - will be set to true if the current browser is Safari3 (Webkit SVN Build) / webkit over version 419.
  245. window.opera - is set to true by opera itself.
  246. */
  247. window.xpath = !!(document.evaluate);
  248. if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
  249. else if (document.childNodes && !document.all && !navigator.taintEnabled) window.webkit = window[window.xpath ? 'webkit420' : 'webkit419'] = true;
  250. else if (document.getBoxObjectFor != null) window.gecko = true;
  251. /*compatibility*/
  252. window.khtml = window.webkit;
  253. Object.extend = $extend;
  254. /*end compatibility*/
  255. //htmlelement
  256. if (typeof HTMLElement == 'undefined'){
  257. var HTMLElement = function(){};
  258. if (window.webkit) document.createElement("iframe"); //fixes safari
  259. HTMLElement.prototype = (window.webkit) ? window["[[DOMElement.prototype]]"] : {};
  260. }
  261. HTMLElement.prototype.htmlElement = function(){};
  262. //enables background image cache for internet explorer 6
  263. if (window.ie6) try {document.execCommand("BackgroundImageCache", false, true);} catch(e){};
  264. /*
  265. Script: Class.js
  266. Contains the Class Function, aims to ease the creation of reusable Classes.
  267. License:
  268. MIT-style license.
  269. */
  270. /*
  271. Class: Class
  272. The base class object of the <http://mootools.net> framework.
  273. Creates a new class, its initialize method will fire upon class instantiation.
  274. Initialize wont fire on instantiation when you pass *null*.
  275. Arguments:
  276. properties - the collection of properties that apply to the class.
  277. Example:
  278. (start code)
  279. var Cat = new Class({
  280. initialize: function(name){
  281. this.name = name;
  282. }
  283. });
  284. var myCat = new Cat('Micia');
  285. alert(myCat.name); //alerts 'Micia'
  286. (end)
  287. */
  288. var Class = function(properties){
  289. var klass = function(){
  290. return (arguments[0] !== null && this.initialize && $type(this.initialize) == 'function') ? this.initialize.apply(this, arguments) : this;
  291. };
  292. $extend(klass, this);
  293. klass.prototype = properties;
  294. klass.constructor = Class;
  295. return klass;
  296. };
  297. /*
  298. Property: empty
  299. Returns an empty function
  300. */
  301. Class.empty = function(){};
  302. Class.prototype = {
  303. /*
  304. Property: extend
  305. Returns the copy of the Class extended with the passed in properties.
  306. Arguments:
  307. properties - the properties to add to the base class in this new Class.
  308. Example:
  309. (start code)
  310. var Animal = new Class({
  311. initialize: function(age){
  312. this.age = age;
  313. }
  314. });
  315. var Cat = Animal.extend({
  316. initialize: function(name, age){
  317. this.parent(age); //will call the previous initialize;
  318. this.name = name;
  319. }
  320. });
  321. var myCat = new Cat('Micia', 20);
  322. alert(myCat.name); //alerts 'Micia'
  323. alert(myCat.age); //alerts 20
  324. (end)
  325. */
  326. extend: function(properties){
  327. var proto = new this(null);
  328. for (var property in properties){
  329. var pp = proto[property];
  330. proto[property] = Class.Merge(pp, properties[property]);
  331. }
  332. return new Class(proto);
  333. },
  334. /*
  335. Property: implement
  336. Implements the passed in properties to the base Class prototypes, altering the base class, unlike <Class.extend>.
  337. Arguments:
  338. properties - the properties to add to the base class.
  339. Example:
  340. (start code)
  341. var Animal = new Class({
  342. initialize: function(age){
  343. this.age = age;
  344. }
  345. });
  346. Animal.implement({
  347. setName: function(name){
  348. this.name = name
  349. }
  350. });
  351. var myAnimal = new Animal(20);
  352. myAnimal.setName('Micia');
  353. alert(myAnimal.name); //alerts 'Micia'
  354. (end)
  355. */
  356. implement: function(){
  357. for (var i = 0, l = arguments.length; i < l; i++) $extend(this.prototype, arguments[i]);
  358. }
  359. };
  360. //internal
  361. Class.Merge = function(previous, current){
  362. if (previous && previous != current){
  363. var type = $type(current);
  364. if (type != $type(previous)) return current;
  365. switch(type){
  366. case 'function':
  367. var merged = function(){
  368. this.parent = arguments.callee.parent;
  369. return current.apply(this, arguments);
  370. };
  371. merged.parent = previous;
  372. return merged;
  373. case 'object': return $merge(previous, current);
  374. }
  375. }
  376. return current;
  377. };
  378. /*
  379. Script: Class.Extras.js
  380. Contains common implementations for custom classes. In Mootools is implemented in <Ajax>, <XHR> and <Fx.Base> and many more.
  381. License:
  382. MIT-style license.
  383. */
  384. /*
  385. Class: Chain
  386. An "Utility" Class. Its methods can be implemented with <Class.implement> into any <Class>.
  387. 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.
  388. The functions will not be fired all togheter, but one every completion, to create custom complex animations.
  389. Example:
  390. (start code)
  391. var myFx = new Fx.Style('element', 'opacity');
  392. myFx.start(1,0).chain(function(){
  393. myFx.start(0,1);
  394. }).chain(function(){
  395. myFx.start(1,0);
  396. }).chain(function(){
  397. myFx.start(0,1);
  398. });
  399. //the element will appear and disappear three times
  400. (end)
  401. */
  402. var Chain = new Class({
  403. /*
  404. Property: chain
  405. adds a function to the Chain instance stack.
  406. Arguments:
  407. fn - the function to append.
  408. */
  409. chain: function(fn){
  410. this.chains = this.chains || [];
  411. this.chains.push(fn);
  412. return this;
  413. },
  414. /*
  415. Property: callChain
  416. Executes the first function of the Chain instance stack, then removes it. The first function will then become the second.
  417. */
  418. callChain: function(){
  419. if (this.chains && this.chains.length) this.chains.shift().delay(10, this);
  420. },
  421. /*
  422. Property: clearChain
  423. Clears the stack of a Chain instance.
  424. */
  425. clearChain: function(){
  426. this.chains = [];
  427. }
  428. });
  429. /*
  430. Class: Events
  431. An "Utility" Class. Its methods can be implemented with <Class.implement> into any <Class>.
  432. 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.
  433. Events in a Class that implements <Events> can be either added as an option, or with addEvent. Never with .options.onEventName.
  434. Example:
  435. (start code)
  436. var myFx = new Fx.Style('element', 'opacity').addEvent('onComplete', function(){
  437. alert('the effect is completed');
  438. }).addEvent('onComplete', function(){
  439. alert('I told you the effect is completed');
  440. });
  441. myFx.start(0,1);
  442. //upon completion it will display the 2 alerts, in order.
  443. (end)
  444. Implementing:
  445. This class can be implemented into other classes to add the functionality to them.
  446. Goes well with the <Options> class.
  447. Example:
  448. (start code)
  449. var Widget = new Class({
  450. initialize: function(){},
  451. finish: function(){
  452. this.fireEvent('onComplete');
  453. }
  454. });
  455. Widget.implement(new Events);
  456. //later...
  457. var myWidget = new Widget();
  458. myWidget.addEvent('onComplete', myfunction);
  459. (end)
  460. */
  461. var Events = new Class({
  462. /*
  463. Property: addEvent
  464. adds an event to the stack of events of the Class instance.
  465. Arguments:
  466. type - string; the event name (e.g. 'onComplete')
  467. fn - function to execute
  468. */
  469. addEvent: function(type, fn){
  470. if (fn != Class.empty){
  471. this.$events = this.$events || {};
  472. this.$events[type] = this.$events[type] || [];
  473. this.$events[type].include(fn);
  474. }
  475. return this;
  476. },
  477. /*
  478. Property: fireEvent
  479. fires all events of the specified type in the Class instance.
  480. Arguments:
  481. type - string; the event name (e.g. 'onComplete')
  482. args - array or single object; arguments to pass to the function; if more than one argument, must be an array
  483. delay - (integer) delay (in ms) to wait to execute the event
  484. Example:
  485. (start code)
  486. var Widget = new Class({
  487. initialize: function(arg1, arg2){
  488. ...
  489. this.fireEvent("onInitialize", [arg1, arg2], 50);
  490. }
  491. });
  492. Widget.implement(new Events);
  493. (end)
  494. */
  495. fireEvent: function(type, args, delay){
  496. if (this.$events && this.$events[type]){
  497. this.$events[type].each(function(fn){
  498. fn.create({'bind': this, 'delay': delay, 'arguments': args})();
  499. }, this);
  500. }
  501. return this;
  502. },
  503. /*
  504. Property: removeEvent
  505. removes an event from the stack of events of the Class instance.
  506. Arguments:
  507. type - string; the event name (e.g. 'onComplete')
  508. fn - function that was added
  509. */
  510. removeEvent: function(type, fn){
  511. if (this.$events && this.$events[type]) this.$events[type].remove(fn);
  512. return this;
  513. }
  514. });
  515. /*
  516. Class: Options
  517. An "Utility" Class. Its methods can be implemented with <Class.implement> into any <Class>.
  518. Used to automate the options settings, also adding Class <Events> when the option begins with on.
  519. Example:
  520. (start code)
  521. var Widget = new Class({
  522. options: {
  523. color: '#fff',
  524. size: {
  525. width: 100
  526. height: 100
  527. }
  528. },
  529. initialize: function(options){
  530. this.setOptions(options);
  531. }
  532. });
  533. Widget.implement(new Options);
  534. //later...
  535. var myWidget = new Widget({
  536. color: '#f00',
  537. size: {
  538. width: 200
  539. }
  540. });
  541. //myWidget.options = {color: #f00, size: {width: 200, height: 100}}
  542. (end)
  543. */
  544. var Options = new Class({
  545. /*
  546. Property: setOptions
  547. sets this.options
  548. Arguments:
  549. defaults - object; the default set of options
  550. options - object; the user entered options. can be empty too.
  551. Note:
  552. if your Class has <Events> implemented, every option beginning with on, followed by a capital letter (onComplete) becomes an Class instance event.
  553. */
  554. setOptions: function(){
  555. this.options = $merge.apply(null, [this.options].extend(arguments));
  556. if (this.addEvent){
  557. for (var option in this.options){
  558. if ($type(this.options[option] == 'function') && (/^on[A-Z]/).test(option)) this.addEvent(option, this.options[option]);
  559. }
  560. }
  561. return this;
  562. }
  563. });
  564. /*
  565. Script: Array.js
  566. Contains Array prototypes, <$A>, <$each>
  567. License:
  568. MIT-style license.
  569. */
  570. /*
  571. Class: Array
  572. A collection of The Array Object prototype methods.
  573. */
  574. //custom methods
  575. Array.extend({
  576. /*
  577. Property: forEach
  578. Iterates through an array; This method is only available for browsers without native *forEach* support.
  579. For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:forEach>
  580. *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.
  581. Arguments:
  582. fn - function to execute with each item in the array; passed the item and the index of that item in the array
  583. bind - the object to bind "this" to (see <Function.bind>)
  584. Example:
  585. >['apple','banana','lemon'].each(function(item, index){
  586. > alert(index + " = " + item); //alerts "0 = apple" etc.
  587. >}, bindObj); //optional second arg for binding, not used here
  588. */
  589. forEach: function(fn, bind){
  590. for (var i = 0, j = this.length; i < j; i++) fn.call(bind, this[i], i, this);
  591. },
  592. /*
  593. Property: filter
  594. This method is provided only for browsers without native *filter* support.
  595. For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:filter>
  596. *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.
  597. Arguments:
  598. fn - function to execute with each item in the array; passed the item and the index of that item in the array
  599. bind - the object to bind "this" to (see <Function.bind>)
  600. Example:
  601. >var biggerThanTwenty = [10,3,25,100].filter(function(item, index){
  602. > return item > 20;
  603. >});
  604. >//biggerThanTwenty = [25,100]
  605. */
  606. filter: function(fn, bind){
  607. var results = [];
  608. for (var i = 0, j = this.length; i < j; i++){
  609. if (fn.call(bind, this[i], i, this)) results.push(this[i]);
  610. }
  611. return results;
  612. },
  613. /*
  614. Property: map
  615. This method is provided only for browsers without native *map* support.
  616. For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:map>
  617. *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.
  618. Arguments:
  619. fn - function to execute with each item in the array; passed the item and the index of that item in the array
  620. bind - the object to bind "this" to (see <Function.bind>)
  621. Example:
  622. >var timesTwo = [1,2,3].map(function(item, index){
  623. > return item*2;
  624. >});
  625. >//timesTwo = [2,4,6];
  626. */
  627. map: function(fn, bind){
  628. var results = [];
  629. for (var i = 0, j = this.length; i < j; i++) results[i] = fn.call(bind, this[i], i, this);
  630. return results;
  631. },
  632. /*
  633. Property: every
  634. This method is provided only for browsers without native *every* support.
  635. For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:every>
  636. *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.
  637. Arguments:
  638. fn - function to execute with each item in the array; passed the item and the index of that item in the array
  639. bind - the object to bind "this" to (see <Function.bind>)
  640. Example:
  641. >var areAllBigEnough = [10,4,25,100].every(function(item, index){
  642. > return item > 20;
  643. >});
  644. >//areAllBigEnough = false
  645. */
  646. every: function(fn, bind){
  647. for (var i = 0, j = this.length; i < j; i++){
  648. if (!fn.call(bind, this[i], i, this)) return false;
  649. }
  650. return true;
  651. },
  652. /*
  653. Property: some
  654. This method is provided only for browsers without native *some* support.
  655. For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:some>
  656. *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.
  657. Arguments:
  658. fn - function to execute with each item in the array; passed the item and the index of that item in the array
  659. bind - the object to bind "this" to (see <Function.bind>)
  660. Example:
  661. >var isAnyBigEnough = [10,4,25,100].some(function(item, index){
  662. > return item > 20;
  663. >});
  664. >//isAnyBigEnough = true
  665. */
  666. some: function(fn, bind){
  667. for (var i = 0, j = this.length; i < j; i++){
  668. if (fn.call(bind, this[i], i, this)) return true;
  669. }
  670. return false;
  671. },
  672. /*
  673. Property: indexOf
  674. This method is provided only for browsers without native *indexOf* support.
  675. For more info see <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:indexOf>
  676. *indexOf* compares a search element to elements of the Array using strict equality (the same method used by the ===, or triple-equals, operator).
  677. Arguments:
  678. item - any type of object; element to locate in the array
  679. from - integer; optional; the index of the array at which to begin the search (defaults to 0)
  680. Example:
  681. >['apple','lemon','banana'].indexOf('lemon'); //returns 1
  682. >['apple','lemon'].indexOf('banana'); //returns -1
  683. */
  684. indexOf: function(item, from){
  685. var len = this.length;
  686. for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
  687. if (this[i] === item) return i;
  688. }
  689. return -1;
  690. },
  691. /*
  692. Property: each
  693. Same as <Array.forEach>.
  694. Arguments:
  695. fn - function to execute with each item in the array; passed the item and the index of that item in the array
  696. bind - optional, the object that the "this" of the function will refer to.
  697. Example:
  698. >var Animals = ['Cat', 'Dog', 'Coala'];
  699. >Animals.each(function(animal){
  700. > document.write(animal)
  701. >});
  702. */
  703. /*
  704. Property: copy
  705. returns a copy of the array.
  706. Returns:
  707. a new array which is a copy of the current one.
  708. Arguments:
  709. 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.
  710. length - integer; optional; the number of elements to copy. By default, copies all elements from start to the end of the array.
  711. Example:
  712. >var letters = ["a","b","c"];
  713. >var copy = letters.copy(); // ["a","b","c"] (new instance)
  714. */
  715. copy: function(start, length){
  716. start = start || 0;
  717. if (start < 0) start = this.length + start;
  718. length = length || (this.length - start);
  719. var newArray = [];
  720. for (var i = 0; i < length; i++) newArray[i] = this[start++];
  721. return newArray;
  722. },
  723. /*
  724. Property: remove
  725. Removes all occurrences of an item from the array.
  726. Arguments:
  727. item - the item to remove
  728. Returns:
  729. the Array with all occurrences of the item removed.
  730. Example:
  731. >["1","2","3","2"].remove("2") // ["1","3"];
  732. */
  733. remove: function(item){
  734. var i = 0;
  735. var len = this.length;
  736. while (i < len){
  737. if (this[i] === item){
  738. this.splice(i, 1);
  739. len--;
  740. } else {
  741. i++;
  742. }
  743. }
  744. return this;
  745. },
  746. /*
  747. Property: contains
  748. Tests an array for the presence of an item.
  749. Arguments:
  750. item - the item to search for in the array.
  751. 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.
  752. Returns:
  753. true - the item was found
  754. false - it wasn't
  755. Example:
  756. >["a","b","c"].contains("a"); // true
  757. >["a","b","c"].contains("d"); // false
  758. */
  759. contains: function(item, from){
  760. return this.indexOf(item, from) != -1;
  761. },
  762. /*
  763. Property: associate
  764. Creates an object with key-value pairs based on the array of keywords passed in
  765. and the current content of the array.
  766. Arguments:
  767. keys - the array of keywords.
  768. Example:
  769. (start code)
  770. var Animals = ['Cat', 'Dog', 'Coala', 'Lizard'];
  771. var Speech = ['Miao', 'Bau', 'Fruuu', 'Mute'];
  772. var Speeches = Animals.associate(Speech);
  773. //Speeches['Miao'] is now Cat.
  774. //Speeches['Bau'] is now Dog.
  775. //...
  776. (end)
  777. */
  778. associate: function(keys){
  779. var obj = {}, length = Math.min(this.length, keys.length);
  780. for (var i = 0; i < length; i++) obj[keys[i]] = this[i];
  781. return obj;
  782. },
  783. /*
  784. Property: extend
  785. Extends an array with another one.
  786. Arguments:
  787. array - the array to extend ours with
  788. Example:
  789. >var Animals = ['Cat', 'Dog', 'Coala'];
  790. >Animals.extend(['Lizard']);
  791. >//Animals is now: ['Cat', 'Dog', 'Coala', 'Lizard'];
  792. */
  793. extend: function(array){
  794. for (var i = 0, j = array.length; i < j; i++) this.push(array[i]);
  795. return this;
  796. },
  797. /*
  798. Property: merge
  799. merges an array in another array, without duplicates. (case- and type-sensitive)
  800. Arguments:
  801. array - the array to merge from.
  802. Example:
  803. >['Cat','Dog'].merge(['Dog','Coala']); //returns ['Cat','Dog','Coala']
  804. */
  805. merge: function(array){
  806. for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
  807. return this;
  808. },
  809. /*
  810. Property: include
  811. includes the passed in element in the array, only if its not already present. (case- and type-sensitive)
  812. Arguments:
  813. item - item to add to the array (if not present)
  814. Example:
  815. >['Cat','Dog'].include('Dog'); //returns ['Cat','Dog']
  816. >['Cat','Dog'].include('Coala'); //returns ['Cat','Dog','Coala']
  817. */
  818. include: function(item){
  819. if (!this.contains(item)) this.push(item);
  820. return this;
  821. },
  822. /*
  823. Property: getRandom
  824. returns a random item in the Array
  825. */
  826. getRandom: function(){
  827. return this[$random(0, this.length - 1)] || null;
  828. },
  829. /*
  830. Property: getLast
  831. returns the last item in the Array
  832. */
  833. getLast: function(){
  834. return this[this.length - 1] || null;
  835. }
  836. });
  837. //copies
  838. Array.prototype.each = Array.prototype.forEach;
  839. Array.each = Array.forEach;
  840. /* Section: Utility Functions */
  841. /*
  842. Function: $A()
  843. Same as <Array.copy>, but as function.
  844. Useful to apply Array prototypes to iterable objects, as a collection of DOM elements or the arguments object.
  845. Example:
  846. (start code)
  847. function myFunction(){
  848. $A(arguments).each(argument, function(){
  849. alert(argument);
  850. });
  851. };
  852. //the above will alert all the arguments passed to the function myFunction.
  853. (end)
  854. */
  855. function $A(array){
  856. return Array.copy(array);
  857. };
  858. /*
  859. Function: $each
  860. Use to iterate through iterables that are not regular arrays, such as builtin getElementsByTagName calls, arguments of a function, or an object.
  861. Arguments:
  862. iterable - an iterable element or an objct.
  863. function - function to apply to the iterable.
  864. bind - optional, the 'this' of the function will refer to this object.
  865. Function argument:
  866. The function argument will be passed the following arguments.
  867. item - the current item in the iterator being procesed
  868. index - integer; the index of the item, or key in case of an object.
  869. Examples:
  870. (start code)
  871. $each(['Sun','Mon','Tue'], function(day, index){
  872. alert('name:' + day + ', index: ' + index);
  873. });
  874. //alerts "name: Sun, index: 0", "name: Mon, index: 1", etc.
  875. //over an object
  876. $each({first: "Sunday", second: "Monday", third: "Tuesday"}, function(value, key){
  877. alert("the " + key + " day of the week is " + value);
  878. });
  879. //alerts "the first day of the week is Sunday",
  880. //"the second day of the week is Monday", etc.
  881. (end)
  882. */
  883. function $each(iterable, fn, bind){
  884. if (iterable && typeof iterable.length == 'number' && $type(iterable) != 'object'){
  885. Array.forEach(iterable, fn, bind);
  886. } else {
  887. for (var name in iterable) fn.call(bind || iterable, iterable[name], name);
  888. }
  889. };
  890. /*compatibility*/
  891. Array.prototype.test = Array.prototype.contains;
  892. /*end compatibility*/
  893. /*
  894. Script: String.js
  895. Contains String prototypes.
  896. License:
  897. MIT-style license.
  898. */
  899. /*
  900. Class: String
  901. A collection of The String Object prototype methods.
  902. */
  903. String.extend({
  904. /*
  905. Property: test
  906. Tests a string with a regular expression.
  907. Arguments:
  908. regex - a string or regular expression object, the regular expression you want to match the string with
  909. params - optional, if first parameter is a string, any parameters you want to pass to the regex ('g' has no effect)
  910. Returns:
  911. true if a match for the regular expression is found in the string, false if not.
  912. See <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:RegExp:test>
  913. Example:
  914. >"I like cookies".test("cookie"); // returns true
  915. >"I like cookies".test("COOKIE", "i") // ignore case, returns true
  916. >"I like cookies".test("cake"); // returns false
  917. */
  918. test: function(regex, params){
  919. return (($type(regex) == 'string') ? new RegExp(regex, params) : regex).test(this);
  920. },
  921. /*
  922. Property: toInt
  923. parses a string to an integer.
  924. Returns:
  925. either an int or "NaN" if the string is not a number.
  926. Example:
  927. >var value = "10px".toInt(); // value is 10
  928. */
  929. toInt: function(){
  930. return parseInt(this, 10);
  931. },
  932. /*
  933. Property: toFloat
  934. parses a string to an float.
  935. Returns:
  936. either a float or "NaN" if the string is not a number.
  937. Example:
  938. >var value = "10.848".toFloat(); // value is 10.848
  939. */
  940. toFloat: function(){
  941. return parseFloat(this);
  942. },
  943. /*
  944. Property: camelCase
  945. Converts a hiphenated string to a camelcase string.
  946. Example:
  947. >"I-like-cookies".camelCase(); //"ILikeCookies"
  948. Returns:
  949. the camel cased string
  950. */
  951. camelCase: function(){
  952. return this.replace(/-\D/g, function(match){
  953. return match.charAt(1).toUpperCase();
  954. });
  955. },
  956. /*
  957. Property: hyphenate
  958. Converts a camelCased string to a hyphen-ated string.
  959. Example:
  960. >"ILikeCookies".hyphenate(); //"I-like-cookies"
  961. */
  962. hyphenate: function(){
  963. return this.replace(/\w[A-Z]/g, function(match){
  964. return (match.charAt(0) + '-' + match.charAt(1).toLowerCase());
  965. });
  966. },
  967. /*
  968. Property: capitalize
  969. Converts the first letter in each word of a string to Uppercase.
  970. Example:
  971. >"i like cookies".capitalize(); //"I Like Cookies"
  972. Returns:
  973. the capitalized string
  974. */
  975. capitalize: function(){
  976. return this.replace(/\b[a-z]/g, function(match){
  977. return match.toUpperCase();
  978. });
  979. },
  980. /*
  981. Property: trim
  982. Trims the leading and trailing spaces off a string.
  983. Example:
  984. >" i like cookies ".trim() //"i like cookies"
  985. Returns:
  986. the trimmed string
  987. */
  988. trim: function(){
  989. return this.replace(/^\s+|\s+$/g, '');
  990. },
  991. /*
  992. Property: clean
  993. trims (<String.trim>) a string AND removes all the double spaces in a string.
  994. Returns:
  995. the cleaned string
  996. Example:
  997. >" i like cookies \n\n".clean() //"i like cookies"
  998. */
  999. clean: function(){
  1000. return this.replace(/\s{2,}/g, ' ').trim();
  1001. },
  1002. /*
  1003. Property: rgbToHex
  1004. Converts an RGB value to hexidecimal. The string must be in the format of "rgb(255,255,255)" or "rgba(255,255,255,1)";
  1005. Arguments:
  1006. array - boolean value, defaults to false. Use true if you want the array ['FF','33','00'] as output instead of "#FF3300"
  1007. Returns:
  1008. hex string or array. returns "transparent" if the output is set as string and the fourth value of rgba in input string is 0.
  1009. Example:
  1010. >"rgb(17,34,51)".rgbToHex(); //"#112233"
  1011. >"rgba(17,34,51,0)".rgbToHex(); //"transparent"
  1012. >"rgb(17,34,51)".rgbToHex(true); //['11','22','33']
  1013. */
  1014. rgbToHex: function(array){
  1015. var rgb = this.match(/\d{1,3}/g);
  1016. return (rgb) ? rgb.rgbToHex(array) : false;
  1017. },
  1018. /*
  1019. Property: hexToRgb
  1020. Converts a hexidecimal color value to RGB. Input string must be the hex color value (with or without the hash). Also accepts triplets ('333');
  1021. Arguments:
  1022. array - boolean value, defaults to false. Use true if you want the array [255,255,255] as output instead of "rgb(255,255,255)";
  1023. Returns:
  1024. rgb string or array.
  1025. Example:
  1026. >"#112233".hexToRgb(); //"rgb(17,34,51)"
  1027. >"#112233".hexToRgb(true); //[17,34,51]
  1028. */
  1029. hexToRgb: function(array){
  1030. var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
  1031. return (hex) ? hex.slice(1).hexToRgb(array) : false;
  1032. },
  1033. /*
  1034. Property: contains
  1035. checks if the passed in string is contained in the String. also accepts an optional second parameter, to check if the string is contained in a list of separated values.
  1036. Example:
  1037. >'a b c'.contains('c', ' '); //true
  1038. >'a bc'.contains('bc'); //true
  1039. >'a bc'.contains('b', ' '); //false
  1040. */
  1041. contains: function(string, s){
  1042. return (s) ? (s + this + s).indexOf(s + string + s) > -1 : this.indexOf(string) > -1;
  1043. },
  1044. /*
  1045. Property: escapeRegExp
  1046. Returns string with escaped regular expression characters
  1047. Example:
  1048. >var search = 'animals.sheeps[1]'.escapeRegExp(); // search is now 'animals\.sheeps\[1\]'
  1049. Returns:
  1050. Escaped string
  1051. */
  1052. escapeRegExp: function(){
  1053. return this.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  1054. }
  1055. });
  1056. Array.extend({
  1057. /*
  1058. Property: rgbToHex
  1059. see <String.rgbToHex>, but as an array method.
  1060. */
  1061. rgbToHex: function(array){
  1062. if (this.length < 3) return false;
  1063. if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
  1064. var hex = [];
  1065. for (var i = 0; i < 3; i++){
  1066. var bit = (this[i] - 0).toString(16);
  1067. hex.push((bit.length == 1) ? '0' + bit : bit);
  1068. }
  1069. return array ? hex : '#' + hex.join('');
  1070. },
  1071. /*
  1072. Property: hexToRgb
  1073. same as <String.hexToRgb>, but as an array method.
  1074. */
  1075. hexToRgb: function(array){
  1076. if (this.length != 3) return false;
  1077. var rgb = [];
  1078. for (var i = 0; i < 3; i++){
  1079. rgb.push(parseInt((this[i].length == 1) ? this[i] + this[i] : this[i], 16));
  1080. }
  1081. return array ? rgb : 'rgb(' + rgb.join(',') + ')';
  1082. }
  1083. });
  1084. /*
  1085. Script: Function.js
  1086. Contains Function prototypes and utility functions .
  1087. License:
  1088. MIT-style license.
  1089. Credits:
  1090. - 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
  1091. */
  1092. /*
  1093. Class: Function
  1094. A collection of The Function Object prototype methods.
  1095. */
  1096. Function.extend({
  1097. /*
  1098. Property: create
  1099. Main function to create closures.
  1100. Returns:
  1101. a function.
  1102. Arguments:
  1103. options - An Options object.
  1104. Options:
  1105. bind - The object that the "this" of the function will refer to. Default is the current function.
  1106. event - If set to true, the function will act as an event listener and receive an event as first argument.
  1107. If set to a class name, the function will receive a new instance of this class (with the event passed as argument's constructor) as first argument.
  1108. Default is false.
  1109. arguments - A single argument or array of arguments that will be passed to the function when called.
  1110. If both the event and arguments options are set, the event is passed as first argument and the arguments array will follow.
  1111. Default is no custom arguments, the function will receive the standard arguments when called.
  1112. delay - Numeric value: if set, the returned function will delay the actual execution by this amount of milliseconds and return a timer handle when called.
  1113. Default is no delay.
  1114. periodical - Numeric value: if set, the returned function will periodically perform the actual execution with this specified interval and return a timer handle when called.
  1115. Default is no periodical execution.
  1116. attempt - If set to true, the returned function will try to execute and return either the results or false on error. Default is false.
  1117. */
  1118. create: function(options){
  1119. var fn = this;
  1120. options = $merge({
  1121. 'bind': fn,
  1122. 'event': false,
  1123. 'arguments': null,
  1124. 'delay': false,
  1125. 'periodical': false,
  1126. 'attempt': false
  1127. }, options);
  1128. if ($chk(options.arguments) && $type(options.arguments) != 'array') options.arguments = [options.arguments];
  1129. return function(event){
  1130. var args;
  1131. if (options.event){
  1132. event = event || window.event;
  1133. args = [(options.event === true) ? event : new options.event(event)];
  1134. if (options.arguments) args.extend(options.arguments);
  1135. }
  1136. else args = options.arguments || arguments;
  1137. var returns = function(){
  1138. return fn.apply($pick(options.bind, fn), args);
  1139. };
  1140. if (options.delay) return setTimeout(returns, options.delay);
  1141. if (options.periodical) return setInterval(returns, options.periodical);
  1142. if (options.attempt) try {return returns();} catch(err){return false;};
  1143. return returns();
  1144. };
  1145. },
  1146. /*
  1147. Property: pass
  1148. Shortcut to create closures with arguments and bind.
  1149. Returns:
  1150. a function.
  1151. Arguments:
  1152. args - the arguments passed. must be an array if arguments > 1
  1153. bind - optional, the object that the "this" of the function will refer to.
  1154. Example:
  1155. >myFunction.pass([arg1, arg2], myElement);
  1156. */
  1157. pass: function(args, bind){
  1158. return this.create({'arguments': args, 'bind': bind});
  1159. },
  1160. /*
  1161. Property: attempt
  1162. Tries to execute the function, returns either the result of the function or false on error.
  1163. Arguments:
  1164. args - the arguments passed. must be an array if arguments > 1
  1165. bind - optional, the object that the "this" of the function will refer to.
  1166. Example:
  1167. >myFunction.attempt([arg1, arg2], myElement);
  1168. */
  1169. attempt: function(args, bind){
  1170. return this.create({'arguments': args, 'bind': bind, 'attempt': true})();
  1171. },
  1172. /*
  1173. Property: bind
  1174. method to easily create closures with "this" altered.
  1175. Arguments:
  1176. bind - optional, the object that the "this" of the function will refer to.
  1177. args - optional, the arguments passed. must be an array if arguments > 1
  1178. Returns:
  1179. a function.
  1180. Example:
  1181. >function myFunction(){
  1182. > this.setStyle('color', 'red');
  1183. > // note that 'this' here refers to myFunction, not an element
  1184. > // we'll need to bind this function to the element we want to alter
  1185. >};
  1186. >var myBoundFunction = myFunction.bind(myElement);
  1187. >myBoundFunction(); // this will make the element myElement red.
  1188. */
  1189. bind: function(bind, args){
  1190. return this.create({'bind': bind, 'arguments': args});
  1191. },
  1192. /*
  1193. Property: bindAsEventListener
  1194. cross browser method to pass event firer
  1195. Arguments:
  1196. bind - optional, the object that the "this" of the function will refer to.
  1197. args - optional, the arguments passed. must be an array if arguments > 1
  1198. Returns:
  1199. a function with the parameter bind as its "this" and as a pre-passed argument event or window.event, depending on the browser.
  1200. Example:
  1201. >function myFunction(event){
  1202. > alert(event.clientx) //returns the coordinates of the mouse..
  1203. >};
  1204. >myElement.onclick = myFunction.bindAsEventListener(myElement);
  1205. */
  1206. bindAsEventListener: function(bind, args){
  1207. return this.create({'bind': bind, 'event': true, 'arguments': args});
  1208. },
  1209. /*
  1210. Property: delay
  1211. Delays the execution of a function by a specified duration.
  1212. Arguments:
  1213. delay - the duration to wait in milliseconds.
  1214. bind - optional, the object that the "this" of the function will refer to.
  1215. args - optional, the arguments passed. must be an array if arguments > 1
  1216. Example:
  1217. >myFunction.delay(50, myElement) //wait 50 milliseconds, then call myFunction and bind myElement to it
  1218. >(function(){alert('one second later...')}).delay(1000); //wait a second and alert
  1219. */
  1220. delay: function(delay, bind, args){
  1221. return this.create({'delay': delay, 'bind': bind, 'arguments': args})();
  1222. },
  1223. /*
  1224. Property: periodical
  1225. Executes a function in the specified intervals of time
  1226. Arguments:
  1227. interval - the duration of the intervals between executions.
  1228. bind - optional, the object that the "this" of the function will refer to.
  1229. args - optional, the arguments passed. must be an array if arguments > 1
  1230. */
  1231. periodical: function(interval, bind, args){
  1232. return this.create({'periodical': interval, 'bind': bind, 'arguments': args})();
  1233. }
  1234. });
  1235. /*
  1236. Script: Number.js
  1237. Contains the Number prototypes.
  1238. License:
  1239. MIT-style license.
  1240. */
  1241. /*
  1242. Class: Number
  1243. A collection of The Number Object prototype methods.
  1244. */
  1245. Number.extend({
  1246. /*
  1247. Property: toInt
  1248. Returns this number; useful because toInt must work on both Strings and Numbers.
  1249. */
  1250. toInt: function(){
  1251. return parseInt(this);
  1252. },
  1253. /*
  1254. Property: toFloat
  1255. Returns this number as a float; useful because toFloat must work on both Strings and Numbers.
  1256. */
  1257. toFloat: function(){
  1258. return parseFloat(this);
  1259. },
  1260. /*
  1261. Property: limit
  1262. Limits the number.
  1263. Arguments:
  1264. min - number, minimum value
  1265. max - number, maximum value
  1266. Returns:
  1267. the number in the given limits.
  1268. Example:
  1269. >(12).limit(2, 6.5) // returns 6.5
  1270. >(-4).limit(2, 6.5) // returns 2
  1271. >(4.3).limit(2, 6.5) // returns 4.3
  1272. */
  1273. limit: function(min, max){
  1274. return Math.min(max, Math.max(min, this));
  1275. },
  1276. /*
  1277. Property: round
  1278. Returns the number rounded to specified precision.
  1279. Arguments:
  1280. precision - integer, number of digits after the decimal point. Can also be negative or zero (default).
  1281. Example:
  1282. >12.45.round() // returns 12
  1283. >12.45.round(1) // returns 12.5
  1284. >12.45.round(-1) // returns 10
  1285. Returns:
  1286. The rounded number.
  1287. */
  1288. round: function(precision){
  1289. precision = Math.pow(10, precision || 0);
  1290. return Math.round(this * precision) / precision;
  1291. },
  1292. /*
  1293. Property: times
  1294. Executes a passed in function the specified number of times
  1295. Arguments:
  1296. function - the function to be executed on each iteration of the loop
  1297. Example:
  1298. >(4).times(alert);
  1299. */
  1300. times: function(fn){
  1301. for (var i = 0; i < this; i++) fn(i);
  1302. }
  1303. });
  1304. /*
  1305. Script: Element.js
  1306. Contains useful Element prototypes, to be used with the dollar function <$>.
  1307. License:
  1308. MIT-style license.
  1309. Credits:
  1310. - 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
  1311. */
  1312. /*
  1313. Class: Element
  1314. Custom class to allow all of its methods to be used with any DOM element via the dollar function <$>.
  1315. */
  1316. var Element = new Class({
  1317. /*
  1318. Property: initialize
  1319. Creates a new element of the type passed in.
  1320. Arguments:
  1321. el - string; the tag name for the element you wish to create. you can also pass in an element reference, in which case it will be extended.
  1322. props - object; the properties you want to add to your element.
  1323. Accepts the same keys as <Element.setProperties>, but also allows events and styles
  1324. Props:
  1325. the key styles will be used as setStyles, the key events will be used as addEvents. any other key is used as setProperty.
  1326. Example:
  1327. (start code)
  1328. new Element('a', {
  1329. 'styles': {
  1330. 'display': 'block',
  1331. 'border': '1px solid black'
  1332. },
  1333. 'events': {
  1334. 'click': function(){
  1335. //aaa
  1336. },
  1337. 'mousedown': function(){
  1338. //aaa
  1339. }
  1340. },
  1341. 'class': 'myClassSuperClass',
  1342. 'href': 'http://mad4milk.net'
  1343. });
  1344. (end)
  1345. */
  1346. initialize: function(el, props){
  1347. if ($type(el) == 'string'){
  1348. if (window.ie && props && (props.name || props.type)){
  1349. var name = (props.name) ? ' name="' + props.name + '"' : '';
  1350. var type = (props.type) ? ' type="' + props.type + '"' : '';
  1351. delete props.name;
  1352. delete props.type;
  1353. el = '<' + el + name + type + '>';
  1354. }
  1355. el = document.createElement(el);
  1356. }
  1357. el = $(el);
  1358. return (!props || !el) ? el : el.set(props);
  1359. }
  1360. });
  1361. /*
  1362. Class: Elements
  1363. - Every dom function such as <$$>, or in general every function that returns a collection of nodes in mootools, returns them as an Elements class.
  1364. - The purpose of the Elements class is to allow <Element> methods to work also on <Elements> array.
  1365. - Elements is also an Array, so it accepts all the <Array> methods.
  1366. - Every node of the Elements instance is already extended with <$>.
  1367. Example:
  1368. >$$('myselector').each(function(el){
  1369. > //...
  1370. >});
  1371. some iterations here, $$('myselector') is also an array.
  1372. >$$('myselector').setStyle('color', 'red');
  1373. every element returned by $$('myselector') also accepts <Element> methods, in this example every element will be made red.
  1374. */
  1375. var Elements = new Class({
  1376. initialize: function(elements){
  1377. return (elements) ? $extend(elements, this) : this;
  1378. }
  1379. });
  1380. Elements.extend = function(props){
  1381. for (var prop in props){
  1382. this.prototype[prop] = props[prop];
  1383. this[prop] = $native.generic(prop);
  1384. }
  1385. };
  1386. /*
  1387. Section: Utility Functions
  1388. Function: $
  1389. returns the element passed in with all the Element prototypes applied.
  1390. Arguments:
  1391. el - a reference to an actual element or a string representing the id of an element
  1392. Example:
  1393. >$('myElement') // gets a DOM element by id with all the Element prototypes applied.
  1394. >var div = document.getElementById('myElement');
  1395. >$(div) //returns an Element also with all the mootools extentions applied.
  1396. You'll use this when you aren't sure if a variable is an actual element or an id, as
  1397. well as just shorthand for document.getElementById().
  1398. Returns:
  1399. a DOM element or false (if no id was found).
  1400. Note:
  1401. you need to call $ on an element only once to get all the prototypes.
  1402. But its no harm to call it multiple times, as it will detect if it has been already extended.
  1403. */
  1404. function $(el){
  1405. if (!el) return null;
  1406. if (el.htmlElement) return Garbage.collect(el);
  1407. if ([window, document].contains(el)) return el;
  1408. var type = $type(el);
  1409. if (type == 'string'){
  1410. el = document.getElementById(el);
  1411. type = (el) ? 'element' : false;
  1412. }
  1413. if (type != 'element') return null;
  1414. if (el.htmlElement) return Garbage.collect(el);
  1415. if (['object', 'embed'].contains(el.tagName.toLowerCase())) return el;
  1416. $extend(el, Element.prototype);
  1417. el.htmlElement = function(){};
  1418. return Garbage.collect(el);
  1419. };
  1420. /*
  1421. Function: $$
  1422. Selects, and extends DOM elements. Elements arrays returned with $$ will also accept all the <Element> methods.
  1423. The return type of element methods run through $$ is always an array. If the return array is only made by elements,
  1424. $$ will be applied automatically.
  1425. Arguments:
  1426. HTML Collections, arrays of elements, arrays of strings as element ids, elements, strings as selectors.
  1427. Any number of the above as arguments are accepted.
  1428. Note:
  1429. if you load <Element.Selectors.js>, $$ will also accept CSS Selectors, otherwise the only selectors supported are tag names.
  1430. Example:
  1431. >$$('a') //an array of all anchor tags on the page
  1432. >$$('a', 'b') //an array of all anchor and bold tags on the page
  1433. >$$('#myElement') //array containing only the element with id = myElement. (only with <Element.Selectors.js>)
  1434. >$$('#myElement a.myClass') //an array of all anchor tags with the class "myClass"
  1435. >//within the DOM element with id "myElement" (only with <Element.Selectors.js>)
  1436. >$$(myelement, myelement2, 'a', ['myid', myid2, 'myid3'], document.getElementsByTagName('div')) //an array containing:
  1437. >// the element referenced as myelement if existing,
  1438. >// the element referenced as myelement2 if existing,
  1439. >// all the elements with a as tag in the page,
  1440. >// the element with id = myid if existing
  1441. >// the element with id = myid2 if existing
  1442. >// the element with id = myid3 if existing
  1443. >// all the elements with div as tag in the page
  1444. Returns:
  1445. array - array of all the dom elements matched, extended with <$>. Returns as <Elements>.
  1446. */
  1447. document.getElementsBySelector = document.getElementsByTagName;
  1448. function $$(){
  1449. var elements = [];
  1450. for (var i = 0, j = arguments.length; i < j; i++){
  1451. var selector = arguments[i];
  1452. switch($type(selector)){
  1453. case 'element': elements.push(selector);
  1454. case 'boolean': break;
  1455. case false: break;
  1456. case 'string': selector = document.getElementsBySelector(selector, true);
  1457. default: elements.extend(selector);
  1458. }
  1459. }
  1460. return $$.unique(elements);
  1461. };
  1462. $$.unique = function(array){
  1463. var elements = [];
  1464. for (var i = 0, l = array.length; i < l; i++){
  1465. if (array[i].$included) continue;
  1466. var element = $(array[i]);
  1467. if (element && !element.$included){
  1468. element.$included = true;
  1469. elements.push(element);
  1470. }
  1471. }
  1472. for (var n = 0, d = elements.length; n < d; n++) elements[n].$included = null;
  1473. return new Elements(elements);
  1474. };
  1475. Elements.Multi = function(property){
  1476. return function(){
  1477. var args = arguments;
  1478. var items = [];
  1479. var elements = true;
  1480. for (var i = 0, j = this.length, returns; i < j; i++){
  1481. returns = this[i][property].apply(this[i], args);
  1482. if ($type(returns) != 'element') elements = false;
  1483. items.push(returns);
  1484. };
  1485. return (elements) ? $$.unique(items) : items;
  1486. };
  1487. };
  1488. Element.extend = function(properties){
  1489. for (var property in properties){
  1490. HTMLElement.prototype[property] = properties[property];
  1491. Element.prototype[property] = properties[property];
  1492. Element[property] = $native.generic(property);
  1493. var elementsProperty = (Array.prototype[property]) ? property + 'Elements' : property;
  1494. Elements.prototype[elementsProperty] = Elements.Multi(property);
  1495. }
  1496. };
  1497. /*
  1498. Class: Element
  1499. Custom class to allow all of its methods to be used with any DOM element via the dollar function <$>.
  1500. */
  1501. Element.extend({
  1502. /*
  1503. Property: set
  1504. you can set events, styles and properties with this shortcut. same as calling new Element.
  1505. */
  1506. set: function(props){
  1507. for (var prop in props){
  1508. var val = props[prop];
  1509. switch(prop){
  1510. case 'styles': this.setStyles(val); break;
  1511. case 'events': if (this.addEvents) this.addEvents(val); break;
  1512. case 'properties': this.setProperties(val); break;
  1513. default: this.setProperty(prop, val);
  1514. }
  1515. }
  1516. return this;
  1517. },
  1518. inject: function(el, where){
  1519. el = $(el);
  1520. switch(where){
  1521. case 'before': el.parentNode.insertBefore(this, el); break;
  1522. case 'after':
  1523. var next = el.getNext();
  1524. if (!next) el.parentNode.appendChild(this);
  1525. else el.parentNode.insertBefore(this, next);
  1526. break;
  1527. case 'top':
  1528. var first = el.firstChild;
  1529. if (first){
  1530. el.insertBefore(this, first);
  1531. break;
  1532. }
  1533. default: el.appendChild(this);
  1534. }
  1535. return this;
  1536. },
  1537. /*
  1538. Property: injectBefore
  1539. Inserts the Element before the passed element.
  1540. Arguments:
  1541. el - an element reference or the id of the element to be injected in.
  1542. Example:
  1543. >html:
  1544. ><div id="myElement"></div>
  1545. ><div id="mySecondElement"></div>
  1546. >js:
  1547. >$('mySecondElement').injectBefore('myElement');
  1548. >resulting html:
  1549. ><div id="mySecondElement"></div>
  1550. ><div id="myElement"></div>
  1551. */
  1552. injectBefore: function(el){
  1553. return this.inject(el, 'before');
  1554. },
  1555. /*
  1556. Property: injectAfter
  1557. Same as <Element.injectBefore>, but inserts the element after.
  1558. */
  1559. injectAfter: function(el){
  1560. return this.inject(el, 'after');
  1561. },
  1562. /*
  1563. Property: injectInside
  1564. Same as <Element.injectBefore>, but inserts the element inside.
  1565. */
  1566. injectInside: function(el){
  1567. return this.inject(el, 'bottom');
  1568. },
  1569. /*
  1570. Property: injectTop
  1571. Same as <Element.injectInside>, but inserts the element inside, at the top.
  1572. */
  1573. injectTop: function(el){
  1574. return this.inject(el, 'top');
  1575. },
  1576. /*
  1577. Property: adopt
  1578. Inserts the passed elements inside the Element.
  1579. Arguments:
  1580. accepts elements references, element ids as string, selectors ($$('stuff')) / array of elements, array of ids as strings and collections.
  1581. */
  1582. adopt: function(){
  1583. var elements = [];
  1584. $each(arguments, function(argument){
  1585. elements = elements.concat(argument);
  1586. });
  1587. $$(elements).inject(this);
  1588. return this;
  1589. },
  1590. /*
  1591. Property: remove
  1592. Removes the Element from the DOM.
  1593. Example:
  1594. >$('myElement').remove() //bye bye
  1595. */
  1596. remove: function(){
  1597. return this.parentNode.removeChild(this);
  1598. },
  1599. /*
  1600. Property: clone
  1601. Clones the Element and returns the cloned one.
  1602. Arguments:
  1603. contents - boolean, when true the Element is cloned with childNodes, default true
  1604. Returns:
  1605. the cloned element
  1606. Example:
  1607. >var clone = $('myElement').clone().injectAfter('myElement');
  1608. >//clones the Element and append the clone after the Element.
  1609. */
  1610. clone: function(contents){
  1611. var el = $(this.cloneNode(contents !== false));
  1612. if (!el.$events) return el;
  1613. el.$events = {};
  1614. for (var type in this.$events) el.$events[type] = {
  1615. 'keys': $A(this.$events[type].keys),
  1616. 'values': $A(this.$events[type].values)
  1617. };
  1618. return el.removeEvents();
  1619. },
  1620. /*
  1621. Property: replaceWith
  1622. Replaces the Element with an element passed.
  1623. Arguments:
  1624. el - a string representing the element to be injected in (myElementId, or div), or an element reference.
  1625. If you pass div or another tag, the element will be created.
  1626. Returns:
  1627. the passed in element
  1628. Example:
  1629. >$('myOldElement').replaceWith($('myNewElement')); //$('myOldElement') is gone, and $('myNewElement') is in its place.
  1630. */
  1631. replaceWith: function(el){
  1632. el = $(el);
  1633. this.parentNode.replaceChild(el, this);
  1634. return el;
  1635. },
  1636. /*
  1637. Property: appendText
  1638. Appends text node to a DOM element.
  1639. Arguments:
  1640. text - the text to append.
  1641. Example:
  1642. ><div id="myElement">hey</div>
  1643. >$('myElement').appendText(' howdy'); //myElement innerHTML is now "hey howdy"
  1644. */
  1645. appendText: function(text){
  1646. this.appendChild(document.createTextNode(text));
  1647. return this;
  1648. },
  1649. /*
  1650. Property: hasClass
  1651. Tests the Element to see if it has the passed in className.
  1652. Returns:
  1653. true - the Element has the class
  1654. false - it doesn't
  1655. Arguments:
  1656. className - string; the class name to test.
  1657. Example:
  1658. ><div id="myElement" class="testClass"></div>
  1659. >$('myElement').hasClass('testClass'); //returns true
  1660. */
  1661. hasClass: function(className){
  1662. return this.className.contains(className, ' ');
  1663. },
  1664. /*
  1665. Property: addClass
  1666. Adds the passed in class to the Element, if the element doesnt already have it.
  1667. Arguments:
  1668. className - string; the class name to add
  1669. Example:
  1670. ><div id="myElement" class="testClass"></div>
  1671. >$('myElement').addClass('newClass'); //<div id="myElement" class="testClass newClass"></div>
  1672. */
  1673. addClass: function(className){
  1674. if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean();
  1675. return this;
  1676. },
  1677. /*
  1678. Property: removeClass
  1679. Works like <Element.addClass>, but removes the class from the element.
  1680. */
  1681. removeClass: function(className){
  1682. this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1').clean();
  1683. return this;
  1684. },
  1685. /*
  1686. Property: toggleClass
  1687. Adds or removes the passed in class name to the element, depending on if it's present or not.
  1688. Arguments:
  1689. className - the class to add or remove
  1690. Example:
  1691. ><div id="myElement" class="myClass"></div>
  1692. >$('myElement').toggleClass('myClass');
  1693. ><div id="myElement" class=""></div>
  1694. >$('myElement').toggleClass('myClass');
  1695. ><div id="myElement" class="myClass"></div>
  1696. */
  1697. toggleClass: function(className){
  1698. return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
  1699. },
  1700. /*
  1701. Property: setStyle
  1702. Sets a css property to the Element.
  1703. Arguments:
  1704. property - the property to set
  1705. value - the value to which to set it; for numeric values that require "px" you can pass an integer
  1706. Example:
  1707. >$('myElement').setStyle('width', '300px'); //the width is now 300px
  1708. >$('myElement').setStyle('width', 300); //the width is now 300px
  1709. */
  1710. setStyle: function(property, value){
  1711. switch(property){
  1712. case 'opacity': return this.setOpacity(parseFloat(value));
  1713. case 'float': property = (window.ie) ? 'styleFloat' : 'cssFloat';
  1714. }
  1715. property = property.camelCase();
  1716. switch($type(value)){
  1717. case 'number': if (!['zIndex', 'zoom'].contains(property)) value += 'px'; break;
  1718. case 'array': value = 'rgb(' + value.join(',') + ')';
  1719. }
  1720. this.style[property] = value;
  1721. return this;
  1722. },
  1723. /*
  1724. Property: setStyles
  1725. Applies a collection of styles to the Element.
  1726. Arguments:
  1727. source - an object or string containing all the styles to apply. When its a string it overrides old style.
  1728. Examples:
  1729. >$('myElement').setStyles({
  1730. > border: '1px solid #000',
  1731. > width: 300,
  1732. > height: 400
  1733. >});
  1734. OR
  1735. >$('myElement').setStyles('border: 1px solid #000; width: 300px; height: 400px;');
  1736. */
  1737. setStyles: function(source){
  1738. switch($type(source)){
  1739. case 'object': Element.setMany(this, 'setStyle', source); break;
  1740. case 'string': this.style.cssText = source;
  1741. }
  1742. return this;
  1743. },
  1744. /*
  1745. Property: setOpacity
  1746. Sets the opacity of the Element, and sets also visibility == "hidden" if opacity == 0, and visibility = "visible" if opacity > 0.
  1747. Arguments:
  1748. opacity - float; Accepts values from 0 to 1.
  1749. Example:
  1750. >$('myElement').setOpacity(0.5) //make it 50% transparent
  1751. */
  1752. setOpacity: function(opacity){
  1753. if (opacity == 0){
  1754. if (this.style.visibility != "hidden") this.style.visibility = "hidden";
  1755. } else {
  1756. if (this.style.visibility != "visible") this.style.visibility = "visible";
  1757. }
  1758. if (!this.currentStyle || !this.currentStyle.hasLayout) this.style.zoom = 1;
  1759. if (window.ie) this.style.filter = (opacity == 1) ? '' : "alpha(opacity=" + opacity * 100 + ")";
  1760. this.style.opacity = this.$tmp.opacity = opacity;
  1761. return this;
  1762. },
  1763. /*
  1764. Property: getStyle
  1765. Returns the style of the Element given the property passed in.
  1766. Arguments:
  1767. property - the css style property you want to retrieve
  1768. Example:
  1769. >$('myElement').getStyle('width'); //returns "400px"
  1770. >//but you can also use
  1771. >$('myElement').getStyle('width').toInt(); //returns 400
  1772. Returns:
  1773. the style as a string
  1774. */
  1775. getStyle: function(property){
  1776. property = property.camelCase();
  1777. var result = this.style[property];
  1778. if (!$chk(result)){
  1779. if (property == 'opacity') return this.$tmp.opacity;
  1780. result = [];
  1781. for (var style in Element.Styles){
  1782. if (property == style){
  1783. Element.Styles[style].each(function(s){
  1784. var style = this.getStyle(s);
  1785. result.push(parseInt(style) ? style : '0px');
  1786. }, this);
  1787. if (property == 'border'){
  1788. var every = result.every(function(bit){
  1789. return (bit == result[0]);
  1790. });
  1791. return (every) ? result[0] : false;
  1792. }
  1793. return result.join(' ');
  1794. }
  1795. }
  1796. if (property.contains('border')){
  1797. if (Element.Styles.border.contains(property)){
  1798. return ['Width', 'Style', 'Color'].map(function(p){
  1799. return this.getStyle(property + p);
  1800. }, this).join(' ');
  1801. } else if (Element.borderShort.contains(property)){
  1802. return ['Top', 'Right', 'Bottom', 'Left'].map(function(p){
  1803. return this.getStyle('border' + p + property.replace('border', ''));
  1804. }, this).join(' ');
  1805. }
  1806. }
  1807. if (document.defaultView) result = document.defaultView.getComputedStyle(this, null).getPropertyValue(property.hyphenate());
  1808. else if (this.currentStyle) result = this.currentStyle[property];
  1809. }
  1810. if (window.ie) result = Element.fixStyle(property, result, this);
  1811. if (result && property.test(/color/i) && result.contains('rgb')){
  1812. return result.split('rgb').splice(1,4).map(function(color){
  1813. return color.rgbToHex();
  1814. }).join(' ');
  1815. }
  1816. return result;
  1817. },
  1818. /*
  1819. Property: getStyles
  1820. Returns an object of styles of the Element for each argument passed in.
  1821. Arguments:
  1822. properties - strings; any number of style properties
  1823. Example:
  1824. >$('myElement').getStyles('width','height','padding');
  1825. >//returns an object like:
  1826. >{width: "10px", height: "10px", padding: "10px 0px 10px 0px"}
  1827. */
  1828. getStyles: function(){
  1829. return Element.getMany(this, 'getStyle', arguments);
  1830. },
  1831. walk: function(brother, start){
  1832. brother += 'Sibling';
  1833. var el = (start) ? this[start] : this[brother];
  1834. while (el && $type(el) != 'element') el = el[brother];
  1835. return $(el);
  1836. },
  1837. /*
  1838. Property: getPrevious
  1839. Returns the previousSibling of the Element, excluding text nodes.
  1840. Example:
  1841. >$('myElement').getPrevious(); //get the previous DOM element from myElement
  1842. Returns:
  1843. the sibling element or undefined if none found.
  1844. */
  1845. getPrevious: function(){
  1846. return this.walk('previous');
  1847. },
  1848. /*
  1849. Property: getNext
  1850. Works as Element.getPrevious, but tries to find the nextSibling.
  1851. */
  1852. getNext: function(){
  1853. return this.walk('next');
  1854. },
  1855. /*
  1856. Property: getFirst
  1857. Works as <Element.getPrevious>, but tries to find the firstChild.
  1858. */
  1859. getFirst: function(){
  1860. return this.walk('next', 'firstChild');
  1861. },
  1862. /*
  1863. Property: getLast
  1864. Works as <Element.getPrevious>, but tries to find the lastChild.
  1865. */
  1866. getLast: function(){
  1867. return this.walk('previous', 'lastChild');
  1868. },
  1869. /*
  1870. Property: getParent
  1871. returns the $(element.parentNode)
  1872. */
  1873. getParent: function(){
  1874. return $(this.parentNode);
  1875. },
  1876. /*
  1877. Property: getChildren
  1878. returns all the $(element.childNodes), excluding text nodes. Returns as <Elements>.
  1879. */
  1880. getChildren: function(){
  1881. return $$(this.childNodes);
  1882. },
  1883. /*
  1884. Property: hasChild
  1885. returns true if the passed in element is a child of the $(element).
  1886. */
  1887. hasChild: function(el){
  1888. return !!$A(this.getElementsByTagName('*')).contains(el);
  1889. },
  1890. /*
  1891. Property: getProperty
  1892. Gets the an attribute of the Element.
  1893. Arguments:
  1894. property - string; the attribute to retrieve
  1895. Example:
  1896. >$('myImage').getProperty('src') // returns whatever.gif
  1897. Returns:
  1898. the value, or an empty string
  1899. */
  1900. getProperty: function(property){
  1901. var index = Element.Properties[property];
  1902. if (index) return this[index];
  1903. var flag = Element.PropertiesIFlag[property] || 0;
  1904. if (!window.ie || flag) return this.getAttribute(property, flag);
  1905. var node = this.attributes[property];
  1906. return (node) ? node.nodeValue : null;
  1907. },
  1908. /*
  1909. Property: removeProperty
  1910. Removes an attribute from the Element
  1911. Arguments:
  1912. property - string; the attribute to remove
  1913. */
  1914. removeProperty: function(property){
  1915. var index = Element.Properties[property];
  1916. if (index) this[index] = '';
  1917. else this.removeAttribute(property);
  1918. return this;
  1919. },
  1920. /*
  1921. Property: getProperties
  1922. same as <Element.getStyles>, but for properties
  1923. */
  1924. getProperties: function(){
  1925. return Element.getMany(this, 'getProperty', arguments);
  1926. },
  1927. /*
  1928. Property: setProperty
  1929. Sets an attribute for the Element.
  1930. Arguments:
  1931. property - string; the property to assign the value passed in
  1932. value - the value to assign to the property passed in
  1933. Example:
  1934. >$('myImage').setProperty('src', 'whatever.gif'); //myImage now points to whatever.gif for its source
  1935. */
  1936. setProperty: function(property, value){
  1937. var index = Element.Properties[property];
  1938. if (index) this[index] = value;
  1939. else this.setAttribute(property, value);
  1940. return this;
  1941. },
  1942. /*
  1943. Property: setProperties
  1944. Sets numerous attributes for the Element.
  1945. Arguments:
  1946. source - an object with key/value pairs.
  1947. Example:
  1948. (start code)
  1949. $('myElement').setProperties({
  1950. src: 'whatever.gif',
  1951. alt: 'whatever dude'
  1952. });
  1953. <img src="whatever.gif" alt="whatever dude">
  1954. (end)
  1955. */
  1956. setProperties: function(source){
  1957. return Element.setMany(this, 'setProperty', source);
  1958. },
  1959. /*
  1960. Property: setHTML
  1961. Sets the innerHTML of the Element.
  1962. Arguments:
  1963. html - string; the new innerHTML for the element.
  1964. Example:
  1965. >$('myElement').setHTML(newHTML) //the innerHTML of myElement is now = newHTML
  1966. */
  1967. setHTML: function(){
  1968. this.innerHTML = $A(arguments).join('');
  1969. return this;
  1970. },
  1971. /*
  1972. Property: setText
  1973. Sets the inner text of the Element.
  1974. Arguments:
  1975. text - string; the new text content for the element.
  1976. Example:
  1977. >$('myElement').setText('some text') //the text of myElement is now = 'some text'
  1978. */
  1979. setText: function(text){
  1980. var tag = this.getTag();
  1981. if (['style', 'script'].contains(tag)){
  1982. if (window.ie){
  1983. if (tag == 'style') this.styleSheet.cssText = text;
  1984. else if (tag == 'script') this.setProperty('text', text);
  1985. return this;
  1986. } else {
  1987. this.removeChild(this.firstChild);
  1988. return this.appendText(text);
  1989. }
  1990. }
  1991. this[$defined(this.innerText) ? 'innerText' : 'textContent'] = text;
  1992. return this;
  1993. },
  1994. /*
  1995. Property: getText
  1996. Gets the inner text of the Element.
  1997. */
  1998. getText: function(){
  1999. var tag = this.getTag();
  2000. if (['style', 'script'].contains(tag)){
  2001. if (window.ie){
  2002. if (tag == 'style') return this.styleSheet.cssText;
  2003. else if (tag == 'script') return this.getProperty('text');
  2004. } else {
  2005. return this.innerHTML;
  2006. }
  2007. }
  2008. return ($pick(this.innerText, this.textContent));
  2009. },
  2010. /*
  2011. Property: getTag
  2012. Returns the tagName of the element in lower case.
  2013. Example:
  2014. >$('myImage').getTag() // returns 'img'
  2015. Returns:
  2016. The tag name in lower case
  2017. */
  2018. getTag: function(){
  2019. return this.tagName.toLowerCase();
  2020. },
  2021. /*
  2022. Property: empty
  2023. Empties an element of all its children.
  2024. Example:
  2025. >$('myDiv').empty() // empties the Div and returns it
  2026. Returns:
  2027. The element.
  2028. */
  2029. empty: function(){
  2030. Garbage.trash(this.getElementsByTagName('*'));
  2031. return this.setHTML('');
  2032. }
  2033. });
  2034. Element.fixStyle = function(property, result, element){
  2035. if ($chk(parseInt(result))) return result;
  2036. if (['height', 'width'].contains(property)){
  2037. var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'];
  2038. var size = 0;
  2039. values.each(function(value){
  2040. size += element.getStyle('border-' + value + '-width').toInt() + element.getStyle('padding-' + value).toInt();
  2041. });
  2042. return element['offset' + property.capitalize()] - size + 'px';
  2043. } else if (property.test(/border(.+)Width|margin|padding/)){
  2044. return '0px';
  2045. }
  2046. return result;
  2047. };
  2048. Element.Styles = {'border': [], 'padding': [], 'margin': []};
  2049. ['Top', 'Right', 'Bottom', 'Left'].each(function(direction){
  2050. for (var style in Element.Styles) Element.Styles[style].push(style + direction);
  2051. });
  2052. Element.borderShort = ['borderWidth', 'borderStyle', 'borderColor'];
  2053. Element.getMany = function(el, method, keys){
  2054. var result = {};
  2055. $each(keys, function(key){
  2056. result[key] = el[method](key);
  2057. });
  2058. return result;
  2059. };
  2060. Element.setMany = function(el, method, pairs){
  2061. for (var key in pairs) el[method](key, pairs[key]);
  2062. return el;
  2063. };
  2064. Element.Properties = new Abstract({
  2065. 'class': 'className', 'for': 'htmlFor', 'colspan': 'colSpan', 'rowspan': 'rowSpan',
  2066. 'accesskey': 'accessKey', 'tabindex': 'tabIndex', 'maxlength': 'maxLength',
  2067. 'readonly': 'readOnly', 'frameborder': 'frameBorder', 'value': 'value',
  2068. 'disabled': 'disabled', 'checked': 'checked', 'multiple': 'multiple', 'selected': 'selected'
  2069. });
  2070. Element.PropertiesIFlag = {
  2071. 'href': 2, 'src': 2
  2072. };
  2073. Element.Methods = {
  2074. Listeners: {
  2075. addListener: function(type, fn){
  2076. if (this.addEventListener) this.addEventListener(type, fn, false);
  2077. else this.attachEvent('on' + type, fn);
  2078. return this;
  2079. },
  2080. removeListener: function(type, fn){
  2081. if (this.removeEventListener) this.removeEventListener(type, fn, false);
  2082. else this.detachEvent('on' + type, fn);
  2083. return this;
  2084. }
  2085. }
  2086. };
  2087. window.extend(Element.Methods.Listeners);
  2088. document.extend(Element.Methods.Listeners);
  2089. Element.extend(Element.Methods.Listeners);
  2090. var Garbage = {
  2091. elements: [],
  2092. collect: function(el){
  2093. if (!el.$tmp){
  2094. Garbage.elements.push(el);
  2095. el.$tmp = {'opacity': 1};
  2096. }
  2097. return el;
  2098. },
  2099. trash: function(elements){
  2100. for (var i = 0, j = elements.length, el; i < j; i++){
  2101. if (!(el = elements[i]) || !el.$tmp) continue;
  2102. if (el.$events) el.fireEvent('trash').removeEvents();
  2103. for (var p in el.$tmp) el.$tmp[p] = null;
  2104. for (var d in Element.prototype) el[d] = null;
  2105. Garbage.elements[Garbage.elements.indexOf(el)] = null;
  2106. el.htmlElement = el.$tmp = el = null;
  2107. }
  2108. Garbage.elements.remove(null);
  2109. },
  2110. empty: function(){
  2111. Garbage.collect(window);
  2112. Garbage.collect(document);
  2113. Garbage.trash(Garbage.elements);
  2114. }
  2115. };
  2116. window.addListener('beforeunload', function(){
  2117. window.addListener('unload', Garbage.empty);
  2118. if (window.ie) window.addListener('unload', CollectGarbage);
  2119. });
  2120. /*
  2121. Script: Element.Event.js
  2122. Contains the Event Class, Element methods to deal with Element events, custom Events, and the Function prototype bindWithEvent.
  2123. License:
  2124. MIT-style license.
  2125. */
  2126. /*
  2127. Class: Event
  2128. Cross browser methods to manage events.
  2129. Arguments:
  2130. event - the event
  2131. Properties:
  2132. shift - true if the user pressed the shift
  2133. control - true if the user pressed the control
  2134. alt - true if the user pressed the alt
  2135. meta - true if the user pressed the meta key
  2136. wheel - the amount of third button scrolling
  2137. code - the keycode of the key pressed
  2138. page.x - the x position of the mouse, relative to the full window
  2139. page.y - the y position of the mouse, relative to the full window
  2140. client.x - the x position of the mouse, relative to the viewport
  2141. client.y - the y position of the mouse, relative to the viewport
  2142. key - the key pressed as a lowercase string. key also returns 'enter', 'up', 'down', 'left', 'right', 'space', 'backspace', 'delete', 'esc'. Handy for these special keys.
  2143. target - the event target
  2144. relatedTarget - the event related target
  2145. Example:
  2146. (start code)
  2147. $('myLink').onkeydown = function(event){
  2148. var event = new Event(event);
  2149. //event is now the Event class.
  2150. alert(event.key); //returns the lowercase letter pressed
  2151. alert(event.shift); //returns true if the key pressed is shift
  2152. if (event.key == 's' && event.control) alert('document saved');
  2153. };
  2154. (end)
  2155. */
  2156. var Event = new Class({
  2157. initialize: function(event){
  2158. if (event && event.$extended) return event;
  2159. this.$extended = true;
  2160. event = event || window.event;
  2161. this.event = event;
  2162. this.type = event.type;
  2163. this.target = event.target || event.srcElement;
  2164. if (this.target.nodeType == 3) this.target = this.target.parentNode;
  2165. this.shift = event.shiftKey;
  2166. this.control = event.ctrlKey;
  2167. this.alt = event.altKey;
  2168. this.meta = event.metaKey;
  2169. if (['DOMMouseScroll', 'mousewheel'].contains(this.type)){
  2170. this.wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3;
  2171. } else if (this.type.contains('key')){
  2172. this.code = event.which || event.keyCode;
  2173. for (var name in Event.keys){
  2174. if (Event.keys[name] == this.code){
  2175. this.key = name;
  2176. break;
  2177. }
  2178. }
  2179. if (this.type == 'keydown'){
  2180. var fKey = this.code - 111;
  2181. if (fKey > 0 && fKey < 13) this.key = 'f' + fKey;
  2182. }
  2183. this.key = this.key || String.fromCharCode(this.code).toLowerCase();
  2184. } else if (this.type.test(/(click|mouse|menu)/)){
  2185. this.page = {
  2186. 'x': event.pageX || event.clientX + document.documentElement.scrollLeft,
  2187. 'y': event.pageY || event.clientY + document.documentElement.scrollTop
  2188. };
  2189. this.client = {
  2190. 'x': event.pageX ? event.pageX - window.pageXOffset : event.clientX,
  2191. 'y': event.pageY ? event.pageY - window.pageYOffset : event.clientY
  2192. };
  2193. this.rightClick = (event.which == 3) || (event.button == 2);
  2194. switch(this.type){
  2195. case 'mouseover': this.relatedTarget = event.relatedTarget || event.fromElement; break;
  2196. case 'mouseout': this.relatedTarget = event.relatedTarget || event.toElement;
  2197. }
  2198. this.fixRelatedTarget();
  2199. }
  2200. return this;
  2201. },
  2202. /*
  2203. Property: stop
  2204. cross browser method to stop an event
  2205. */
  2206. stop: function(){
  2207. return this.stopPropagation().preventDefault();
  2208. },
  2209. /*
  2210. Property: stopPropagation
  2211. cross browser method to stop the propagation of an event
  2212. */
  2213. stopPropagation: function(){
  2214. if (this.event.stopPropagation) this.event.stopPropagation();
  2215. else this.event.cancelBubble = true;
  2216. return this;
  2217. },
  2218. /*
  2219. Property: preventDefault
  2220. cross browser method to prevent the default action of the event
  2221. */
  2222. preventDefault: function(){
  2223. if (this.event.preventDefault) this.event.preventDefault();
  2224. else this.event.returnValue = false;
  2225. return this;
  2226. }
  2227. });
  2228. Event.fix = {
  2229. relatedTarget: function(){
  2230. if (this.relatedTarget && this.relatedTarget.nodeType == 3) this.relatedTarget = this.relatedTarget.parentNode;
  2231. },
  2232. relatedTargetGecko: function(){
  2233. try {Event.fix.relatedTarget.call(this);} catch(e){this.relatedTarget = this.target;}
  2234. }
  2235. };
  2236. Event.prototype.fixRelatedTarget = (window.gecko) ? Event.fix.relatedTargetGecko : Event.fix.relatedTarget;
  2237. /*
  2238. Property: keys
  2239. you can add additional Event keys codes this way:
  2240. Example:
  2241. (start code)
  2242. Event.keys.whatever = 80;
  2243. $(myelement).addEvent(keydown, function(event){
  2244. event = new Event(event);
  2245. if (event.key == 'whatever') console.log(whatever key clicked).
  2246. });
  2247. (end)
  2248. */
  2249. Event.keys = new Abstract({
  2250. 'enter': 13,
  2251. 'up': 38,
  2252. 'down': 40,
  2253. 'left': 37,
  2254. 'right': 39,
  2255. 'esc': 27,
  2256. 'space': 32,
  2257. 'backspace': 8,
  2258. 'tab': 9,
  2259. 'delete': 46
  2260. });
  2261. /*
  2262. Class: Element
  2263. Custom class to allow all of its methods to be used with any DOM element via the dollar function <$>.
  2264. */
  2265. Element.Methods.Events = {
  2266. /*
  2267. Property: addEvent
  2268. Attaches an event listener to a DOM element.
  2269. Arguments:
  2270. type - the event to monitor ('click', 'load', etc) without the prefix 'on'.
  2271. fn - the function to execute
  2272. Example:
  2273. >$('myElement').addEvent('click', function(){alert('clicked!')});
  2274. */
  2275. addEvent: function(type, fn){
  2276. this.$events = this.$events || {};
  2277. this.$events[type] = this.$events[type] || {'keys': [], 'values': []};
  2278. if (this.$events[type].keys.contains(fn)) return this;
  2279. this.$events[type].keys.push(fn);
  2280. var realType = type;
  2281. var custom = Element.Events[type];
  2282. if (custom){
  2283. if (custom.add) custom.add.call(this, fn);
  2284. if (custom.map) fn = custom.map;
  2285. if (custom.type) realType = custom.type;
  2286. }
  2287. if (!this.addEventListener) fn = fn.create({'bind': this, 'event': true});
  2288. this.$events[type].values.push(fn);
  2289. return (Element.NativeEvents.contains(realType)) ? this.addListener(realType, fn) : this;
  2290. },
  2291. /*
  2292. Property: removeEvent
  2293. Works as Element.addEvent, but instead removes the previously added event listener.
  2294. */
  2295. removeEvent: function(type, fn){
  2296. if (!this.$events || !this.$events[type]) return this;
  2297. var pos = this.$events[type].keys.indexOf(fn);
  2298. if (pos == -1) return this;
  2299. var key = this.$events[type].keys.splice(pos,1)[0];
  2300. var value = this.$events[type].values.splice(pos,1)[0];
  2301. var custom = Element.Events[type];
  2302. if (custom){
  2303. if (custom.remove) custom.remove.call(this, fn);
  2304. if (custom.type) type = custom.type;
  2305. }
  2306. return (Element.NativeEvents.contains(type)) ? this.removeListener(type, value) : this;
  2307. },
  2308. /*
  2309. Property: addEvents
  2310. As <addEvent>, but accepts an object and add multiple events at once.
  2311. */
  2312. addEvents: function(source){
  2313. return Element.setMany(this, 'addEvent', source);
  2314. },
  2315. /*
  2316. Property: removeEvents
  2317. removes all events of a certain type from an element. if no argument is passed in, removes all events.
  2318. Arguments:
  2319. type - string; the event name (e.g. 'click')
  2320. */
  2321. removeEvents: function(type){
  2322. if (!this.$events) return this;
  2323. if (!type){
  2324. for (var evType in this.$events) this.removeEvents(evType);
  2325. this.$events = null;
  2326. } else if (this.$events[type]){
  2327. this.$events[type].keys.each(function(fn){
  2328. this.removeEvent(type, fn);
  2329. }, this);
  2330. this.$events[type] = null;
  2331. }
  2332. return this;
  2333. },
  2334. /*
  2335. Property: fireEvent
  2336. executes all events of the specified type present in the element.
  2337. Arguments:
  2338. type - string; the event name (e.g. 'click')
  2339. args - array or single object; arguments to pass to the function; if more than one argument, must be an array
  2340. delay - (integer) delay (in ms) to wait to execute the event
  2341. */
  2342. fireEvent: function(type, args, delay){
  2343. if (this.$events && this.$events[type]){
  2344. this.$events[type].keys.each(function(fn){
  2345. fn.create({'bind': this, 'delay': delay, 'arguments': args})();
  2346. }, this);
  2347. }
  2348. return this;
  2349. },
  2350. /*
  2351. Property: cloneEvents
  2352. Clones all events from an element to this element.
  2353. Arguments:
  2354. from - element, copy all events from this element
  2355. type - optional, copies only events of this type
  2356. */
  2357. cloneEvents: function(from, type){
  2358. if (!from.$events) return this;
  2359. if (!type){
  2360. for (var evType in from.$events) this.cloneEvents(from, evType);
  2361. } else if (from.$events[type]){
  2362. from.$events[type].keys.each(function(fn){
  2363. this.addEvent(type, fn);
  2364. }, this);
  2365. }
  2366. return this;
  2367. }
  2368. };
  2369. window.extend(Element.Methods.Events);
  2370. document.extend(Element.Methods.Events);
  2371. Element.extend(Element.Methods.Events);
  2372. /* Section: Custom Events */
  2373. Element.Events = new Abstract({
  2374. /*
  2375. Event: mouseenter
  2376. In addition to the standard javascript events (load, mouseover, mouseout, click, etc.) <Event.js> contains two custom events
  2377. this event fires when the mouse enters the area of the dom element; will not be fired again if the mouse crosses over children of the element (unlike mouseover)
  2378. Example:
  2379. >$(myElement).addEvent('mouseenter', myFunction);
  2380. */
  2381. 'mouseenter': {
  2382. type: 'mouseover',
  2383. map: function(event){
  2384. event = new Event(event);
  2385. if (event.relatedTarget != this && !this.hasChild(event.relatedTarget)) this.fireEvent('mouseenter', event);
  2386. }
  2387. },
  2388. /*
  2389. Event: mouseleave
  2390. this event fires when the mouse exits the area of the dom element; will not be fired again if the mouse crosses over children of the element (unlike mouseout)
  2391. Example:
  2392. >$(myElement).addEvent('mouseleave', myFunction);
  2393. */
  2394. 'mouseleave': {
  2395. type: 'mouseout',
  2396. map: function(event){
  2397. event = new Event(event);
  2398. if (event.relatedTarget != this && !this.hasChild(event.relatedTarget)) this.fireEvent('mouseleave', event);
  2399. }
  2400. },
  2401. 'mousewheel': {
  2402. type: (window.gecko) ? 'DOMMouseScroll' : 'mousewheel'
  2403. }
  2404. });
  2405. Element.NativeEvents = [
  2406. 'click', 'dblclick', 'mouseup', 'mousedown', //mouse buttons
  2407. 'mousewheel', 'DOMMouseScroll', //mouse wheel
  2408. 'mouseover', 'mouseout', 'mousemove', //mouse movement
  2409. 'keydown', 'keypress', 'keyup', //keys
  2410. 'load', 'unload', 'beforeunload', 'resize', 'move', //window
  2411. 'focus', 'blur', 'change', 'submit', 'reset', 'select', //forms elements
  2412. 'error', 'abort', 'contextmenu', 'scroll' //misc
  2413. ];
  2414. /*
  2415. Class: Function
  2416. A collection of The Function Object prototype methods.
  2417. */
  2418. Function.extend({
  2419. /*
  2420. Property: bindWithEvent
  2421. automatically passes MooTools Event Class.
  2422. Arguments:
  2423. bind - optional, the object that the "this" of the function will refer to.
  2424. args - optional, an argument to pass to the function; if more than one argument, it must be an array of arguments.
  2425. Returns:
  2426. a function with the parameter bind as its "this" and as a pre-passed argument event or window.event, depending on the browser.
  2427. Example:
  2428. >function myFunction(event){
  2429. > alert(event.client.x) //returns the coordinates of the mouse..
  2430. >};
  2431. >myElement.addEvent('click', myFunction.bindWithEvent(myElement));
  2432. */
  2433. bindWithEvent: function(bind, args){
  2434. return this.create({'bind': bind, 'arguments': args, 'event': Event});
  2435. }
  2436. });
  2437. /*
  2438. Script: Element.Filters.js
  2439. add Filters capability to <Elements>.
  2440. License:
  2441. MIT-style license.
  2442. */
  2443. /*
  2444. Class: Elements
  2445. A collection of methods to be used with <$$> elements collections.
  2446. */
  2447. Elements.extend({
  2448. /*
  2449. Property: filterByTag
  2450. Filters the collection by a specified tag name.
  2451. Returns a new Elements collection, while the original remains untouched.
  2452. */
  2453. filterByTag: function(tag){
  2454. return new Elements(this.filter(function(el){
  2455. return (Element.getTag(el) == tag);
  2456. }));
  2457. },
  2458. /*
  2459. Property: filterByClass
  2460. Filters the collection by a specified class name.
  2461. Returns a new Elements collection, while the original remains untouched.
  2462. */
  2463. filterByClass: function(className, nocash){
  2464. var elements = this.filter(function(el){
  2465. return (el.className && el.className.contains(className, ' '));
  2466. });
  2467. return (nocash) ? elements : new Elements(elements);
  2468. },
  2469. /*
  2470. Property: filterById
  2471. Filters the collection by a specified ID.
  2472. Returns a new Elements collection, while the original remains untouched.
  2473. */
  2474. filterById: function(id, nocash){
  2475. var elements = this.filter(function(el){
  2476. return (el.id == id);
  2477. });
  2478. return (nocash) ? elements : new Elements(elements);
  2479. },
  2480. /*
  2481. Property: filterByAttribute
  2482. Filters the collection by a specified attribute.
  2483. Returns a new Elements collection, while the original remains untouched.
  2484. Arguments:
  2485. name - the attribute name.
  2486. operator - optional, the attribute operator.
  2487. value - optional, the attribute value, only valid if the operator is specified.
  2488. */
  2489. filterByAttribute: function(name, operator, value, nocash){
  2490. var elements = this.filter(function(el){
  2491. var current = Element.getProperty(el, name);
  2492. if (!current) return false;
  2493. if (!operator) return true;
  2494. switch(operator){
  2495. case '=': return (current == value);
  2496. case '*=': return (current.contains(value));
  2497. case '^=': return (current.substr(0, value.length) == value);
  2498. case '$=': return (current.substr(current.length - value.length) == value);
  2499. case '!=': return (current != value);
  2500. case '~=': return current.contains(value, ' ');
  2501. }
  2502. return false;
  2503. });
  2504. return (nocash) ? elements : new Elements(elements);
  2505. }
  2506. });
  2507. /*
  2508. Script: Element.Selectors.js
  2509. Css Query related functions and <Element> extensions
  2510. License:
  2511. MIT-style license.
  2512. */
  2513. /* Section: Utility Functions */
  2514. /*
  2515. Function: $E
  2516. Selects a single (i.e. the first found) Element based on the selector passed in and an optional filter element.
  2517. Returns as <Element>.
  2518. Arguments:
  2519. selector - string; the css selector to match
  2520. filter - optional; a DOM element to limit the scope of the selector match; defaults to document.
  2521. Example:
  2522. >$E('a', 'myElement') //find the first anchor tag inside the DOM element with id 'myElement'
  2523. Returns:
  2524. a DOM element - the first element that matches the selector
  2525. */
  2526. function $E(selector, filter){
  2527. return ($(filter) || document).getElement(selector);
  2528. };
  2529. /*
  2530. Function: $ES
  2531. Returns a collection of Elements that match the selector passed in limited to the scope of the optional filter.
  2532. See Also: <Element.getElements> for an alternate syntax.
  2533. Returns as <Elements>.
  2534. Returns:
  2535. an array of dom elements that match the selector within the filter
  2536. Arguments:
  2537. selector - string; css selector to match
  2538. filter - optional; a DOM element to limit the scope of the selector match; defaults to document.
  2539. Examples:
  2540. >$ES("a") //gets all the anchor tags; synonymous with $$("a")
  2541. >$ES('a','myElement') //get all the anchor tags within $('myElement')
  2542. */
  2543. function $ES(selector, filter){
  2544. return ($(filter) || document).getElementsBySelector(selector);
  2545. };
  2546. $$.shared = {
  2547. 'regexp': /^(\w*|\*)(?:#([\w-]+)|\.([\w-]+))?(?:\[(\w+)(?:([!*^$]?=)["']?([^"'\]]*)["']?)?])?$/,
  2548. 'xpath': {
  2549. getParam: function(items, context, param, i){
  2550. var temp = [context.namespaceURI ? 'xhtml:' : '', param[1]];
  2551. if (param[2]) temp.push('[@id="', param[2], '"]');
  2552. if (param[3]) temp.push('[contains(concat(" ", @class, " "), " ', param[3], ' ")]');
  2553. if (param[4]){
  2554. if (param[5] && param[6]){
  2555. switch(param[5]){
  2556. case '*=': temp.push('[contains(@', param[4], ', "', param[6], '")]'); break;
  2557. case '^=': temp.push('[starts-with(@', param[4], ', "', param[6], '")]'); break;
  2558. case '$=': temp.push('[substring(@', param[4], ', string-length(@', param[4], ') - ', param[6].length, ' + 1) = "', param[6], '"]'); break;
  2559. case '=': temp.push('[@', param[4], '="', param[6], '"]'); break;
  2560. case '!=': temp.push('[@', param[4], '!="', param[6], '"]');
  2561. }
  2562. } else {
  2563. temp.push('[@', param[4], ']');
  2564. }
  2565. }
  2566. items.push(temp.join(''));
  2567. return items;
  2568. },
  2569. getItems: function(items, context, nocash){
  2570. var elements = [];
  2571. var xpath = document.evaluate('.//' + items.join('//'), context, $$.shared.resolver, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  2572. for (var i = 0, j = xpath.snapshotLength; i < j; i++) elements.push(xpath.snapshotItem(i));
  2573. return (nocash) ? elements : new Elements(elements.map($));
  2574. }
  2575. },
  2576. 'normal': {
  2577. getParam: function(items, context, param, i){
  2578. if (i == 0){
  2579. if (param[2]){
  2580. var el = context.getElementById(param[2]);
  2581. if (!el || ((param[1] != '*') && (Element.getTag(el) != param[1]))) return false;
  2582. items = [el];
  2583. } else {
  2584. items = $A(context.getElementsByTagName(param[1]));
  2585. }
  2586. } else {
  2587. items = $$.shared.getElementsByTagName(items, param[1]);
  2588. if (param[2]) items = Elements.filterById(items, param[2], true);
  2589. }
  2590. if (param[3]) items = Elements.filterByClass(items, param[3], true);
  2591. if (param[4]) items = Elements.filterByAttribute(items, param[4], param[5], param[6], true);
  2592. return items;
  2593. },
  2594. getItems: function(items, context, nocash){
  2595. return (nocash) ? items : $$.unique(items);
  2596. }
  2597. },
  2598. resolver: function(prefix){
  2599. return (prefix == 'xhtml') ? 'http://www.w3.org/1999/xhtml' : false;
  2600. },
  2601. getElementsByTagName: function(context, tagName){
  2602. var found = [];
  2603. for (var i = 0, j = context.length; i < j; i++) found.extend(context[i].getElementsByTagName(tagName));
  2604. return found;
  2605. }
  2606. };
  2607. $$.shared.method = (window.xpath) ? 'xpath' : 'normal';
  2608. /*
  2609. Class: Element
  2610. Custom class to allow all of its methods to be used with any DOM element via the dollar function <$>.
  2611. */
  2612. Element.Methods.Dom = {
  2613. /*
  2614. Property: getElements
  2615. Gets all the elements within an element that match the given (single) selector.
  2616. Returns as <Elements>.
  2617. Arguments:
  2618. selector - string; the css selector to match
  2619. Examples:
  2620. >$('myElement').getElements('a'); // get all anchors within myElement
  2621. >$('myElement').getElements('input[name=dialog]') //get all input tags with name 'dialog'
  2622. >$('myElement').getElements('input[name$=log]') //get all input tags with names ending with 'log'
  2623. Notes:
  2624. Supports these operators in attribute selectors:
  2625. - = : is equal to
  2626. - ^= : starts-with
  2627. - $= : ends-with
  2628. - != : is not equal to
  2629. Xpath is used automatically for compliant browsers.
  2630. */
  2631. getElements: function(selector, nocash){
  2632. var items = [];
  2633. selector = selector.trim().split(' ');
  2634. for (var i = 0, j = selector.length; i < j; i++){
  2635. var sel = selector[i];
  2636. var param = sel.match($$.shared.regexp);
  2637. if (!param) break;
  2638. param[1] = param[1] || '*';
  2639. var temp = $$.shared[$$.shared.method].getParam(items, this, param, i);
  2640. if (!temp) break;
  2641. items = temp;
  2642. }
  2643. return $$.shared[$$.shared.method].getItems(items, this, nocash);
  2644. },
  2645. /*
  2646. Property: getElement
  2647. Same as <Element.getElements>, but returns only the first. Alternate syntax for <$E>, where filter is the Element.
  2648. Returns as <Element>.
  2649. Arguments:
  2650. selector - string; css selector
  2651. */
  2652. getElement: function(selector){
  2653. return $(this.getElements(selector, true)[0] || false);
  2654. },
  2655. /*
  2656. Property: getElementsBySelector
  2657. Same as <Element.getElements>, but allows for comma separated selectors, as in css. Alternate syntax for <$$>, where filter is the Element.
  2658. Returns as <Elements>.
  2659. Arguments:
  2660. selector - string; css selector
  2661. */
  2662. getElementsBySelector: function(selector, nocash){
  2663. var elements = [];
  2664. selector = selector.split(',');
  2665. for (var i = 0, j = selector.length; i < j; i++) elements = elements.concat(this.getElements(selector[i], true));
  2666. return (nocash) ? elements : $$.unique(elements);
  2667. }
  2668. };
  2669. Element.extend({
  2670. /*
  2671. Property: getElementById
  2672. Targets an element with the specified id found inside the Element. Does not overwrite document.getElementById.
  2673. Arguments:
  2674. id - string; the id of the element to find.
  2675. */
  2676. getElementById: function(id){
  2677. var el = document.getElementById(id);
  2678. if (!el) return false;
  2679. for (var parent = el.parentNode; parent != this; parent = parent.parentNode){
  2680. if (!parent) return false;
  2681. }
  2682. return el;
  2683. }/*compatibility*/,
  2684. getElementsByClassName: function(className){
  2685. return this.getElements('.' + className);
  2686. }
  2687. /*end compatibility*/
  2688. });
  2689. document.extend(Element.Methods.Dom);
  2690. Element.extend(Element.Methods.Dom);
  2691. /*
  2692. Script: Element.Form.js
  2693. Contains Element prototypes to deal with Forms and their elements.
  2694. License:
  2695. MIT-style license.
  2696. */
  2697. /*
  2698. Class: Element
  2699. Custom class to allow all of its methods to be used with any DOM element via the dollar function <$>.
  2700. */
  2701. Element.extend({
  2702. /*
  2703. Property: getValue
  2704. Returns the value of the Element, if its tag is textarea, select or input. getValue called on a multiple select will return an array.
  2705. */
  2706. getValue: function(){
  2707. switch(this.getTag()){
  2708. case 'select':
  2709. var values = [];
  2710. $each(this.options, function(option){
  2711. if (option.selected) values.push($pick(option.value, option.text));
  2712. });
  2713. return (this.multiple) ? values : values[0];
  2714. case 'input': if (!(this.checked && ['checkbox', 'radio'].contains(this.type)) && !['hidden', 'text', 'password'].contains(this.type)) break;
  2715. case 'textarea': return this.value;
  2716. }
  2717. return false;
  2718. },
  2719. getFormElements: function(){
  2720. return $$(this.getElementsByTagName('input'), this.getElementsByTagName('select'), this.getElementsByTagName('textarea'));
  2721. },
  2722. /*
  2723. Property: toQueryString
  2724. Reads the children inputs of the Element and generates a query string, based on their values. Used internally in <Ajax>
  2725. Example:
  2726. (start code)
  2727. <form id="myForm" action="submit.php">
  2728. <input name="email" value="bob@bob.com">
  2729. <input name="zipCode" value="90210">
  2730. </form>
  2731. <script>
  2732. $('myForm').toQueryString()
  2733. </script>
  2734. (end)
  2735. Returns:
  2736. email=bob@bob.com&zipCode=90210
  2737. */
  2738. toQueryString: function(){
  2739. var queryString = [];
  2740. this.getFormElements().each(function(el){
  2741. var name = el.name;
  2742. var value = el.getValue();
  2743. if (value === false || !name || el.disabled) return;
  2744. var qs = function(val){
  2745. queryString.push(name + '=' + encodeURIComponent(val));
  2746. };
  2747. if ($type(value) == 'array') value.each(qs);
  2748. else qs(value);
  2749. });
  2750. return queryString.join('&');
  2751. }
  2752. });
  2753. /*
  2754. Script: Element.Dimensions.js
  2755. Contains Element prototypes to deal with Element size and position in space.
  2756. Note:
  2757. The functions in this script require n XHTML doctype.
  2758. License:
  2759. MIT-style license.
  2760. */
  2761. /*
  2762. Class: Element
  2763. Custom class to allow all of its methods to be used with any DOM element via the dollar function <$>.
  2764. */
  2765. Element.extend({
  2766. /*
  2767. Property: scrollTo
  2768. Scrolls the element to the specified coordinated (if the element has an overflow)
  2769. Arguments:
  2770. x - the x coordinate
  2771. y - the y coordinate
  2772. Example:
  2773. >$('myElement').scrollTo(0, 100)
  2774. */
  2775. scrollTo: function(x, y){
  2776. this.scrollLeft = x;
  2777. this.scrollTop = y;
  2778. },
  2779. /*
  2780. Property: getSize
  2781. Return an Object representing the size/scroll values of the element.
  2782. Example:
  2783. (start code)
  2784. $('myElement').getSize();
  2785. (end)
  2786. Returns:
  2787. (start code)
  2788. {
  2789. 'scroll': {'x': 100, 'y': 100},
  2790. 'size': {'x': 200, 'y': 400},
  2791. 'scrollSize': {'x': 300, 'y': 500}
  2792. }
  2793. (end)
  2794. */
  2795. getSize: function(){
  2796. return {
  2797. 'scroll': {'x': this.scrollLeft, 'y': this.scrollTop},
  2798. 'size': {'x': this.offsetWidth, 'y': this.offsetHeight},
  2799. 'scrollSize': {'x': this.scrollWidth, 'y': this.scrollHeight}
  2800. };
  2801. },
  2802. /*
  2803. Property: getPosition
  2804. Returns the real offsets of the element.
  2805. Arguments:
  2806. overflown - optional, an array of nested scrolling containers for scroll offset calculation, use this if your element is inside any element containing scrollbars
  2807. Example:
  2808. >$('element').getPosition();
  2809. Returns:
  2810. >{x: 100, y:500};
  2811. */
  2812. getPosition: function(overflown){
  2813. overflown = overflown || [];
  2814. var el = this, left = 0, top = 0;
  2815. do {
  2816. left += el.offsetLeft || 0;
  2817. top += el.offsetTop || 0;
  2818. el = el.offsetParent;
  2819. } while (el);
  2820. overflown.each(function(element){
  2821. left -= element.scrollLeft || 0;
  2822. top -= element.scrollTop || 0;
  2823. });
  2824. return {'x': left, 'y': top};
  2825. },
  2826. /*
  2827. Property: getTop
  2828. Returns the distance from the top of the window to the Element.
  2829. Arguments:
  2830. overflown - optional, an array of nested scrolling containers, see Element::getPosition
  2831. */
  2832. getTop: function(overflown){
  2833. return this.getPosition(overflown).y;
  2834. },
  2835. /*
  2836. Property: getLeft
  2837. Returns the distance from the left of the window to the Element.
  2838. Arguments:
  2839. overflown - optional, an array of nested scrolling containers, see Element::getPosition
  2840. */
  2841. getLeft: function(overflown){
  2842. return this.getPosition(overflown).x;
  2843. },
  2844. /*
  2845. Property: getCoordinates
  2846. Returns an object with width, height, left, right, top, and bottom, representing the values of the Element
  2847. Arguments:
  2848. overflown - optional, an array of nested scrolling containers, see Element::getPosition
  2849. Example:
  2850. (start code)
  2851. var myValues = $('myElement').getCoordinates();
  2852. (end)
  2853. Returns:
  2854. (start code)
  2855. {
  2856. width: 200,
  2857. height: 300,
  2858. left: 100,
  2859. top: 50,
  2860. right: 300,
  2861. bottom: 350
  2862. }
  2863. (end)
  2864. */
  2865. getCoordinates: function(overflown){
  2866. var position = this.getPosition(overflown);
  2867. var obj = {
  2868. 'width': this.offsetWidth,
  2869. 'height': this.offsetHeight,
  2870. 'left': position.x,
  2871. 'top': position.y
  2872. };
  2873. obj.right = obj.left + obj.width;
  2874. obj.bottom = obj.top + obj.height;
  2875. return obj;
  2876. }
  2877. });
  2878. /*
  2879. Script: Window.DomReady.js
  2880. Contains the custom event domready, for window.
  2881. License:
  2882. MIT-style license.
  2883. */
  2884. /* Section: Custom Events */
  2885. /*
  2886. Event: domready
  2887. executes a function when the dom tree is loaded, without waiting for images. Only works when called from window.
  2888. Credits:
  2889. (c) Dean Edwards/Matthias Miller/John Resig, remastered for MooTools.
  2890. Arguments:
  2891. fn - the function to execute when the DOM is ready
  2892. Example:
  2893. > window.addEvent('domready', function(){
  2894. > alert('the dom is ready');
  2895. > });
  2896. */
  2897. Element.Events.domready = {
  2898. add: function(fn){
  2899. if (window.loaded){
  2900. fn.call(this);
  2901. return;
  2902. }
  2903. var domReady = function(){
  2904. if (window.loaded) return;
  2905. window.loaded = true;
  2906. window.timer = $clear(window.timer);
  2907. this.fireEvent('domready');
  2908. }.bind(this);
  2909. if (document.readyState && window.webkit){
  2910. window.timer = function(){
  2911. if (['loaded','complete'].contains(document.readyState)) domReady();
  2912. }.periodical(50);
  2913. } else if (document.readyState && window.ie){
  2914. if (!$('ie_ready')){
  2915. var src = (window.location.protocol == 'https:') ? '://0' : 'javascript:void(0)';
  2916. document.write('<script id="ie_ready" defer src="' + src + '"><\/script>');
  2917. $('ie_ready').onreadystatechange = function(){
  2918. if (this.readyState == 'complete') domReady();
  2919. };
  2920. }
  2921. } else {
  2922. window.addListener("load", domReady);
  2923. document.addListener("DOMContentLoaded", domReady);
  2924. }
  2925. }
  2926. };
  2927. /*compatibility*/
  2928. window.onDomReady = function(fn){
  2929. return this.addEvent('domready', fn);
  2930. };
  2931. /*end compatibility*/
  2932. /*
  2933. Script: Window.Size.js
  2934. Window cross-browser dimensions methods.
  2935. Note:
  2936. The Functions in this script require an XHTML doctype.
  2937. License:
  2938. MIT-style license.
  2939. */
  2940. /*
  2941. Class: window
  2942. Cross browser methods to get various window dimensions.
  2943. Warning: All these methods require that the browser operates in strict mode, not quirks mode.
  2944. */
  2945. window.extend({
  2946. /*
  2947. Property: getWidth
  2948. Returns an integer representing the width of the browser window (without the scrollbar).
  2949. */
  2950. getWidth: function(){
  2951. if (this.webkit419) return this.innerWidth;
  2952. if (this.opera) return document.body.clientWidth;
  2953. return document.documentElement.clientWidth;
  2954. },
  2955. /*
  2956. Property: getHeight
  2957. Returns an integer representing the height of the browser window (without the scrollbar).
  2958. */
  2959. getHeight: function(){
  2960. if (this.webkit419) return this.innerHeight;
  2961. if (this.opera) return document.body.clientHeight;
  2962. return document.documentElement.clientHeight;
  2963. },
  2964. /*
  2965. Property: getScrollWidth
  2966. Returns an integer representing the scrollWidth of the window.
  2967. This value is equal to or bigger than <getWidth>.
  2968. See Also:
  2969. <http://developer.mozilla.org/en/docs/DOM:element.scrollWidth>
  2970. */
  2971. getScrollWidth: function(){
  2972. if (this.ie) return Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
  2973. if (this.webkit) return document.body.scrollWidth;
  2974. return document.documentElement.scrollWidth;
  2975. },
  2976. /*
  2977. Property: getScrollHeight
  2978. Returns an integer representing the scrollHeight of the window.
  2979. This value is equal to or bigger than <getHeight>.
  2980. See Also:
  2981. <http://developer.mozilla.org/en/docs/DOM:element.scrollHeight>
  2982. */
  2983. getScrollHeight: function(){
  2984. if (this.ie) return Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
  2985. if (this.webkit) return document.body.scrollHeight;
  2986. return document.documentElement.scrollHeight;
  2987. },
  2988. /*
  2989. Property: getScrollLeft
  2990. Returns an integer representing the scrollLeft of the window (the number of pixels the window has scrolled from the left).
  2991. See Also:
  2992. <http://developer.mozilla.org/en/docs/DOM:element.scrollLeft>
  2993. */
  2994. getScrollLeft: function(){
  2995. return this.pageXOffset || document.documentElement.scrollLeft;
  2996. },
  2997. /*
  2998. Property: getScrollTop
  2999. Returns an integer representing the scrollTop of the window (the number of pixels the window has scrolled from the top).
  3000. See Also:
  3001. <http://developer.mozilla.org/en/docs/DOM:element.scrollTop>
  3002. */
  3003. getScrollTop: function(){
  3004. return this.pageYOffset || document.documentElement.scrollTop;
  3005. },
  3006. /*
  3007. Property: getSize
  3008. Same as <Element.getSize>
  3009. */
  3010. getSize: function(){
  3011. return {
  3012. 'size': {'x': this.getWidth(), 'y': this.getHeight()},
  3013. 'scrollSize': {'x': this.getScrollWidth(), 'y': this.getScrollHeight()},
  3014. 'scroll': {'x': this.getScrollLeft(), 'y': this.getScrollTop()}
  3015. };
  3016. },
  3017. //ignore
  3018. getPosition: function(){return {'x': 0, 'y': 0};}
  3019. });
  3020. /*
  3021. Script: Fx.Base.js
  3022. Contains <Fx.Base>, the foundamentals of the MooTools Effects.
  3023. License:
  3024. MIT-style license.
  3025. */
  3026. var Fx = {};
  3027. /*
  3028. Class: Fx.Base
  3029. Base class for the Effects.
  3030. Options:
  3031. transition - the equation to use for the effect see <Fx.Transitions>; default is <Fx.Transitions.Sine.easeInOut>
  3032. duration - the duration of the effect in ms; 500 is the default.
  3033. unit - the unit is 'px' by default (other values include things like 'em' for fonts or '%').
  3034. wait - boolean: to wait or not to wait for a current transition to end before running another of the same instance. defaults to true.
  3035. fps - the frames per second for the transition; default is 50
  3036. Events:
  3037. onStart - the function to execute as the effect begins; nothing (<Class.empty>) by default.
  3038. onComplete - the function to execute after the effect has processed; nothing (<Class.empty>) by default.
  3039. onCancel - the function to execute when you manually stop the effect.
  3040. */
  3041. Fx.Base = new Class({
  3042. options: {
  3043. onStart: Class.empty,
  3044. onComplete: Class.empty,
  3045. onCancel: Class.empty,
  3046. transition: function(p){
  3047. return -(Math.cos(Math.PI * p) - 1) / 2;
  3048. },
  3049. duration: 500,
  3050. unit: 'px',
  3051. wait: true,
  3052. fps: 50
  3053. },
  3054. initialize: function(options){
  3055. this.element = this.element || null;
  3056. this.setOptions(options);
  3057. if (this.options.initialize) this.options.initialize.call(this);
  3058. },
  3059. step: function(){
  3060. var time = $time();
  3061. if (time < this.time + this.options.duration){
  3062. this.delta = this.options.transition((time - this.time) / this.options.duration);
  3063. this.setNow();
  3064. this.increase();
  3065. } else {
  3066. this.stop(true);
  3067. this.set(this.to);
  3068. this.fireEvent('onComplete', this.element, 10);
  3069. this.callChain();
  3070. }
  3071. },
  3072. /*
  3073. Property: set
  3074. Immediately sets the value with no transition.
  3075. Arguments:
  3076. to - the point to jump to
  3077. Example:
  3078. >var myFx = new Fx.Style('myElement', 'opacity').set(0); //will make it immediately transparent
  3079. */
  3080. set: function(to){
  3081. this.now = to;
  3082. this.increase();
  3083. return this;
  3084. },
  3085. setNow: function(){
  3086. this.now = this.compute(this.from, this.to);
  3087. },
  3088. compute: function(from, to){
  3089. return (to - from) * this.delta + from;
  3090. },
  3091. /*
  3092. Property: start
  3093. Executes an effect from one position to the other.
  3094. Arguments:
  3095. from - integer: staring value
  3096. to - integer: the ending value
  3097. Examples:
  3098. >var myFx = new Fx.Style('myElement', 'opacity').start(0,1); //display a transition from transparent to opaque.
  3099. */
  3100. start: function(from, to){
  3101. if (!this.options.wait) this.stop();
  3102. else if (this.timer) return this;
  3103. this.from = from;
  3104. this.to = to;
  3105. this.change = this.to - this.from;
  3106. this.time = $time();
  3107. this.timer = this.step.periodical(Math.round(1000 / this.options.fps), this);
  3108. this.fireEvent('onStart', this.element);
  3109. return this;
  3110. },
  3111. /*
  3112. Property: stop
  3113. Stops the transition.
  3114. */
  3115. stop: function(end){
  3116. if (!this.timer) return this;
  3117. this.timer = $clear(this.timer);
  3118. if (!end) this.fireEvent('onCancel', this.element);
  3119. return this;
  3120. }/*compatibility*/,
  3121. custom: function(from, to){
  3122. return this.start(from, to);
  3123. },
  3124. clearTimer: function(end){
  3125. return this.stop(end);
  3126. }
  3127. /*end compatibility*/
  3128. });
  3129. Fx.Base.implement(new Chain, new Events, new Options);
  3130. /*
  3131. Script: Fx.CSS.js
  3132. Css parsing class for effects. Required by <Fx.Style>, <Fx.Styles>, <Fx.Elements>. No documentation needed, as its used internally.
  3133. License:
  3134. MIT-style license.
  3135. */
  3136. Fx.CSS = {
  3137. select: function(property, to){
  3138. if (property.test(/color/i)) return this.Color;
  3139. var type = $type(to);
  3140. if ((type == 'array') || (type == 'string' && to.contains(' '))) return this.Multi;
  3141. return this.Single;
  3142. },
  3143. parse: function(el, property, fromTo){
  3144. if (!fromTo.push) fromTo = [fromTo];
  3145. var from = fromTo[0], to = fromTo[1];
  3146. if (!$chk(to)){
  3147. to = from;
  3148. from = el.getStyle(property);
  3149. }
  3150. var css = this.select(property, to);
  3151. return {'from': css.parse(from), 'to': css.parse(to), 'css': css};
  3152. }
  3153. };
  3154. Fx.CSS.Single = {
  3155. parse: function(value){
  3156. return parseFloat(value);
  3157. },
  3158. getNow: function(from, to, fx){
  3159. return fx.compute(from, to);
  3160. },
  3161. getValue: function(value, unit, property){
  3162. if (unit == 'px' && property != 'opacity') value = Math.round(value);
  3163. return value + unit;
  3164. }
  3165. };
  3166. Fx.CSS.Multi = {
  3167. parse: function(value){
  3168. return value.push ? value : value.split(' ').map(function(v){
  3169. return parseFloat(v);
  3170. });
  3171. },
  3172. getNow: function(from, to, fx){
  3173. var now = [];
  3174. for (var i = 0; i < from.length; i++) now[i] = fx.compute(from[i], to[i]);
  3175. return now;
  3176. },
  3177. getValue: function(value, unit, property){
  3178. if (unit == 'px' && property != 'opacity') value = value.map(Math.round);
  3179. return value.join(unit + ' ') + unit;
  3180. }
  3181. };
  3182. Fx.CSS.Color = {
  3183. parse: function(value){
  3184. return value.push ? value : value.hexToRgb(true);
  3185. },
  3186. getNow: function(from, to, fx){
  3187. var now = [];
  3188. for (var i = 0; i < from.length; i++) now[i] = Math.round(fx.compute(from[i], to[i]));
  3189. return now;
  3190. },
  3191. getValue: function(value){
  3192. return 'rgb(' + value.join(',') + ')';
  3193. }
  3194. };
  3195. /*
  3196. Script: Fx.Style.js
  3197. Contains <Fx.Style>
  3198. License:
  3199. MIT-style license.
  3200. */
  3201. /*
  3202. Class: Fx.Style
  3203. The Style effect, used to transition any css property from one value to another. Includes colors.
  3204. Colors must be in hex format.
  3205. Inherits methods, properties, options and events from <Fx.Base>.
  3206. Arguments:
  3207. el - the $(element) to apply the style transition to
  3208. property - the property to transition
  3209. options - the Fx.Base options (see: <Fx.Base>)
  3210. Example:
  3211. >var marginChange = new Fx.Style('myElement', 'margin-top', {duration:500});
  3212. >marginChange.start(10, 100);
  3213. */
  3214. Fx.Style = Fx.Base.extend({
  3215. initialize: function(el, property, options){
  3216. this.element = $(el);
  3217. this.property = property;
  3218. this.parent(options);
  3219. },
  3220. /*
  3221. Property: hide
  3222. Same as <Fx.Base.set> (0); hides the element immediately without transition.
  3223. */
  3224. hide: function(){
  3225. return this.set(0);
  3226. },
  3227. setNow: function(){
  3228. this.now = this.css.getNow(this.from, this.to, this);
  3229. },
  3230. /*
  3231. Property: set
  3232. Sets the element's css property (specified at instantiation) to the specified value immediately.
  3233. Example:
  3234. (start code)
  3235. var marginChange = new Fx.Style('myElement', 'margin-top', {duration:500});
  3236. marginChange.set(10); //margin-top is set to 10px immediately
  3237. (end)
  3238. */
  3239. set: function(to){
  3240. this.css = Fx.CSS.select(this.property, to);
  3241. return this.parent(this.css.parse(to));
  3242. },
  3243. /*
  3244. Property: start
  3245. Displays the transition to the value/values passed in
  3246. Arguments:
  3247. from - (integer; optional) the starting position for the transition
  3248. to - (integer) the ending position for the transition
  3249. Note:
  3250. If you provide only one argument, the transition will use the current css value for its starting value.
  3251. Example:
  3252. (start code)
  3253. var marginChange = new Fx.Style('myElement', 'margin-top', {duration:500});
  3254. marginChange.start(10); //tries to read current margin top value and goes from current to 10
  3255. (end)
  3256. */
  3257. start: function(from, to){
  3258. if (this.timer && this.options.wait) return this;
  3259. var parsed = Fx.CSS.parse(this.element, this.property, [from, to]);
  3260. this.css = parsed.css;
  3261. return this.parent(parsed.from, parsed.to);
  3262. },
  3263. increase: function(){
  3264. this.element.setStyle(this.property, this.css.getValue(this.now, this.options.unit, this.property));
  3265. }
  3266. });
  3267. /*
  3268. Class: Element
  3269. Custom class to allow all of its methods to be used with any DOM element via the dollar function <$>.
  3270. */
  3271. Element.extend({
  3272. /*
  3273. Property: effect
  3274. Applies an <Fx.Style> to the Element; This a shortcut for <Fx.Style>.
  3275. Arguments:
  3276. property - (string) the css property to alter
  3277. options - (object; optional) key/value set of options (see <Fx.Style>)
  3278. Example:
  3279. >var myEffect = $('myElement').effect('height', {duration: 1000, transition: Fx.Transitions.linear});
  3280. >myEffect.start(10, 100);
  3281. >//OR
  3282. >$('myElement').effect('height', {duration: 1000, transition: Fx.Transitions.linear}).start(10,100);
  3283. */
  3284. effect: function(property, options){
  3285. return new Fx.Style(this, property, options);
  3286. }
  3287. });
  3288. /*
  3289. Script: Json.js
  3290. Simple Json parser and Stringyfier, See: <http://www.json.org/>
  3291. License:
  3292. MIT-style license.
  3293. */
  3294. /*
  3295. Class: Json
  3296. Simple Json parser and Stringyfier, See: <http://www.json.org/>
  3297. */
  3298. var Json = {
  3299. /*
  3300. Property: toString
  3301. Converts an object to a string, to be passed in server-side scripts as a parameter. Although its not normal usage for this class, this method can also be used to convert functions and arrays to strings.
  3302. Arguments:
  3303. obj - the object to convert to string
  3304. Returns:
  3305. A json string
  3306. Example:
  3307. (start code)
  3308. Json.toString({apple: 'red', lemon: 'yellow'}); '{"apple":"red","lemon":"yellow"}'
  3309. (end)
  3310. */
  3311. toString: function(obj){
  3312. switch($type(obj)){
  3313. case 'string':
  3314. return '"' + obj.replace(/(["\\])/g, '\\$1') + '"';
  3315. case 'array':
  3316. return '[' + obj.map(Json.toString).join(',') + ']';
  3317. case 'object':
  3318. var string = [];
  3319. for (var property in obj) string.push(Json.toString(property) + ':' + Json.toString(obj[property]));
  3320. return '{' + string.join(',') + '}';
  3321. case 'number':
  3322. if (isFinite(obj)) break;
  3323. case false:
  3324. return 'null';
  3325. }
  3326. return String(obj);
  3327. },
  3328. /*
  3329. Property: evaluate
  3330. converts a json string to an javascript Object.
  3331. Arguments:
  3332. str - the string to evaluate. if its not a string, it returns false.
  3333. secure - optionally, performs syntax check on json string. Defaults to false.
  3334. Credits:
  3335. Json test regexp is by Douglas Crockford <http://crockford.org>.
  3336. Example:
  3337. >var myObject = Json.evaluate('{"apple":"red","lemon":"yellow"}');
  3338. >//myObject will become {apple: 'red', lemon: 'yellow'}
  3339. */
  3340. evaluate: function(str, secure){
  3341. return (($type(str) != 'string') || (secure && !str.test(/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/))) ? null : eval('(' + str + ')');
  3342. }
  3343. };
  3344. /*
  3345. Script: Hash.js
  3346. Contains the class Hash.
  3347. License:
  3348. MIT-style license.
  3349. */
  3350. /*
  3351. Class: Hash
  3352. It wraps an object that it uses internally as a map. The user must use set(), get(), and remove() to add/change, retrieve and remove values, it must not access the internal object directly. null/undefined values are allowed.
  3353. Note:
  3354. Each hash instance has the length property.
  3355. Arguments:
  3356. obj - an object to convert into a Hash instance.
  3357. Example:
  3358. (start code)
  3359. var hash = new Hash({a: 'hi', b: 'world', c: 'howdy'});
  3360. hash.remove('b'); // b is removed.
  3361. hash.set('c', 'hello');
  3362. hash.get('c'); // returns 'hello'
  3363. hash.length // returns 2 (a and c)
  3364. (end)
  3365. */
  3366. var Hash = new Class({
  3367. length: 0,
  3368. initialize: function(object){
  3369. this.obj = object || {};
  3370. this.setLength();
  3371. },
  3372. /*
  3373. Property: get
  3374. Retrieves a value from the hash.
  3375. Arguments:
  3376. key - The key
  3377. Returns:
  3378. The value
  3379. */
  3380. get: function(key){
  3381. return (this.hasKey(key)) ? this.obj[key] : null;
  3382. },
  3383. /*
  3384. Property: hasKey
  3385. Check the presence of a specified key-value pair in the hash.
  3386. Arguments:
  3387. key - The key
  3388. Returns:
  3389. True if the Hash contains a value for the specified key, otherwise false
  3390. */
  3391. hasKey: function(key){
  3392. return (key in this.obj);
  3393. },
  3394. /*
  3395. Property: set
  3396. Adds a key-value pair to the hash or replaces a previous value associated with the key.
  3397. Arguments:
  3398. key - The key
  3399. value - The value
  3400. */
  3401. set: function(key, value){
  3402. if (!this.hasKey(key)) this.length++;
  3403. this.obj[key] = value;
  3404. return this;
  3405. },
  3406. setLength: function(){
  3407. this.length = 0;
  3408. for (var p in this.obj) this.length++;
  3409. return this;
  3410. },
  3411. /*
  3412. Property: remove
  3413. Removes a key-value pair from the hash.
  3414. Arguments:
  3415. key - The key
  3416. */
  3417. remove: function(key){
  3418. if (this.hasKey(key)){
  3419. delete this.obj[key];
  3420. this.length--;
  3421. }
  3422. return this;
  3423. },
  3424. /*
  3425. Property: each
  3426. Calls a function for each key-value pair. The first argument passed to the function will be the value, the second one will be the key, like $each.
  3427. Arguments:
  3428. fn - The function to call for each key-value pair
  3429. bind - Optional, the object that will be referred to as "this" in the function
  3430. */
  3431. each: function(fn, bind){
  3432. $each(this.obj, fn, bind);
  3433. },
  3434. /*
  3435. Property: extend
  3436. Extends the current hash with an object containing key-value pairs. Values for duplicate keys will be replaced by the new ones.
  3437. Arguments:
  3438. obj - An object containing key-value pairs
  3439. */
  3440. extend: function(obj){
  3441. $extend(this.obj, obj);
  3442. return this.setLength();
  3443. },
  3444. /*
  3445. Property: merge
  3446. Merges the current hash with multiple objects.
  3447. */
  3448. merge: function(){
  3449. this.obj = $merge.apply(null, [this.obj].extend(arguments));
  3450. return this.setLength();
  3451. },
  3452. /*
  3453. Property: empty
  3454. Empties all hash values properties and values.
  3455. */
  3456. empty: function(){
  3457. this.obj = {};
  3458. this.length = 0;
  3459. return this;
  3460. },
  3461. /*
  3462. Property: keys
  3463. Returns an array containing all the keys, in the same order as the values returned by <Hash.values>.
  3464. Returns:
  3465. An array containing all the keys of the hash
  3466. */
  3467. keys: function(){
  3468. var keys = [];
  3469. for (var property in this.obj) keys.push(property);
  3470. return keys;
  3471. },
  3472. /*
  3473. Property: values
  3474. Returns an array containing all the values, in the same order as the keys returned by <Hash.keys>.
  3475. Returns:
  3476. An array containing all the values of the hash
  3477. */
  3478. values: function(){
  3479. var values = [];
  3480. for (var property in this.obj) values.push(this.obj[property]);
  3481. return values;
  3482. }
  3483. });
  3484. /* Section: Utility Functions */
  3485. /*
  3486. Function: $H
  3487. Shortcut to create a Hash from an Object.
  3488. */
  3489. function $H(obj){
  3490. return new Hash(obj);
  3491. };