PageRenderTime 103ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/gemcache/ruby/1.9.1/arch/linux32/json-1.6.6/data/prototype.js

https://bitbucket.org/technopunk2099/metasploit-framework
JavaScript | 4184 lines | 3628 code | 487 blank | 69 comment | 627 complexity | 825f0652efea9e6013898700aa1b7585 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, LGPL-2.1, GPL-2.0, MIT

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

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

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