PageRenderTime 69ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/test-data/scriptaculous-raw.js

https://github.com/aristus/parse-n-load
JavaScript | 8467 lines | 7824 code | 480 blank | 163 comment | 767 complexity | 2bcf66334b8291f3b20cebf97348d4f4 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /* Prototype JavaScript framework, version 1.6.1
  2. * (c) 2005-2009 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.6.1',
  10. Browser: (function(){
  11. var ua = navigator.userAgent;
  12. var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
  13. return {
  14. IE: !!window.attachEvent && !isOpera,
  15. Opera: isOpera,
  16. WebKit: ua.indexOf('AppleWebKit/') > -1,
  17. Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
  18. MobileSafari: /Apple.*Mobile.*Safari/.test(ua)
  19. }
  20. })(),
  21. BrowserFeatures: {
  22. XPath: !!document.evaluate,
  23. SelectorsAPI: !!document.querySelector,
  24. ElementExtensions: (function() {
  25. var constructor = window.Element || window.HTMLElement;
  26. return !!(constructor && constructor.prototype);
  27. })(),
  28. SpecificElementExtensions: (function() {
  29. if (typeof window.HTMLDivElement !== 'undefined')
  30. return true;
  31. var div = document.createElement('div');
  32. var form = document.createElement('form');
  33. var isSupported = false;
  34. if (div['__proto__'] && (div['__proto__'] !== form['__proto__'])) {
  35. isSupported = true;
  36. }
  37. div = form = null;
  38. return isSupported;
  39. })()
  40. },
  41. ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
  42. JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
  43. emptyFunction: function() { },
  44. K: function(x) { return x }
  45. };
  46. if (Prototype.Browser.MobileSafari)
  47. Prototype.BrowserFeatures.SpecificElementExtensions = false;
  48. var Abstract = { };
  49. var Try = {
  50. these: function() {
  51. var returnValue;
  52. for (var i = 0, length = arguments.length; i < length; i++) {
  53. var lambda = arguments[i];
  54. try {
  55. returnValue = lambda();
  56. break;
  57. } catch (e) { }
  58. }
  59. return returnValue;
  60. }
  61. };
  62. /* Based on Alex Arnell's inheritance implementation. */
  63. var Class = (function() {
  64. function subclass() {};
  65. function create() {
  66. var parent = null, properties = $A(arguments);
  67. if (Object.isFunction(properties[0]))
  68. parent = properties.shift();
  69. function klass() {
  70. this.initialize.apply(this, arguments);
  71. }
  72. Object.extend(klass, Class.Methods);
  73. klass.superclass = parent;
  74. klass.subclasses = [];
  75. if (parent) {
  76. subclass.prototype = parent.prototype;
  77. klass.prototype = new subclass;
  78. parent.subclasses.push(klass);
  79. }
  80. for (var i = 0; i < properties.length; i++)
  81. klass.addMethods(properties[i]);
  82. if (!klass.prototype.initialize)
  83. klass.prototype.initialize = Prototype.emptyFunction;
  84. klass.prototype.constructor = klass;
  85. return klass;
  86. }
  87. function addMethods(source) {
  88. var ancestor = this.superclass && this.superclass.prototype;
  89. var properties = Object.keys(source);
  90. if (!Object.keys({ toString: true }).length) {
  91. if (source.toString != Object.prototype.toString)
  92. properties.push("toString");
  93. if (source.valueOf != Object.prototype.valueOf)
  94. properties.push("valueOf");
  95. }
  96. for (var i = 0, length = properties.length; i < length; i++) {
  97. var property = properties[i], value = source[property];
  98. if (ancestor && Object.isFunction(value) &&
  99. value.argumentNames().first() == "$super") {
  100. var method = value;
  101. value = (function(m) {
  102. return function() { return ancestor[m].apply(this, arguments); };
  103. })(property).wrap(method);
  104. value.valueOf = method.valueOf.bind(method);
  105. value.toString = method.toString.bind(method);
  106. }
  107. this.prototype[property] = value;
  108. }
  109. return this;
  110. }
  111. return {
  112. create: create,
  113. Methods: {
  114. addMethods: addMethods
  115. }
  116. };
  117. })();
  118. (function() {
  119. var _toString = Object.prototype.toString;
  120. function extend(destination, source) {
  121. for (var property in source)
  122. destination[property] = source[property];
  123. return destination;
  124. }
  125. function inspect(object) {
  126. try {
  127. if (isUndefined(object)) return 'undefined';
  128. if (object === null) return 'null';
  129. return object.inspect ? object.inspect() : String(object);
  130. } catch (e) {
  131. if (e instanceof RangeError) return '...';
  132. throw e;
  133. }
  134. }
  135. function toJSON(object) {
  136. var type = typeof object;
  137. switch (type) {
  138. case 'undefined':
  139. case 'function':
  140. case 'unknown': return;
  141. case 'boolean': return object.toString();
  142. }
  143. if (object === null) return 'null';
  144. if (object.toJSON) return object.toJSON();
  145. if (isElement(object)) return;
  146. var results = [];
  147. for (var property in object) {
  148. var value = toJSON(object[property]);
  149. if (!isUndefined(value))
  150. results.push(property.toJSON() + ': ' + value);
  151. }
  152. return '{' + results.join(', ') + '}';
  153. }
  154. function toQueryString(object) {
  155. return $H(object).toQueryString();
  156. }
  157. function toHTML(object) {
  158. return object && object.toHTML ? object.toHTML() : String.interpret(object);
  159. }
  160. function keys(object) {
  161. var results = [];
  162. for (var property in object)
  163. results.push(property);
  164. return results;
  165. }
  166. function values(object) {
  167. var results = [];
  168. for (var property in object)
  169. results.push(object[property]);
  170. return results;
  171. }
  172. function clone(object) {
  173. return extend({ }, object);
  174. }
  175. function isElement(object) {
  176. return !!(object && object.nodeType == 1);
  177. }
  178. function isArray(object) {
  179. return _toString.call(object) == "[object Array]";
  180. }
  181. function isHash(object) {
  182. return object instanceof Hash;
  183. }
  184. function isFunction(object) {
  185. return typeof object === "function";
  186. }
  187. function isString(object) {
  188. return _toString.call(object) == "[object String]";
  189. }
  190. function isNumber(object) {
  191. return _toString.call(object) == "[object Number]";
  192. }
  193. function isUndefined(object) {
  194. return typeof object === "undefined";
  195. }
  196. extend(Object, {
  197. extend: extend,
  198. inspect: inspect,
  199. toJSON: toJSON,
  200. toQueryString: toQueryString,
  201. toHTML: toHTML,
  202. keys: keys,
  203. values: values,
  204. clone: clone,
  205. isElement: isElement,
  206. isArray: isArray,
  207. isHash: isHash,
  208. isFunction: isFunction,
  209. isString: isString,
  210. isNumber: isNumber,
  211. isUndefined: isUndefined
  212. });
  213. })();
  214. Object.extend(Function.prototype, (function() {
  215. var slice = Array.prototype.slice;
  216. function update(array, args) {
  217. var arrayLength = array.length, length = args.length;
  218. while (length--) array[arrayLength + length] = args[length];
  219. return array;
  220. }
  221. function merge(array, args) {
  222. array = slice.call(array, 0);
  223. return update(array, args);
  224. }
  225. function argumentNames() {
  226. var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
  227. .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
  228. .replace(/\s+/g, '').split(',');
  229. return names.length == 1 && !names[0] ? [] : names;
  230. }
  231. function bind(context) {
  232. if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
  233. var __method = this, args = slice.call(arguments, 1);
  234. return function() {
  235. var a = merge(args, arguments);
  236. return __method.apply(context, a);
  237. }
  238. }
  239. function bindAsEventListener(context) {
  240. var __method = this, args = slice.call(arguments, 1);
  241. return function(event) {
  242. var a = update([event || window.event], args);
  243. return __method.apply(context, a);
  244. }
  245. }
  246. function curry() {
  247. if (!arguments.length) return this;
  248. var __method = this, args = slice.call(arguments, 0);
  249. return function() {
  250. var a = merge(args, arguments);
  251. return __method.apply(this, a);
  252. }
  253. }
  254. function delay(timeout) {
  255. var __method = this, args = slice.call(arguments, 1);
  256. timeout = timeout * 1000
  257. return window.setTimeout(function() {
  258. return __method.apply(__method, args);
  259. }, timeout);
  260. }
  261. function defer() {
  262. var args = update([0.01], arguments);
  263. return this.delay.apply(this, args);
  264. }
  265. function wrap(wrapper) {
  266. var __method = this;
  267. return function() {
  268. var a = update([__method.bind(this)], arguments);
  269. return wrapper.apply(this, a);
  270. }
  271. }
  272. function methodize() {
  273. if (this._methodized) return this._methodized;
  274. var __method = this;
  275. return this._methodized = function() {
  276. var a = update([this], arguments);
  277. return __method.apply(null, a);
  278. };
  279. }
  280. return {
  281. argumentNames: argumentNames,
  282. bind: bind,
  283. bindAsEventListener: bindAsEventListener,
  284. curry: curry,
  285. delay: delay,
  286. defer: defer,
  287. wrap: wrap,
  288. methodize: methodize
  289. }
  290. })());
  291. Date.prototype.toJSON = function() {
  292. return '"' + this.getUTCFullYear() + '-' +
  293. (this.getUTCMonth() + 1).toPaddedString(2) + '-' +
  294. this.getUTCDate().toPaddedString(2) + 'T' +
  295. this.getUTCHours().toPaddedString(2) + ':' +
  296. this.getUTCMinutes().toPaddedString(2) + ':' +
  297. this.getUTCSeconds().toPaddedString(2) + 'Z"';
  298. };
  299. RegExp.prototype.match = RegExp.prototype.test;
  300. RegExp.escape = function(str) {
  301. return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
  302. };
  303. var PeriodicalExecuter = Class.create({
  304. initialize: function(callback, frequency) {
  305. this.callback = callback;
  306. this.frequency = frequency;
  307. this.currentlyExecuting = false;
  308. this.registerCallback();
  309. },
  310. registerCallback: function() {
  311. this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
  312. },
  313. execute: function() {
  314. this.callback(this);
  315. },
  316. stop: function() {
  317. if (!this.timer) return;
  318. clearInterval(this.timer);
  319. this.timer = null;
  320. },
  321. onTimerEvent: function() {
  322. if (!this.currentlyExecuting) {
  323. try {
  324. this.currentlyExecuting = true;
  325. this.execute();
  326. this.currentlyExecuting = false;
  327. } catch(e) {
  328. this.currentlyExecuting = false;
  329. throw e;
  330. }
  331. }
  332. }
  333. });
  334. Object.extend(String, {
  335. interpret: function(value) {
  336. return value == null ? '' : String(value);
  337. },
  338. specialChar: {
  339. '\b': '\\b',
  340. '\t': '\\t',
  341. '\n': '\\n',
  342. '\f': '\\f',
  343. '\r': '\\r',
  344. '\\': '\\\\'
  345. }
  346. });
  347. Object.extend(String.prototype, (function() {
  348. function prepareReplacement(replacement) {
  349. if (Object.isFunction(replacement)) return replacement;
  350. var template = new Template(replacement);
  351. return function(match) { return template.evaluate(match) };
  352. }
  353. function gsub(pattern, replacement) {
  354. var result = '', source = this, match;
  355. replacement = prepareReplacement(replacement);
  356. if (Object.isString(pattern))
  357. pattern = RegExp.escape(pattern);
  358. if (!(pattern.length || pattern.source)) {
  359. replacement = replacement('');
  360. return replacement + source.split('').join(replacement) + replacement;
  361. }
  362. while (source.length > 0) {
  363. if (match = source.match(pattern)) {
  364. result += source.slice(0, match.index);
  365. result += String.interpret(replacement(match));
  366. source = source.slice(match.index + match[0].length);
  367. } else {
  368. result += source, source = '';
  369. }
  370. }
  371. return result;
  372. }
  373. function sub(pattern, replacement, count) {
  374. replacement = prepareReplacement(replacement);
  375. count = Object.isUndefined(count) ? 1 : count;
  376. return this.gsub(pattern, function(match) {
  377. if (--count < 0) return match[0];
  378. return replacement(match);
  379. });
  380. }
  381. function scan(pattern, iterator) {
  382. this.gsub(pattern, iterator);
  383. return String(this);
  384. }
  385. function truncate(length, truncation) {
  386. length = length || 30;
  387. truncation = Object.isUndefined(truncation) ? '...' : truncation;
  388. return this.length > length ?
  389. this.slice(0, length - truncation.length) + truncation : String(this);
  390. }
  391. function strip() {
  392. return this.replace(/^\s+/, '').replace(/\s+$/, '');
  393. }
  394. function stripTags() {
  395. return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi, '');
  396. }
  397. function stripScripts() {
  398. return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
  399. }
  400. function extractScripts() {
  401. var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
  402. var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
  403. return (this.match(matchAll) || []).map(function(scriptTag) {
  404. return (scriptTag.match(matchOne) || ['', ''])[1];
  405. });
  406. }
  407. function evalScripts() {
  408. return this.extractScripts().map(function(script) { return eval(script) });
  409. }
  410. function escapeHTML() {
  411. return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
  412. }
  413. function unescapeHTML() {
  414. return this.stripTags().replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
  415. }
  416. function toQueryParams(separator) {
  417. var match = this.strip().match(/([^?#]*)(#.*)?$/);
  418. if (!match) return { };
  419. return match[1].split(separator || '&').inject({ }, function(hash, pair) {
  420. if ((pair = pair.split('='))[0]) {
  421. var key = decodeURIComponent(pair.shift());
  422. var value = pair.length > 1 ? pair.join('=') : pair[0];
  423. if (value != undefined) value = decodeURIComponent(value);
  424. if (key in hash) {
  425. if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
  426. hash[key].push(value);
  427. }
  428. else hash[key] = value;
  429. }
  430. return hash;
  431. });
  432. }
  433. function toArray() {
  434. return this.split('');
  435. }
  436. function succ() {
  437. return this.slice(0, this.length - 1) +
  438. String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
  439. }
  440. function times(count) {
  441. return count < 1 ? '' : new Array(count + 1).join(this);
  442. }
  443. function camelize() {
  444. var parts = this.split('-'), len = parts.length;
  445. if (len == 1) return parts[0];
  446. var camelized = this.charAt(0) == '-'
  447. ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
  448. : parts[0];
  449. for (var i = 1; i < len; i++)
  450. camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
  451. return camelized;
  452. }
  453. function capitalize() {
  454. return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
  455. }
  456. function underscore() {
  457. return this.replace(/::/g, '/')
  458. .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
  459. .replace(/([a-z\d])([A-Z])/g, '$1_$2')
  460. .replace(/-/g, '_')
  461. .toLowerCase();
  462. }
  463. function dasherize() {
  464. return this.replace(/_/g, '-');
  465. }
  466. function inspect(useDoubleQuotes) {
  467. var escapedString = this.replace(/[\x00-\x1f\\]/g, function(character) {
  468. if (character in String.specialChar) {
  469. return String.specialChar[character];
  470. }
  471. return '\\u00' + character.charCodeAt().toPaddedString(2, 16);
  472. });
  473. if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
  474. return "'" + escapedString.replace(/'/g, '\\\'') + "'";
  475. }
  476. function toJSON() {
  477. return this.inspect(true);
  478. }
  479. function unfilterJSON(filter) {
  480. return this.replace(filter || Prototype.JSONFilter, '$1');
  481. }
  482. function isJSON() {
  483. var str = this;
  484. if (str.blank()) return false;
  485. str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
  486. return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
  487. }
  488. function evalJSON(sanitize) {
  489. var json = this.unfilterJSON();
  490. try {
  491. if (!sanitize || json.isJSON()) return eval('(' + json + ')');
  492. } catch (e) { }
  493. throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
  494. }
  495. function include(pattern) {
  496. return this.indexOf(pattern) > -1;
  497. }
  498. function startsWith(pattern) {
  499. return this.indexOf(pattern) === 0;
  500. }
  501. function endsWith(pattern) {
  502. var d = this.length - pattern.length;
  503. return d >= 0 && this.lastIndexOf(pattern) === d;
  504. }
  505. function empty() {
  506. return this == '';
  507. }
  508. function blank() {
  509. return /^\s*$/.test(this);
  510. }
  511. function interpolate(object, pattern) {
  512. return new Template(this, pattern).evaluate(object);
  513. }
  514. return {
  515. gsub: gsub,
  516. sub: sub,
  517. scan: scan,
  518. truncate: truncate,
  519. strip: String.prototype.trim ? String.prototype.trim : strip,
  520. stripTags: stripTags,
  521. stripScripts: stripScripts,
  522. extractScripts: extractScripts,
  523. evalScripts: evalScripts,
  524. escapeHTML: escapeHTML,
  525. unescapeHTML: unescapeHTML,
  526. toQueryParams: toQueryParams,
  527. parseQuery: toQueryParams,
  528. toArray: toArray,
  529. succ: succ,
  530. times: times,
  531. camelize: camelize,
  532. capitalize: capitalize,
  533. underscore: underscore,
  534. dasherize: dasherize,
  535. inspect: inspect,
  536. toJSON: toJSON,
  537. unfilterJSON: unfilterJSON,
  538. isJSON: isJSON,
  539. evalJSON: evalJSON,
  540. include: include,
  541. startsWith: startsWith,
  542. endsWith: endsWith,
  543. empty: empty,
  544. blank: blank,
  545. interpolate: interpolate
  546. };
  547. })());
  548. var Template = Class.create({
  549. initialize: function(template, pattern) {
  550. this.template = template.toString();
  551. this.pattern = pattern || Template.Pattern;
  552. },
  553. evaluate: function(object) {
  554. if (object && Object.isFunction(object.toTemplateReplacements))
  555. object = object.toTemplateReplacements();
  556. return this.template.gsub(this.pattern, function(match) {
  557. if (object == null) return (match[1] + '');
  558. var before = match[1] || '';
  559. if (before == '\\') return match[2];
  560. var ctx = object, expr = match[3];
  561. var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
  562. match = pattern.exec(expr);
  563. if (match == null) return before;
  564. while (match != null) {
  565. var comp = match[1].startsWith('[') ? match[2].replace(/\\\\]/g, ']') : match[1];
  566. ctx = ctx[comp];
  567. if (null == ctx || '' == match[3]) break;
  568. expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
  569. match = pattern.exec(expr);
  570. }
  571. return before + String.interpret(ctx);
  572. });
  573. }
  574. });
  575. Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
  576. var $break = { };
  577. var Enumerable = (function() {
  578. function each(iterator, context) {
  579. var index = 0;
  580. try {
  581. this._each(function(value) {
  582. iterator.call(context, value, index++);
  583. });
  584. } catch (e) {
  585. if (e != $break) throw e;
  586. }
  587. return this;
  588. }
  589. function eachSlice(number, iterator, context) {
  590. var index = -number, slices = [], array = this.toArray();
  591. if (number < 1) return array;
  592. while ((index += number) < array.length)
  593. slices.push(array.slice(index, index+number));
  594. return slices.collect(iterator, context);
  595. }
  596. function all(iterator, context) {
  597. iterator = iterator || Prototype.K;
  598. var result = true;
  599. this.each(function(value, index) {
  600. result = result && !!iterator.call(context, value, index);
  601. if (!result) throw $break;
  602. });
  603. return result;
  604. }
  605. function any(iterator, context) {
  606. iterator = iterator || Prototype.K;
  607. var result = false;
  608. this.each(function(value, index) {
  609. if (result = !!iterator.call(context, value, index))
  610. throw $break;
  611. });
  612. return result;
  613. }
  614. function collect(iterator, context) {
  615. iterator = iterator || Prototype.K;
  616. var results = [];
  617. this.each(function(value, index) {
  618. results.push(iterator.call(context, value, index));
  619. });
  620. return results;
  621. }
  622. function detect(iterator, context) {
  623. var result;
  624. this.each(function(value, index) {
  625. if (iterator.call(context, value, index)) {
  626. result = value;
  627. throw $break;
  628. }
  629. });
  630. return result;
  631. }
  632. function findAll(iterator, context) {
  633. var results = [];
  634. this.each(function(value, index) {
  635. if (iterator.call(context, value, index))
  636. results.push(value);
  637. });
  638. return results;
  639. }
  640. function grep(filter, iterator, context) {
  641. iterator = iterator || Prototype.K;
  642. var results = [];
  643. if (Object.isString(filter))
  644. filter = new RegExp(RegExp.escape(filter));
  645. this.each(function(value, index) {
  646. if (filter.match(value))
  647. results.push(iterator.call(context, value, index));
  648. });
  649. return results;
  650. }
  651. function include(object) {
  652. if (Object.isFunction(this.indexOf))
  653. if (this.indexOf(object) != -1) return true;
  654. var found = false;
  655. this.each(function(value) {
  656. if (value == object) {
  657. found = true;
  658. throw $break;
  659. }
  660. });
  661. return found;
  662. }
  663. function inGroupsOf(number, fillWith) {
  664. fillWith = Object.isUndefined(fillWith) ? null : fillWith;
  665. return this.eachSlice(number, function(slice) {
  666. while(slice.length < number) slice.push(fillWith);
  667. return slice;
  668. });
  669. }
  670. function inject(memo, iterator, context) {
  671. this.each(function(value, index) {
  672. memo = iterator.call(context, memo, value, index);
  673. });
  674. return memo;
  675. }
  676. function invoke(method) {
  677. var args = $A(arguments).slice(1);
  678. return this.map(function(value) {
  679. return value[method].apply(value, args);
  680. });
  681. }
  682. function max(iterator, context) {
  683. iterator = iterator || Prototype.K;
  684. var result;
  685. this.each(function(value, index) {
  686. value = iterator.call(context, value, index);
  687. if (result == null || value >= result)
  688. result = value;
  689. });
  690. return result;
  691. }
  692. function min(iterator, context) {
  693. iterator = iterator || Prototype.K;
  694. var result;
  695. this.each(function(value, index) {
  696. value = iterator.call(context, value, index);
  697. if (result == null || value < result)
  698. result = value;
  699. });
  700. return result;
  701. }
  702. function partition(iterator, context) {
  703. iterator = iterator || Prototype.K;
  704. var trues = [], falses = [];
  705. this.each(function(value, index) {
  706. (iterator.call(context, value, index) ?
  707. trues : falses).push(value);
  708. });
  709. return [trues, falses];
  710. }
  711. function pluck(property) {
  712. var results = [];
  713. this.each(function(value) {
  714. results.push(value[property]);
  715. });
  716. return results;
  717. }
  718. function reject(iterator, context) {
  719. var results = [];
  720. this.each(function(value, index) {
  721. if (!iterator.call(context, value, index))
  722. results.push(value);
  723. });
  724. return results;
  725. }
  726. function sortBy(iterator, context) {
  727. return this.map(function(value, index) {
  728. return {
  729. value: value,
  730. criteria: iterator.call(context, value, index)
  731. };
  732. }).sort(function(left, right) {
  733. var a = left.criteria, b = right.criteria;
  734. return a < b ? -1 : a > b ? 1 : 0;
  735. }).pluck('value');
  736. }
  737. function toArray() {
  738. return this.map();
  739. }
  740. function zip() {
  741. var iterator = Prototype.K, args = $A(arguments);
  742. if (Object.isFunction(args.last()))
  743. iterator = args.pop();
  744. var collections = [this].concat(args).map($A);
  745. return this.map(function(value, index) {
  746. return iterator(collections.pluck(index));
  747. });
  748. }
  749. function size() {
  750. return this.toArray().length;
  751. }
  752. function inspect() {
  753. return '#<Enumerable:' + this.toArray().inspect() + '>';
  754. }
  755. return {
  756. each: each,
  757. eachSlice: eachSlice,
  758. all: all,
  759. every: all,
  760. any: any,
  761. some: any,
  762. collect: collect,
  763. map: collect,
  764. detect: detect,
  765. findAll: findAll,
  766. select: findAll,
  767. filter: findAll,
  768. grep: grep,
  769. include: include,
  770. member: include,
  771. inGroupsOf: inGroupsOf,
  772. inject: inject,
  773. invoke: invoke,
  774. max: max,
  775. min: min,
  776. partition: partition,
  777. pluck: pluck,
  778. reject: reject,
  779. sortBy: sortBy,
  780. toArray: toArray,
  781. entries: toArray,
  782. zip: zip,
  783. size: size,
  784. inspect: inspect,
  785. find: detect
  786. };
  787. })();
  788. function $A(iterable) {
  789. if (!iterable) return [];
  790. if ('toArray' in Object(iterable)) return iterable.toArray();
  791. var length = iterable.length || 0, results = new Array(length);
  792. while (length--) results[length] = iterable[length];
  793. return results;
  794. }
  795. function $w(string) {
  796. if (!Object.isString(string)) return [];
  797. string = string.strip();
  798. return string ? string.split(/\s+/) : [];
  799. }
  800. Array.from = $A;
  801. (function() {
  802. var arrayProto = Array.prototype,
  803. slice = arrayProto.slice,
  804. _each = arrayProto.forEach; // use native browser JS 1.6 implementation if available
  805. function each(iterator) {
  806. for (var i = 0, length = this.length; i < length; i++)
  807. iterator(this[i]);
  808. }
  809. if (!_each) _each = each;
  810. function clear() {
  811. this.length = 0;
  812. return this;
  813. }
  814. function first() {
  815. return this[0];
  816. }
  817. function last() {
  818. return this[this.length - 1];
  819. }
  820. function compact() {
  821. return this.select(function(value) {
  822. return value != null;
  823. });
  824. }
  825. function flatten() {
  826. return this.inject([], function(array, value) {
  827. if (Object.isArray(value))
  828. return array.concat(value.flatten());
  829. array.push(value);
  830. return array;
  831. });
  832. }
  833. function without() {
  834. var values = slice.call(arguments, 0);
  835. return this.select(function(value) {
  836. return !values.include(value);
  837. });
  838. }
  839. function reverse(inline) {
  840. return (inline !== false ? this : this.toArray())._reverse();
  841. }
  842. function uniq(sorted) {
  843. return this.inject([], function(array, value, index) {
  844. if (0 == index || (sorted ? array.last() != value : !array.include(value)))
  845. array.push(value);
  846. return array;
  847. });
  848. }
  849. function intersect(array) {
  850. return this.uniq().findAll(function(item) {
  851. return array.detect(function(value) { return item === value });
  852. });
  853. }
  854. function clone() {
  855. return slice.call(this, 0);
  856. }
  857. function size() {
  858. return this.length;
  859. }
  860. function inspect() {
  861. return '[' + this.map(Object.inspect).join(', ') + ']';
  862. }
  863. function toJSON() {
  864. var results = [];
  865. this.each(function(object) {
  866. var value = Object.toJSON(object);
  867. if (!Object.isUndefined(value)) results.push(value);
  868. });
  869. return '[' + results.join(', ') + ']';
  870. }
  871. function indexOf(item, i) {
  872. i || (i = 0);
  873. var length = this.length;
  874. if (i < 0) i = length + i;
  875. for (; i < length; i++)
  876. if (this[i] === item) return i;
  877. return -1;
  878. }
  879. function lastIndexOf(item, i) {
  880. i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;
  881. var n = this.slice(0, i).reverse().indexOf(item);
  882. return (n < 0) ? n : i - n - 1;
  883. }
  884. function concat() {
  885. var array = slice.call(this, 0), item;
  886. for (var i = 0, length = arguments.length; i < length; i++) {
  887. item = arguments[i];
  888. if (Object.isArray(item) && !('callee' in item)) {
  889. for (var j = 0, arrayLength = item.length; j < arrayLength; j++)
  890. array.push(item[j]);
  891. } else {
  892. array.push(item);
  893. }
  894. }
  895. return array;
  896. }
  897. Object.extend(arrayProto, Enumerable);
  898. if (!arrayProto._reverse)
  899. arrayProto._reverse = arrayProto.reverse;
  900. Object.extend(arrayProto, {
  901. _each: _each,
  902. clear: clear,
  903. first: first,
  904. last: last,
  905. compact: compact,
  906. flatten: flatten,
  907. without: without,
  908. reverse: reverse,
  909. uniq: uniq,
  910. intersect: intersect,
  911. clone: clone,
  912. toArray: clone,
  913. size: size,
  914. inspect: inspect,
  915. toJSON: toJSON
  916. });
  917. var CONCAT_ARGUMENTS_BUGGY = (function() {
  918. return [].concat(arguments)[0][0] !== 1;
  919. })(1,2)
  920. if (CONCAT_ARGUMENTS_BUGGY) arrayProto.concat = concat;
  921. if (!arrayProto.indexOf) arrayProto.indexOf = indexOf;
  922. if (!arrayProto.lastIndexOf) arrayProto.lastIndexOf = lastIndexOf;
  923. })();
  924. function $H(object) {
  925. return new Hash(object);
  926. };
  927. var Hash = Class.create(Enumerable, (function() {
  928. function initialize(object) {
  929. this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
  930. }
  931. function _each(iterator) {
  932. for (var key in this._object) {
  933. var value = this._object[key], pair = [key, value];
  934. pair.key = key;
  935. pair.value = value;
  936. iterator(pair);
  937. }
  938. }
  939. function set(key, value) {
  940. return this._object[key] = value;
  941. }
  942. function get(key) {
  943. if (this._object[key] !== Object.prototype[key])
  944. return this._object[key];
  945. }
  946. function unset(key) {
  947. var value = this._object[key];
  948. delete this._object[key];
  949. return value;
  950. }
  951. function toObject() {
  952. return Object.clone(this._object);
  953. }
  954. function keys() {
  955. return this.pluck('key');
  956. }
  957. function values() {
  958. return this.pluck('value');
  959. }
  960. function index(value) {
  961. var match = this.detect(function(pair) {
  962. return pair.value === value;
  963. });
  964. return match && match.key;
  965. }
  966. function merge(object) {
  967. return this.clone().update(object);
  968. }
  969. function update(object) {
  970. return new Hash(object).inject(this, function(result, pair) {
  971. result.set(pair.key, pair.value);
  972. return result;
  973. });
  974. }
  975. function toQueryPair(key, value) {
  976. if (Object.isUndefined(value)) return key;
  977. return key + '=' + encodeURIComponent(String.interpret(value));
  978. }
  979. function toQueryString() {
  980. return this.inject([], function(results, pair) {
  981. var key = encodeURIComponent(pair.key), values = pair.value;
  982. if (values && typeof values == 'object') {
  983. if (Object.isArray(values))
  984. return results.concat(values.map(toQueryPair.curry(key)));
  985. } else results.push(toQueryPair(key, values));
  986. return results;
  987. }).join('&');
  988. }
  989. function inspect() {
  990. return '#<Hash:{' + this.map(function(pair) {
  991. return pair.map(Object.inspect).join(': ');
  992. }).join(', ') + '}>';
  993. }
  994. function toJSON() {
  995. return Object.toJSON(this.toObject());
  996. }
  997. function clone() {
  998. return new Hash(this);
  999. }
  1000. return {
  1001. initialize: initialize,
  1002. _each: _each,
  1003. set: set,
  1004. get: get,
  1005. unset: unset,
  1006. toObject: toObject,
  1007. toTemplateReplacements: toObject,
  1008. keys: keys,
  1009. values: values,
  1010. index: index,
  1011. merge: merge,
  1012. update: update,
  1013. toQueryString: toQueryString,
  1014. inspect: inspect,
  1015. toJSON: toJSON,
  1016. clone: clone
  1017. };
  1018. })());
  1019. Hash.from = $H;
  1020. Object.extend(Number.prototype, (function() {
  1021. function toColorPart() {
  1022. return this.toPaddedString(2, 16);
  1023. }
  1024. function succ() {
  1025. return this + 1;
  1026. }
  1027. function times(iterator, context) {
  1028. $R(0, this, true).each(iterator, context);
  1029. return this;
  1030. }
  1031. function toPaddedString(length, radix) {
  1032. var string = this.toString(radix || 10);
  1033. return '0'.times(length - string.length) + string;
  1034. }
  1035. function toJSON() {
  1036. return isFinite(this) ? this.toString() : 'null';
  1037. }
  1038. function abs() {
  1039. return Math.abs(this);
  1040. }
  1041. function round() {
  1042. return Math.round(this);
  1043. }
  1044. function ceil() {
  1045. return Math.ceil(this);
  1046. }
  1047. function floor() {
  1048. return Math.floor(this);
  1049. }
  1050. return {
  1051. toColorPart: toColorPart,
  1052. succ: succ,
  1053. times: times,
  1054. toPaddedString: toPaddedString,
  1055. toJSON: toJSON,
  1056. abs: abs,
  1057. round: round,
  1058. ceil: ceil,
  1059. floor: floor
  1060. };
  1061. })());
  1062. function $R(start, end, exclusive) {
  1063. return new ObjectRange(start, end, exclusive);
  1064. }
  1065. var ObjectRange = Class.create(Enumerable, (function() {
  1066. function initialize(start, end, exclusive) {
  1067. this.start = start;
  1068. this.end = end;
  1069. this.exclusive = exclusive;
  1070. }
  1071. function _each(iterator) {
  1072. var value = this.start;
  1073. while (this.include(value)) {
  1074. iterator(value);
  1075. value = value.succ();
  1076. }
  1077. }
  1078. function include(value) {
  1079. if (value < this.start)
  1080. return false;
  1081. if (this.exclusive)
  1082. return value < this.end;
  1083. return value <= this.end;
  1084. }
  1085. return {
  1086. initialize: initialize,
  1087. _each: _each,
  1088. include: include
  1089. };
  1090. })());
  1091. var Ajax = {
  1092. getTransport: function() {
  1093. return Try.these(
  1094. function() {return new XMLHttpRequest()},
  1095. function() {return new ActiveXObject('Msxml2.XMLHTTP')},
  1096. function() {return new ActiveXObject('Microsoft.XMLHTTP')}
  1097. ) || false;
  1098. },
  1099. activeRequestCount: 0
  1100. };
  1101. Ajax.Responders = {
  1102. responders: [],
  1103. _each: function(iterator) {
  1104. this.responders._each(iterator);
  1105. },
  1106. register: function(responder) {
  1107. if (!this.include(responder))
  1108. this.responders.push(responder);
  1109. },
  1110. unregister: function(responder) {
  1111. this.responders = this.responders.without(responder);
  1112. },
  1113. dispatch: function(callback, request, transport, json) {
  1114. this.each(function(responder) {
  1115. if (Object.isFunction(responder[callback])) {
  1116. try {
  1117. responder[callback].apply(responder, [request, transport, json]);
  1118. } catch (e) { }
  1119. }
  1120. });
  1121. }
  1122. };
  1123. Object.extend(Ajax.Responders, Enumerable);
  1124. Ajax.Responders.register({
  1125. onCreate: function() { Ajax.activeRequestCount++ },
  1126. onComplete: function() { Ajax.activeRequestCount-- }
  1127. });
  1128. Ajax.Base = Class.create({
  1129. initialize: function(options) {
  1130. this.options = {
  1131. method: 'post',
  1132. asynchronous: true,
  1133. contentType: 'application/x-www-form-urlencoded',
  1134. encoding: 'UTF-8',
  1135. parameters: '',
  1136. evalJSON: true,
  1137. evalJS: true
  1138. };
  1139. Object.extend(this.options, options || { });
  1140. this.options.method = this.options.method.toLowerCase();
  1141. if (Object.isString(this.options.parameters))
  1142. this.options.parameters = this.options.parameters.toQueryParams();
  1143. else if (Object.isHash(this.options.parameters))
  1144. this.options.parameters = this.options.parameters.toObject();
  1145. }
  1146. });
  1147. Ajax.Request = Class.create(Ajax.Base, {
  1148. _complete: false,
  1149. initialize: function($super, url, options) {
  1150. $super(options);
  1151. this.transport = Ajax.getTransport();
  1152. this.request(url);
  1153. },
  1154. request: function(url) {
  1155. this.url = url;
  1156. this.method = this.options.method;
  1157. var params = Object.clone(this.options.parameters);
  1158. if (!['get', 'post'].include(this.method)) {
  1159. params['_method'] = this.method;
  1160. this.method = 'post';
  1161. }
  1162. this.parameters = params;
  1163. if (params = Object.toQueryString(params)) {
  1164. if (this.method == 'get')
  1165. this.url += (this.url.include('?') ? '&' : '?') + params;
  1166. else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))
  1167. params += '&_=';
  1168. }
  1169. try {
  1170. var response = new Ajax.Response(this);
  1171. if (this.options.onCreate) this.options.onCreate(response);
  1172. Ajax.Responders.dispatch('onCreate', this, response);
  1173. this.transport.open(this.method.toUpperCase(), this.url,
  1174. this.options.asynchronous);
  1175. if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
  1176. this.transport.onreadystatechange = this.onStateChange.bind(this);
  1177. this.setRequestHeaders();
  1178. this.body = this.method == 'post' ? (this.options.postBody || params) : null;
  1179. this.transport.send(this.body);
  1180. /* Force Firefox to handle ready state 4 for synchronous requests */
  1181. if (!this.options.asynchronous && this.transport.overrideMimeType)
  1182. this.onStateChange();
  1183. }
  1184. catch (e) {
  1185. this.dispatchException(e);
  1186. }
  1187. },
  1188. onStateChange: function() {
  1189. var readyState = this.transport.readyState;
  1190. if (readyState > 1 && !((readyState == 4) && this._complete))
  1191. this.respondToReadyState(this.transport.readyState);
  1192. },
  1193. setRequestHeaders: function() {
  1194. var headers = {
  1195. 'X-Requested-With': 'XMLHttpRequest',
  1196. 'X-Prototype-Version': Prototype.Version,
  1197. 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
  1198. };
  1199. if (this.method == 'post') {
  1200. headers['Content-type'] = this.options.contentType +
  1201. (this.options.encoding ? '; charset=' + this.options.encoding : '');
  1202. /* Force "Connection: close" for older Mozilla browsers to work
  1203. * around a bug where XMLHttpRequest sends an incorrect
  1204. * Content-length header. See Mozilla Bugzilla #246651.
  1205. */
  1206. if (this.transport.overrideMimeType &&
  1207. (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
  1208. headers['Connection'] = 'close';
  1209. }
  1210. if (typeof this.options.requestHeaders == 'object') {
  1211. var extras = this.options.requestHeaders;
  1212. if (Object.isFunction(extras.push))
  1213. for (var i = 0, length = extras.length; i < length; i += 2)
  1214. headers[extras[i]] = extras[i+1];
  1215. else
  1216. $H(extras).each(function(pair) { headers[pair.key] = pair.value });
  1217. }
  1218. for (var name in headers)
  1219. this.transport.setRequestHeader(name, headers[name]);
  1220. },
  1221. success: function() {
  1222. var status = this.getStatus();
  1223. return !status || (status >= 200 && status < 300);
  1224. },
  1225. getStatus: function() {
  1226. try {
  1227. return this.transport.status || 0;
  1228. } catch (e) { return 0 }
  1229. },
  1230. respondToReadyState: function(readyState) {
  1231. var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
  1232. if (state == 'Complete') {
  1233. try {
  1234. this._complete = true;
  1235. (this.options['on' + response.status]
  1236. || this.options['on' + (this.success() ? 'Success' : 'Failure')]
  1237. || Prototype.emptyFunction)(response, response.headerJSON);
  1238. } catch (e) {
  1239. this.dispatchException(e);
  1240. }
  1241. var contentType = response.getHeader('Content-type');
  1242. if (this.options.evalJS == 'force'
  1243. || (this.options.evalJS && this.isSameOrigin() && contentType
  1244. && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
  1245. this.evalResponse();
  1246. }
  1247. try {
  1248. (this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
  1249. Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
  1250. } catch (e) {
  1251. this.dispatchException(e);
  1252. }
  1253. if (state == 'Complete') {
  1254. this.transport.onreadystatechange = Prototype.emptyFunction;
  1255. }
  1256. },
  1257. isSameOrigin: function() {
  1258. var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
  1259. return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
  1260. protocol: location.protocol,
  1261. domain: document.domain,
  1262. port: location.port ? ':' + location.port : ''
  1263. }));
  1264. },
  1265. getHeader: function(name) {
  1266. try {
  1267. return this.transport.getResponseHeader(name) || null;
  1268. } catch (e) { return null; }
  1269. },
  1270. evalResponse: function() {
  1271. try {
  1272. return eval((this.transport.responseText || '').unfilterJSON());
  1273. } catch (e) {
  1274. this.dispatchException(e);
  1275. }
  1276. },
  1277. dispatchException: function(exception) {
  1278. (this.options.onException || Prototype.emptyFunction)(this, exception);
  1279. Ajax.Responders.dispatch('onException', this, exception);
  1280. }
  1281. });
  1282. Ajax.Request.Events =
  1283. ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
  1284. Ajax.Response = Class.create({
  1285. initialize: function(request){
  1286. this.request = request;
  1287. var transport = this.transport = request.transport,
  1288. readyState = this.readyState = transport.readyState;
  1289. if((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
  1290. this.status = this.getStatus();
  1291. this.statusText = this.getStatusText();
  1292. this.responseText = String.interpret(transport.responseText);
  1293. this.headerJSON = this._getHeaderJSON();
  1294. }
  1295. if(readyState == 4) {
  1296. var xml = transport.responseXML;
  1297. this.responseXML = Object.isUndefined(xml) ? null : xml;
  1298. this.responseJSON = this._getResponseJSON();
  1299. }
  1300. },
  1301. status: 0,
  1302. statusText: '',
  1303. getStatus: Ajax.Request.prototype.getStatus,
  1304. getStatusText: function() {
  1305. try {
  1306. return this.transport.statusText || '';
  1307. } catch (e) { return '' }
  1308. },
  1309. getHeader: Ajax.Request.prototype.getHeader,
  1310. getAllHeaders: function() {
  1311. try {
  1312. return this.getAllResponseHeaders();
  1313. } catch (e) { return null }
  1314. },
  1315. getResponseHeader: function(name) {
  1316. return this.transport.getResponseHeader(name);
  1317. },
  1318. getAllResponseHeaders: function() {
  1319. return this.transport.getAllResponseHeaders();
  1320. },
  1321. _getHeaderJSON: function() {
  1322. var json = this.getHeader('X-JSON');
  1323. if (!json) return null;
  1324. json = decodeURIComponent(escape(json));
  1325. try {
  1326. return json.evalJSON(this.request.options.sanitizeJSON ||
  1327. !this.request.isSameOrigin());
  1328. } catch (e) {
  1329. this.request.dispatchException(e);
  1330. }
  1331. },
  1332. _getResponseJSON: function() {
  1333. var options = this.request.options;
  1334. if (!options.evalJSON || (options.evalJSON != 'force' &&
  1335. !(this.getHeader('Content-type') || '').include('application/json')) ||
  1336. this.responseText.blank())
  1337. return null;
  1338. try {
  1339. return this.responseText.evalJSON(options.sanitizeJSON ||
  1340. !this.request.isSameOrigin());
  1341. } catch (e) {
  1342. this.request.dispatchException(e);
  1343. }
  1344. }
  1345. });
  1346. Ajax.Updater = Class.create(Ajax.Request, {
  1347. initialize: function($super, container, url, options) {
  1348. this.container = {
  1349. success: (container.success || container),
  1350. failure: (container.failure || (container.success ? null : container))
  1351. };
  1352. options = Object.clone(options);
  1353. var onComplete = options.onComplete;
  1354. options.onComplete = (function(response, json) {
  1355. this.updateContent(response.responseText);
  1356. if (Object.isFunction(onComplete)) onComplete(response, json);
  1357. }).bind(this);
  1358. $super(url, options);
  1359. },
  1360. updateContent: function(responseText) {
  1361. var receiver = this.container[this.success() ? 'success' : 'failure'],
  1362. options = this.options;
  1363. if (!options.evalScripts) responseText = responseText.stripScripts();
  1364. if (receiver = $(receiver)) {
  1365. if (options.insertion) {
  1366. if (Object.isString(options.insertion)) {
  1367. var insertion = { }; insertion[options.insertion] = responseText;
  1368. receiver.insert(insertion);
  1369. }
  1370. else options.insertion(receiver, responseText);
  1371. }
  1372. else receiver.update(responseText);
  1373. }
  1374. }
  1375. });
  1376. Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
  1377. initialize: function($super, container, url, options) {
  1378. $super(options);
  1379. this.onComplete = this.options.onComplete;
  1380. this.frequency = (this.options.frequency || 2);
  1381. this.decay = (this.options.decay || 1);
  1382. this.updater = { };
  1383. this.container = container;
  1384. this.url = url;
  1385. this.start();
  1386. },
  1387. start: function() {
  1388. this.options.onComplete = this.updateComplete.bind(this);
  1389. this.onTimerEvent();
  1390. },
  1391. stop: function() {
  1392. this.updater.options.onComplete = undefined;
  1393. clearTimeout(this.timer);
  1394. (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
  1395. },
  1396. updateComplete: function(response) {
  1397. if (this.options.decay) {
  1398. this.decay = (response.responseText == this.lastText ?
  1399. this.decay * this.options.decay : 1);
  1400. this.lastText = response.responseText;
  1401. }
  1402. this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
  1403. },
  1404. onTimerEvent: function() {
  1405. this.updater = new Ajax.Updater(this.container, this.url, this.options);
  1406. }
  1407. });
  1408. function $(element) {
  1409. if (arguments.length > 1) {
  1410. for (var i = 0, elements = [], length = arguments.length; i < length; i++)
  1411. elements.push($(arguments[i]));
  1412. return elements;
  1413. }
  1414. if (Object.isString(element))
  1415. element = document.getElementById(element);
  1416. return Element.extend(element);
  1417. }
  1418. if (Prototype.BrowserFeatures.XPath) {
  1419. document._getElementsByXPath = function(expression, parentElement) {
  1420. var results = [];
  1421. var query = document.evaluate(expression, $(parentElement) || document,
  1422. null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1423. for (var i = 0, length = query.snapshotLength; i < length; i++)
  1424. results.push(Element.extend(query.snapshotItem(i)));
  1425. return results;
  1426. };
  1427. }
  1428. /*--------------------------------------------------------------------------*/
  1429. if (!window.Node) var Node = { };
  1430. if (!Node.ELEMENT_NODE) {
  1431. Object.extend(Node, {
  1432. ELEMENT_NODE: 1,
  1433. ATTRIBUTE_NODE: 2,
  1434. TEXT_NODE: 3,
  1435. CDATA_SECTION_NODE: 4,
  1436. ENTITY_REFERENCE_NODE: 5,
  1437. ENTITY_NODE: 6,
  1438. PROCESSING_INSTRUCTION_NODE: 7,
  1439. COMMENT_NODE: 8,
  1440. DOCUMENT_NODE: 9,
  1441. DOCUMENT_TYPE_NODE: 10,
  1442. DOCUMENT_FRAGMENT_NODE: 11,
  1443. NOTATION_NODE: 12
  1444. });
  1445. }
  1446. (function(global) {
  1447. var SETATTRIBUTE_IGNORES_NAME = (function(){
  1448. var elForm = document.createElement("form");
  1449. var elInput = document.createElement("input");
  1450. var root = document.documentElement;
  1451. elInput.setAttribute("name", "test");
  1452. elForm.appendChild(elInput);
  1453. root.appendChild(elForm);
  1454. var isBuggy = elForm.elements
  1455. ? (typeof elForm.elements.test == "undefined")
  1456. : null;
  1457. root.removeChild(elForm);
  1458. elForm = elInput = null;
  1459. return isBuggy;
  1460. })();
  1461. var element = global.Element;
  1462. global.Element = function(tagName, attributes) {
  1463. attributes = attributes || { };
  1464. tagName = tagName.toLowerCase();
  1465. var cache = Element.cache;
  1466. if (SETATTRIBUTE_IGNORES_NAME && attributes.name) {
  1467. tagName = '<' + tagName + ' name="' + attributes.name + '">';
  1468. delete attributes.name;
  1469. return Element.writeAttribute(document.createElement(tagName), attributes);
  1470. }
  1471. if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
  1472. return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
  1473. };
  1474. Object.extend(global.Element, element || { });
  1475. if (element) global.Element.prototype = element.prototype;
  1476. })(this);
  1477. Element.cache = { };
  1478. Element.idCounter = 1;
  1479. Element.Methods = {
  1480. visible: function(element) {
  1481. return $(element).style.display != 'none';
  1482. },
  1483. toggle: function(element) {
  1484. element = $(element);
  1485. Element[Element.visible(element) ? 'hide' : 'show'](element);
  1486. return element;
  1487. },
  1488. hide: function(element) {
  1489. element = $(element);
  1490. element.style.display = 'none';
  1491. return element;
  1492. },
  1493. show: function(element) {
  1494. element = $(element);
  1495. element.style.display = '';
  1496. return element;
  1497. },
  1498. remove: function(element) {
  1499. element = $(element);
  1500. element.parentNode.removeChild(element);
  1501. return element;
  1502. },
  1503. update: (function(){
  1504. var SELECT_ELEMENT_INNERHTML_BUGGY = (function(){
  1505. var el = document.createElement("select"),
  1506. isBuggy = true;
  1507. el.innerHTML = "<option value=\"test\">test</option>";
  1508. if (el.options && el.options[0]) {
  1509. isBuggy = el.options[0].nodeName.toUpperCase() !== "OPTION";
  1510. }
  1511. el = null;
  1512. return isBuggy;
  1513. })();
  1514. var TABLE_ELEMENT_INNERHTML_BUGGY = (function(){
  1515. try {
  1516. var el = document.createElement("table");
  1517. if (el && el.tBodies) {
  1518. el.innerHTML = "<tbody><tr><td>test</td></tr></tbody>";
  1519. var isBuggy = typeof el.tBodies[0] == "undefined";
  1520. el = null;
  1521. return isBuggy;
  1522. }
  1523. } catch (e) {
  1524. return true;
  1525. }
  1526. })();
  1527. var SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING = (function () {
  1528. var s = document.createElement("script"),
  1529. isBuggy = false;
  1530. try {
  1531. s.appendChild(document.createTextNode(""));
  1532. isBuggy = !s.firstChild ||
  1533. s.firstChild && s.firstChild.nodeType !== 3;
  1534. } catch (e) {
  1535. isBuggy = true;
  1536. }
  1537. s = null;
  1538. return isBuggy;
  1539. })();
  1540. function update(element, content) {
  1541. element = $(element);
  1542. if (content && content.toElement)
  1543. content = content.toElement();
  1544. if (Object.isElement(content))
  1545. return element.update().insert(content);
  1546. content = Object.toHTML(content);
  1547. var tagName = element.tagName.toUpperCase();
  1548. if (tagName === 'SCRIPT' && SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING) {
  1549. element.text = content;
  1550. return element;
  1551. }
  1552. if (SELECT_ELEMENT_INNERHTML_BUGGY || TABLE_ELEMENT_INNERHTML_BUGGY) {
  1553. if (tagName in Element._insertionTranslations.tags) {
  1554. while (element.firstChild) {
  1555. element.removeChild(element.firstChild);
  1556. }
  1557. Element._getContentFromAnonymousElement(tagName, content.stripScripts())
  1558. .each(function(node) {
  1559. element.appendChild(node)
  1560. });
  1561. }
  1562. else {
  1563. element.innerHTML = content.stripScripts();
  1564. }
  1565. }
  1566. else {
  1567. element.innerHTML = content.stripScripts();
  1568. }
  1569. content.evalScripts.bind(content).defer();
  1570. return element;
  1571. }
  1572. return update;
  1573. })(),
  1574. replace: function(element, content) {
  1575. element = $(element);
  1576. if (content && content.toElement) content = content.toElement();
  1577. else if (!Object.isElement(content)) {
  1578. content = Object.toHTML(content);
  1579. var range = element.ownerDocument.createRange();
  1580. range.selectNode(element);
  1581. content.evalScripts.bind(content).defer();
  1582. content = range.createContextualFragment(content.stripScripts());
  1583. }
  1584. element.parentNode.replaceChild(content, element);
  1585. return element;
  1586. },
  1587. insert: function(element, insertions) {
  1588. element = $(element);
  1589. if (Object.isString(insertions) || Object.isNumber(insertions) ||

Large files files are truncated, but you can click here to view the full file