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

/lib/gemcache/ruby/1.9.1/arch/win32/thin-1.3.0-x86-mingw32/spec/rails_app/public/javascripts/prototype.js

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

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