PageRenderTime 52ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/dom/tests/mochitest/ajax/scriptaculous/lib/prototype.js

http://github.com/zpao/v8monkey
JavaScript | 3271 lines | 2911 code | 321 blank | 39 comment | 419 complexity | ffe25226686c01d33019619f86d021ab MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, LGPL-2.1, BSD-3-Clause, GPL-2.0, JSON, Apache-2.0, 0BSD

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

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

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