PageRenderTime 76ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

/hudson-war/src/main/webapp/scripts/prototype.js

http://github.com/hudson/hudson
JavaScript | 2281 lines | 1912 code | 323 blank | 46 comment | 427 complexity | 10e9fac7f2dc36362ea8f98bf8401c0a MD5 | raw file
Possible License(s): MIT, BSD-3-Clause
  1. /* Prototype JavaScript framework, version 1.5.1.1
  2. * (c) 2005-2007 Sam Stephenson
  3. *
  4. * Prototype is freely distributable under the terms of an MIT-style license.
  5. * For details, see the Prototype web site: http://www.prototypejs.org/
  6. *
  7. /*--------------------------------------------------------------------------*/
  8. var Prototype = {
  9. Version: '1.5.1.1',
  10. Browser: {
  11. IE: !!(window.attachEvent && !window.opera),
  12. Opera: !!window.opera,
  13. WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
  14. Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
  15. },
  16. BrowserFeatures: {
  17. XPath: !!document.evaluate,
  18. ElementExtensions: !!window.HTMLElement,
  19. SpecificElementExtensions:
  20. (document.createElement('div').__proto__ !==
  21. document.createElement('form').__proto__)
  22. },
  23. ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
  24. JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
  25. emptyFunction: function() { },
  26. K: function(x) { return x }
  27. }
  28. var Class = {
  29. create: function() {
  30. return function() {
  31. this.initialize.apply(this, arguments);
  32. }
  33. }
  34. }
  35. var Abstract = new Object();
  36. Object.extend = function(destination, source) {
  37. for (var property in source) {
  38. destination[property] = source[property];
  39. }
  40. return destination;
  41. }
  42. Object.extend(Object, {
  43. inspect: function(object) {
  44. try {
  45. if (object === undefined) return 'undefined';
  46. if (object === null) return 'null';
  47. return object.inspect ? object.inspect() : object.toString();
  48. } catch (e) {
  49. if (e instanceof RangeError) return '...';
  50. throw e;
  51. }
  52. },
  53. toJSON: function(object) {
  54. var type = typeof object;
  55. switch(type) {
  56. case 'undefined':
  57. case 'function':
  58. case 'unknown': return;
  59. case 'boolean': return object.toString();
  60. }
  61. if (object === null) return 'null';
  62. // "|| object.toJSON" below is workaround for Opera 10.52/53 bug, see HUDSON-6424
  63. if (object.toJSON || object.toJSON) return object.toJSON();
  64. if (object.ownerDocument === document) return;
  65. var results = [];
  66. for (var property in object) {
  67. var value = Object.toJSON(object[property]);
  68. if (value !== undefined)
  69. results.push(property.toJSON() + ': ' + value);
  70. }
  71. return '{' + results.join(', ') + '}';
  72. },
  73. keys: function(object) {
  74. var keys = [];
  75. for (var property in object)
  76. keys.push(property);
  77. return keys;
  78. },
  79. values: function(object) {
  80. var values = [];
  81. for (var property in object)
  82. values.push(object[property]);
  83. return values;
  84. },
  85. clone: function(object) {
  86. return Object.extend({}, object);
  87. }
  88. });
  89. Function.prototype.bind = function() {
  90. var __method = this, args = $A(arguments), object = args.shift();
  91. return function() {
  92. return __method.apply(object, args.concat($A(arguments)));
  93. }
  94. }
  95. Function.prototype.bindAsEventListener = function(object) {
  96. var __method = this, args = $A(arguments), object = args.shift();
  97. return function(event) {
  98. return __method.apply(object, [event || window.event].concat(args));
  99. }
  100. }
  101. Object.extend(Number.prototype, {
  102. toColorPart: function() {
  103. return this.toPaddedString(2, 16);
  104. },
  105. succ: function() {
  106. return this + 1;
  107. },
  108. times: function(iterator) {
  109. $R(0, this, true).each(iterator);
  110. return this;
  111. },
  112. toPaddedString: function(length, radix) {
  113. var string = this.toString(radix || 10);
  114. return '0'.times(length - string.length) + string;
  115. },
  116. toJSON: function() {
  117. return isFinite(this) ? this.toString() : 'null';
  118. }
  119. });
  120. Date.prototype.toJSON = function() {
  121. return '"' + this.getFullYear() + '-' +
  122. (this.getMonth() + 1).toPaddedString(2) + '-' +
  123. this.getDate().toPaddedString(2) + 'T' +
  124. this.getHours().toPaddedString(2) + ':' +
  125. this.getMinutes().toPaddedString(2) + ':' +
  126. this.getSeconds().toPaddedString(2) + '"';
  127. };
  128. var Try = {
  129. these: function() {
  130. var returnValue;
  131. for (var i = 0, length = arguments.length; i < length; i++) {
  132. var lambda = arguments[i];
  133. try {
  134. returnValue = lambda();
  135. break;
  136. } catch (e) {}
  137. }
  138. return returnValue;
  139. }
  140. }
  141. /*--------------------------------------------------------------------------*/
  142. var PeriodicalExecuter = Class.create();
  143. PeriodicalExecuter.prototype = {
  144. initialize: function(callback, frequency) {
  145. this.callback = callback;
  146. this.frequency = frequency;
  147. this.currentlyExecuting = false;
  148. this.registerCallback();
  149. },
  150. registerCallback: function() {
  151. this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
  152. },
  153. stop: function() {
  154. if (!this.timer) return;
  155. clearInterval(this.timer);
  156. this.timer = null;
  157. },
  158. onTimerEvent: function() {
  159. if (!this.currentlyExecuting) {
  160. try {
  161. this.currentlyExecuting = true;
  162. this.callback(this);
  163. } finally {
  164. this.currentlyExecuting = false;
  165. }
  166. }
  167. }
  168. }
  169. Object.extend(String, {
  170. interpret: function(value) {
  171. return value == null ? '' : String(value);
  172. },
  173. specialChar: {
  174. '\b': '\\b',
  175. '\t': '\\t',
  176. '\n': '\\n',
  177. '\f': '\\f',
  178. '\r': '\\r',
  179. '\\': '\\\\'
  180. }
  181. });
  182. Object.extend(String.prototype, {
  183. gsub: function(pattern, replacement) {
  184. var result = '', source = this, match;
  185. replacement = arguments.callee.prepareReplacement(replacement);
  186. while (source.length > 0) {
  187. if (match = source.match(pattern)) {
  188. result += source.slice(0, match.index);
  189. result += String.interpret(replacement(match));
  190. source = source.slice(match.index + match[0].length);
  191. } else {
  192. result += source, source = '';
  193. }
  194. }
  195. return result;
  196. },
  197. sub: function(pattern, replacement, count) {
  198. replacement = this.gsub.prepareReplacement(replacement);
  199. count = count === undefined ? 1 : count;
  200. return this.gsub(pattern, function(match) {
  201. if (--count < 0) return match[0];
  202. return replacement(match);
  203. });
  204. },
  205. scan: function(pattern, iterator) {
  206. this.gsub(pattern, iterator);
  207. return this;
  208. },
  209. truncate: function(length, truncation) {
  210. length = length || 30;
  211. truncation = truncation === undefined ? '...' : truncation;
  212. return this.length > length ?
  213. this.slice(0, length - truncation.length) + truncation : this;
  214. },
  215. strip: function() {
  216. return this.replace(/^\s+/, '').replace(/\s+$/, '');
  217. },
  218. stripTags: function() {
  219. return this.replace(/<\/?[^>]+>/gi, '');
  220. },
  221. stripScripts: function() {
  222. return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
  223. },
  224. extractScripts: function() {
  225. var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
  226. var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
  227. return (this.match(matchAll) || []).map(function(scriptTag) {
  228. return (scriptTag.match(matchOne) || ['', ''])[1];
  229. });
  230. },
  231. evalScripts: function() {
  232. return this.extractScripts().map(function(script) { return eval(script) });
  233. },
  234. escapeHTML: function() {
  235. var self = arguments.callee;
  236. self.text.data = this;
  237. return self.div.innerHTML;
  238. },
  239. unescapeHTML: function() {
  240. var div = document.createElement('div');
  241. div.innerHTML = this.stripTags();
  242. return div.childNodes[0] ? (div.childNodes.length > 1 ?
  243. $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) :
  244. div.childNodes[0].nodeValue) : '';
  245. },
  246. toQueryParams: function(separator) {
  247. var match = this.strip().match(/([^?#]*)(#.*)?$/);
  248. if (!match) return {};
  249. return match[1].split(separator || '&').inject({}, function(hash, pair) {
  250. if ((pair = pair.split('='))[0]) {
  251. var key = decodeURIComponent(pair.shift());
  252. var value = pair.length > 1 ? pair.join('=') : pair[0];
  253. if (value != undefined) value = decodeURIComponent(value);
  254. if (key in hash) {
  255. if (hash[key].constructor != Array) hash[key] = [hash[key]];
  256. hash[key].push(value);
  257. }
  258. else hash[key] = value;
  259. }
  260. return hash;
  261. });
  262. },
  263. toArray: function() {
  264. return this.split('');
  265. },
  266. succ: function() {
  267. return this.slice(0, this.length - 1) +
  268. String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
  269. },
  270. times: function(count) {
  271. var result = '';
  272. for (var i = 0; i < count; i++) result += this;
  273. return result;
  274. },
  275. camelize: function() {
  276. var parts = this.split('-'), len = parts.length;
  277. if (len == 1) return parts[0];
  278. var camelized = this.charAt(0) == '-'
  279. ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
  280. : parts[0];
  281. for (var i = 1; i < len; i++)
  282. camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
  283. return camelized;
  284. },
  285. capitalize: function() {
  286. return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
  287. },
  288. underscore: function() {
  289. return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();
  290. },
  291. dasherize: function() {
  292. return this.gsub(/_/,'-');
  293. },
  294. inspect: function(useDoubleQuotes) {
  295. var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) {
  296. var character = String.specialChar[match[0]];
  297. return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);
  298. });
  299. if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
  300. return "'" + escapedString.replace(/'/g, '\\\'') + "'";
  301. },
  302. toJSON: function() {
  303. return this.inspect(true);
  304. },
  305. unfilterJSON: function(filter) {
  306. return this.sub(filter || Prototype.JSONFilter, '#{1}');
  307. },
  308. isJSON: function() {
  309. var str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
  310. return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
  311. },
  312. evalJSON: function(sanitize) {
  313. var json = this.unfilterJSON();
  314. try {
  315. if (!sanitize || json.isJSON()) return eval('(' + json + ')');
  316. } catch (e) { }
  317. throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
  318. },
  319. include: function(pattern) {
  320. return this.indexOf(pattern) > -1;
  321. },
  322. startsWith: function(pattern) {
  323. return this.indexOf(pattern) === 0;
  324. },
  325. endsWith: function(pattern) {
  326. var d = this.length - pattern.length;
  327. return d >= 0 && this.lastIndexOf(pattern) === d;
  328. },
  329. empty: function() {
  330. return this == '';
  331. },
  332. blank: function() {
  333. return /^\s*$/.test(this);
  334. }
  335. });
  336. if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, {
  337. escapeHTML: function() {
  338. return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
  339. },
  340. unescapeHTML: function() {
  341. return this.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
  342. }
  343. });
  344. String.prototype.gsub.prepareReplacement = function(replacement) {
  345. if (typeof replacement == 'function') return replacement;
  346. var template = new Template(replacement);
  347. return function(match) { return template.evaluate(match) };
  348. }
  349. String.prototype.parseQuery = String.prototype.toQueryParams;
  350. Object.extend(String.prototype.escapeHTML, {
  351. div: document.createElement('div'),
  352. text: document.createTextNode('')
  353. });
  354. with (String.prototype.escapeHTML) div.appendChild(text);
  355. var Template = Class.create();
  356. Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
  357. Template.prototype = {
  358. initialize: function(template, pattern) {
  359. this.template = template.toString();
  360. this.pattern = pattern || Template.Pattern;
  361. },
  362. evaluate: function(object) {
  363. return this.template.gsub(this.pattern, function(match) {
  364. var before = match[1];
  365. if (before == '\\') return match[2];
  366. return before + String.interpret(object[match[3]]);
  367. });
  368. }
  369. }
  370. var $break = {}, $continue = new Error('"throw $continue" is deprecated, use "return" instead');
  371. var Enumerable = {
  372. each: function(iterator) {
  373. var index = 0;
  374. try {
  375. this._each(function(value) {
  376. iterator(value, index++);
  377. });
  378. } catch (e) {
  379. if (e != $break) throw e;
  380. }
  381. return this;
  382. },
  383. eachSlice: function(number, iterator) {
  384. var index = -number, slices = [], array = this.toArray();
  385. while ((index += number) < array.length)
  386. slices.push(array.slice(index, index+number));
  387. return slices.map(iterator);
  388. },
  389. all: function(iterator) {
  390. var result = true;
  391. this.each(function(value, index) {
  392. result = result && !!(iterator || Prototype.K)(value, index);
  393. if (!result) throw $break;
  394. });
  395. return result;
  396. },
  397. any: function(iterator) {
  398. var result = false;
  399. this.each(function(value, index) {
  400. if (result = !!(iterator || Prototype.K)(value, index))
  401. throw $break;
  402. });
  403. return result;
  404. },
  405. collect: function(iterator) {
  406. var results = [];
  407. this.each(function(value, index) {
  408. results.push((iterator || Prototype.K)(value, index));
  409. });
  410. return results;
  411. },
  412. detect: function(iterator) {
  413. var result;
  414. this.each(function(value, index) {
  415. if (iterator(value, index)) {
  416. result = value;
  417. throw $break;
  418. }
  419. });
  420. return result;
  421. },
  422. findAll: function(iterator) {
  423. var results = [];
  424. this.each(function(value, index) {
  425. if (iterator(value, index))
  426. results.push(value);
  427. });
  428. return results;
  429. },
  430. grep: function(pattern, iterator) {
  431. var results = [];
  432. this.each(function(value, index) {
  433. var stringValue = value.toString();
  434. if (stringValue.match(pattern))
  435. results.push((iterator || Prototype.K)(value, index));
  436. })
  437. return results;
  438. },
  439. include: function(object) {
  440. var found = false;
  441. this.each(function(value) {
  442. if (value == object) {
  443. found = true;
  444. throw $break;
  445. }
  446. });
  447. return found;
  448. },
  449. inGroupsOf: function(number, fillWith) {
  450. fillWith = fillWith === undefined ? null : fillWith;
  451. return this.eachSlice(number, function(slice) {
  452. while(slice.length < number) slice.push(fillWith);
  453. return slice;
  454. });
  455. },
  456. inject: function(memo, iterator) {
  457. this.each(function(value, index) {
  458. memo = iterator(memo, value, index);
  459. });
  460. return memo;
  461. },
  462. invoke: function(method) {
  463. var args = $A(arguments).slice(1);
  464. return this.map(function(value) {
  465. return value[method].apply(value, args);
  466. });
  467. },
  468. max: function(iterator) {
  469. var result;
  470. this.each(function(value, index) {
  471. value = (iterator || Prototype.K)(value, index);
  472. if (result == undefined || value >= result)
  473. result = value;
  474. });
  475. return result;
  476. },
  477. min: function(iterator) {
  478. var result;
  479. this.each(function(value, index) {
  480. value = (iterator || Prototype.K)(value, index);
  481. if (result == undefined || value < result)
  482. result = value;
  483. });
  484. return result;
  485. },
  486. partition: function(iterator) {
  487. var trues = [], falses = [];
  488. this.each(function(value, index) {
  489. ((iterator || Prototype.K)(value, index) ?
  490. trues : falses).push(value);
  491. });
  492. return [trues, falses];
  493. },
  494. pluck: function(property) {
  495. var results = [];
  496. this.each(function(value, index) {
  497. results.push(value[property]);
  498. });
  499. return results;
  500. },
  501. reject: function(iterator) {
  502. var results = [];
  503. this.each(function(value, index) {
  504. if (!iterator(value, index))
  505. results.push(value);
  506. });
  507. return results;
  508. },
  509. sortBy: function(iterator) {
  510. return this.map(function(value, index) {
  511. return {value: value, criteria: iterator(value, index)};
  512. }).sort(function(left, right) {
  513. var a = left.criteria, b = right.criteria;
  514. return a < b ? -1 : a > b ? 1 : 0;
  515. }).pluck('value');
  516. },
  517. toArray: function() {
  518. return this.map();
  519. },
  520. zip: function() {
  521. var iterator = Prototype.K, args = $A(arguments);
  522. if (typeof args.last() == 'function')
  523. iterator = args.pop();
  524. var collections = [this].concat(args).map($A);
  525. return this.map(function(value, index) {
  526. return iterator(collections.pluck(index));
  527. });
  528. },
  529. size: function() {
  530. return this.toArray().length;
  531. },
  532. inspect: function() {
  533. return '#<Enumerable:' + this.toArray().inspect() + '>';
  534. }
  535. }
  536. Object.extend(Enumerable, {
  537. map: Enumerable.collect,
  538. find: Enumerable.detect,
  539. select: Enumerable.findAll,
  540. member: Enumerable.include,
  541. entries: Enumerable.toArray
  542. });
  543. var $A = Array.from = function(iterable) {
  544. if (!iterable) return [];
  545. if (iterable.toArray) {
  546. return iterable.toArray();
  547. } else {
  548. var results = [];
  549. for (var i = 0, length = iterable.length; i < length; i++)
  550. results.push(iterable[i]);
  551. return results;
  552. }
  553. }
  554. if (Prototype.Browser.WebKit) {
  555. $A = Array.from = function(iterable) {
  556. if (!iterable) return [];
  557. if (!(typeof iterable == 'function' && iterable == '[object NodeList]') &&
  558. iterable.toArray) {
  559. return iterable.toArray();
  560. } else {
  561. var results = [];
  562. for (var i = 0, length = iterable.length; i < length; i++)
  563. results.push(iterable[i]);
  564. return results;
  565. }
  566. }
  567. }
  568. Object.extend(Array.prototype, Enumerable);
  569. if (!Array.prototype._reverse)
  570. Array.prototype._reverse = Array.prototype.reverse;
  571. Object.extend(Array.prototype, {
  572. _each: function(iterator) {
  573. for (var i = 0, length = this.length; i < length; i++)
  574. iterator(this[i]);
  575. },
  576. clear: function() {
  577. this.length = 0;
  578. return this;
  579. },
  580. first: function() {
  581. return this[0];
  582. },
  583. last: function() {
  584. return this[this.length - 1];
  585. },
  586. compact: function() {
  587. return this.select(function(value) {
  588. return value != null;
  589. });
  590. },
  591. flatten: function() {
  592. return this.inject([], function(array, value) {
  593. return array.concat(value && value.constructor == Array ?
  594. value.flatten() : [value]);
  595. });
  596. },
  597. without: function() {
  598. var values = $A(arguments);
  599. return this.select(function(value) {
  600. return !values.include(value);
  601. });
  602. },
  603. indexOf: function(object) {
  604. for (var i = 0, length = this.length; i < length; i++)
  605. if (this[i] == object) return i;
  606. return -1;
  607. },
  608. reverse: function(inline) {
  609. return (inline !== false ? this : this.toArray())._reverse();
  610. },
  611. reduce: function() {
  612. return this.length > 1 ? this : this[0];
  613. },
  614. uniq: function(sorted) {
  615. return this.inject([], function(array, value, index) {
  616. if (0 == index || (sorted ? array.last() != value : !array.include(value)))
  617. array.push(value);
  618. return array;
  619. });
  620. },
  621. clone: function() {
  622. return [].concat(this);
  623. },
  624. size: function() {
  625. return this.length;
  626. },
  627. inspect: function() {
  628. return '[' + this.map(Object.inspect).join(', ') + ']';
  629. },
  630. toJSON: function() {
  631. var results = [];
  632. this.each(function(object) {
  633. var value = Object.toJSON(object);
  634. if (value !== undefined) results.push(value);
  635. });
  636. return '[' + results.join(', ') + ']';
  637. }
  638. });
  639. Array.prototype.toArray = Array.prototype.clone;
  640. function $w(string) {
  641. string = string.strip();
  642. return string ? string.split(/\s+/) : [];
  643. }
  644. if (Prototype.Browser.Opera){
  645. Array.prototype.concat = function() {
  646. var array = [];
  647. for (var i = 0, length = this.length; i < length; i++) array.push(this[i]);
  648. for (var i = 0, length = arguments.length; i < length; i++) {
  649. if (arguments[i].constructor == Array) {
  650. for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)
  651. array.push(arguments[i][j]);
  652. } else {
  653. array.push(arguments[i]);
  654. }
  655. }
  656. return array;
  657. }
  658. }
  659. var Hash = function(object) {
  660. if (object instanceof Hash) this.merge(object);
  661. else Object.extend(this, object || {});
  662. };
  663. Object.extend(Hash, {
  664. toQueryString: function(obj) {
  665. var parts = [];
  666. parts.add = arguments.callee.addPair;
  667. this.prototype._each.call(obj, function(pair) {
  668. if (!pair.key) return;
  669. var value = pair.value;
  670. if (value && typeof value == 'object') {
  671. if (value.constructor == Array) value.each(function(value) {
  672. parts.add(pair.key, value);
  673. });
  674. return;
  675. }
  676. parts.add(pair.key, value);
  677. });
  678. return parts.join('&');
  679. },
  680. toJSON: function(object) {
  681. var results = [];
  682. this.prototype._each.call(object, function(pair) {
  683. var value = Object.toJSON(pair.value);
  684. if (value !== undefined) results.push(pair.key.toJSON() + ': ' + value);
  685. });
  686. return '{' + results.join(', ') + '}';
  687. }
  688. });
  689. Hash.toQueryString.addPair = function(key, value, prefix) {
  690. key = encodeURIComponent(key);
  691. if (value === undefined) this.push(key);
  692. else this.push(key + '=' + (value == null ? '' : encodeURIComponent(value)));
  693. }
  694. Object.extend(Hash.prototype, Enumerable);
  695. Object.extend(Hash.prototype, {
  696. _each: function(iterator) {
  697. for (var key in this) {
  698. var value = this[key];
  699. if (value && value == Hash.prototype[key]) continue;
  700. var pair = [key, value];
  701. pair.key = key;
  702. pair.value = value;
  703. iterator(pair);
  704. }
  705. },
  706. keys: function() {
  707. return this.pluck('key');
  708. },
  709. values: function() {
  710. return this.pluck('value');
  711. },
  712. merge: function(hash) {
  713. return $H(hash).inject(this, function(mergedHash, pair) {
  714. mergedHash[pair.key] = pair.value;
  715. return mergedHash;
  716. });
  717. },
  718. remove: function() {
  719. var result;
  720. for(var i = 0, length = arguments.length; i < length; i++) {
  721. var value = this[arguments[i]];
  722. if (value !== undefined){
  723. if (result === undefined) result = value;
  724. else {
  725. if (result.constructor != Array) result = [result];
  726. result.push(value)
  727. }
  728. }
  729. delete this[arguments[i]];
  730. }
  731. return result;
  732. },
  733. toQueryString: function() {
  734. return Hash.toQueryString(this);
  735. },
  736. inspect: function() {
  737. return '#<Hash:{' + this.map(function(pair) {
  738. return pair.map(Object.inspect).join(': ');
  739. }).join(', ') + '}>';
  740. },
  741. toJSON: function() {
  742. return Hash.toJSON(this);
  743. }
  744. });
  745. function $H(object) {
  746. if (object instanceof Hash) return object;
  747. return new Hash(object);
  748. };
  749. // Safari iterates over shadowed properties
  750. if (function() {
  751. var i = 0, Test = function(value) { this.key = value };
  752. Test.prototype.key = 'foo';
  753. for (var property in new Test('bar')) i++;
  754. return i > 1;
  755. }()) Hash.prototype._each = function(iterator) {
  756. var cache = [];
  757. for (var key in this) {
  758. var value = this[key];
  759. if ((value && value == Hash.prototype[key]) || cache.include(key)) continue;
  760. cache.push(key);
  761. var pair = [key, value];
  762. pair.key = key;
  763. pair.value = value;
  764. iterator(pair);
  765. }
  766. };
  767. ObjectRange = Class.create();
  768. Object.extend(ObjectRange.prototype, Enumerable);
  769. Object.extend(ObjectRange.prototype, {
  770. initialize: function(start, end, exclusive) {
  771. this.start = start;
  772. this.end = end;
  773. this.exclusive = exclusive;
  774. },
  775. _each: function(iterator) {
  776. var value = this.start;
  777. while (this.include(value)) {
  778. iterator(value);
  779. value = value.succ();
  780. }
  781. },
  782. include: function(value) {
  783. if (value < this.start)
  784. return false;
  785. if (this.exclusive)
  786. return value < this.end;
  787. return value <= this.end;
  788. }
  789. });
  790. var $R = function(start, end, exclusive) {
  791. return new ObjectRange(start, end, exclusive);
  792. }
  793. var Ajax = {
  794. getTransport: function() {
  795. return Try.these(
  796. function() {return new XMLHttpRequest()},
  797. function() {return new ActiveXObject('Msxml2.XMLHTTP')},
  798. function() {return new ActiveXObject('Microsoft.XMLHTTP')}
  799. ) || false;
  800. },
  801. activeRequestCount: 0
  802. }
  803. Ajax.Responders = {
  804. responders: [],
  805. _each: function(iterator) {
  806. this.responders._each(iterator);
  807. },
  808. register: function(responder) {
  809. if (!this.include(responder))
  810. this.responders.push(responder);
  811. },
  812. unregister: function(responder) {
  813. this.responders = this.responders.without(responder);
  814. },
  815. dispatch: function(callback, request, transport, json) {
  816. this.each(function(responder) {
  817. if (typeof responder[callback] == 'function') {
  818. try {
  819. responder[callback].apply(responder, [request, transport, json]);
  820. } catch (e) {}
  821. }
  822. });
  823. }
  824. };
  825. Object.extend(Ajax.Responders, Enumerable);
  826. Ajax.Responders.register({
  827. onCreate: function() {
  828. Ajax.activeRequestCount++;
  829. },
  830. onComplete: function() {
  831. Ajax.activeRequestCount--;
  832. }
  833. });
  834. Ajax.Base = function() {};
  835. Ajax.Base.prototype = {
  836. setOptions: function(options) {
  837. this.options = {
  838. method: 'post',
  839. asynchronous: true,
  840. contentType: 'application/x-www-form-urlencoded',
  841. encoding: 'UTF-8',
  842. parameters: ''
  843. }
  844. Object.extend(this.options, options || {});
  845. this.options.method = this.options.method.toLowerCase();
  846. if (typeof this.options.parameters == 'string')
  847. this.options.parameters = this.options.parameters.toQueryParams();
  848. // KK patch -- handle crumb for POST automatically by adding a header
  849. if(this.options.method=="post") {
  850. if(this.options.requestHeaders==undefined)
  851. this.options.requestHeaders = {};
  852. crumb.wrap(this.options.requestHeaders);
  853. }
  854. // KK patch until here
  855. }
  856. }
  857. Ajax.Request = Class.create();
  858. Ajax.Request.Events =
  859. ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
  860. Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
  861. _complete: false,
  862. initialize: function(url, options) {
  863. this.transport = Ajax.getTransport();
  864. this.setOptions(options);
  865. this.request(url);
  866. },
  867. request: function(url) {
  868. this.url = url;
  869. this.method = this.options.method;
  870. var params = Object.clone(this.options.parameters);
  871. if (!['get', 'post'].include(this.method)) {
  872. // simulate other verbs over post
  873. params['_method'] = this.method;
  874. this.method = 'post';
  875. }
  876. this.parameters = params;
  877. if (params = Hash.toQueryString(params)) {
  878. // when GET, append parameters to URL
  879. if (this.method == 'get')
  880. this.url += (this.url.include('?') ? '&' : '?') + params;
  881. else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))
  882. params += '&_=';
  883. }
  884. try {
  885. if (this.options.onCreate) this.options.onCreate(this.transport);
  886. Ajax.Responders.dispatch('onCreate', this, this.transport);
  887. this.transport.open(this.method.toUpperCase(), this.url,
  888. this.options.asynchronous);
  889. if (this.options.asynchronous)
  890. setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10);
  891. this.transport.onreadystatechange = this.onStateChange.bind(this);
  892. this.setRequestHeaders();
  893. this.body = this.method == 'post' ? (this.options.postBody || params) : null;
  894. this.transport.send(this.body);
  895. /* Force Firefox to handle ready state 4 for synchronous requests */
  896. if (!this.options.asynchronous && this.transport.overrideMimeType)
  897. this.onStateChange();
  898. }
  899. catch (e) {
  900. this.dispatchException(e);
  901. }
  902. },
  903. onStateChange: function() {
  904. var readyState = this.transport.readyState;
  905. if (readyState > 1 && !((readyState == 4) && this._complete))
  906. this.respondToReadyState(this.transport.readyState);
  907. },
  908. setRequestHeaders: function() {
  909. var headers = {
  910. 'X-Requested-With': 'XMLHttpRequest',
  911. 'X-Prototype-Version': Prototype.Version,
  912. 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
  913. };
  914. if (this.method == 'post') {
  915. headers['Content-type'] = this.options.contentType +
  916. (this.options.encoding ? '; charset=' + this.options.encoding : '');
  917. /* Force "Connection: close" for older Mozilla browsers to work
  918. * around a bug where XMLHttpRequest sends an incorrect
  919. * Content-length header. See Mozilla Bugzilla #246651.
  920. */
  921. if (this.transport.overrideMimeType &&
  922. (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
  923. headers['Connection'] = 'close';
  924. }
  925. // user-defined headers
  926. if (typeof this.options.requestHeaders == 'object') {
  927. var extras = this.options.requestHeaders;
  928. if (typeof extras.push == 'function')
  929. for (var i = 0, length = extras.length; i < length; i += 2)
  930. headers[extras[i]] = extras[i+1];
  931. else
  932. $H(extras).each(function(pair) { headers[pair.key] = pair.value });
  933. }
  934. for (var name in headers)
  935. this.transport.setRequestHeader(name, headers[name]);
  936. },
  937. success: function() {
  938. return !this.transport.status
  939. || (this.transport.status >= 200 && this.transport.status < 300);
  940. },
  941. respondToReadyState: function(readyState) {
  942. var state = Ajax.Request.Events[readyState];
  943. var transport = this.transport, json = this.evalJSON();
  944. if (state == 'Complete') {
  945. try {
  946. this._complete = true;
  947. (this.options['on' + this.transport.status]
  948. || this.options['on' + (this.success() ? 'Success' : 'Failure')]
  949. || Prototype.emptyFunction)(transport, json);
  950. } catch (e) {
  951. this.dispatchException(e);
  952. }
  953. // var contentType = this.getHeader('Content-type');
  954. // if (contentType && contentType.strip().
  955. // match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i))
  956. // this.evalResponse();
  957. }
  958. try {
  959. (this.options['on' + state] || Prototype.emptyFunction)(transport, json);
  960. Ajax.Responders.dispatch('on' + state, this, transport, json);
  961. } catch (e) {
  962. this.dispatchException(e);
  963. }
  964. if (state == 'Complete') {
  965. // avoid memory leak in MSIE: clean up
  966. this.transport.onreadystatechange = Prototype.emptyFunction;
  967. }
  968. },
  969. getHeader: function(name) {
  970. try {
  971. return this.transport.getResponseHeader(name);
  972. } catch (e) { return null }
  973. },
  974. evalJSON: function() {
  975. try {
  976. var json = this.getHeader('X-JSON');
  977. return json ? json.evalJSON() : null;
  978. } catch (e) { return null }
  979. },
  980. evalResponse: function() {
  981. try {
  982. return eval('('+(this.transport.responseText || '').unfilterJSON()+')');
  983. } catch (e) {
  984. this.dispatchException(e);
  985. }
  986. },
  987. dispatchException: function(exception) {
  988. (this.options.onException || Prototype.emptyFunction)(this, exception);
  989. Ajax.Responders.dispatch('onException', this, exception);
  990. }
  991. });
  992. Ajax.Updater = Class.create();
  993. Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
  994. initialize: function(container, url, options) {
  995. this.container = {
  996. success: (container.success || container),
  997. failure: (container.failure || (container.success ? null : container))
  998. }
  999. this.transport = Ajax.getTransport();
  1000. this.setOptions(options);
  1001. var onComplete = this.options.onComplete || Prototype.emptyFunction;
  1002. this.options.onComplete = (function(transport, param) {
  1003. this.updateContent();
  1004. onComplete(transport, param);
  1005. }).bind(this);
  1006. this.request(url);
  1007. },
  1008. updateContent: function() {
  1009. var receiver = this.container[this.success() ? 'success' : 'failure'];
  1010. var response = this.transport.responseText;
  1011. if (!this.options.evalScripts) response = response.stripScripts();
  1012. if (receiver = $(receiver)) {
  1013. if (this.options.insertion)
  1014. new this.options.insertion(receiver, response);
  1015. else
  1016. receiver.update(response);
  1017. }
  1018. if (this.success()) {
  1019. if (this.onComplete)
  1020. setTimeout(this.onComplete.bind(this), 10);
  1021. }
  1022. }
  1023. });
  1024. Ajax.PeriodicalUpdater = Class.create();
  1025. Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), {
  1026. initialize: function(container, url, options) {
  1027. this.setOptions(options);
  1028. this.onComplete = this.options.onComplete;
  1029. this.frequency = (this.options.frequency || 2);
  1030. this.decay = (this.options.decay || 1);
  1031. this.updater = {};
  1032. this.container = container;
  1033. this.url = url;
  1034. this.start();
  1035. },
  1036. start: function() {
  1037. this.options.onComplete = this.updateComplete.bind(this);
  1038. this.onTimerEvent();
  1039. },
  1040. stop: function() {
  1041. this.updater.options.onComplete = undefined;
  1042. clearTimeout(this.timer);
  1043. (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
  1044. },
  1045. updateComplete: function(request) {
  1046. if (this.options.decay) {
  1047. this.decay = (request.responseText == this.lastText ?
  1048. this.decay * this.options.decay : 1);
  1049. this.lastText = request.responseText;
  1050. }
  1051. this.timer = setTimeout(this.onTimerEvent.bind(this),
  1052. this.decay * this.frequency * 1000);
  1053. },
  1054. onTimerEvent: function() {
  1055. this.updater = new Ajax.Updater(this.container, this.url, this.options);
  1056. }
  1057. });
  1058. function $(element) {
  1059. if (arguments.length > 1) {
  1060. for (var i = 0, elements = [], length = arguments.length; i < length; i++)
  1061. elements.push($(arguments[i]));
  1062. return elements;
  1063. }
  1064. if (typeof element == 'string')
  1065. element = document.getElementById(element);
  1066. return Element.extend(element);
  1067. }
  1068. if (Prototype.BrowserFeatures.XPath) {
  1069. document._getElementsByXPath = function(expression, parentElement) {
  1070. var results = [];
  1071. var query = document.evaluate(expression, $(parentElement) || document,
  1072. null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1073. for (var i = 0, length = query.snapshotLength; i < length; i++)
  1074. results.push(query.snapshotItem(i));
  1075. return results;
  1076. };
  1077. document.getElementsByClassName = function(className, parentElement) {
  1078. var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";
  1079. return document._getElementsByXPath(q, parentElement);
  1080. }
  1081. } else document.getElementsByClassName = function(className, parentElement) {
  1082. var children = ($(parentElement) || document.body).getElementsByTagName('*');
  1083. var elements = [], child, pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
  1084. for (var i = 0, length = children.length; i < length; i++) {
  1085. child = children[i];
  1086. var elementClassName = child.className;
  1087. if (elementClassName.length == 0) continue;
  1088. if (elementClassName == className || elementClassName.match(pattern))
  1089. elements.push(Element.extend(child));
  1090. }
  1091. return elements;
  1092. };
  1093. /*--------------------------------------------------------------------------*/
  1094. if (!window.Element) var Element = {};
  1095. Element.extend = function(element) {
  1096. var F = Prototype.BrowserFeatures;
  1097. if (!element || !element.tagName || element.nodeType == 3 ||
  1098. element._extended || F.SpecificElementExtensions || element == window)
  1099. return element;
  1100. var methods = {}, tagName = element.tagName, cache = Element.extend.cache,
  1101. T = Element.Methods.ByTag;
  1102. // extend methods for all tags (Safari doesn't need this)
  1103. if (!F.ElementExtensions) {
  1104. Object.extend(methods, Element.Methods),
  1105. Object.extend(methods, Element.Methods.Simulated);
  1106. }
  1107. // extend methods for specific tags
  1108. if (T[tagName]) Object.extend(methods, T[tagName]);
  1109. for (var property in methods) {
  1110. var value = methods[property];
  1111. if (typeof value == 'function' && !(property in element))
  1112. element[property] = cache.findOrStore(value);
  1113. }
  1114. element._extended = Prototype.emptyFunction;
  1115. return element;
  1116. };
  1117. Element.extend.cache = {
  1118. findOrStore: function(value) {
  1119. return this[value] = this[value] || function() {
  1120. return value.apply(null, [this].concat($A(arguments)));
  1121. }
  1122. }
  1123. };
  1124. Element.Methods = {
  1125. visible: function(element) {
  1126. return $(element).style.display != 'none';
  1127. },
  1128. toggle: function(element) {
  1129. element = $(element);
  1130. Element[Element.visible(element) ? 'hide' : 'show'](element);
  1131. return element;
  1132. },
  1133. hide: function(element) {
  1134. $(element).style.display = 'none';
  1135. return element;
  1136. },
  1137. show: function(element) {
  1138. $(element).style.display = '';
  1139. return element;
  1140. },
  1141. remove: function(element) {
  1142. element = $(element);
  1143. element.parentNode.removeChild(element);
  1144. return element;
  1145. },
  1146. update: function(element, html) {
  1147. html = typeof html == 'undefined' ? '' : html.toString();
  1148. $(element).innerHTML = html.stripScripts();
  1149. setTimeout(function() {html.evalScripts()}, 10);
  1150. return element;
  1151. },
  1152. replace: function(element, html) {
  1153. element = $(element);
  1154. html = typeof html == 'undefined' ? '' : html.toString();
  1155. if (element.outerHTML) {
  1156. element.outerHTML = html.stripScripts();
  1157. } else {
  1158. var range = element.ownerDocument.createRange();
  1159. range.selectNodeContents(element);
  1160. element.parentNode.replaceChild(
  1161. range.createContextualFragment(html.stripScripts()), element);
  1162. }
  1163. setTimeout(function() {html.evalScripts()}, 10);
  1164. return element;
  1165. },
  1166. inspect: function(element) {
  1167. element = $(element);
  1168. var result = '<' + element.tagName.toLowerCase();
  1169. $H({'id': 'id', 'className': 'class'}).each(function(pair) {
  1170. var property = pair.first(), attribute = pair.last();
  1171. var value = (element[property] || '').toString();
  1172. if (value) result += ' ' + attribute + '=' + value.inspect(true);
  1173. });
  1174. return result + '>';
  1175. },
  1176. recursivelyCollect: function(element, property) {
  1177. element = $(element);
  1178. var elements = [];
  1179. while (element = element[property])
  1180. if (element.nodeType == 1)
  1181. elements.push(Element.extend(element));
  1182. return elements;
  1183. },
  1184. ancestors: function(element) {
  1185. return $(element).recursivelyCollect('parentNode');
  1186. },
  1187. descendants: function(element) {
  1188. return $A($(element).getElementsByTagName('*')).each(Element.extend);
  1189. },
  1190. firstDescendant: function(element) {
  1191. element = $(element).firstChild;
  1192. while (element && element.nodeType != 1) element = element.nextSibling;
  1193. return $(element);
  1194. },
  1195. immediateDescendants: function(element) {
  1196. if (!(element = $(element).firstChild)) return [];
  1197. while (element && element.nodeType != 1) element = element.nextSibling;
  1198. if (element) return [element].concat($(element).nextSiblings());
  1199. return [];
  1200. },
  1201. previousSiblings: function(element) {
  1202. return $(element).recursivelyCollect('previousSibling');
  1203. },
  1204. nextSiblings: function(element) {
  1205. return $(element).recursivelyCollect('nextSibling');
  1206. },
  1207. siblings: function(element) {
  1208. element = $(element);
  1209. return element.previousSiblings().reverse().concat(element.nextSiblings());
  1210. },
  1211. match: function(element, selector) {
  1212. if (typeof selector == 'string')
  1213. selector = new Selector(selector);
  1214. return selector.match($(element));
  1215. },
  1216. up: function(element, expression, index) {
  1217. element = $(element);
  1218. if (arguments.length == 1) return $(element.parentNode);
  1219. var ancestors = element.ancestors();
  1220. return expression ? Selector.findElement(ancestors, expression, index) :
  1221. ancestors[index || 0];
  1222. },
  1223. down: function(element, expression, index) {
  1224. element = $(element);
  1225. if (arguments.length == 1) return element.firstDescendant();
  1226. var descendants = element.descendants();
  1227. return expression ? Selector.findElement(descendants, expression, index) :
  1228. descendants[index || 0];
  1229. },
  1230. previous: function(element, expression, index) {
  1231. element = $(element);
  1232. if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));
  1233. var previousSiblings = element.previousSiblings();
  1234. return expression ? Selector.findElement(previousSiblings, expression, index) :
  1235. previousSiblings[index || 0];
  1236. },
  1237. next: function(element, expression, index) {
  1238. element = $(element);
  1239. if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));
  1240. var nextSiblings = element.nextSiblings();
  1241. return expression ? Selector.findElement(nextSiblings, expression, index) :
  1242. nextSiblings[index || 0];
  1243. },
  1244. getElementsBySelector: function() {
  1245. var args = $A(arguments), element = $(args.shift());
  1246. return Selector.findChildElements(element, args);
  1247. },
  1248. getElementsByClassName: function(element, className) {
  1249. return document.getElementsByClassName(className, element);
  1250. },
  1251. readAttribute: function(element, name) {
  1252. element = $(element);
  1253. if (Prototype.Browser.IE) {
  1254. if (!element.attributes) return null;
  1255. var t = Element._attributeTranslations;
  1256. if (t.values[name]) return t.values[name](element, name);
  1257. if (t.names[name]) name = t.names[name];
  1258. var attribute = element.attributes[name];
  1259. return attribute ? attribute.nodeValue : null;
  1260. }
  1261. return element.getAttribute(name);
  1262. },
  1263. getHeight: function(element) {
  1264. return $(element).getDimensions().height;
  1265. },
  1266. getWidth: function(element) {
  1267. return $(element).getDimensions().width;
  1268. },
  1269. classNames: function(element) {
  1270. return new Element.ClassNames(element);
  1271. },
  1272. hasClassName: function(element, className) {
  1273. if (!(element = $(element))) return;
  1274. var elementClassName = element.className;
  1275. if (!elementClassName || elementClassName.length == 0) return false;
  1276. if (elementClassName == className ||
  1277. elementClassName.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
  1278. return true;
  1279. return false;
  1280. },
  1281. addClassName: function(element, className) {
  1282. if (!(element = $(element))) return;
  1283. Element.classNames(element).add(className);
  1284. return element;
  1285. },
  1286. removeClassName: function(element, className) {
  1287. if (!(element = $(element))) return;
  1288. Element.classNames(element).remove(className);
  1289. return element;
  1290. },
  1291. toggleClassName: function(element, className) {
  1292. if (!(element = $(element))) return;
  1293. Element.classNames(element)[element.hasClassName(className) ? 'remove' : 'add'](className);
  1294. return element;
  1295. },
  1296. observe: function() {
  1297. Event.observe.apply(Event, arguments);
  1298. return $A(arguments).first();
  1299. },
  1300. stopObserving: function() {
  1301. Event.stopObserving.apply(Event, arguments);
  1302. return $A(arguments).first();
  1303. },
  1304. // removes whitespace-only text node children
  1305. cleanWhitespace: function(element) {
  1306. element = $(element);
  1307. var node = element.firstChild;
  1308. while (node) {
  1309. var nextNode = node.nextSibling;
  1310. if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
  1311. element.removeChild(node);
  1312. node = nextNode;
  1313. }
  1314. return element;
  1315. },
  1316. empty: function(element) {
  1317. return $(element).innerHTML.blank();
  1318. },
  1319. descendantOf: function(element, ancestor) {
  1320. element = $(element), ancestor = $(ancestor);
  1321. while (element = element.parentNode)
  1322. if (element == ancestor) return true;
  1323. return false;
  1324. },
  1325. scrollTo: function(element) {
  1326. element = $(element);
  1327. var pos = Position.cumulativeOffset(element);
  1328. window.scrollTo(pos[0], pos[1]);
  1329. return element;
  1330. },
  1331. getStyle: function(element, style) {
  1332. element = $(element);
  1333. style = style == 'float' ? 'cssFloat' : style.camelize();
  1334. var value = element.style[style];
  1335. if (!value) {
  1336. var css = document.defaultView.getComputedStyle(element, null);
  1337. value = css ? css[style] : null;
  1338. }
  1339. if (style == 'opacity') return value ? parseFloat(value) : 1.0;
  1340. return value == 'auto' ? null : value;
  1341. },
  1342. getOpacity: function(element) {
  1343. return $(element).getStyle('opacity');
  1344. },
  1345. setStyle: function(element, styles, camelized) {
  1346. element = $(element);
  1347. var elementStyle = element.style;
  1348. for (var property in styles)
  1349. if (property == 'opacity') element.setOpacity(styles[property])
  1350. else
  1351. elementStyle[(property == 'float' || property == 'cssFloat') ?
  1352. (elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') :
  1353. (camelized ? property : property.camelize())] = styles[property];
  1354. return element;
  1355. },
  1356. setOpacity: function(element, value) {
  1357. element = $(element);
  1358. element.style.opacity = (value == 1 || value === '') ? '' :
  1359. (value < 0.00001) ? 0 : value;
  1360. return element;
  1361. },
  1362. getDimensions: function(element) {
  1363. element = $(element);
  1364. var display = $(element).getStyle('display');
  1365. if (display != 'none' && display != null) // Safari bug
  1366. return {width: element.offsetWidth, height: element.offsetHeight};
  1367. // All *Width and *Height properties give 0 on elements with display none,
  1368. // so enable the element temporarily
  1369. var els = element.style;
  1370. var originalVisibility = els.visibility;
  1371. var originalPosition = els.position;
  1372. var originalDisplay = els.display;
  1373. els.visibility = 'hidden';
  1374. els.position = 'absolute';
  1375. els.display = 'block';
  1376. var originalWidth = element.clientWidth;
  1377. var originalHeight = element.clientHeight;
  1378. els.display = originalDisplay;
  1379. els.position = originalPosition;
  1380. els.visibility = originalVisibility;
  1381. return {width: originalWidth, height: originalHeight};
  1382. },
  1383. makePositioned: function(element) {
  1384. element = $(element);
  1385. var pos = Element.getStyle(element, 'position');
  1386. if (pos == 'static' || !pos) {
  1387. element._madePositioned = true;
  1388. element.style.position = 'relative';
  1389. // Opera returns the offset relative to the positioning context, when an
  1390. // element is position relative but top and left have not been defined
  1391. if (window.opera) {
  1392. element.style.top = 0;
  1393. element.style.left = 0;
  1394. }
  1395. }
  1396. return element;
  1397. },
  1398. undoPositioned: function(element) {
  1399. element = $(element);
  1400. if (element._madePositioned) {
  1401. element._madePositioned = undefined;
  1402. element.style.position =
  1403. element.style.top =
  1404. element.style.left =
  1405. element.style.bottom =
  1406. element.style.right = '';
  1407. }
  1408. return element;
  1409. },
  1410. makeClipping: function(element) {
  1411. element = $(element);
  1412. if (element._overflow) return element;
  1413. element._overflow = element.style.overflow || 'auto';
  1414. if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden')
  1415. element.style.overflow = 'hidden';
  1416. return element;
  1417. },
  1418. undoClipping: function(element) {
  1419. element = $(element);
  1420. if (!element._overflow) return element;
  1421. element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
  1422. element._overflow = null;
  1423. return element;
  1424. }
  1425. };
  1426. Object.extend(Element.Methods, {
  1427. childOf: Element.Methods.descendantOf,
  1428. childElements: Element.Methods.immediateDescendants
  1429. });
  1430. if (Prototype.Browser.Opera) {
  1431. Element.Methods._getStyle = Element.Methods.getStyle;
  1432. Element.Methods.getStyle = function(element, style) {
  1433. switch(style) {
  1434. case 'left':
  1435. case 'top':
  1436. case 'right':
  1437. case 'bottom':
  1438. if (Element._getStyle(element, 'position') == 'static') return null;
  1439. default: return Element._getStyle(element, style);
  1440. }
  1441. };
  1442. }
  1443. else if (Prototype.Browser.IE) {
  1444. Element.Methods.getStyle = function(element, style) {
  1445. element = $(element);
  1446. style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
  1447. var value = element.style[style];
  1448. if (!value && element.currentStyle) value = element.currentStyle[style];
  1449. if (style == 'opacity') {
  1450. if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
  1451. if (value[1]) return parseFloat(value[1]) / 100;
  1452. return 1.0;
  1453. }
  1454. if (value == 'auto') {
  1455. if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
  1456. return element['offset'+style.capitalize()] + 'px';
  1457. return null;
  1458. }
  1459. return value;
  1460. };
  1461. Element.Methods.setOpacity = function(element, value) {
  1462. element = $(element);
  1463. var filter = element.getStyle('filter'), style = element.style;
  1464. if (value == 1 || value === '') {
  1465. style.filter = filter.replace(/alpha\([^\)]*\)/gi,'');
  1466. return element;
  1467. } else if (value < 0.00001) value = 0;
  1468. style.filter = filter.replace(/alpha\([^\)]*\)/gi, '') +
  1469. 'alpha(opacity=' + (value * 100) + ')';
  1470. return element;
  1471. };
  1472. // IE is missing .innerHTML support for TABLE-related elements
  1473. Element.Methods.update = function(element, html) {
  1474. element = $(element);
  1475. html = typeof html == 'undefined' ? '' : html.toString();
  1476. var tagName = element.tagName.toUpperCase();
  1477. if (['THEAD','TBODY','TR','TD'].include(tagName)) {
  1478. var div = document.createElement('div');
  1479. switch (tagName) {
  1480. case 'THEAD':
  1481. case 'TBODY':
  1482. div.innerHTML = '<table><tbody>' + html.stripScripts() + '</tbody></table>';
  1483. depth = 2;
  1484. break;
  1485. case 'TR':
  1486. div.innerHTML = '<table><tbody><tr>' + html.stripScripts() + '</tr></tbody></table>';
  1487. depth = 3;
  1488. break;
  1489. case 'TD':
  1490. div.innerHTML = '<table><tbody><tr><td>' + html.stripScripts() + '</td></tr></tbody></table>';
  1491. depth = 4;
  1492. }
  1493. $A(element.childNodes).each(function(node) { element.removeChild(node) });
  1494. depth.times(function() { div = div.firstChild });
  1495. $A(div.childNodes).each(function(node) { element.appendChild(node) });
  1496. } else {
  1497. element.innerHTML = html.stripScripts();
  1498. }
  1499. setTimeout(function() { html.evalScripts() }, 10);
  1500. return element;
  1501. }
  1502. }
  1503. else if (Prototype.Browser.Gecko) {
  1504. Element.Methods.setOpacity = function(element, value) {
  1505. element = $(element);
  1506. element.style.opacity = (value == 1) ? 0.999999 :
  1507. (value === '') ? '' : (value < 0.00001) ? 0 : value;
  1508. return element;
  1509. };
  1510. }
  1511. Element._attributeTranslations = {
  1512. names: {
  1513. colspan: "colSpan",
  1514. rowspan: "rowSpan",
  1515. valign: "vAlign",
  1516. datetime: "dateTime",
  1517. accesskey: "accessKey",
  1518. tabindex: "tabIndex",
  1519. enctype: "encType",
  1520. maxlength: "maxLength",
  1521. readonly: "readOnly",
  1522. longdesc: "longDesc"
  1523. },
  1524. values: {
  1525. _getAttr: function(element, attribute) {
  1526. return element.getAttribute(attribute, 2);
  1527. },
  1528. _flag: function(element, attribute) {
  1529. return $(element).hasAttribute(attribute) ? attribute : null;
  1530. },
  1531. style: function(element) {
  1532. return element.style.cssText.toLowerCase();
  1533. },
  1534. title: function(element) {
  1535. var node = element.getAttributeNode('title');
  1536. return node.specified ? node.nodeValue : null;
  1537. }
  1538. }
  1539. };
  1540. (function() {
  1541. Object.extend(this, {
  1542. href: this._getAttr,
  1543. src: this._getAttr,
  1544. type: this._getAttr,
  1545. disabled: this._flag,
  1546. checked: this._flag,
  1547. readonly: this._flag,
  1548. multiple: this._flag
  1549. });
  1550. }).call(Element._attributeTranslations.values);
  1551. Element.Methods.Simulated = {
  1552. hasAttribute: function(element, attribute) {
  1553. var t = Element._attributeTranslations, node;
  1554. attribute = t.names[attribute] || attribute;
  1555. node = $(element).getAttributeNode(attribute);
  1556. return node && node.specified;
  1557. }
  1558. };
  1559. Element.Methods.ByTag = {};
  1560. Object.extend(Element, Element.Methods);
  1561. if (!Prototype.BrowserFeatures.ElementExtensions &&
  1562. document.createElement('div').__proto__) {
  1563. window.HTMLElement = {};
  1564. window.HTMLElement.prototype = document.createElement('div').__proto__;
  1565. Prototype.BrowserFeatures.ElementExtensions = true;
  1566. }
  1567. Element.hasAttribute = function(element, attribute) {
  1568. if (element.hasAttribute) return element.hasAttribute(attribute);
  1569. return Element.Methods.Simulated.hasAttribute(element, attribute);
  1570. };
  1571. Element.addMethods = function(methods) {
  1572. var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
  1573. if (!methods) {
  1574. Object.extend(Form, Form.Methods);
  1575. Object.extend(Form.Element, Form.Element.Methods);
  1576. Object.extend(Element.Methods.ByTag, {
  1577. "FORM": Object.clone(Form.Methods),
  1578. "INPUT": Object.clone(Form.Element.Methods),
  1579. "SELECT": Object.clone(Form.Element.Methods),
  1580. "TEXTAREA": Object.clone(Form.Element.Methods)
  1581. });
  1582. }
  1583. if (arguments.length == 2) {
  1584. var tagName = methods;
  1585. methods = arguments[1];
  1586. }
  1587. if (!tagName) Object.extend(Element.Methods, methods || {});
  1588. else {
  1589. if (tagName.constructor == Array) tagName.each(extend);
  1590. else extend(tagName);
  1591. }
  1592. function extend(tagName) {
  1593. tagName = tagName.toUpperCase();
  1594. if (!Element.Methods.ByTag[tagName])
  1595. Element.Methods.ByTag[tagName] = {};
  1596. Object.extend(Element.Methods.ByTag[tagName], methods);
  1597. }
  1598. function copy(methods, destination, onlyIfAbsent) {
  1599. onlyIfAbsent = onlyIfAbsent || false;
  1600. var cache = Element.extend.cache;
  1601. for (var property in methods) {
  1602. var value = methods[property];
  1603. if (!onlyIfAbsent || !(property in destination))
  1604. destination[property] = cache.findOrStore(value);
  1605. }
  1606. }
  1607. function findDOMClass(tagName) {
  1608. var klass;
  1609. var trans = {
  1610. "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
  1611. "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
  1612. "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
  1613. "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
  1614. "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
  1615. "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
  1616. "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
  1617. "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
  1618. "FrameSet", "IFRAME": "IFrame"
  1619. };
  1620. if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
  1621. if (window[klass]) return window[klass];
  1622. klass = 'HTML' + tagName + 'Element';
  1623. if (window[klass]) return window[klass];
  1624. klass = 'HTML' + tagName.capitalize() + 'Element';
  1625. if (window[klass]) return window[klass];
  1626. window[klass] = {};
  1627. window[klass].prototype = document.createElement(tagName).__proto__;
  1628. return window[klass];
  1629. }
  1630. if (F.ElementExtensions) {
  1631. copy(Element.Methods, HTMLElement.prototype);
  1632. copy(Element.Methods.Simulated, HTMLElement.prototype, true);
  1633. }
  1634. if (F.SpecificElementExtensions) {
  1635. for (var tag in Element.Methods.ByTag) {
  1636. var klass = findDOMClass(tag);
  1637. if (typeof klass == "undefined") continue;
  1638. copy(T[tag], klass.prototype);
  1639. }
  1640. }
  1641. Object.extend(Element, Element.Methods);
  1642. delete Element.ByTag;
  1643. };
  1644. var Toggle = { display: Element.toggle };
  1645. /*--------------------------------------------------------------------------*/
  1646. Abstract.Insertion = function(adjacency) {
  1647. this.adjacency = adjacency;
  1648. }
  1649. Abstract.Insertion.prototype = {
  1650. initialize: function(element, content) {
  1651. this.element = $(element);
  1652. this.content = content.stripScripts();
  1653. if (this.adjacency && this.element.insertAdjacentHTML) {
  1654. try {
  1655. this.element.insertAdjacentHTML(this.adjacency, this.content);
  1656. } catch (e) {
  1657. var tagName = this.element.tagName.toUpperCase();
  1658. if (['TBODY', 'TR'].include(tagName)) {
  1659. this.insertContent(this.contentFromAnonymousTable());
  1660. } else {
  1661. throw e;
  1662. }
  1663. }
  1664. } else {
  1665. this.range = this.element.ownerDocument.createRange();
  1666. if (this.initializeRange) this.initializeRange();
  1667. this.insertContent([this.range.createContextualFragment(this.content)]);
  1668. }
  1669. setTimeout(function() {content.evalScripts()}, 10);
  1670. },
  1671. contentFromAnonymousTable: function() {
  1672. var div = document.createElement('div');
  1673. div.innerHTML = '<table><tbody>' + this.content + '</tbody></table>';
  1674. return $A(div.childNodes[0].childNodes[0].childNodes);
  1675. }
  1676. }
  1677. var Insertion = new Object();
  1678. Insertion.Before = Class.create();
  1679. Insertion.Before.prototype = Object.extend(new Abstract.Insertion('beforeBegin'), {
  1680. initializeRange: function() {
  1681. this.range.setStartBefore(this.element);
  1682. },
  1683. insertContent: function(fragments) {
  1684. fragments.each((function(fragment) {
  1685. this.element.parentNode.insertBefore(fragment, this.element);
  1686. }).bind(this));
  1687. }
  1688. });
  1689. Insertion.Top = Class.create();
  1690. Insertion.Top.prototype = Object.extend(new Abstract.Insertion('afterBegin'), {
  1691. initializeRange: function() {
  1692. this.range.selectNodeContents(this.element);
  1693. this.range.collapse(true);
  1694. },
  1695. insertContent: function(fragments) {
  1696. fragments.reverse(false).each((function(fragment) {
  1697. this.element.insertBefore(fragment, this.element.firstChild);
  1698. }).bind(this));
  1699. }
  1700. });
  1701. Insertion.Bottom = Class.create();
  1702. Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion('beforeEnd'), {
  1703. initializeRange: function() {
  1704. this.range.selectNodeContents(this.element);
  1705. this.range.collapse(this.element);
  1706. },
  1707. insertContent: function(fragments) {
  1708. fragments.each((function(fragment) {
  1709. this.element.appendChild(fragment);
  1710. }).bind(this));
  1711. }
  1712. });
  1713. Insertion.After = Class.create();
  1714. Insertion.After.prototype = Object.extend(new Abstract.Insertion('afterEnd'), {
  1715. initializeRange: function() {
  1716. this.range.setStartAfter(this.element);
  1717. },
  1718. insertContent: function(fragments) {
  1719. fragments.each((function(fragment) {
  1720. this.element.parentNode.insertBefore(fragment,
  1721. this.element.nextSibling);
  1722. }).bind(this));
  1723. }
  1724. });
  1725. /*--------------------------------------------------------------------------*/
  1726. Element.ClassNames = Class.create();
  1727. Element.ClassNames.prototype = {
  1728. initialize: function(element) {
  1729. this.element = $(element);
  1730. },
  1731. _each: function(iterator) {
  1732. this.element.className.split(/\s+/).select(function(name) {
  1733. return name.length > 0;
  1734. })._each(iterator);
  1735. },
  1736. set: function(className) {
  1737. this.element.className = className;
  1738. },
  1739. add: function(classNameToAdd) {
  1740. if (this.include(classNameToAdd)) return;
  1741. this.set($A(this).concat(classNameToAdd).join(' '));
  1742. },
  1743. remove: function(classNameToRemove) {
  1744. if (!this.include(classNameToRemove)) return;
  1745. this.set($A(this).without(classNameToRemove).join(' '));
  1746. },
  1747. toString: function() {
  1748. return $A(this).join(' ');
  1749. }
  1750. };
  1751. Object.extend(Element.ClassNames.prototype, Enumerable);
  1752. /* Portions of the Selector class are derived from Jack Slocumâ&#x20AC;&#x2122;s DomQuery,
  1753. * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style
  1754. * license. Please see http://www.yui-ext.com/ for more information. */
  1755. var Selector = Class.create();
  1756. Selector.prototype = {
  1757. initialize: function(expression) {
  1758. this.expression = expression.strip();
  1759. this.compileMatcher();
  1760. },
  1761. compileMatcher: function() {
  1762. // Selectors with namespaced attributes can't use the XPath version
  1763. if (Prototype.BrowserFeatures.XPath && !(/\[[\w-]*?:/).test(this.expression))
  1764. return this.compileXPathMatcher();
  1765. var e = this.expression, ps = Selector.patterns, h = Selector.handlers,
  1766. c = Selector.criteria, le, p, m;
  1767. if (Selector._cache[e]) {
  1768. this.matcher = Selector._cache[e]; return;
  1769. }
  1770. this.matcher = ["this.matcher = function(root) {",
  1771. "var r = root, h = Selector.handlers, c = false, n;"];
  1772. while (e && le != e && (/\S/).test(e)) {
  1773. le = e;
  1774. for (var i in ps) {
  1775. p = ps[i];
  1776. if (m = e.match(p)) {
  1777. this.matcher.push(typeof c[i] == 'function' ? c[i](m) :
  1778. new Template(c[i]).evaluate(m));
  1779. e = e.replace(m[0], '');
  1780. break;
  1781. }
  1782. }
  1783. }
  1784. this.matcher.push("return h.unique(n);\n}");
  1785. eval(this.matcher.join('\n'));
  1786. Selector._cache[this.expression] = this.matcher;
  1787. },
  1788. compileXPathMatcher: function() {
  1789. var e = this.expression, ps = Selector.patterns,
  1790. x = Selector.xpath, le, m;
  1791. if (Selector._cache[e]) {
  1792. this.xpath = Selector._cache[e]; return;
  1793. }
  1794. this.matcher = ['.//*'];
  1795. while (e && le != e && (/\S/).test(e)) {
  1796. le = e;
  1797. for (var i in ps) {
  1798. if (m = e.match(ps[i])) {
  1799. this.matcher.push(typeof x[i] == 'function' ? x[i](m) :
  1800. new Template(x[i]).evaluate(m));
  1801. e = e.replace(m[0], '');
  1802. break;
  1803. }
  1804. }
  1805. }
  1806. this.xpath = this.matcher.join('');
  1807. Selector._cache[this.expression] = this.xpath;
  1808. },
  1809. findElements: function(root) {
  1810. root = root || document;
  1811. if (this.xpath) return document._getElementsByXPath(this.xpath, root);
  1812. return this.matcher(root);
  1813. },
  1814. match: function(element) {
  1815. return this.findElements(document).include(element);
  1816. },
  1817. toString: function() {
  1818. return this.expression;
  1819. },
  1820. inspect: function() {
  1821. return "#<Selector:" + this.expression.inspect() + ">";
  1822. }
  1823. };
  1824. Object.extend(Selector, {
  1825. _cache: {},
  1826. xpath: {
  1827. descendant: "//*",
  1828. child: "/*",
  1829. adjacent: "/following-sibling::*[1]",
  1830. laterSibling: '/following-sibling::*',
  1831. tagName: function(m) {
  1832. if (m[1] == '*') return '';
  1833. return "[local-name()='" + m[1].toLowerCase() +
  1834. "' or local-name()='" + m[1].toUpperCase() + "']";
  1835. },
  1836. className: "[contains(concat(' ', @class, ' '), ' #{1} ')]",
  1837. id: "[@id='#{1}']",
  1838. attrPresence: "[@#{1}]",
  1839. attr: function(m) {
  1840. m[3] = m[5] || m[6];
  1841. return new Template(Selector.xpath.operators[m[2]]).evaluate(m);
  1842. },
  1843. pseudo: function(m) {
  1844. var h = Selector.xpath.pseudos[m[1]];
  1845. if (!h) return '';
  1846. if (typeof h === 'function') return h(m);
  1847. return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m);
  1848. },
  1849. operators: {
  1850. '=': "[@#{1}='#{3}']",
  1851. '!=': "[@#{1}!='#{3}']",
  1852. '^=': "[starts-with(@#{1}, '#{3}')]",
  1853. '$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']",
  1854. '*=': "[contains(@#{1}, '#{3}')]",
  1855. '~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]",
  1856. '|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]"
  1857. },
  1858. pseudos: {
  1859. 'first-child': '[not(preceding-sibling::*)]',
  1860. 'last-child': '[not(following-sibling::*)]',
  1861. 'only-child': '[not(preceding-sibling::* or following-sibling::*)]',
  1862. 'empty': "[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]",
  1863. 'checked': "[@checked]",
  1864. 'disabled': "[@disabled]",
  1865. 'enabled': "[not(@disabled)]",
  1866. 'not': function(m) {
  1867. var e = m[6], p = Selector.patterns,
  1868. x = Selector.xpath, le, m, v;
  1869. var exclusion = [];
  1870. while (e && le != e && (/\S/).test(e)) {
  1871. le = e;
  1872. for (var i in p) {
  1873. if (m = e.match(p[i])) {
  1874. v = typeof x[i] == 'function' ? x[i](m) : new Template(x[i]).evaluate(m);
  1875. exclusion.push("(" + v.substring(1, v.length - 1) + ")");
  1876. e = e.replace(m[0], '');
  1877. break;
  1878. }
  1879. }
  1880. }
  1881. return "[not(" + exclusion.join(" and ") + ")]";
  1882. },
  1883. 'nth-child': function(m) {
  1884. return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m);
  1885. },
  1886. 'nth-last-child': function(m) {
  1887. return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m);
  1888. },
  1889. 'nth-of-type': function(m) {
  1890. return Selector.xpath.pseudos.nth("position() ", m);
  1891. },
  1892. 'nth-last-of-type': function(m) {
  1893. return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m);
  1894. },
  1895. 'first-of-type': function(m) {
  1896. m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m);
  1897. },
  1898. 'last-of-type': function(m) {
  1899. m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m);
  1900. },
  1901. 'only-of-type': function(m) {
  1902. var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m);
  1903. },
  1904. nth: function(fragment, m) {
  1905. var mm, formula = m[6], predicate;
  1906. if (formula == 'even') formula = '2n+0';
  1907. if (formula == 'odd') formula = '2n+1';
  1908. if (mm = formula.match(/^(\d+)$/)) // digit only
  1909. return '[' + fragment + "= " + mm[1] + ']';
  1910. if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
  1911. if (mm[1] == "-") mm[1] = -1;
  1912. var a = mm[1] ? Number(mm[1]) : 1;
  1913. var b = mm[2] ? Number(mm[2]) : 0;
  1914. predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " +
  1915. "((#{fragment} - #{b}) div #{a} >= 0)]";
  1916. return new Template(predicate).evaluate({
  1917. fragment: fragment, a: a, b: b });
  1918. }
  1919. }
  1920. }
  1921. },
  1922. criteria: {
  1923. tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;',
  1924. className: 'n = h.className(n, r, "#{1}", c); c = false;',
  1925. id: 'n = h.id(n, r, "#{1}", c); c = false;',
  1926. attrPresence: 'n = h.attrPresence(n, r, "#{1}"); c = false;',
  1927. attr: function(m) {
  1928. m[3] = (m[5] || m[6]);
  1929. return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}"); c = false;').evaluate(m);
  1930. },
  1931. pseudo: function(m) {
  1932. if (m[6]) m[6] = m[6].replace(/"/g, '\\"');
  1933. return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m);
  1934. },
  1935. descendant: 'c = "descendant";',
  1936. child: 'c = "child";',
  1937. adjacent: 'c = "adjacent";',
  1938. laterSibling: 'c = "laterSibling";'
  1939. },
  1940. patterns: {
  1941. // combinators must be listed first
  1942. // (and descendant needs to be last combinator)
  1943. laterSibling: /^\s*~\s*/,
  1944. child: /^\s*>\s*/,
  1945. adjacent: /^\s*\+\s*/,
  1946. descendant: /^\s/,
  1947. // selectors follow
  1948. tagName: /^\s*(\*|[\w\-]+)(\b|$)?/,
  1949. id: /^#([\w\-\*]+)(\b|$)/,
  1950. className: /^\.([\w\-\*]+)(\b|$)/,
  1951. pseudo: /^:((first|last|nth|nth-last|