PageRenderTime 37ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/files/mootools/1.4.5/mootools-core-compat.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 2145 lines | 1461 code | 422 blank | 262 comment | 475 complexity | 8f3732c4df858fc361154a049bdb0cc3 MD5 | raw file
  1. /*
  2. ---
  3. MooTools: the javascript framework
  4. web build:
  5. - http://mootools.net/core/76bf47062d6c1983d66ce47ad66aa0e0
  6. packager build:
  7. - packager build Core/Core Core/Array Core/String Core/Number Core/Function Core/Object Core/Event Core/Browser Core/Class Core/Class.Extras Core/Slick.Parser Core/Slick.Finder Core/Element Core/Element.Style Core/Element.Event Core/Element.Delegation Core/Element.Dimensions Core/Fx Core/Fx.CSS Core/Fx.Tween Core/Fx.Morph Core/Fx.Transitions Core/Request Core/Request.HTML Core/Request.JSON Core/Cookie Core/JSON Core/DOMReady Core/Swiff
  8. ...
  9. */
  10. /*
  11. ---
  12. name: Core
  13. description: The heart of MooTools.
  14. license: MIT-style license.
  15. copyright: Copyright (c) 2006-2012 [Valerio Proietti](http://mad4milk.net/).
  16. authors: The MooTools production team (http://mootools.net/developers/)
  17. inspiration:
  18. - 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)
  19. - Some functionality inspired by [Prototype.js](http://prototypejs.org) Copyright (c) 2005-2007 Sam Stephenson, [MIT License](http://opensource.org/licenses/mit-license.php)
  20. provides: [Core, MooTools, Type, typeOf, instanceOf, Native]
  21. ...
  22. */
  23. (function(){
  24. this.MooTools = {
  25. version: '1.4.5',
  26. build: 'ab8ea8824dc3b24b6666867a2c4ed58ebb762cf0'
  27. };
  28. // typeOf, instanceOf
  29. var typeOf = this.typeOf = function(item){
  30. if (item == null) return 'null';
  31. if (item.$family != null) return item.$family();
  32. if (item.nodeName){
  33. if (item.nodeType == 1) return 'element';
  34. if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
  35. } else if (typeof item.length == 'number'){
  36. if (item.callee) return 'arguments';
  37. if ('item' in item) return 'collection';
  38. }
  39. return typeof item;
  40. };
  41. var instanceOf = this.instanceOf = function(item, object){
  42. if (item == null) return false;
  43. var constructor = item.$constructor || item.constructor;
  44. while (constructor){
  45. if (constructor === object) return true;
  46. constructor = constructor.parent;
  47. }
  48. /*<ltIE8>*/
  49. if (!item.hasOwnProperty) return false;
  50. /*</ltIE8>*/
  51. return item instanceof object;
  52. };
  53. // Function overloading
  54. var Function = this.Function;
  55. var enumerables = true;
  56. for (var i in {toString: 1}) enumerables = null;
  57. if (enumerables) enumerables = ['hasOwnProperty', 'valueOf', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'constructor'];
  58. Function.prototype.overloadSetter = function(usePlural){
  59. var self = this;
  60. return function(a, b){
  61. if (a == null) return this;
  62. if (usePlural || typeof a != 'string'){
  63. for (var k in a) self.call(this, k, a[k]);
  64. if (enumerables) for (var i = enumerables.length; i--;){
  65. k = enumerables[i];
  66. if (a.hasOwnProperty(k)) self.call(this, k, a[k]);
  67. }
  68. } else {
  69. self.call(this, a, b);
  70. }
  71. return this;
  72. };
  73. };
  74. Function.prototype.overloadGetter = function(usePlural){
  75. var self = this;
  76. return function(a){
  77. var args, result;
  78. if (typeof a != 'string') args = a;
  79. else if (arguments.length > 1) args = arguments;
  80. else if (usePlural) args = [a];
  81. if (args){
  82. result = {};
  83. for (var i = 0; i < args.length; i++) result[args[i]] = self.call(this, args[i]);
  84. } else {
  85. result = self.call(this, a);
  86. }
  87. return result;
  88. };
  89. };
  90. Function.prototype.extend = function(key, value){
  91. this[key] = value;
  92. }.overloadSetter();
  93. Function.prototype.implement = function(key, value){
  94. this.prototype[key] = value;
  95. }.overloadSetter();
  96. // From
  97. var slice = Array.prototype.slice;
  98. Function.from = function(item){
  99. return (typeOf(item) == 'function') ? item : function(){
  100. return item;
  101. };
  102. };
  103. Array.from = function(item){
  104. if (item == null) return [];
  105. return (Type.isEnumerable(item) && typeof item != 'string') ? (typeOf(item) == 'array') ? item : slice.call(item) : [item];
  106. };
  107. Number.from = function(item){
  108. var number = parseFloat(item);
  109. return isFinite(number) ? number : null;
  110. };
  111. String.from = function(item){
  112. return item + '';
  113. };
  114. // hide, protect
  115. Function.implement({
  116. hide: function(){
  117. this.$hidden = true;
  118. return this;
  119. },
  120. protect: function(){
  121. this.$protected = true;
  122. return this;
  123. }
  124. });
  125. // Type
  126. var Type = this.Type = function(name, object){
  127. if (name){
  128. var lower = name.toLowerCase();
  129. var typeCheck = function(item){
  130. return (typeOf(item) == lower);
  131. };
  132. Type['is' + name] = typeCheck;
  133. if (object != null){
  134. object.prototype.$family = (function(){
  135. return lower;
  136. }).hide();
  137. //<1.2compat>
  138. object.type = typeCheck;
  139. //</1.2compat>
  140. }
  141. }
  142. if (object == null) return null;
  143. object.extend(this);
  144. object.$constructor = Type;
  145. object.prototype.$constructor = object;
  146. return object;
  147. };
  148. var toString = Object.prototype.toString;
  149. Type.isEnumerable = function(item){
  150. return (item != null && typeof item.length == 'number' && toString.call(item) != '[object Function]' );
  151. };
  152. var hooks = {};
  153. var hooksOf = function(object){
  154. var type = typeOf(object.prototype);
  155. return hooks[type] || (hooks[type] = []);
  156. };
  157. var implement = function(name, method){
  158. if (method && method.$hidden) return;
  159. var hooks = hooksOf(this);
  160. for (var i = 0; i < hooks.length; i++){
  161. var hook = hooks[i];
  162. if (typeOf(hook) == 'type') implement.call(hook, name, method);
  163. else hook.call(this, name, method);
  164. }
  165. var previous = this.prototype[name];
  166. if (previous == null || !previous.$protected) this.prototype[name] = method;
  167. if (this[name] == null && typeOf(method) == 'function') extend.call(this, name, function(item){
  168. return method.apply(item, slice.call(arguments, 1));
  169. });
  170. };
  171. var extend = function(name, method){
  172. if (method && method.$hidden) return;
  173. var previous = this[name];
  174. if (previous == null || !previous.$protected) this[name] = method;
  175. };
  176. Type.implement({
  177. implement: implement.overloadSetter(),
  178. extend: extend.overloadSetter(),
  179. alias: function(name, existing){
  180. implement.call(this, name, this.prototype[existing]);
  181. }.overloadSetter(),
  182. mirror: function(hook){
  183. hooksOf(this).push(hook);
  184. return this;
  185. }
  186. });
  187. new Type('Type', Type);
  188. // Default Types
  189. var force = function(name, object, methods){
  190. var isType = (object != Object),
  191. prototype = object.prototype;
  192. if (isType) object = new Type(name, object);
  193. for (var i = 0, l = methods.length; i < l; i++){
  194. var key = methods[i],
  195. generic = object[key],
  196. proto = prototype[key];
  197. if (generic) generic.protect();
  198. if (isType && proto) object.implement(key, proto.protect());
  199. }
  200. if (isType){
  201. var methodsEnumerable = prototype.propertyIsEnumerable(methods[0]);
  202. object.forEachMethod = function(fn){
  203. if (!methodsEnumerable) for (var i = 0, l = methods.length; i < l; i++){
  204. fn.call(prototype, prototype[methods[i]], methods[i]);
  205. }
  206. for (var key in prototype) fn.call(prototype, prototype[key], key)
  207. };
  208. }
  209. return force;
  210. };
  211. force('String', String, [
  212. 'charAt', 'charCodeAt', 'concat', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search',
  213. 'slice', 'split', 'substr', 'substring', 'trim', 'toLowerCase', 'toUpperCase'
  214. ])('Array', Array, [
  215. 'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice',
  216. 'indexOf', 'lastIndexOf', 'filter', 'forEach', 'every', 'map', 'some', 'reduce', 'reduceRight'
  217. ])('Number', Number, [
  218. 'toExponential', 'toFixed', 'toLocaleString', 'toPrecision'
  219. ])('Function', Function, [
  220. 'apply', 'call', 'bind'
  221. ])('RegExp', RegExp, [
  222. 'exec', 'test'
  223. ])('Object', Object, [
  224. 'create', 'defineProperty', 'defineProperties', 'keys',
  225. 'getPrototypeOf', 'getOwnPropertyDescriptor', 'getOwnPropertyNames',
  226. 'preventExtensions', 'isExtensible', 'seal', 'isSealed', 'freeze', 'isFrozen'
  227. ])('Date', Date, ['now']);
  228. Object.extend = extend.overloadSetter();
  229. Date.extend('now', function(){
  230. return +(new Date);
  231. });
  232. new Type('Boolean', Boolean);
  233. // fixes NaN returning as Number
  234. Number.prototype.$family = function(){
  235. return isFinite(this) ? 'number' : 'null';
  236. }.hide();
  237. // Number.random
  238. Number.extend('random', function(min, max){
  239. return Math.floor(Math.random() * (max - min + 1) + min);
  240. });
  241. // forEach, each
  242. var hasOwnProperty = Object.prototype.hasOwnProperty;
  243. Object.extend('forEach', function(object, fn, bind){
  244. for (var key in object){
  245. if (hasOwnProperty.call(object, key)) fn.call(bind, object[key], key, object);
  246. }
  247. });
  248. Object.each = Object.forEach;
  249. Array.implement({
  250. forEach: function(fn, bind){
  251. for (var i = 0, l = this.length; i < l; i++){
  252. if (i in this) fn.call(bind, this[i], i, this);
  253. }
  254. },
  255. each: function(fn, bind){
  256. Array.forEach(this, fn, bind);
  257. return this;
  258. }
  259. });
  260. // Array & Object cloning, Object merging and appending
  261. var cloneOf = function(item){
  262. switch (typeOf(item)){
  263. case 'array': return item.clone();
  264. case 'object': return Object.clone(item);
  265. default: return item;
  266. }
  267. };
  268. Array.implement('clone', function(){
  269. var i = this.length, clone = new Array(i);
  270. while (i--) clone[i] = cloneOf(this[i]);
  271. return clone;
  272. });
  273. var mergeOne = function(source, key, current){
  274. switch (typeOf(current)){
  275. case 'object':
  276. if (typeOf(source[key]) == 'object') Object.merge(source[key], current);
  277. else source[key] = Object.clone(current);
  278. break;
  279. case 'array': source[key] = current.clone(); break;
  280. default: source[key] = current;
  281. }
  282. return source;
  283. };
  284. Object.extend({
  285. merge: function(source, k, v){
  286. if (typeOf(k) == 'string') return mergeOne(source, k, v);
  287. for (var i = 1, l = arguments.length; i < l; i++){
  288. var object = arguments[i];
  289. for (var key in object) mergeOne(source, key, object[key]);
  290. }
  291. return source;
  292. },
  293. clone: function(object){
  294. var clone = {};
  295. for (var key in object) clone[key] = cloneOf(object[key]);
  296. return clone;
  297. },
  298. append: function(original){
  299. for (var i = 1, l = arguments.length; i < l; i++){
  300. var extended = arguments[i] || {};
  301. for (var key in extended) original[key] = extended[key];
  302. }
  303. return original;
  304. }
  305. });
  306. // Object-less types
  307. ['Object', 'WhiteSpace', 'TextNode', 'Collection', 'Arguments'].each(function(name){
  308. new Type(name);
  309. });
  310. // Unique ID
  311. var UID = Date.now();
  312. String.extend('uniqueID', function(){
  313. return (UID++).toString(36);
  314. });
  315. //<1.2compat>
  316. var Hash = this.Hash = new Type('Hash', function(object){
  317. if (typeOf(object) == 'hash') object = Object.clone(object.getClean());
  318. for (var key in object) this[key] = object[key];
  319. return this;
  320. });
  321. Hash.implement({
  322. forEach: function(fn, bind){
  323. Object.forEach(this, fn, bind);
  324. },
  325. getClean: function(){
  326. var clean = {};
  327. for (var key in this){
  328. if (this.hasOwnProperty(key)) clean[key] = this[key];
  329. }
  330. return clean;
  331. },
  332. getLength: function(){
  333. var length = 0;
  334. for (var key in this){
  335. if (this.hasOwnProperty(key)) length++;
  336. }
  337. return length;
  338. }
  339. });
  340. Hash.alias('each', 'forEach');
  341. Object.type = Type.isObject;
  342. var Native = this.Native = function(properties){
  343. return new Type(properties.name, properties.initialize);
  344. };
  345. Native.type = Type.type;
  346. Native.implement = function(objects, methods){
  347. for (var i = 0; i < objects.length; i++) objects[i].implement(methods);
  348. return Native;
  349. };
  350. var arrayType = Array.type;
  351. Array.type = function(item){
  352. return instanceOf(item, Array) || arrayType(item);
  353. };
  354. this.$A = function(item){
  355. return Array.from(item).slice();
  356. };
  357. this.$arguments = function(i){
  358. return function(){
  359. return arguments[i];
  360. };
  361. };
  362. this.$chk = function(obj){
  363. return !!(obj || obj === 0);
  364. };
  365. this.$clear = function(timer){
  366. clearTimeout(timer);
  367. clearInterval(timer);
  368. return null;
  369. };
  370. this.$defined = function(obj){
  371. return (obj != null);
  372. };
  373. this.$each = function(iterable, fn, bind){
  374. var type = typeOf(iterable);
  375. ((type == 'arguments' || type == 'collection' || type == 'array' || type == 'elements') ? Array : Object).each(iterable, fn, bind);
  376. };
  377. this.$empty = function(){};
  378. this.$extend = function(original, extended){
  379. return Object.append(original, extended);
  380. };
  381. this.$H = function(object){
  382. return new Hash(object);
  383. };
  384. this.$merge = function(){
  385. var args = Array.slice(arguments);
  386. args.unshift({});
  387. return Object.merge.apply(null, args);
  388. };
  389. this.$lambda = Function.from;
  390. this.$mixin = Object.merge;
  391. this.$random = Number.random;
  392. this.$splat = Array.from;
  393. this.$time = Date.now;
  394. this.$type = function(object){
  395. var type = typeOf(object);
  396. if (type == 'elements') return 'array';
  397. return (type == 'null') ? false : type;
  398. };
  399. this.$unlink = function(object){
  400. switch (typeOf(object)){
  401. case 'object': return Object.clone(object);
  402. case 'array': return Array.clone(object);
  403. case 'hash': return new Hash(object);
  404. default: return object;
  405. }
  406. };
  407. //</1.2compat>
  408. })();
  409. /*
  410. ---
  411. name: Array
  412. description: Contains Array Prototypes like each, contains, and erase.
  413. license: MIT-style license.
  414. requires: Type
  415. provides: Array
  416. ...
  417. */
  418. Array.implement({
  419. /*<!ES5>*/
  420. every: function(fn, bind){
  421. for (var i = 0, l = this.length >>> 0; i < l; i++){
  422. if ((i in this) && !fn.call(bind, this[i], i, this)) return false;
  423. }
  424. return true;
  425. },
  426. filter: function(fn, bind){
  427. var results = [];
  428. for (var value, i = 0, l = this.length >>> 0; i < l; i++) if (i in this){
  429. value = this[i];
  430. if (fn.call(bind, value, i, this)) results.push(value);
  431. }
  432. return results;
  433. },
  434. indexOf: function(item, from){
  435. var length = this.length >>> 0;
  436. for (var i = (from < 0) ? Math.max(0, length + from) : from || 0; i < length; i++){
  437. if (this[i] === item) return i;
  438. }
  439. return -1;
  440. },
  441. map: function(fn, bind){
  442. var length = this.length >>> 0, results = Array(length);
  443. for (var i = 0; i < length; i++){
  444. if (i in this) results[i] = fn.call(bind, this[i], i, this);
  445. }
  446. return results;
  447. },
  448. some: function(fn, bind){
  449. for (var i = 0, l = this.length >>> 0; i < l; i++){
  450. if ((i in this) && fn.call(bind, this[i], i, this)) return true;
  451. }
  452. return false;
  453. },
  454. /*</!ES5>*/
  455. clean: function(){
  456. return this.filter(function(item){
  457. return item != null;
  458. });
  459. },
  460. invoke: function(methodName){
  461. var args = Array.slice(arguments, 1);
  462. return this.map(function(item){
  463. return item[methodName].apply(item, args);
  464. });
  465. },
  466. associate: function(keys){
  467. var obj = {}, length = Math.min(this.length, keys.length);
  468. for (var i = 0; i < length; i++) obj[keys[i]] = this[i];
  469. return obj;
  470. },
  471. link: function(object){
  472. var result = {};
  473. for (var i = 0, l = this.length; i < l; i++){
  474. for (var key in object){
  475. if (object[key](this[i])){
  476. result[key] = this[i];
  477. delete object[key];
  478. break;
  479. }
  480. }
  481. }
  482. return result;
  483. },
  484. contains: function(item, from){
  485. return this.indexOf(item, from) != -1;
  486. },
  487. append: function(array){
  488. this.push.apply(this, array);
  489. return this;
  490. },
  491. getLast: function(){
  492. return (this.length) ? this[this.length - 1] : null;
  493. },
  494. getRandom: function(){
  495. return (this.length) ? this[Number.random(0, this.length - 1)] : null;
  496. },
  497. include: function(item){
  498. if (!this.contains(item)) this.push(item);
  499. return this;
  500. },
  501. combine: function(array){
  502. for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
  503. return this;
  504. },
  505. erase: function(item){
  506. for (var i = this.length; i--;){
  507. if (this[i] === item) this.splice(i, 1);
  508. }
  509. return this;
  510. },
  511. empty: function(){
  512. this.length = 0;
  513. return this;
  514. },
  515. flatten: function(){
  516. var array = [];
  517. for (var i = 0, l = this.length; i < l; i++){
  518. var type = typeOf(this[i]);
  519. if (type == 'null') continue;
  520. array = array.concat((type == 'array' || type == 'collection' || type == 'arguments' || instanceOf(this[i], Array)) ? Array.flatten(this[i]) : this[i]);
  521. }
  522. return array;
  523. },
  524. pick: function(){
  525. for (var i = 0, l = this.length; i < l; i++){
  526. if (this[i] != null) return this[i];
  527. }
  528. return null;
  529. },
  530. hexToRgb: function(array){
  531. if (this.length != 3) return null;
  532. var rgb = this.map(function(value){
  533. if (value.length == 1) value += value;
  534. return value.toInt(16);
  535. });
  536. return (array) ? rgb : 'rgb(' + rgb + ')';
  537. },
  538. rgbToHex: function(array){
  539. if (this.length < 3) return null;
  540. if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
  541. var hex = [];
  542. for (var i = 0; i < 3; i++){
  543. var bit = (this[i] - 0).toString(16);
  544. hex.push((bit.length == 1) ? '0' + bit : bit);
  545. }
  546. return (array) ? hex : '#' + hex.join('');
  547. }
  548. });
  549. //<1.2compat>
  550. Array.alias('extend', 'append');
  551. var $pick = function(){
  552. return Array.from(arguments).pick();
  553. };
  554. //</1.2compat>
  555. /*
  556. ---
  557. name: String
  558. description: Contains String Prototypes like camelCase, capitalize, test, and toInt.
  559. license: MIT-style license.
  560. requires: Type
  561. provides: String
  562. ...
  563. */
  564. String.implement({
  565. test: function(regex, params){
  566. return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this);
  567. },
  568. contains: function(string, separator){
  569. return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : String(this).indexOf(string) > -1;
  570. },
  571. trim: function(){
  572. return String(this).replace(/^\s+|\s+$/g, '');
  573. },
  574. clean: function(){
  575. return String(this).replace(/\s+/g, ' ').trim();
  576. },
  577. camelCase: function(){
  578. return String(this).replace(/-\D/g, function(match){
  579. return match.charAt(1).toUpperCase();
  580. });
  581. },
  582. hyphenate: function(){
  583. return String(this).replace(/[A-Z]/g, function(match){
  584. return ('-' + match.charAt(0).toLowerCase());
  585. });
  586. },
  587. capitalize: function(){
  588. return String(this).replace(/\b[a-z]/g, function(match){
  589. return match.toUpperCase();
  590. });
  591. },
  592. escapeRegExp: function(){
  593. return String(this).replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
  594. },
  595. toInt: function(base){
  596. return parseInt(this, base || 10);
  597. },
  598. toFloat: function(){
  599. return parseFloat(this);
  600. },
  601. hexToRgb: function(array){
  602. var hex = String(this).match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
  603. return (hex) ? hex.slice(1).hexToRgb(array) : null;
  604. },
  605. rgbToHex: function(array){
  606. var rgb = String(this).match(/\d{1,3}/g);
  607. return (rgb) ? rgb.rgbToHex(array) : null;
  608. },
  609. substitute: function(object, regexp){
  610. return String(this).replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
  611. if (match.charAt(0) == '\\') return match.slice(1);
  612. return (object[name] != null) ? object[name] : '';
  613. });
  614. }
  615. });
  616. /*
  617. ---
  618. name: Number
  619. description: Contains Number Prototypes like limit, round, times, and ceil.
  620. license: MIT-style license.
  621. requires: Type
  622. provides: Number
  623. ...
  624. */
  625. Number.implement({
  626. limit: function(min, max){
  627. return Math.min(max, Math.max(min, this));
  628. },
  629. round: function(precision){
  630. precision = Math.pow(10, precision || 0).toFixed(precision < 0 ? -precision : 0);
  631. return Math.round(this * precision) / precision;
  632. },
  633. times: function(fn, bind){
  634. for (var i = 0; i < this; i++) fn.call(bind, i, this);
  635. },
  636. toFloat: function(){
  637. return parseFloat(this);
  638. },
  639. toInt: function(base){
  640. return parseInt(this, base || 10);
  641. }
  642. });
  643. Number.alias('each', 'times');
  644. (function(math){
  645. var methods = {};
  646. math.each(function(name){
  647. if (!Number[name]) methods[name] = function(){
  648. return Math[name].apply(null, [this].concat(Array.from(arguments)));
  649. };
  650. });
  651. Number.implement(methods);
  652. })(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']);
  653. /*
  654. ---
  655. name: Function
  656. description: Contains Function Prototypes like create, bind, pass, and delay.
  657. license: MIT-style license.
  658. requires: Type
  659. provides: Function
  660. ...
  661. */
  662. Function.extend({
  663. attempt: function(){
  664. for (var i = 0, l = arguments.length; i < l; i++){
  665. try {
  666. return arguments[i]();
  667. } catch (e){}
  668. }
  669. return null;
  670. }
  671. });
  672. Function.implement({
  673. attempt: function(args, bind){
  674. try {
  675. return this.apply(bind, Array.from(args));
  676. } catch (e){}
  677. return null;
  678. },
  679. /*<!ES5-bind>*/
  680. bind: function(that){
  681. var self = this,
  682. args = arguments.length > 1 ? Array.slice(arguments, 1) : null,
  683. F = function(){};
  684. var bound = function(){
  685. var context = that, length = arguments.length;
  686. if (this instanceof bound){
  687. F.prototype = self.prototype;
  688. context = new F;
  689. }
  690. var result = (!args && !length)
  691. ? self.call(context)
  692. : self.apply(context, args && length ? args.concat(Array.slice(arguments)) : args || arguments);
  693. return context == that ? result : context;
  694. };
  695. return bound;
  696. },
  697. /*</!ES5-bind>*/
  698. pass: function(args, bind){
  699. var self = this;
  700. if (args != null) args = Array.from(args);
  701. return function(){
  702. return self.apply(bind, args || arguments);
  703. };
  704. },
  705. delay: function(delay, bind, args){
  706. return setTimeout(this.pass((args == null ? [] : args), bind), delay);
  707. },
  708. periodical: function(periodical, bind, args){
  709. return setInterval(this.pass((args == null ? [] : args), bind), periodical);
  710. }
  711. });
  712. //<1.2compat>
  713. delete Function.prototype.bind;
  714. Function.implement({
  715. create: function(options){
  716. var self = this;
  717. options = options || {};
  718. return function(event){
  719. var args = options.arguments;
  720. args = (args != null) ? Array.from(args) : Array.slice(arguments, (options.event) ? 1 : 0);
  721. if (options.event) args = [event || window.event].extend(args);
  722. var returns = function(){
  723. return self.apply(options.bind || null, args);
  724. };
  725. if (options.delay) return setTimeout(returns, options.delay);
  726. if (options.periodical) return setInterval(returns, options.periodical);
  727. if (options.attempt) return Function.attempt(returns);
  728. return returns();
  729. };
  730. },
  731. bind: function(bind, args){
  732. var self = this;
  733. if (args != null) args = Array.from(args);
  734. return function(){
  735. return self.apply(bind, args || arguments);
  736. };
  737. },
  738. bindWithEvent: function(bind, args){
  739. var self = this;
  740. if (args != null) args = Array.from(args);
  741. return function(event){
  742. return self.apply(bind, (args == null) ? arguments : [event].concat(args));
  743. };
  744. },
  745. run: function(args, bind){
  746. return this.apply(bind, Array.from(args));
  747. }
  748. });
  749. if (Object.create == Function.prototype.create) Object.create = null;
  750. var $try = Function.attempt;
  751. //</1.2compat>
  752. /*
  753. ---
  754. name: Object
  755. description: Object generic methods
  756. license: MIT-style license.
  757. requires: Type
  758. provides: [Object, Hash]
  759. ...
  760. */
  761. (function(){
  762. var hasOwnProperty = Object.prototype.hasOwnProperty;
  763. Object.extend({
  764. subset: function(object, keys){
  765. var results = {};
  766. for (var i = 0, l = keys.length; i < l; i++){
  767. var k = keys[i];
  768. if (k in object) results[k] = object[k];
  769. }
  770. return results;
  771. },
  772. map: function(object, fn, bind){
  773. var results = {};
  774. for (var key in object){
  775. if (hasOwnProperty.call(object, key)) results[key] = fn.call(bind, object[key], key, object);
  776. }
  777. return results;
  778. },
  779. filter: function(object, fn, bind){
  780. var results = {};
  781. for (var key in object){
  782. var value = object[key];
  783. if (hasOwnProperty.call(object, key) && fn.call(bind, value, key, object)) results[key] = value;
  784. }
  785. return results;
  786. },
  787. every: function(object, fn, bind){
  788. for (var key in object){
  789. if (hasOwnProperty.call(object, key) && !fn.call(bind, object[key], key)) return false;
  790. }
  791. return true;
  792. },
  793. some: function(object, fn, bind){
  794. for (var key in object){
  795. if (hasOwnProperty.call(object, key) && fn.call(bind, object[key], key)) return true;
  796. }
  797. return false;
  798. },
  799. keys: function(object){
  800. var keys = [];
  801. for (var key in object){
  802. if (hasOwnProperty.call(object, key)) keys.push(key);
  803. }
  804. return keys;
  805. },
  806. values: function(object){
  807. var values = [];
  808. for (var key in object){
  809. if (hasOwnProperty.call(object, key)) values.push(object[key]);
  810. }
  811. return values;
  812. },
  813. getLength: function(object){
  814. return Object.keys(object).length;
  815. },
  816. keyOf: function(object, value){
  817. for (var key in object){
  818. if (hasOwnProperty.call(object, key) && object[key] === value) return key;
  819. }
  820. return null;
  821. },
  822. contains: function(object, value){
  823. return Object.keyOf(object, value) != null;
  824. },
  825. toQueryString: function(object, base){
  826. var queryString = [];
  827. Object.each(object, function(value, key){
  828. if (base) key = base + '[' + key + ']';
  829. var result;
  830. switch (typeOf(value)){
  831. case 'object': result = Object.toQueryString(value, key); break;
  832. case 'array':
  833. var qs = {};
  834. value.each(function(val, i){
  835. qs[i] = val;
  836. });
  837. result = Object.toQueryString(qs, key);
  838. break;
  839. default: result = key + '=' + encodeURIComponent(value);
  840. }
  841. if (value != null) queryString.push(result);
  842. });
  843. return queryString.join('&');
  844. }
  845. });
  846. })();
  847. //<1.2compat>
  848. Hash.implement({
  849. has: Object.prototype.hasOwnProperty,
  850. keyOf: function(value){
  851. return Object.keyOf(this, value);
  852. },
  853. hasValue: function(value){
  854. return Object.contains(this, value);
  855. },
  856. extend: function(properties){
  857. Hash.each(properties || {}, function(value, key){
  858. Hash.set(this, key, value);
  859. }, this);
  860. return this;
  861. },
  862. combine: function(properties){
  863. Hash.each(properties || {}, function(value, key){
  864. Hash.include(this, key, value);
  865. }, this);
  866. return this;
  867. },
  868. erase: function(key){
  869. if (this.hasOwnProperty(key)) delete this[key];
  870. return this;
  871. },
  872. get: function(key){
  873. return (this.hasOwnProperty(key)) ? this[key] : null;
  874. },
  875. set: function(key, value){
  876. if (!this[key] || this.hasOwnProperty(key)) this[key] = value;
  877. return this;
  878. },
  879. empty: function(){
  880. Hash.each(this, function(value, key){
  881. delete this[key];
  882. }, this);
  883. return this;
  884. },
  885. include: function(key, value){
  886. if (this[key] == null) this[key] = value;
  887. return this;
  888. },
  889. map: function(fn, bind){
  890. return new Hash(Object.map(this, fn, bind));
  891. },
  892. filter: function(fn, bind){
  893. return new Hash(Object.filter(this, fn, bind));
  894. },
  895. every: function(fn, bind){
  896. return Object.every(this, fn, bind);
  897. },
  898. some: function(fn, bind){
  899. return Object.some(this, fn, bind);
  900. },
  901. getKeys: function(){
  902. return Object.keys(this);
  903. },
  904. getValues: function(){
  905. return Object.values(this);
  906. },
  907. toQueryString: function(base){
  908. return Object.toQueryString(this, base);
  909. }
  910. });
  911. Hash.extend = Object.append;
  912. Hash.alias({indexOf: 'keyOf', contains: 'hasValue'});
  913. //</1.2compat>
  914. /*
  915. ---
  916. name: Browser
  917. description: The Browser Object. Contains Browser initialization, Window and Document, and the Browser Hash.
  918. license: MIT-style license.
  919. requires: [Array, Function, Number, String]
  920. provides: [Browser, Window, Document]
  921. ...
  922. */
  923. (function(){
  924. var document = this.document;
  925. var window = document.window = this;
  926. var ua = navigator.userAgent.toLowerCase(),
  927. platform = navigator.platform.toLowerCase(),
  928. UA = ua.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, 'unknown', 0],
  929. mode = UA[1] == 'ie' && document.documentMode;
  930. var Browser = this.Browser = {
  931. extend: Function.prototype.extend,
  932. name: (UA[1] == 'version') ? UA[3] : UA[1],
  933. version: mode || parseFloat((UA[1] == 'opera' && UA[4]) ? UA[4] : UA[2]),
  934. Platform: {
  935. name: ua.match(/ip(?:ad|od|hone)/) ? 'ios' : (ua.match(/(?:webos|android)/) || platform.match(/mac|win|linux/) || ['other'])[0]
  936. },
  937. Features: {
  938. xpath: !!(document.evaluate),
  939. air: !!(window.runtime),
  940. query: !!(document.querySelector),
  941. json: !!(window.JSON)
  942. },
  943. Plugins: {}
  944. };
  945. Browser[Browser.name] = true;
  946. Browser[Browser.name + parseInt(Browser.version, 10)] = true;
  947. Browser.Platform[Browser.Platform.name] = true;
  948. // Request
  949. Browser.Request = (function(){
  950. var XMLHTTP = function(){
  951. return new XMLHttpRequest();
  952. };
  953. var MSXML2 = function(){
  954. return new ActiveXObject('MSXML2.XMLHTTP');
  955. };
  956. var MSXML = function(){
  957. return new ActiveXObject('Microsoft.XMLHTTP');
  958. };
  959. return Function.attempt(function(){
  960. XMLHTTP();
  961. return XMLHTTP;
  962. }, function(){
  963. MSXML2();
  964. return MSXML2;
  965. }, function(){
  966. MSXML();
  967. return MSXML;
  968. });
  969. })();
  970. Browser.Features.xhr = !!(Browser.Request);
  971. // Flash detection
  972. var version = (Function.attempt(function(){
  973. return navigator.plugins['Shockwave Flash'].description;
  974. }, function(){
  975. return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
  976. }) || '0 r0').match(/\d+/g);
  977. Browser.Plugins.Flash = {
  978. version: Number(version[0] || '0.' + version[1]) || 0,
  979. build: Number(version[2]) || 0
  980. };
  981. // String scripts
  982. Browser.exec = function(text){
  983. if (!text) return text;
  984. if (window.execScript){
  985. window.execScript(text);
  986. } else {
  987. var script = document.createElement('script');
  988. script.setAttribute('type', 'text/javascript');
  989. script.text = text;
  990. document.head.appendChild(script);
  991. document.head.removeChild(script);
  992. }
  993. return text;
  994. };
  995. String.implement('stripScripts', function(exec){
  996. var scripts = '';
  997. var text = this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(all, code){
  998. scripts += code + '\n';
  999. return '';
  1000. });
  1001. if (exec === true) Browser.exec(scripts);
  1002. else if (typeOf(exec) == 'function') exec(scripts, text);
  1003. return text;
  1004. });
  1005. // Window, Document
  1006. Browser.extend({
  1007. Document: this.Document,
  1008. Window: this.Window,
  1009. Element: this.Element,
  1010. Event: this.Event
  1011. });
  1012. this.Window = this.$constructor = new Type('Window', function(){});
  1013. this.$family = Function.from('window').hide();
  1014. Window.mirror(function(name, method){
  1015. window[name] = method;
  1016. });
  1017. this.Document = document.$constructor = new Type('Document', function(){});
  1018. document.$family = Function.from('document').hide();
  1019. Document.mirror(function(name, method){
  1020. document[name] = method;
  1021. });
  1022. document.html = document.documentElement;
  1023. if (!document.head) document.head = document.getElementsByTagName('head')[0];
  1024. if (document.execCommand) try {
  1025. document.execCommand("BackgroundImageCache", false, true);
  1026. } catch (e){}
  1027. /*<ltIE9>*/
  1028. if (this.attachEvent && !this.addEventListener){
  1029. var unloadEvent = function(){
  1030. this.detachEvent('onunload', unloadEvent);
  1031. document.head = document.html = document.window = null;
  1032. };
  1033. this.attachEvent('onunload', unloadEvent);
  1034. }
  1035. // IE fails on collections and <select>.options (refers to <select>)
  1036. var arrayFrom = Array.from;
  1037. try {
  1038. arrayFrom(document.html.childNodes);
  1039. } catch(e){
  1040. Array.from = function(item){
  1041. if (typeof item != 'string' && Type.isEnumerable(item) && typeOf(item) != 'array'){
  1042. var i = item.length, array = new Array(i);
  1043. while (i--) array[i] = item[i];
  1044. return array;
  1045. }
  1046. return arrayFrom(item);
  1047. };
  1048. var prototype = Array.prototype,
  1049. slice = prototype.slice;
  1050. ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice'].each(function(name){
  1051. var method = prototype[name];
  1052. Array[name] = function(item){
  1053. return method.apply(Array.from(item), slice.call(arguments, 1));
  1054. };
  1055. });
  1056. }
  1057. /*</ltIE9>*/
  1058. //<1.2compat>
  1059. if (Browser.Platform.ios) Browser.Platform.ipod = true;
  1060. Browser.Engine = {};
  1061. var setEngine = function(name, version){
  1062. Browser.Engine.name = name;
  1063. Browser.Engine[name + version] = true;
  1064. Browser.Engine.version = version;
  1065. };
  1066. if (Browser.ie){
  1067. Browser.Engine.trident = true;
  1068. switch (Browser.version){
  1069. case 6: setEngine('trident', 4); break;
  1070. case 7: setEngine('trident', 5); break;
  1071. case 8: setEngine('trident', 6);
  1072. }
  1073. }
  1074. if (Browser.firefox){
  1075. Browser.Engine.gecko = true;
  1076. if (Browser.version >= 3) setEngine('gecko', 19);
  1077. else setEngine('gecko', 18);
  1078. }
  1079. if (Browser.safari || Browser.chrome){
  1080. Browser.Engine.webkit = true;
  1081. switch (Browser.version){
  1082. case 2: setEngine('webkit', 419); break;
  1083. case 3: setEngine('webkit', 420); break;
  1084. case 4: setEngine('webkit', 525);
  1085. }
  1086. }
  1087. if (Browser.opera){
  1088. Browser.Engine.presto = true;
  1089. if (Browser.version >= 9.6) setEngine('presto', 960);
  1090. else if (Browser.version >= 9.5) setEngine('presto', 950);
  1091. else setEngine('presto', 925);
  1092. }
  1093. if (Browser.name == 'unknown'){
  1094. switch ((ua.match(/(?:webkit|khtml|gecko)/) || [])[0]){
  1095. case 'webkit':
  1096. case 'khtml':
  1097. Browser.Engine.webkit = true;
  1098. break;
  1099. case 'gecko':
  1100. Browser.Engine.gecko = true;
  1101. }
  1102. }
  1103. this.$exec = Browser.exec;
  1104. //</1.2compat>
  1105. })();
  1106. /*
  1107. ---
  1108. name: Event
  1109. description: Contains the Event Type, to make the event object cross-browser.
  1110. license: MIT-style license.
  1111. requires: [Window, Document, Array, Function, String, Object]
  1112. provides: Event
  1113. ...
  1114. */
  1115. (function() {
  1116. var _keys = {};
  1117. var DOMEvent = this.DOMEvent = new Type('DOMEvent', function(event, win){
  1118. if (!win) win = window;
  1119. event = event || win.event;
  1120. if (event.$extended) return event;
  1121. this.event = event;
  1122. this.$extended = true;
  1123. this.shift = event.shiftKey;
  1124. this.control = event.ctrlKey;
  1125. this.alt = event.altKey;
  1126. this.meta = event.metaKey;
  1127. var type = this.type = event.type;
  1128. var target = event.target || event.srcElement;
  1129. while (target && target.nodeType == 3) target = target.parentNode;
  1130. this.target = document.id(target);
  1131. if (type.indexOf('key') == 0){
  1132. var code = this.code = (event.which || event.keyCode);
  1133. this.key = _keys[code]/*<1.3compat>*/ || Object.keyOf(Event.Keys, code)/*</1.3compat>*/;
  1134. if (type == 'keydown'){
  1135. if (code > 111 && code < 124) this.key = 'f' + (code - 111);
  1136. else if (code > 95 && code < 106) this.key = code - 96;
  1137. }
  1138. if (this.key == null) this.key = String.fromCharCode(code).toLowerCase();
  1139. } else if (type == 'click' || type == 'dblclick' || type == 'contextmenu' || type == 'DOMMouseScroll' || type.indexOf('mouse') == 0){
  1140. var doc = win.document;
  1141. doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
  1142. this.page = {
  1143. x: (event.pageX != null) ? event.pageX : event.clientX + doc.scrollLeft,
  1144. y: (event.pageY != null) ? event.pageY : event.clientY + doc.scrollTop
  1145. };
  1146. this.client = {
  1147. x: (event.pageX != null) ? event.pageX - win.pageXOffset : event.clientX,
  1148. y: (event.pageY != null) ? event.pageY - win.pageYOffset : event.clientY
  1149. };
  1150. if (type == 'DOMMouseScroll' || type == 'mousewheel')
  1151. this.wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3;
  1152. this.rightClick = (event.which == 3 || event.button == 2);
  1153. if (type == 'mouseover' || type == 'mouseout'){
  1154. var related = event.relatedTarget || event[(type == 'mouseover' ? 'from' : 'to') + 'Element'];
  1155. while (related && related.nodeType == 3) related = related.parentNode;
  1156. this.relatedTarget = document.id(related);
  1157. }
  1158. } else if (type.indexOf('touch') == 0 || type.indexOf('gesture') == 0){
  1159. this.rotation = event.rotation;
  1160. this.scale = event.scale;
  1161. this.targetTouches = event.targetTouches;
  1162. this.changedTouches = event.changedTouches;
  1163. var touches = this.touches = event.touches;
  1164. if (touches && touches[0]){
  1165. var touch = touches[0];
  1166. this.page = {x: touch.pageX, y: touch.pageY};
  1167. this.client = {x: touch.clientX, y: touch.clientY};
  1168. }
  1169. }
  1170. if (!this.client) this.client = {};
  1171. if (!this.page) this.page = {};
  1172. });
  1173. DOMEvent.implement({
  1174. stop: function(){
  1175. return this.preventDefault().stopPropagation();
  1176. },
  1177. stopPropagation: function(){
  1178. if (this.event.stopPropagation) this.event.stopPropagation();
  1179. else this.event.cancelBubble = true;
  1180. return this;
  1181. },
  1182. preventDefault: function(){
  1183. if (this.event.preventDefault) this.event.preventDefault();
  1184. else this.event.returnValue = false;
  1185. return this;
  1186. }
  1187. });
  1188. DOMEvent.defineKey = function(code, key){
  1189. _keys[code] = key;
  1190. return this;
  1191. };
  1192. DOMEvent.defineKeys = DOMEvent.defineKey.overloadSetter(true);
  1193. DOMEvent.defineKeys({
  1194. '38': 'up', '40': 'down', '37': 'left', '39': 'right',
  1195. '27': 'esc', '32': 'space', '8': 'backspace', '9': 'tab',
  1196. '46': 'delete', '13': 'enter'
  1197. });
  1198. })();
  1199. /*<1.3compat>*/
  1200. var Event = DOMEvent;
  1201. Event.Keys = {};
  1202. /*</1.3compat>*/
  1203. /*<1.2compat>*/
  1204. Event.Keys = new Hash(Event.Keys);
  1205. /*</1.2compat>*/
  1206. /*
  1207. ---
  1208. name: Class
  1209. description: Contains the Class Function for easily creating, extending, and implementing reusable Classes.
  1210. license: MIT-style license.
  1211. requires: [Array, String, Function, Number]
  1212. provides: Class
  1213. ...
  1214. */
  1215. (function(){
  1216. var Class = this.Class = new Type('Class', function(params){
  1217. if (instanceOf(params, Function)) params = {initialize: params};
  1218. var newClass = function(){
  1219. reset(this);
  1220. if (newClass.$prototyping) return this;
  1221. this.$caller = null;
  1222. var value = (this.initialize) ? this.initialize.apply(this, arguments) : this;
  1223. this.$caller = this.caller = null;
  1224. return value;
  1225. }.extend(this).implement(params);
  1226. newClass.$constructor = Class;
  1227. newClass.prototype.$constructor = newClass;
  1228. newClass.prototype.parent = parent;
  1229. return newClass;
  1230. });
  1231. var parent = function(){
  1232. if (!this.$caller) throw new Error('The method "parent" cannot be called.');
  1233. var name = this.$caller.$name,
  1234. parent = this.$caller.$owner.parent,
  1235. previous = (parent) ? parent.prototype[name] : null;
  1236. if (!previous) throw new Error('The method "' + name + '" has no parent.');
  1237. return previous.apply(this, arguments);
  1238. };
  1239. var reset = function(object){
  1240. for (var key in object){
  1241. var value = object[key];
  1242. switch (typeOf(value)){
  1243. case 'object':
  1244. var F = function(){};
  1245. F.prototype = value;
  1246. object[key] = reset(new F);
  1247. break;
  1248. case 'array': object[key] = value.clone(); break;
  1249. }
  1250. }
  1251. return object;
  1252. };
  1253. var wrap = function(self, key, method){
  1254. if (method.$origin) method = method.$origin;
  1255. var wrapper = function(){
  1256. if (method.$protected && this.$caller == null) throw new Error('The method "' + key + '" cannot be called.');
  1257. var caller = this.caller, current = this.$caller;
  1258. this.caller = current; this.$caller = wrapper;
  1259. var result = method.apply(this, arguments);
  1260. this.$caller = current; this.caller = caller;
  1261. return result;
  1262. }.extend({$owner: self, $origin: method, $name: key});
  1263. return wrapper;
  1264. };
  1265. var implement = function(key, value, retain){
  1266. if (Class.Mutators.hasOwnProperty(key)){
  1267. value = Class.Mutators[key].call(this, value);
  1268. if (value == null) return this;
  1269. }
  1270. if (typeOf(value) == 'function'){
  1271. if (value.$hidden) return this;
  1272. this.prototype[key] = (retain) ? value : wrap(this, key, value);
  1273. } else {
  1274. Object.merge(this.prototype, key, value);
  1275. }
  1276. return this;
  1277. };
  1278. var getInstance = function(klass){
  1279. klass.$prototyping = true;
  1280. var proto = new klass;
  1281. delete klass.$prototyping;
  1282. return proto;
  1283. };
  1284. Class.implement('implement', implement.overloadSetter());
  1285. Class.Mutators = {
  1286. Extends: function(parent){
  1287. this.parent = parent;
  1288. this.prototype = getInstance(parent);
  1289. },
  1290. Implements: function(items){
  1291. Array.from(items).each(function(item){
  1292. var instance = new item;
  1293. for (var key in instance) implement.call(this, key, instance[key], true);
  1294. }, this);
  1295. }
  1296. };
  1297. })();
  1298. /*
  1299. ---
  1300. name: Class.Extras
  1301. description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks.
  1302. license: MIT-style license.
  1303. requires: Class
  1304. provides: [Class.Extras, Chain, Events, Options]
  1305. ...
  1306. */
  1307. (function(){
  1308. this.Chain = new Class({
  1309. $chain: [],
  1310. chain: function(){
  1311. this.$chain.append(Array.flatten(arguments));
  1312. return this;
  1313. },
  1314. callChain: function(){
  1315. return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false;
  1316. },
  1317. clearChain: function(){
  1318. this.$chain.empty();
  1319. return this;
  1320. }
  1321. });
  1322. var removeOn = function(string){
  1323. return string.replace(/^on([A-Z])/, function(full, first){
  1324. return first.toLowerCase();
  1325. });
  1326. };
  1327. this.Events = new Class({
  1328. $events: {},
  1329. addEvent: function(type, fn, internal){
  1330. type = removeOn(type);
  1331. /*<1.2compat>*/
  1332. if (fn == $empty) return this;
  1333. /*</1.2compat>*/
  1334. this.$events[type] = (this.$events[type] || []).include(fn);
  1335. if (internal) fn.internal = true;
  1336. return this;
  1337. },
  1338. addEvents: function(events){
  1339. for (var type in events) this.addEvent(type, events[type]);
  1340. return this;
  1341. },
  1342. fireEvent: function(type, args, delay){
  1343. type = removeOn(type);
  1344. var events = this.$events[type];
  1345. if (!events) return this;
  1346. args = Array.from(args);
  1347. events.each(function(fn){
  1348. if (delay) fn.delay(delay, this, args);
  1349. else fn.apply(this, args);
  1350. }, this);
  1351. return this;
  1352. },
  1353. removeEvent: function(type, fn){
  1354. type = removeOn(type);
  1355. var events = this.$events[type];
  1356. if (events && !fn.internal){
  1357. var index = events.indexOf(fn);
  1358. if (index != -1) delete events[index];
  1359. }
  1360. return this;
  1361. },
  1362. removeEvents: function(events){
  1363. var type;
  1364. if (typeOf(events) == 'object'){
  1365. for (type in events) this.removeEvent(type, events[type]);
  1366. return this;
  1367. }
  1368. if (events) events = removeOn(events);
  1369. for (type in this.$events){
  1370. if (events && events != type) continue;
  1371. var fns = this.$events[type];
  1372. for (var i = fns.length; i--;) if (i in fns){
  1373. this.removeEvent(type, fns[i]);
  1374. }
  1375. }
  1376. return this;
  1377. }
  1378. });
  1379. this.Options = new Class({
  1380. setOptions: function(){
  1381. var options = this.options = Object.merge.apply(null, [{}, this.options].append(arguments));
  1382. if (this.addEvent) for (var option in options){
  1383. if (typeOf(options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue;
  1384. this.addEvent(option, options[option]);
  1385. delete options[option];
  1386. }
  1387. return this;
  1388. }
  1389. });
  1390. })();
  1391. /*
  1392. ---
  1393. name: Slick.Parser
  1394. description: Standalone CSS3 Selector parser
  1395. provides: Slick.Parser
  1396. ...
  1397. */
  1398. ;(function(){
  1399. var parsed,
  1400. separatorIndex,
  1401. combinatorIndex,
  1402. reversed,
  1403. cache = {},
  1404. reverseCache = {},
  1405. reUnescape = /\\/g;
  1406. var parse = function(expression, isReversed){
  1407. if (expression == null) return null;
  1408. if (expression.Slick === true) return expression;
  1409. expression = ('' + expression).replace(/^\s+|\s+$/g, '');
  1410. reversed = !!isReversed;
  1411. var currentCache = (reversed) ? reverseCache : cache;
  1412. if (currentCache[expression]) return currentCache[expression];
  1413. parsed = {
  1414. Slick: true,
  1415. expressions: [],
  1416. raw: expression,
  1417. reverse: function(){
  1418. return parse(this.raw, true);
  1419. }
  1420. };
  1421. separatorIndex = -1;
  1422. while (expression != (expression = expression.replace(regexp, parser)));
  1423. parsed.length = parsed.expressions.length;
  1424. return currentCache[parsed.raw] = (reversed) ? reverse(parsed) : parsed;
  1425. };
  1426. var reverseCombinator = function(combinator){
  1427. if (combinator === '!') return ' ';
  1428. else if (combinator === ' ') return '!';
  1429. else if ((/^!/).test(combinator)) return combinator.replace(/^!/, '');
  1430. else return '!' + combinator;
  1431. };
  1432. var reverse = function(expression){
  1433. var expressions = expression.expressions;
  1434. for (var i = 0; i < expressions.length; i++){
  1435. var exp = expressions[i];
  1436. var last = {parts: [], tag: '*', combinator: reverseCombinator(exp[0].combinator)};
  1437. for (var j = 0; j < exp.length; j++){
  1438. var cexp = exp[j];
  1439. if (!cexp.reverseCombinator) cexp.reverseCombinator = ' ';
  1440. cexp.combinator = cexp.reverseCombinator;
  1441. delete cexp.reverseCombinator;
  1442. }
  1443. exp.reverse().push(last);
  1444. }
  1445. return expression;
  1446. };
  1447. var escapeRegExp = function(string){// Credit: XRegExp 0.6.1 (c) 2007-2008 Steven Levithan <http://stevenlevithan.com/regex/xregexp/> MIT License
  1448. return string.replace(/[-[\]{}()*+?.\\^$|,#\s]/g, function(match){
  1449. return '\\' + match;
  1450. });
  1451. };
  1452. var regexp = new RegExp(
  1453. /*
  1454. #!/usr/bin/env ruby
  1455. puts "\t\t" + DATA.read.gsub(/\(\?x\)|\s+#.*$|\s+|\\$|\\n/,'')
  1456. __END__
  1457. "(?x)^(?:\
  1458. \\s* ( , ) \\s* # Separator \n\
  1459. | \\s* ( <combinator>+ ) \\s* # Combinator \n\
  1460. | ( \\s+ ) # CombinatorChildren \n\
  1461. | ( <unicode>+ | \\* ) # Tag \n\
  1462. | \\# ( <unicode>+ ) # ID \n\
  1463. | \\. ( <unicode>+ ) # ClassName \n\
  1464. | # Attribute \n\
  1465. \\[ \
  1466. \\s* (<unicode1>+) (?: \
  1467. \\s* ([*^$!~|]?=) (?: \
  1468. \\s* (?:\
  1469. ([\"']?)(.*?)\\9 \
  1470. )\
  1471. ) \
  1472. )? \\s* \
  1473. \\](?!\\]) \n\
  1474. | :+ ( <unicode>+ )(?:\
  1475. \\( (?:\
  1476. (?:([\"'])([^\\12]*)\\12)|((?:\\([^)]+\\)|[^()]*)+)\
  1477. ) \\)\
  1478. )?\
  1479. )"
  1480. */
  1481. "^(?:\\s*(,)\\s*|\\s*(<combinator>+)\\s*|(\\s+)|(<unicode>+|\\*)|\\#(<unicode>+)|\\.(<unicode>+)|\\[\\s*(<unicode1>+)(?:\\s*([*^$!~|]?=)(?:\\s*(?:([\"']?)(.*?)\\9)))?\\s*\\](?!\\])|(:+)(<unicode>+)(?:\\((?:(?:([\"'])([^\\13]*)\\13)|((?:\\([^)]+\\)|[^()]*)+))\\))?)"
  1482. .replace(/<combinator>/, '[' + escapeRegExp(">+~`!@$%^&={}\\;</") + ']')
  1483. .replace(/<unicode>/g, '(?:[\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])')
  1484. .replace(/<unicode1>/g, '(?:[:\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])')
  1485. );
  1486. function parser(
  1487. rawMatch,
  1488. separator,
  1489. combinator,
  1490. combinatorChildren,
  1491. tagName,
  1492. id,
  1493. className,
  1494. attributeKey,
  1495. attributeOperator,
  1496. attributeQuote,
  1497. attributeValue,
  1498. pseudoMarker,
  1499. pseudoClass,
  1500. pseudoQuote,
  1501. pseudoClassQuotedValue,
  1502. pseudoClassValue
  1503. ){
  1504. if (separator || separatorIndex === -1){
  1505. parsed.expressions[++separatorIndex] = [];
  1506. combinatorIndex = -1;
  1507. if (separator) return '';
  1508. }
  1509. if (combinator || combinatorChildren || combinatorIndex === -1){
  1510. combinator = combinator || ' ';
  1511. var currentSeparator = parsed.expressions[separatorIndex];
  1512. if (reversed && currentSeparator[combinatorIndex])
  1513. currentSeparator[combinatorIndex].reverseCombinator = reverseCombinator(combinator);
  1514. currentSeparator[++combinatorIndex] = {combinator: combinator, tag: '*'};
  1515. }
  1516. var currentParsed = parsed.expressions[separatorIndex][combinatorIndex];
  1517. if (tagName){
  1518. currentParsed.tag = tagName.replace(reUnescape, '');
  1519. } else if (id){
  1520. currentParsed.id = id.replace(reUnescape, '');
  1521. } else if (className){
  1522. className = className.replace(reUnescape, '');
  1523. if (!currentParsed.classList) currentParsed.classList = [];
  1524. if (!currentParsed.classes) currentParsed.classes = [];
  1525. currentParsed.classList.push(className);
  1526. currentParsed.classes.push({
  1527. value: className,
  1528. regexp: new RegExp('(^|\\s)' + escapeRegExp(className) + '(\\s|$)')
  1529. });
  1530. } else if (pseudoClass){
  1531. pseudoClassValue = pseudoClassValue || pseudoClassQuotedValue;
  1532. pseudoClassValue = pseudoClassValue ? pseudoClassValue.replace(reUnescape, '') : null;
  1533. if (!currentParsed.pseudos) currentParsed.pseudos = [];
  1534. currentParsed.pseudos.push({
  1535. key: pseudoClass.replace(reUnescape, ''),
  1536. value: pseudoClassValue,
  1537. type: pseudoMarker.length == 1 ? 'class' : 'element'
  1538. });
  1539. } else if (attributeKey){
  1540. attributeKey = attributeKey.replace(reUnescape, '');
  1541. attributeValue = (attributeValue || '').replace(reUnescape, '');
  1542. var test, regexp;
  1543. switch (attributeOperator){
  1544. case '^=' : regexp = new RegExp( '^'+ escapeRegExp(attributeValue) ); break;
  1545. case '$=' : regexp = new RegExp( escapeRegExp(attributeValue) +'$' ); break;
  1546. case '~=' : regexp = new RegExp( '(^|\\s)'+ escapeRegExp(attributeValue) +'(\\s|$)' ); break;
  1547. case '|=' : regexp = new RegExp( '^'+ escapeRegExp(attributeValue) +'(-|$)' ); break;
  1548. case '=' : test = function(value){
  1549. return attributeValue == value;
  1550. }; break;
  1551. case '*=' : test = function(value){
  1552. return value && value.indexOf(attributeValue) > -1;
  1553. }; break;
  1554. case '!=' : test = function(value){
  1555. return attributeValue != value;
  1556. }; break;
  1557. default : test = function(value){
  1558. return !!value;
  1559. };
  1560. }
  1561. if (attributeValue == '' && (/^[*$^]=$/).test(attributeOperator)) test = function(){
  1562. return false;
  1563. };
  1564. if (!test) test = function(value){
  1565. return value && regexp.test(value);
  1566. };
  1567. if (!currentParsed.attributes) currentParsed.attributes = [];
  1568. currentParsed.attributes.push({
  1569. key: attributeKey,
  1570. operator: attributeOperator,
  1571. value: attributeValue,
  1572. test: test
  1573. });
  1574. }
  1575. return '';
  1576. };
  1577. // Slick NS
  1578. var Slick = (this.Slick || {});
  1579. Slick.parse = function(expression){
  1580. return parse(expression);
  1581. };
  1582. Slick.escapeRegExp = escapeRegExp;
  1583. if (!this.Slick) this.Slick = Slick;
  1584. }).apply(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);
  1585. /*
  1586. ---
  1587. name: Slick.Finder
  1588. description: The new, superfast css selector engine.
  1589. provides: Slick.Finder
  1590. requires: Slick.Parser
  1591. ...
  1592. */
  1593. ;(function(){
  1594. var local = {},
  1595. featuresCache = {},
  1596. toString = Object.prototype.toString;
  1597. // Feature / Bug detection
  1598. local.isNativeCode = function(fn){
  1599. return (/\{\s*\[native code\]\s*\}/).test('' + fn);
  1600. };
  1601. local.isXML = function(document){
  1602. return (!!document.xmlVersion) || (!!document.xml) || (toString.call(document) == '[object XMLDocument]') ||
  1603. (document.nodeType == 9 && document.documentElement.nodeName != 'HTML');
  1604. };
  1605. local.setDocument = function(document){
  1606. // convert elements / window arguments to document. if document cannot be extrapolated, the function returns.
  1607. var nodeType = document.nodeType;
  1608. if (nodeType == 9); // document
  1609. else if (nodeType) document = document.ownerDocument; // node
  1610. else if (document.navigator) document = document.document; // window
  1611. else return;
  1612. // check if it's the old document
  1613. if (this.document === document) return;
  1614. this.document = document;
  1615. // check if we have done feature detection on this document before
  1616. var root = document.documentElement,
  1617. rootUid = this.getUIDXML(root),
  1618. features = featuresCache[rootUid],
  1619. feature;
  1620. if (features){
  1621. for (feature in features){
  1622. this[feature] = features[feature];
  1623. }
  1624. return;
  1625. }
  1626. features = featuresCache[rootUid] = {};
  1627. features.root = root;
  1628. features.isXMLDocument = this.isXML(document);
  1629. features.brokenStarGEBTN
  1630. = features.starSelectsClosedQSA
  1631. = features.idGetsName
  1632. = features.brokenMixedCaseQSA
  1633. = features.brokenGEBCN
  1634. = features.brokenCheckedQSA
  1635. = features.brokenEmptyAttributeQSA
  1636. = features.isHTMLDocument
  1637. = features.nativeMatchesSelector
  1638. = false;
  1639. var starSelectsClosed, starSelectsComments,
  1640. brokenSecondClassNameGEBCN, cachedGetElementsByClassName,
  1641. brokenFormAttributeGetter;
  1642. var selected, id = 'slick_uniqueid';
  1643. var testNode = document.createElement('div');
  1644. var testRoot = document.body || document.getElementsByTagName('body')[0] || root;
  1645. testRoot.appendChild(testNode);
  1646. // on non-HTML documents innerHTML and getElementsById doesnt work properly
  1647. try {
  1648. testNode.innerHTML = '<a id="'+id+'"></a>';
  1649. features.isHTMLDocument = !!document.getElementById(id);
  1650. } catch(e){};
  1651. if (features.isHTMLDocument){
  1652. testNode.style.display = 'none';
  1653. // IE returns comment nodes for getElementsByTagName('*') for some documents
  1654. testNode.appendChild(document.createComment(''));
  1655. starSelectsComments = (testNode.getElementsByTagName('*').length > 1);
  1656. // IE returns closed nodes (EG:"</foo>") for getElementsByTagName('*') for some documents
  1657. try {
  1658. testNode.innerHTML = 'foo</f