PageRenderTime 52ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/javascript/frameworks/mootools/mootools-1.2.5.js

https://github.com/quarkness/piwik
JavaScript | 2092 lines | 1667 code | 268 blank | 157 comment | 259 complexity | c2baf2d0bde2498fcd810fb68c24551b MD5 | raw file
  1. /*
  2. ---
  3. name: Core
  4. description: The core of MooTools, contains all the base functions and the Native and Hash implementations. Required by all the other scripts.
  5. license: MIT-style license.
  6. copyright: Copyright (c) 2006-2008 [Valerio Proietti](http://mad4milk.net/).
  7. authors: The MooTools production team (http://mootools.net/developers/)
  8. inspiration:
  9. - Class implementation inspired by [Base.js](http://dean.edwards.name/weblog/2006/03/base/) Copyright (c) 2006 Dean Edwards, [GNU Lesser General Public License](http://opensource.org/licenses/lgpl-license.php)
  10. - Some functionality inspired by [Prototype.js](http://prototypejs.org) Copyright (c) 2005-2007 Sam Stephenson, [MIT License](http://opensource.org/licenses/mit-license.php)
  11. provides: [MooTools, Native, Hash.base, Array.each, $util]
  12. ...
  13. */
  14. var MooTools = {
  15. 'version': '1.2.5',
  16. 'build': '008d8f0f2fcc2044e54fdd3635341aaab274e757'
  17. };
  18. var Native = function(options){
  19. options = options || {};
  20. var name = options.name;
  21. var legacy = options.legacy;
  22. var protect = options.protect;
  23. var methods = options.implement;
  24. var generics = options.generics;
  25. var initialize = options.initialize;
  26. var afterImplement = options.afterImplement || function(){};
  27. var object = initialize || legacy;
  28. generics = generics !== false;
  29. object.constructor = Native;
  30. object.$family = {name: 'native'};
  31. if (legacy && initialize) object.prototype = legacy.prototype;
  32. object.prototype.constructor = object;
  33. if (name){
  34. var family = name.toLowerCase();
  35. object.prototype.$family = {name: family};
  36. Native.typize(object, family);
  37. }
  38. var add = function(obj, name, method, force){
  39. if (!protect || force || !obj.prototype[name]) obj.prototype[name] = method;
  40. if (generics) Native.genericize(obj, name, protect);
  41. afterImplement.call(obj, name, method);
  42. return obj;
  43. };
  44. object.alias = function(a1, a2, a3){
  45. if (typeof a1 == 'string'){
  46. var pa1 = this.prototype[a1];
  47. if ((a1 = pa1)) return add(this, a2, a1, a3);
  48. }
  49. for (var a in a1) this.alias(a, a1[a], a2);
  50. return this;
  51. };
  52. object.implement = function(a1, a2, a3){
  53. if (typeof a1 == 'string') return add(this, a1, a2, a3);
  54. for (var p in a1) add(this, p, a1[p], a2);
  55. return this;
  56. };
  57. if (methods) object.implement(methods);
  58. return object;
  59. };
  60. Native.genericize = function(object, property, check){
  61. if ((!check || !object[property]) && typeof object.prototype[property] == 'function') object[property] = function(){
  62. var args = Array.prototype.slice.call(arguments);
  63. return object.prototype[property].apply(args.shift(), args);
  64. };
  65. };
  66. Native.implement = function(objects, properties){
  67. for (var i = 0, l = objects.length; i < l; i++) objects[i].implement(properties);
  68. };
  69. Native.typize = function(object, family){
  70. if (!object.type) object.type = function(item){
  71. return ($type(item) === family);
  72. };
  73. };
  74. (function(){
  75. var natives = {'Array': Array, 'Date': Date, 'Function': Function, 'Number': Number, 'RegExp': RegExp, 'String': String};
  76. for (var n in natives) new Native({name: n, initialize: natives[n], protect: true});
  77. var types = {'boolean': Boolean, 'native': Native, 'object': Object};
  78. for (var t in types) Native.typize(types[t], t);
  79. var generics = {
  80. 'Array': ["concat", "indexOf", "join", "lastIndexOf", "pop", "push", "reverse", "shift", "slice", "sort", "splice", "toString", "unshift", "valueOf"],
  81. 'String': ["charAt", "charCodeAt", "concat", "indexOf", "lastIndexOf", "match", "replace", "search", "slice", "split", "substr", "substring", "toLowerCase", "toUpperCase", "valueOf"]
  82. };
  83. for (var g in generics){
  84. for (var i = generics[g].length; i--;) Native.genericize(natives[g], generics[g][i], true);
  85. }
  86. })();
  87. var Hash = new Native({
  88. name: 'Hash',
  89. initialize: function(object){
  90. if ($type(object) == 'hash') object = $unlink(object.getClean());
  91. for (var key in object) this[key] = object[key];
  92. return this;
  93. }
  94. });
  95. Hash.implement({
  96. forEach: function(fn, bind){
  97. for (var key in this){
  98. if (this.hasOwnProperty(key)) fn.call(bind, this[key], key, this);
  99. }
  100. },
  101. getClean: function(){
  102. var clean = {};
  103. for (var key in this){
  104. if (this.hasOwnProperty(key)) clean[key] = this[key];
  105. }
  106. return clean;
  107. },
  108. getLength: function(){
  109. var length = 0;
  110. for (var key in this){
  111. if (this.hasOwnProperty(key)) length++;
  112. }
  113. return length;
  114. }
  115. });
  116. Hash.alias('forEach', 'each');
  117. Array.implement({
  118. forEach: function(fn, bind){
  119. for (var i = 0, l = this.length; i < l; i++) fn.call(bind, this[i], i, this);
  120. }
  121. });
  122. Array.alias('forEach', 'each');
  123. function $A(iterable){
  124. if (iterable.item){
  125. var l = iterable.length, array = new Array(l);
  126. while (l--) array[l] = iterable[l];
  127. return array;
  128. }
  129. return Array.prototype.slice.call(iterable);
  130. };
  131. function $arguments(i){
  132. return function(){
  133. return arguments[i];
  134. };
  135. };
  136. function $chk(obj){
  137. return !!(obj || obj === 0);
  138. };
  139. function $clear(timer){
  140. clearTimeout(timer);
  141. clearInterval(timer);
  142. return null;
  143. };
  144. function $defined(obj){
  145. return (obj != undefined);
  146. };
  147. function $each(iterable, fn, bind){
  148. var type = $type(iterable);
  149. ((type == 'arguments' || type == 'collection' || type == 'array') ? Array : Hash).each(iterable, fn, bind);
  150. };
  151. function $empty(){};
  152. function $extend(original, extended){
  153. for (var key in (extended || {})) original[key] = extended[key];
  154. return original;
  155. };
  156. function $H(object){
  157. return new Hash(object);
  158. };
  159. function $lambda(value){
  160. return ($type(value) == 'function') ? value : function(){
  161. return value;
  162. };
  163. };
  164. function $merge(){
  165. var args = Array.slice(arguments);
  166. args.unshift({});
  167. return $mixin.apply(null, args);
  168. };
  169. function $mixin(mix){
  170. for (var i = 1, l = arguments.length; i < l; i++){
  171. var object = arguments[i];
  172. if ($type(object) != 'object') continue;
  173. for (var key in object){
  174. var op = object[key], mp = mix[key];
  175. mix[key] = (mp && $type(op) == 'object' && $type(mp) == 'object') ? $mixin(mp, op) : $unlink(op);
  176. }
  177. }
  178. return mix;
  179. };
  180. function $pick(){
  181. for (var i = 0, l = arguments.length; i < l; i++){
  182. if (arguments[i] != undefined) return arguments[i];
  183. }
  184. return null;
  185. };
  186. function $random(min, max){
  187. return Math.floor(Math.random() * (max - min + 1) + min);
  188. };
  189. function $splat(obj){
  190. var type = $type(obj);
  191. return (type) ? ((type != 'array' && type != 'arguments') ? [obj] : obj) : [];
  192. };
  193. var $time = Date.now || function(){
  194. return +new Date;
  195. };
  196. function $try(){
  197. for (var i = 0, l = arguments.length; i < l; i++){
  198. try {
  199. return arguments[i]();
  200. } catch(e){}
  201. }
  202. return null;
  203. };
  204. function $type(obj){
  205. if (obj == undefined) return false;
  206. if (obj.$family) return (obj.$family.name == 'number' && !isFinite(obj)) ? false : obj.$family.name;
  207. if (obj.nodeName){
  208. switch (obj.nodeType){
  209. case 1: return 'element';
  210. case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace';
  211. }
  212. } else if (typeof obj.length == 'number'){
  213. if (obj.callee) return 'arguments';
  214. else if (obj.item) return 'collection';
  215. }
  216. return typeof obj;
  217. };
  218. function $unlink(object){
  219. var unlinked;
  220. switch ($type(object)){
  221. case 'object':
  222. unlinked = {};
  223. for (var p in object) unlinked[p] = $unlink(object[p]);
  224. break;
  225. case 'hash':
  226. unlinked = new Hash(object);
  227. break;
  228. case 'array':
  229. unlinked = [];
  230. for (var i = 0, l = object.length; i < l; i++) unlinked[i] = $unlink(object[i]);
  231. break;
  232. default: return object;
  233. }
  234. return unlinked;
  235. };
  236. /*
  237. ---
  238. name: Array
  239. description: Contains Array Prototypes like each, contains, and erase.
  240. license: MIT-style license.
  241. requires: [$util, Array.each]
  242. provides: Array
  243. ...
  244. */
  245. Array.implement({
  246. every: function(fn, bind){
  247. for (var i = 0, l = this.length; i < l; i++){
  248. if (!fn.call(bind, this[i], i, this)) return false;
  249. }
  250. return true;
  251. },
  252. filter: function(fn, bind){
  253. var results = [];
  254. for (var i = 0, l = this.length; i < l; i++){
  255. if (fn.call(bind, this[i], i, this)) results.push(this[i]);
  256. }
  257. return results;
  258. },
  259. clean: function(){
  260. return this.filter($defined);
  261. },
  262. indexOf: function(item, from){
  263. var len = this.length;
  264. for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
  265. if (this[i] === item) return i;
  266. }
  267. return -1;
  268. },
  269. map: function(fn, bind){
  270. var results = [];
  271. for (var i = 0, l = this.length; i < l; i++) results[i] = fn.call(bind, this[i], i, this);
  272. return results;
  273. },
  274. some: function(fn, bind){
  275. for (var i = 0, l = this.length; i < l; i++){
  276. if (fn.call(bind, this[i], i, this)) return true;
  277. }
  278. return false;
  279. },
  280. associate: function(keys){
  281. var obj = {}, length = Math.min(this.length, keys.length);
  282. for (var i = 0; i < length; i++) obj[keys[i]] = this[i];
  283. return obj;
  284. },
  285. link: function(object){
  286. var result = {};
  287. for (var i = 0, l = this.length; i < l; i++){
  288. for (var key in object){
  289. if (object[key](this[i])){
  290. result[key] = this[i];
  291. delete object[key];
  292. break;
  293. }
  294. }
  295. }
  296. return result;
  297. },
  298. contains: function(item, from){
  299. return this.indexOf(item, from) != -1;
  300. },
  301. extend: function(array){
  302. for (var i = 0, j = array.length; i < j; i++) this.push(array[i]);
  303. return this;
  304. },
  305. getLast: function(){
  306. return (this.length) ? this[this.length - 1] : null;
  307. },
  308. getRandom: function(){
  309. return (this.length) ? this[$random(0, this.length - 1)] : null;
  310. },
  311. include: function(item){
  312. if (!this.contains(item)) this.push(item);
  313. return this;
  314. },
  315. combine: function(array){
  316. for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
  317. return this;
  318. },
  319. erase: function(item){
  320. for (var i = this.length; i--; i){
  321. if (this[i] === item) this.splice(i, 1);
  322. }
  323. return this;
  324. },
  325. empty: function(){
  326. this.length = 0;
  327. return this;
  328. },
  329. flatten: function(){
  330. var array = [];
  331. for (var i = 0, l = this.length; i < l; i++){
  332. var type = $type(this[i]);
  333. if (!type) continue;
  334. array = array.concat((type == 'array' || type == 'collection' || type == 'arguments') ? Array.flatten(this[i]) : this[i]);
  335. }
  336. return array;
  337. },
  338. hexToRgb: function(array){
  339. if (this.length != 3) return null;
  340. var rgb = this.map(function(value){
  341. if (value.length == 1) value += value;
  342. return value.toInt(16);
  343. });
  344. return (array) ? rgb : 'rgb(' + rgb + ')';
  345. },
  346. rgbToHex: function(array){
  347. if (this.length < 3) return null;
  348. if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
  349. var hex = [];
  350. for (var i = 0; i < 3; i++){
  351. var bit = (this[i] - 0).toString(16);
  352. hex.push((bit.length == 1) ? '0' + bit : bit);
  353. }
  354. return (array) ? hex : '#' + hex.join('');
  355. }
  356. });
  357. /*
  358. ---
  359. name: String
  360. description: Contains String Prototypes like camelCase, capitalize, test, and toInt.
  361. license: MIT-style license.
  362. requires: Native
  363. provides: String
  364. ...
  365. */
  366. String.implement({
  367. test: function(regex, params){
  368. return ((typeof regex == 'string') ? new RegExp(regex, params) : regex).test(this);
  369. },
  370. contains: function(string, separator){
  371. return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1;
  372. },
  373. trim: function(){
  374. return this.replace(/^\s+|\s+$/g, '');
  375. },
  376. clean: function(){
  377. return this.replace(/\s+/g, ' ').trim();
  378. },
  379. camelCase: function(){
  380. return this.replace(/-\D/g, function(match){
  381. return match.charAt(1).toUpperCase();
  382. });
  383. },
  384. hyphenate: function(){
  385. return this.replace(/[A-Z]/g, function(match){
  386. return ('-' + match.charAt(0).toLowerCase());
  387. });
  388. },
  389. capitalize: function(){
  390. return this.replace(/\b[a-z]/g, function(match){
  391. return match.toUpperCase();
  392. });
  393. },
  394. escapeRegExp: function(){
  395. return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
  396. },
  397. toInt: function(base){
  398. return parseInt(this, base || 10);
  399. },
  400. toFloat: function(){
  401. return parseFloat(this);
  402. },
  403. hexToRgb: function(array){
  404. var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
  405. return (hex) ? hex.slice(1).hexToRgb(array) : null;
  406. },
  407. rgbToHex: function(array){
  408. var rgb = this.match(/\d{1,3}/g);
  409. return (rgb) ? rgb.rgbToHex(array) : null;
  410. },
  411. stripScripts: function(option){
  412. var scripts = '';
  413. var text = this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
  414. scripts += arguments[1] + '\n';
  415. return '';
  416. });
  417. if (option === true) $exec(scripts);
  418. else if ($type(option) == 'function') option(scripts, text);
  419. return text;
  420. },
  421. substitute: function(object, regexp){
  422. return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
  423. if (match.charAt(0) == '\\') return match.slice(1);
  424. return (object[name] != undefined) ? object[name] : '';
  425. });
  426. }
  427. });
  428. /*
  429. ---
  430. name: Function
  431. description: Contains Function Prototypes like create, bind, pass, and delay.
  432. license: MIT-style license.
  433. requires: [Native, $util]
  434. provides: Function
  435. ...
  436. */
  437. try {
  438. delete Function.prototype.bind;
  439. } catch(e){}
  440. Function.implement({
  441. extend: function(properties){
  442. for (var property in properties) this[property] = properties[property];
  443. return this;
  444. },
  445. create: function(options){
  446. var self = this;
  447. options = options || {};
  448. return function(event){
  449. var args = options.arguments;
  450. args = (args != undefined) ? $splat(args) : Array.slice(arguments, (options.event) ? 1 : 0);
  451. if (options.event) args = [event || window.event].extend(args);
  452. var returns = function(){
  453. return self.apply(options.bind || null, args);
  454. };
  455. if (options.delay) return setTimeout(returns, options.delay);
  456. if (options.periodical) return setInterval(returns, options.periodical);
  457. if (options.attempt) return $try(returns);
  458. return returns();
  459. };
  460. },
  461. run: function(args, bind){
  462. return this.apply(bind, $splat(args));
  463. },
  464. pass: function(args, bind){
  465. return this.create({bind: bind, arguments: args});
  466. },
  467. bind: function(bind, args){
  468. return this.create({bind: bind, arguments: args});
  469. },
  470. bindWithEvent: function(bind, args){
  471. return this.create({bind: bind, arguments: args, event: true});
  472. },
  473. attempt: function(args, bind){
  474. return this.create({bind: bind, arguments: args, attempt: true})();
  475. },
  476. delay: function(delay, bind, args){
  477. return this.create({bind: bind, arguments: args, delay: delay})();
  478. },
  479. periodical: function(periodical, bind, args){
  480. return this.create({bind: bind, arguments: args, periodical: periodical})();
  481. }
  482. });
  483. /*
  484. ---
  485. name: Number
  486. description: Contains Number Prototypes like limit, round, times, and ceil.
  487. license: MIT-style license.
  488. requires: [Native, $util]
  489. provides: Number
  490. ...
  491. */
  492. Number.implement({
  493. limit: function(min, max){
  494. return Math.min(max, Math.max(min, this));
  495. },
  496. round: function(precision){
  497. precision = Math.pow(10, precision || 0);
  498. return Math.round(this * precision) / precision;
  499. },
  500. times: function(fn, bind){
  501. for (var i = 0; i < this; i++) fn.call(bind, i, this);
  502. },
  503. toFloat: function(){
  504. return parseFloat(this);
  505. },
  506. toInt: function(base){
  507. return parseInt(this, base || 10);
  508. }
  509. });
  510. Number.alias('times', 'each');
  511. (function(math){
  512. var methods = {};
  513. math.each(function(name){
  514. if (!Number[name]) methods[name] = function(){
  515. return Math[name].apply(null, [this].concat($A(arguments)));
  516. };
  517. });
  518. Number.implement(methods);
  519. })(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']);
  520. /*
  521. ---
  522. name: Hash
  523. description: Contains Hash Prototypes. Provides a means for overcoming the JavaScript practical impossibility of extending native Objects.
  524. license: MIT-style license.
  525. requires: Hash.base
  526. provides: Hash
  527. ...
  528. */
  529. Hash.implement({
  530. has: Object.prototype.hasOwnProperty,
  531. keyOf: function(value){
  532. for (var key in this){
  533. if (this.hasOwnProperty(key) && this[key] === value) return key;
  534. }
  535. return null;
  536. },
  537. hasValue: function(value){
  538. return (Hash.keyOf(this, value) !== null);
  539. },
  540. extend: function(properties){
  541. Hash.each(properties || {}, function(value, key){
  542. Hash.set(this, key, value);
  543. }, this);
  544. return this;
  545. },
  546. combine: function(properties){
  547. Hash.each(properties || {}, function(value, key){
  548. Hash.include(this, key, value);
  549. }, this);
  550. return this;
  551. },
  552. erase: function(key){
  553. if (this.hasOwnProperty(key)) delete this[key];
  554. return this;
  555. },
  556. get: function(key){
  557. return (this.hasOwnProperty(key)) ? this[key] : null;
  558. },
  559. set: function(key, value){
  560. if (!this[key] || this.hasOwnProperty(key)) this[key] = value;
  561. return this;
  562. },
  563. empty: function(){
  564. Hash.each(this, function(value, key){
  565. delete this[key];
  566. }, this);
  567. return this;
  568. },
  569. include: function(key, value){
  570. if (this[key] == undefined) this[key] = value;
  571. return this;
  572. },
  573. map: function(fn, bind){
  574. var results = new Hash;
  575. Hash.each(this, function(value, key){
  576. results.set(key, fn.call(bind, value, key, this));
  577. }, this);
  578. return results;
  579. },
  580. filter: function(fn, bind){
  581. var results = new Hash;
  582. Hash.each(this, function(value, key){
  583. if (fn.call(bind, value, key, this)) results.set(key, value);
  584. }, this);
  585. return results;
  586. },
  587. every: function(fn, bind){
  588. for (var key in this){
  589. if (this.hasOwnProperty(key) && !fn.call(bind, this[key], key)) return false;
  590. }
  591. return true;
  592. },
  593. some: function(fn, bind){
  594. for (var key in this){
  595. if (this.hasOwnProperty(key) && fn.call(bind, this[key], key)) return true;
  596. }
  597. return false;
  598. },
  599. getKeys: function(){
  600. var keys = [];
  601. Hash.each(this, function(value, key){
  602. keys.push(key);
  603. });
  604. return keys;
  605. },
  606. getValues: function(){
  607. var values = [];
  608. Hash.each(this, function(value){
  609. values.push(value);
  610. });
  611. return values;
  612. },
  613. toQueryString: function(base){
  614. var queryString = [];
  615. Hash.each(this, function(value, key){
  616. if (base) key = base + '[' + key + ']';
  617. var result;
  618. switch ($type(value)){
  619. case 'object': result = Hash.toQueryString(value, key); break;
  620. case 'array':
  621. var qs = {};
  622. value.each(function(val, i){
  623. qs[i] = val;
  624. });
  625. result = Hash.toQueryString(qs, key);
  626. break;
  627. default: result = key + '=' + encodeURIComponent(value);
  628. }
  629. if (value != undefined) queryString.push(result);
  630. });
  631. return queryString.join('&');
  632. }
  633. });
  634. Hash.alias({keyOf: 'indexOf', hasValue: 'contains'});
  635. /*
  636. ---
  637. name: Class
  638. description: Contains the Class Function for easily creating, extending, and implementing reusable Classes.
  639. license: MIT-style license.
  640. requires: [$util, Native, Array, String, Function, Number, Hash]
  641. provides: Class
  642. ...
  643. */
  644. function Class(params){
  645. if (params instanceof Function) params = {initialize: params};
  646. var newClass = function(){
  647. Object.reset(this);
  648. if (newClass._prototyping) return this;
  649. this._current = $empty;
  650. var value = (this.initialize) ? this.initialize.apply(this, arguments) : this;
  651. delete this._current; delete this.caller;
  652. return value;
  653. }.extend(this);
  654. newClass.implement(params);
  655. newClass.constructor = Class;
  656. newClass.prototype.constructor = newClass;
  657. return newClass;
  658. };
  659. Function.prototype.protect = function(){
  660. this._protected = true;
  661. return this;
  662. };
  663. Object.reset = function(object, key){
  664. if (key == null){
  665. for (var p in object) Object.reset(object, p);
  666. return object;
  667. }
  668. delete object[key];
  669. switch ($type(object[key])){
  670. case 'object':
  671. var F = function(){};
  672. F.prototype = object[key];
  673. var i = new F;
  674. object[key] = Object.reset(i);
  675. break;
  676. case 'array': object[key] = $unlink(object[key]); break;
  677. }
  678. return object;
  679. };
  680. new Native({name: 'Class', initialize: Class}).extend({
  681. instantiate: function(F){
  682. F._prototyping = true;
  683. var proto = new F;
  684. delete F._prototyping;
  685. return proto;
  686. },
  687. wrap: function(self, key, method){
  688. if (method._origin) method = method._origin;
  689. return function(){
  690. if (method._protected && this._current == null) throw new Error('The method "' + key + '" cannot be called.');
  691. var caller = this.caller, current = this._current;
  692. this.caller = current; this._current = arguments.callee;
  693. var result = method.apply(this, arguments);
  694. this._current = current; this.caller = caller;
  695. return result;
  696. }.extend({_owner: self, _origin: method, _name: key});
  697. }
  698. });
  699. Class.implement({
  700. implement: function(key, value){
  701. if ($type(key) == 'object'){
  702. for (var p in key) this.implement(p, key[p]);
  703. return this;
  704. }
  705. var mutator = Class.Mutators[key];
  706. if (mutator){
  707. value = mutator.call(this, value);
  708. if (value == null) return this;
  709. }
  710. var proto = this.prototype;
  711. switch ($type(value)){
  712. case 'function':
  713. if (value._hidden) return this;
  714. proto[key] = Class.wrap(this, key, value);
  715. break;
  716. case 'object':
  717. var previous = proto[key];
  718. if ($type(previous) == 'object') $mixin(previous, value);
  719. else proto[key] = $unlink(value);
  720. break;
  721. case 'array':
  722. proto[key] = $unlink(value);
  723. break;
  724. default: proto[key] = value;
  725. }
  726. return this;
  727. }
  728. });
  729. Class.Mutators = {
  730. Extends: function(parent){
  731. this.parent = parent;
  732. this.prototype = Class.instantiate(parent);
  733. this.implement('parent', function(){
  734. var name = this.caller._name, previous = this.caller._owner.parent.prototype[name];
  735. if (!previous) throw new Error('The method "' + name + '" has no parent.');
  736. return previous.apply(this, arguments);
  737. }.protect());
  738. },
  739. Implements: function(items){
  740. $splat(items).each(function(item){
  741. if (item instanceof Function) item = Class.instantiate(item);
  742. this.implement(item);
  743. }, this);
  744. }
  745. };
  746. /*
  747. ---
  748. name: Class.Extras
  749. description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks.
  750. license: MIT-style license.
  751. requires: Class
  752. provides: [Chain, Events, Options, Class.Extras]
  753. ...
  754. */
  755. var Chain = new Class({
  756. $chain: [],
  757. chain: function(){
  758. this.$chain.extend(Array.flatten(arguments));
  759. return this;
  760. },
  761. callChain: function(){
  762. return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false;
  763. },
  764. clearChain: function(){
  765. this.$chain.empty();
  766. return this;
  767. }
  768. });
  769. var Events = new Class({
  770. $events: {},
  771. addEvent: function(type, fn, internal){
  772. type = Events.removeOn(type);
  773. if (fn != $empty){
  774. this.$events[type] = this.$events[type] || [];
  775. this.$events[type].include(fn);
  776. if (internal) fn.internal = true;
  777. }
  778. return this;
  779. },
  780. addEvents: function(events){
  781. for (var type in events) this.addEvent(type, events[type]);
  782. return this;
  783. },
  784. fireEvent: function(type, args, delay){
  785. type = Events.removeOn(type);
  786. if (!this.$events || !this.$events[type]) return this;
  787. this.$events[type].each(function(fn){
  788. fn.create({'bind': this, 'delay': delay, 'arguments': args})();
  789. }, this);
  790. return this;
  791. },
  792. removeEvent: function(type, fn){
  793. type = Events.removeOn(type);
  794. if (!this.$events[type]) return this;
  795. if (!fn.internal) this.$events[type].erase(fn);
  796. return this;
  797. },
  798. removeEvents: function(events){
  799. var type;
  800. if ($type(events) == 'object'){
  801. for (type in events) this.removeEvent(type, events[type]);
  802. return this;
  803. }
  804. if (events) events = Events.removeOn(events);
  805. for (type in this.$events){
  806. if (events && events != type) continue;
  807. var fns = this.$events[type];
  808. for (var i = fns.length; i--; i) this.removeEvent(type, fns[i]);
  809. }
  810. return this;
  811. }
  812. });
  813. Events.removeOn = function(string){
  814. return string.replace(/^on([A-Z])/, function(full, first){
  815. return first.toLowerCase();
  816. });
  817. };
  818. var Options = new Class({
  819. setOptions: function(){
  820. this.options = $merge.run([this.options].extend(arguments));
  821. if (!this.addEvent) return this;
  822. for (var option in this.options){
  823. if ($type(this.options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue;
  824. this.addEvent(option, this.options[option]);
  825. delete this.options[option];
  826. }
  827. return this;
  828. }
  829. });
  830. /*
  831. ---
  832. name: Browser
  833. description: The Browser Core. Contains Browser initialization, Window and Document, and the Browser Hash.
  834. license: MIT-style license.
  835. requires: [Native, $util]
  836. provides: [Browser, Window, Document, $exec]
  837. ...
  838. */
  839. var Browser = $merge({
  840. Engine: {name: 'unknown', version: 0},
  841. Platform: {name: (window.orientation != undefined) ? 'ipod' : (navigator.platform.match(/mac|win|linux/i) || ['other'])[0].toLowerCase()},
  842. Features: {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)},
  843. Plugins: {},
  844. Engines: {
  845. presto: function(){
  846. return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925));
  847. },
  848. trident: function(){
  849. return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? ((document.querySelectorAll) ? 6 : 5) : 4);
  850. },
  851. webkit: function(){
  852. return (navigator.taintEnabled) ? false : ((Browser.Features.xpath) ? ((Browser.Features.query) ? 525 : 420) : 419);
  853. },
  854. gecko: function(){
  855. return (!document.getBoxObjectFor && window.mozInnerScreenX == null) ? false : ((document.getElementsByClassName) ? 19 : 18);
  856. }
  857. }
  858. }, Browser || {});
  859. Browser.Platform[Browser.Platform.name] = true;
  860. Browser.detect = function(){
  861. for (var engine in this.Engines){
  862. var version = this.Engines[engine]();
  863. if (version){
  864. this.Engine = {name: engine, version: version};
  865. this.Engine[engine] = this.Engine[engine + version] = true;
  866. break;
  867. }
  868. }
  869. return {name: engine, version: version};
  870. };
  871. Browser.detect();
  872. Browser.Request = function(){
  873. return $try(function(){
  874. return new XMLHttpRequest();
  875. }, function(){
  876. return new ActiveXObject('MSXML2.XMLHTTP');
  877. }, function(){
  878. return new ActiveXObject('Microsoft.XMLHTTP');
  879. });
  880. };
  881. Browser.Features.xhr = !!(Browser.Request());
  882. Browser.Plugins.Flash = (function(){
  883. var version = ($try(function(){
  884. return navigator.plugins['Shockwave Flash'].description;
  885. }, function(){
  886. return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
  887. }) || '0 r0').match(/\d+/g);
  888. return {version: parseInt(version[0] || 0 + '.' + version[1], 10) || 0, build: parseInt(version[2], 10) || 0};
  889. })();
  890. function $exec(text){
  891. if (!text) return text;
  892. if (window.execScript){
  893. window.execScript(text);
  894. } else {
  895. var script = document.createElement('script');
  896. script.setAttribute('type', 'text/javascript');
  897. script[(Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerText' : 'text'] = text;
  898. document.head.appendChild(script);
  899. document.head.removeChild(script);
  900. }
  901. return text;
  902. };
  903. Native.UID = 1;
  904. var $uid = (Browser.Engine.trident) ? function(item){
  905. return (item.uid || (item.uid = [Native.UID++]))[0];
  906. } : function(item){
  907. return item.uid || (item.uid = Native.UID++);
  908. };
  909. var Window = new Native({
  910. name: 'Window',
  911. legacy: (Browser.Engine.trident) ? null: window.Window,
  912. initialize: function(win){
  913. $uid(win);
  914. if (!win.Element){
  915. win.Element = $empty;
  916. if (Browser.Engine.webkit) win.document.createElement("iframe"); //fixes safari 2
  917. win.Element.prototype = (Browser.Engine.webkit) ? window["[[DOMElement.prototype]]"] : {};
  918. }
  919. win.document.window = win;
  920. return $extend(win, Window.Prototype);
  921. },
  922. afterImplement: function(property, value){
  923. window[property] = Window.Prototype[property] = value;
  924. }
  925. });
  926. Window.Prototype = {$family: {name: 'window'}};
  927. new Window(window);
  928. var Document = new Native({
  929. name: 'Document',
  930. legacy: (Browser.Engine.trident) ? null: window.Document,
  931. initialize: function(doc){
  932. $uid(doc);
  933. doc.head = doc.getElementsByTagName('head')[0];
  934. doc.html = doc.getElementsByTagName('html')[0];
  935. if (Browser.Engine.trident && Browser.Engine.version <= 4) $try(function(){
  936. doc.execCommand("BackgroundImageCache", false, true);
  937. });
  938. if (Browser.Engine.trident) doc.window.attachEvent('onunload', function(){
  939. doc.window.detachEvent('onunload', arguments.callee);
  940. doc.head = doc.html = doc.window = null;
  941. });
  942. return $extend(doc, Document.Prototype);
  943. },
  944. afterImplement: function(property, value){
  945. document[property] = Document.Prototype[property] = value;
  946. }
  947. });
  948. Document.Prototype = {$family: {name: 'document'}};
  949. new Document(document);
  950. /*
  951. ---
  952. name: Element
  953. description: One of the most important items in MooTools. Contains the dollar function, the dollars function, and an handful of cross-browser, time-saver methods to let you easily work with HTML Elements.
  954. license: MIT-style license.
  955. requires: [Window, Document, Array, String, Function, Number, Hash]
  956. provides: [Element, Elements, $, $$, Iframe]
  957. ...
  958. */
  959. var Element = new Native({
  960. name: 'Element',
  961. legacy: window.Element,
  962. initialize: function(tag, props){
  963. var konstructor = Element.Constructors.get(tag);
  964. if (konstructor) return konstructor(props);
  965. if (typeof tag == 'string') return document.newElement(tag, props);
  966. return document.id(tag).set(props);
  967. },
  968. afterImplement: function(key, value){
  969. Element.Prototype[key] = value;
  970. if (Array[key]) return;
  971. Elements.implement(key, function(){
  972. var items = [], elements = true;
  973. for (var i = 0, j = this.length; i < j; i++){
  974. var returns = this[i][key].apply(this[i], arguments);
  975. items.push(returns);
  976. if (elements) elements = ($type(returns) == 'element');
  977. }
  978. return (elements) ? new Elements(items) : items;
  979. });
  980. }
  981. });
  982. Element.Prototype = {$family: {name: 'element'}};
  983. Element.Constructors = new Hash;
  984. var IFrame = new Native({
  985. name: 'IFrame',
  986. generics: false,
  987. initialize: function(){
  988. var params = Array.link(arguments, {properties: Object.type, iframe: $defined});
  989. var props = params.properties || {};
  990. var iframe = document.id(params.iframe);
  991. var onload = props.onload || $empty;
  992. delete props.onload;
  993. props.id = props.name = $pick(props.id, props.name, iframe ? (iframe.id || iframe.name) : 'IFrame_' + $time());
  994. iframe = new Element(iframe || 'iframe', props);
  995. var onFrameLoad = function(){
  996. var host = $try(function(){
  997. return iframe.contentWindow.location.host;
  998. });
  999. if (!host || host == window.location.host){
  1000. var win = new Window(iframe.contentWindow);
  1001. new Document(iframe.contentWindow.document);
  1002. $extend(win.Element.prototype, Element.Prototype);
  1003. }
  1004. onload.call(iframe.contentWindow, iframe.contentWindow.document);
  1005. };
  1006. var contentWindow = $try(function(){
  1007. return iframe.contentWindow;
  1008. });
  1009. ((contentWindow && contentWindow.document.body) || window.frames[props.id]) ? onFrameLoad() : iframe.addListener('load', onFrameLoad);
  1010. return iframe;
  1011. }
  1012. });
  1013. var Elements = new Native({
  1014. initialize: function(elements, options){
  1015. options = $extend({ddup: true, cash: true}, options);
  1016. elements = elements || [];
  1017. if (options.ddup || options.cash){
  1018. var uniques = {}, returned = [];
  1019. for (var i = 0, l = elements.length; i < l; i++){
  1020. var el = document.id(elements[i], !options.cash);
  1021. if (options.ddup){
  1022. if (uniques[el.uid]) continue;
  1023. uniques[el.uid] = true;
  1024. }
  1025. if (el) returned.push(el);
  1026. }
  1027. elements = returned;
  1028. }
  1029. return (options.cash) ? $extend(elements, this) : elements;
  1030. }
  1031. });
  1032. Elements.implement({
  1033. filter: function(filter, bind){
  1034. if (!filter) return this;
  1035. return new Elements(Array.filter(this, (typeof filter == 'string') ? function(item){
  1036. return item.match(filter);
  1037. } : filter, bind));
  1038. }
  1039. });
  1040. (function(){
  1041. /*<ltIE8>*/
  1042. var createElementAcceptsHTML;
  1043. try {
  1044. var x = document.createElement('<input name=x>');
  1045. createElementAcceptsHTML = (x.name == 'x');
  1046. } catch(e){}
  1047. var escapeQuotes = function(html){
  1048. return ('' + html).replace(/&/g,'&amp;').replace(/"/g,'&quot;');
  1049. };
  1050. /*</ltIE8>*/
  1051. Document.implement({
  1052. newElement: function(tag, props){
  1053. if (props && props.checked != null) props.defaultChecked = props.checked;
  1054. /*<ltIE8>*/// Fix for readonly name and type properties in IE < 8
  1055. if (createElementAcceptsHTML && props){
  1056. tag = '<' + tag;
  1057. if (props.name) tag += ' name="' + escapeQuotes(props.name) + '"';
  1058. if (props.type) tag += ' type="' + escapeQuotes(props.type) + '"';
  1059. tag += '>';
  1060. delete props.name;
  1061. delete props.type;
  1062. }
  1063. /*</ltIE8>*/
  1064. return this.id(this.createElement(tag)).set(props);
  1065. },
  1066. newTextNode: function(text){
  1067. return this.createTextNode(text);
  1068. },
  1069. getDocument: function(){
  1070. return this;
  1071. },
  1072. getWindow: function(){
  1073. return this.window;
  1074. },
  1075. id: (function(){
  1076. var types = {
  1077. string: function(id, nocash, doc){
  1078. id = doc.getElementById(id);
  1079. return (id) ? types.element(id, nocash) : null;
  1080. },
  1081. element: function(el, nocash){
  1082. $uid(el);
  1083. if (!nocash && !el.$family && !(/^object|embed$/i).test(el.tagName)){
  1084. var proto = Element.Prototype;
  1085. for (var p in proto) el[p] = proto[p];
  1086. };
  1087. return el;
  1088. },
  1089. object: function(obj, nocash, doc){
  1090. if (obj.toElement) return types.element(obj.toElement(doc), nocash);
  1091. return null;
  1092. }
  1093. };
  1094. types.textnode = types.whitespace = types.window = types.document = $arguments(0);
  1095. return function(el, nocash, doc){
  1096. if (el && el.$family && el.uid) return el;
  1097. var type = $type(el);
  1098. return (types[type]) ? types[type](el, nocash, doc || document) : null;
  1099. };
  1100. })()
  1101. });
  1102. })();
  1103. if (window.$ == null) Window.implement({
  1104. $: function(el, nc){
  1105. return document.id(el, nc, this.document);
  1106. }
  1107. });
  1108. Window.implement({
  1109. $$: function(selector){
  1110. if (arguments.length == 1 && typeof selector == 'string') return this.document.getElements(selector);
  1111. var elements = [];
  1112. var args = Array.flatten(arguments);
  1113. for (var i = 0, l = args.length; i < l; i++){
  1114. var item = args[i];
  1115. switch ($type(item)){
  1116. case 'element': elements.push(item); break;
  1117. case 'string': elements.extend(this.document.getElements(item, true));
  1118. }
  1119. }
  1120. return new Elements(elements);
  1121. },
  1122. getDocument: function(){
  1123. return this.document;
  1124. },
  1125. getWindow: function(){
  1126. return this;
  1127. }
  1128. });
  1129. Native.implement([Element, Document], {
  1130. getElement: function(selector, nocash){
  1131. return document.id(this.getElements(selector, true)[0] || null, nocash);
  1132. },
  1133. getElements: function(tags, nocash){
  1134. tags = tags.split(',');
  1135. var elements = [];
  1136. var ddup = (tags.length > 1);
  1137. tags.each(function(tag){
  1138. var partial = this.getElementsByTagName(tag.trim());
  1139. (ddup) ? elements.extend(partial) : elements = partial;
  1140. }, this);
  1141. return new Elements(elements, {ddup: ddup, cash: !nocash});
  1142. }
  1143. });
  1144. (function(){
  1145. var collected = {}, storage = {};
  1146. var props = {input: 'checked', option: 'selected', textarea: (Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerHTML' : 'value'};
  1147. var get = function(uid){
  1148. return (storage[uid] || (storage[uid] = {}));
  1149. };
  1150. var clean = function(item, retain){
  1151. if (!item) return;
  1152. var uid = item.uid;
  1153. if (retain !== true) retain = false;
  1154. if (Browser.Engine.trident){
  1155. if (item.clearAttributes){
  1156. var clone = retain && item.cloneNode(false);
  1157. item.clearAttributes();
  1158. if (clone) item.mergeAttributes(clone);
  1159. } else if (item.removeEvents){
  1160. item.removeEvents();
  1161. }
  1162. if ((/object/i).test(item.tagName)){
  1163. for (var p in item){
  1164. if (typeof item[p] == 'function') item[p] = $empty;
  1165. }
  1166. Element.dispose(item);
  1167. }
  1168. }
  1169. if (!uid) return;
  1170. collected[uid] = storage[uid] = null;
  1171. };
  1172. var purge = function(){
  1173. Hash.each(collected, clean);
  1174. if (Browser.Engine.trident) $A(document.getElementsByTagName('object')).each(clean);
  1175. if (window.CollectGarbage) CollectGarbage();
  1176. collected = storage = null;
  1177. };
  1178. var walk = function(element, walk, start, match, all, nocash){
  1179. var el = element[start || walk];
  1180. var elements = [];
  1181. while (el){
  1182. if (el.nodeType == 1 && (!match || Element.match(el, match))){
  1183. if (!all) return document.id(el, nocash);
  1184. elements.push(el);
  1185. }
  1186. el = el[walk];
  1187. }
  1188. return (all) ? new Elements(elements, {ddup: false, cash: !nocash}) : null;
  1189. };
  1190. var attributes = {
  1191. 'html': 'innerHTML',
  1192. 'class': 'className',
  1193. 'for': 'htmlFor',
  1194. 'defaultValue': 'defaultValue',
  1195. 'text': (Browser.Engine.trident || (Browser.Engine.webkit && Browser.Engine.version < 420)) ? 'innerText' : 'textContent'
  1196. };
  1197. var bools = ['compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked', 'disabled', 'readonly', 'multiple', 'selected', 'noresize', 'defer'];
  1198. var camels = ['value', 'type', 'defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'maxLength', 'readOnly', 'rowSpan', 'tabIndex', 'useMap'];
  1199. bools = bools.associate(bools);
  1200. Hash.extend(attributes, bools);
  1201. Hash.extend(attributes, camels.associate(camels.map(String.toLowerCase)));
  1202. var inserters = {
  1203. before: function(context, element){
  1204. if (element.parentNode) element.parentNode.insertBefore(context, element);
  1205. },
  1206. after: function(context, element){
  1207. if (!element.parentNode) return;
  1208. var next = element.nextSibling;
  1209. (next) ? element.parentNode.insertBefore(context, next) : element.parentNode.appendChild(context);
  1210. },
  1211. bottom: function(context, element){
  1212. element.appendChild(context);
  1213. },
  1214. top: function(context, element){
  1215. var first = element.firstChild;
  1216. (first) ? element.insertBefore(context, first) : element.appendChild(context);
  1217. }
  1218. };
  1219. inserters.inside = inserters.bottom;
  1220. Hash.each(inserters, function(inserter, where){
  1221. where = where.capitalize();
  1222. Element.implement('inject' + where, function(el){
  1223. inserter(this, document.id(el, true));
  1224. return this;
  1225. });
  1226. Element.implement('grab' + where, function(el){
  1227. inserter(document.id(el, true), this);
  1228. return this;
  1229. });
  1230. });
  1231. Element.implement({
  1232. set: function(prop, value){
  1233. switch ($type(prop)){
  1234. case 'object':
  1235. for (var p in prop) this.set(p, prop[p]);
  1236. break;
  1237. case 'string':
  1238. var property = Element.Properties.get(prop);
  1239. (property && property.set) ? property.set.apply(this, Array.slice(arguments, 1)) : this.setProperty(prop, value);
  1240. }
  1241. return this;
  1242. },
  1243. get: function(prop){
  1244. var property = Element.Properties.get(prop);
  1245. return (property && property.get) ? property.get.apply(this, Array.slice(arguments, 1)) : this.getProperty(prop);
  1246. },
  1247. erase: function(prop){
  1248. var property = Element.Properties.get(prop);
  1249. (property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop);
  1250. return this;
  1251. },
  1252. setProperty: function(attribute, value){
  1253. var key = attributes[attribute];
  1254. if (value == undefined) return this.removeProperty(attribute);
  1255. if (key && bools[attribute]) value = !!value;
  1256. (key) ? this[key] = value : this.setAttribute(attribute, '' + value);
  1257. return this;
  1258. },
  1259. setProperties: function(attributes){
  1260. for (var attribute in attributes) this.setProperty(attribute, attributes[attribute]);
  1261. return this;
  1262. },
  1263. getProperty: function(attribute){
  1264. var key = attributes[attribute];
  1265. var value = (key) ? this[key] : this.getAttribute(attribute, 2);
  1266. return (bools[attribute]) ? !!value : (key) ? value : value || null;
  1267. },
  1268. getProperties: function(){
  1269. var args = $A(arguments);
  1270. return args.map(this.getProperty, this).associate(args);
  1271. },
  1272. removeProperty: function(attribute){
  1273. var key = attributes[attribute];
  1274. (key) ? this[key] = (key && bools[attribute]) ? false : '' : this.removeAttribute(attribute);
  1275. return this;
  1276. },
  1277. removeProperties: function(){
  1278. Array.each(arguments, this.removeProperty, this);
  1279. return this;
  1280. },
  1281. hasClass: function(className){
  1282. return this.className.contains(className, ' ');
  1283. },
  1284. addClass: function(className){
  1285. if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean();
  1286. return this;
  1287. },
  1288. removeClass: function(className){
  1289. this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1');
  1290. return this;
  1291. },
  1292. toggleClass: function(className){
  1293. return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
  1294. },
  1295. adopt: function(){
  1296. Array.flatten(arguments).each(function(element){
  1297. element = document.id(element, true);
  1298. if (element) this.appendChild(element);
  1299. }, this);
  1300. return this;
  1301. },
  1302. appendText: function(text, where){
  1303. return this.grab(this.getDocument().newTextNode(text), where);
  1304. },
  1305. grab: function(el, where){
  1306. inserters[where || 'bottom'](document.id(el, true), this);
  1307. return this;
  1308. },
  1309. inject: function(el, where){
  1310. inserters[where || 'bottom'](this, document.id(el, true));
  1311. return this;
  1312. },
  1313. replaces: function(el){
  1314. el = document.id(el, true);
  1315. el.parentNode.replaceChild(this, el);
  1316. return this;
  1317. },
  1318. wraps: function(el, where){
  1319. el = document.id(el, true);
  1320. return this.replaces(el).grab(el, where);
  1321. },
  1322. getPrevious: function(match, nocash){
  1323. return walk(this, 'previousSibling', null, match, false, nocash);
  1324. },
  1325. getAllPrevious: function(match, nocash){
  1326. return walk(this, 'previousSibling', null, match, true, nocash);
  1327. },
  1328. getNext: function(match, nocash){
  1329. return walk(this, 'nextSibling', null, match, false, nocash);
  1330. },
  1331. getAllNext: function(match, nocash){
  1332. return walk(this, 'nextSibling', null, match, true, nocash);
  1333. },
  1334. getFirst: function(match, nocash){
  1335. return walk(this, 'nextSibling', 'firstChild', match, false, nocash);
  1336. },
  1337. getLast: function(match, nocash){
  1338. return walk(this, 'previousSibling', 'lastChild', match, false, nocash);
  1339. },
  1340. getParent: function(match, nocash){
  1341. return walk(this, 'parentNode', null, match, false, nocash);
  1342. },
  1343. getParents: function(match, nocash){
  1344. return walk(this, 'parentNode', null, match, true, nocash);
  1345. },
  1346. getSiblings: function(match, nocash){
  1347. return this.getParent().getChildren(match, nocash).erase(this);
  1348. },
  1349. getChildren: function(match, nocash){
  1350. return walk(this, 'nextSibling', 'firstChild', match, true, nocash);
  1351. },
  1352. getWindow: function(){
  1353. return this.ownerDocument.window;
  1354. },
  1355. getDocument: function(){
  1356. return this.ownerDocument;
  1357. },
  1358. getElementById: function(id, nocash){
  1359. var el = this.ownerDocument.getElementById(id);
  1360. if (!el) return null;
  1361. for (var parent = el.parentNode; parent != this; parent = parent.parentNode){
  1362. if (!parent) return null;
  1363. }
  1364. return document.id(el, nocash);
  1365. },
  1366. getSelected: function(){
  1367. return new Elements($A(this.options).filter(function(option){
  1368. return option.selected;
  1369. }));
  1370. },
  1371. getComputedStyle: function(property){
  1372. if (this.currentStyle) return this.currentStyle[property.camelCase()];
  1373. var computed = this.getDocument().defaultView.getComputedStyle(this, null);
  1374. return (computed) ? computed.getPropertyValue([property.hyphenate()]) : null;
  1375. },
  1376. toQueryString: function(){
  1377. var queryString = [];
  1378. this.getElements('input, select, textarea', true).each(function(el){
  1379. if (!el.name || el.disabled || el.type == 'submit' || el.type == 'reset' || el.type == 'file') return;
  1380. var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){
  1381. return opt.value;
  1382. }) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value;
  1383. $splat(value).each(function(val){
  1384. if (typeof val != 'undefined') queryString.push(el.name + '=' + encodeURIComponent(val));
  1385. });
  1386. });
  1387. return queryString.join('&');
  1388. },
  1389. clone: function(contents, keepid){
  1390. contents = contents !== false;
  1391. var clone = this.cloneNode(contents);
  1392. var clean = function(node, element){
  1393. if (!keepid) node.removeAttribute('id');
  1394. if (Browser.Engine.trident){
  1395. node.clearAttributes();
  1396. node.mergeAttributes(element);
  1397. node.removeAttribute('uid');
  1398. if (node.options){
  1399. var no = node.options, eo = element.options;
  1400. for (var j = no.length; j--;) no[j].selected = eo[j].selected;
  1401. }
  1402. }
  1403. var prop = props[element.tagName.toLowerCase()];
  1404. if (prop && element[prop]) node[prop] = element[prop];
  1405. };
  1406. if (contents){
  1407. var ce = clone.getElementsByTagName('*'), te = this.getElementsByTagName('*');
  1408. for (var i = ce.length; i--;) clean(ce[i], te[i]);
  1409. }
  1410. clean(clone, this);
  1411. return document.id(clone);
  1412. },
  1413. destroy: function(){
  1414. Element.empty(this);
  1415. Element.dispose(this);
  1416. clean(this, true);
  1417. return null;
  1418. },
  1419. empty: function(){
  1420. $A(this.childNodes).each(function(node){
  1421. Element.destroy(node);
  1422. });
  1423. return this;
  1424. },
  1425. dispose: function(){
  1426. return (this.parentNode) ? this.parentNode.removeChild(this) : this;
  1427. },
  1428. hasChild: function(el){
  1429. el = document.id(el, true);
  1430. if (!el) return false;
  1431. if (Browser.Engine.webkit && Browser.Engine.version < 420) return $A(this.getElementsByTagName(el.tagName)).contains(el);
  1432. return (this.contains) ? (this != el && this.contains(el)) : !!(this.compareDocumentPosition(el) & 16);
  1433. },
  1434. match: function(tag){
  1435. return (!tag || (tag == this) || (Element.get(this, 'tag') == tag));
  1436. }
  1437. });
  1438. Native.implement([Element, Window, Document], {
  1439. addListener: function(type, fn){
  1440. if (type == 'unload'){
  1441. var old = fn, self = this;
  1442. fn = function(){
  1443. self.removeListener('unload', fn);
  1444. old();
  1445. };
  1446. } else {
  1447. collected[this.uid] = this;
  1448. }
  1449. if (this.addEventListener) this.addEventListener(type, fn, false);
  1450. else this.attachEvent('on' + type, fn);
  1451. return this;
  1452. },
  1453. removeListener: function(type, fn){
  1454. if (this.removeEventListener) this.removeEventListener(type, fn, false);
  1455. else this.detachEvent('on' + type, fn);
  1456. return this;
  1457. },
  1458. retrieve: function(property, dflt){
  1459. var storage = get(this.uid), prop = storage[property];
  1460. if (dflt != undefined && prop == undefined) prop = storage[property] = dflt;
  1461. return $pick(prop);
  1462. },
  1463. store: function(property, value){
  1464. var storage = get(this.uid);
  1465. storage[property] = value;
  1466. return this;
  1467. },
  1468. eliminate: function(property){
  1469. var storage = get(this.uid);
  1470. delete storage[property];
  1471. return this;
  1472. }
  1473. });
  1474. window.addListener('unload', purge);
  1475. })();
  1476. Element.Properties = new Hash;
  1477. Element.Properties.style = {
  1478. set: function(style){
  1479. this.style.cssText = style;
  1480. },
  1481. get: function(){
  1482. return this.style.cssText;
  1483. },
  1484. erase: function(){
  1485. this.style.cssText = '';
  1486. }
  1487. };
  1488. Element.Properties.tag = {
  1489. get: function(){
  1490. return this.tagName.toLowerCase();
  1491. }
  1492. };
  1493. Element.Properties.html = (function(){
  1494. var wrapper = document.createElement('div');
  1495. var translations = {
  1496. table: [1, '<table>', '</table>'],
  1497. select: [1, '<select>', '</select>'],
  1498. tbody: [2, '<table><tbody>', '</tbody></table>'],
  1499. tr: [3, '<table><tbody><tr>', '</tr></tbody></table>']
  1500. };
  1501. translations.thead = translations.tfoot = translations.tbody;
  1502. var html = {
  1503. set: function(){
  1504. var html = Array.flatten(arguments).join('');
  1505. var wrap = Browser.Engine.trident && translations[this.get('tag')];
  1506. if (wrap){
  1507. var first = wrapper;
  1508. first.innerHTML = wrap[1] + html + wrap[2];
  1509. for (var i = wrap[0]; i--;) first = first.firstChild;
  1510. this.empty().adopt(first.childNodes);
  1511. } else {
  1512. this.innerHTML = html;
  1513. }
  1514. }
  1515. };
  1516. html.erase = html.set;
  1517. return html;
  1518. })();
  1519. if (Browser.Engine.webkit && Browser.Engine.version < 420) Element.Properties.text = {
  1520. get: function(){
  1521. if (this.innerText) return this.innerText;
  1522. var temp = this.ownerDocument.newElement('div', {html: this.innerHTML}).inject(this.ownerDocument.body);
  1523. var text = temp.innerText;
  1524. temp.destroy();
  1525. return text;
  1526. }
  1527. };
  1528. /*
  1529. ---
  1530. name: Element.Dimensions
  1531. description: Contains methods to work with size, scroll, or positioning of Elements and the window object.
  1532. license: MIT-style license.
  1533. credits:
  1534. - Element positioning based on the [qooxdoo](http://qooxdoo.org/) code and smart browser fixes, [LGPL License](http://www.gnu.org/licenses/lgpl.html).
  1535. - Viewport dimensions based on [YUI](http://developer.yahoo.com/yui/) code, [BSD License](http://developer.yahoo.com/yui/license.html).
  1536. requires: Element
  1537. provides: Element.Dimensions
  1538. ...
  1539. */
  1540. (function(){
  1541. Element.implement({
  1542. scrollTo: function(x, y){
  1543. if (isBody(this)){
  1544. this.getWindow().scrollTo(x, y);
  1545. } else {
  1546. this.scrollLeft = x;
  1547. this.scrollTop = y;
  1548. }
  1549. return this;
  1550. },
  1551. getSize: function(){
  1552. if (isBody(this)) return this.getWindow().getSize();
  1553. return {x: this.offsetWidth, y: this.offsetHeight};
  1554. },
  1555. getScrollSize: function(){
  1556. if (isBody(this)) return this.getWindow().getScrollSize();
  1557. return {x: this.scrollWidth, y: this.scrollHeight};
  1558. },
  1559. getScroll: function(){
  1560. if (isBody(this)) return this.getWindow().getScroll();
  1561. return {x: this.scrollLeft, y: this.scrollTop};
  1562. },
  1563. getScrolls: function(){
  1564. var element = this, position = {x: 0, y: 0};
  1565. while (element && !isBody(element)){
  1566. position.x += element.scrollLeft;
  1567. position.y += element.scrollTop;
  1568. element = element.parentNode;
  1569. }
  1570. return position;
  1571. },
  1572. getOffsetParent: function(){
  1573. var element = this;
  1574. if (isBody(element)) return null;
  1575. if (!Browser.Engine.trident) return element.offsetParent;
  1576. while ((element = element.parentNode) && !isBody(element)){
  1577. if (styleString(element, 'position') != 'static') return element;
  1578. }
  1579. return null;
  1580. },
  1581. getOffsets: function(){
  1582. if (this.getBoundingClientRect){
  1583. var bound = this.getBoundingClientRect(),
  1584. html = document.id(this.getDocument().documentElement),
  1585. htmlScroll = html.getScroll(),
  1586. elemScrolls = this.getScrolls(),
  1587. elemScroll = this.getScroll(),
  1588. isFixed = (styleString(this, 'position') == 'fixed');
  1589. return {
  1590. x: bound.left.toInt() + elemScrolls.x - elemScroll.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft,
  1591. y: bound.top.toInt() + elemScrolls.y - elemScroll.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop
  1592. };
  1593. }
  1594. var element = this, position = {x: 0, y: 0};
  1595. if (isBody(this)) return position;
  1596. while (element && !isBody(element)){
  1597. position.x += element.offsetLeft;
  1598. position.y += element.offsetTop;
  1599. if (Browser.Engine.gecko){
  1600. if (!borderBox(element)){
  1601. position.x += leftBorder(element);
  1602. position.y += topBorder(element);
  1603. }
  1604. var parent = element.parentNode;
  1605. if (parent && styleString(parent, 'overflow') != 'visible'){
  1606. position.x += leftBorder(parent);
  1607. position.y += topBorder(parent);
  1608. }
  1609. } else if (element != this && Browser.Engine.webkit){
  1610. position.x += leftBorder(element);
  1611. position.y += topBorder(element);
  1612. }
  1613. element = element.offsetParent;
  1614. }
  1615. if (Browser.Engine.gecko && !borderBox(this)){
  1616. position.x -= leftBorder(this);
  1617. position.y -= topBorder(this);
  1618. }
  1619. return position;
  1620. },
  1621. getPosition: function(relative){
  1622. if (isBody(this)) return {x: 0, y: 0