PageRenderTime 68ms CodeModel.GetById 17ms RepoModel.GetById 2ms app.codeStats 0ms

/files/mootools/1.5.0/mootools-core-nocompat.js

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