/trunk/FE.presentation/pages/include/script/prototype.js

http://fatal-error.googlecode.com/ · JavaScript · 2268 lines · 1900 code · 323 blank · 45 comment · 419 complexity · 44b2a731dcf5df4cd29e50896fd6be14 MD5 · raw file

Large files are truncated click here to view the full file

  1. /* Prototype JavaScript framework, version 1.5.1_rc3
  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_rc3',
  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 = new Object();
  367. var $continue = new Object();
  368. var Enumerable = {
  369. each: function(iterator) {
  370. var index = 0;
  371. try {
  372. this._each(function(value) {
  373. iterator(value, index++);
  374. });
  375. } catch (e) {
  376. if (e != $break) throw e;
  377. }
  378. return this;
  379. },
  380. eachSlice: function(number, iterator) {
  381. var index = -number, slices = [], array = this.toArray();
  382. while ((index += number) < array.length)
  383. slices.push(array.slice(index, index+number));
  384. return slices.map(iterator);
  385. },
  386. all: function(iterator) {
  387. var result = true;
  388. this.each(function(value, index) {
  389. result = result && !!(iterator || Prototype.K)(value, index);
  390. if (!result) throw $break;
  391. });
  392. return result;
  393. },
  394. any: function(iterator) {
  395. var result = false;
  396. this.each(function(value, index) {
  397. if (result = !!(iterator || Prototype.K)(value, index))
  398. throw $break;
  399. });
  400. return result;
  401. },
  402. collect: function(iterator) {
  403. var results = [];
  404. this.each(function(value, index) {
  405. results.push((iterator || Prototype.K)(value, index));
  406. });
  407. return results;
  408. },
  409. detect: function(iterator) {
  410. var result;
  411. this.each(function(value, index) {
  412. if (iterator(value, index)) {
  413. result = value;
  414. throw $break;
  415. }
  416. });
  417. return result;
  418. },
  419. findAll: function(iterator) {
  420. var results = [];
  421. this.each(function(value, index) {
  422. if (iterator(value, index))
  423. results.push(value);
  424. });
  425. return results;
  426. },
  427. grep: function(pattern, iterator) {
  428. var results = [];
  429. this.each(function(value, index) {
  430. var stringValue = value.toString();
  431. if (stringValue.match(pattern))
  432. results.push((iterator || Prototype.K)(value, index));
  433. })
  434. return results;
  435. },
  436. include: function(object) {
  437. var found = false;
  438. this.each(function(value) {
  439. if (value == object) {
  440. found = true;
  441. throw $break;
  442. }
  443. });
  444. return found;
  445. },
  446. inGroupsOf: function(number, fillWith) {
  447. fillWith = fillWith === undefined ? null : fillWith;
  448. return this.eachSlice(number, function(slice) {
  449. while(slice.length < number) slice.push(fillWith);
  450. return slice;
  451. });
  452. },
  453. inject: function(memo, iterator) {
  454. this.each(function(value, index) {
  455. memo = iterator(memo, value, index);
  456. });
  457. return memo;
  458. },
  459. invoke: function(method) {
  460. var args = $A(arguments).slice(1);
  461. return this.map(function(value) {
  462. return value[method].apply(value, args);
  463. });
  464. },
  465. max: function(iterator) {
  466. var result;
  467. this.each(function(value, index) {
  468. value = (iterator || Prototype.K)(value, index);
  469. if (result == undefined || value >= result)
  470. result = value;
  471. });
  472. return result;
  473. },
  474. min: function(iterator) {
  475. var result;
  476. this.each(function(value, index) {
  477. value = (iterator || Prototype.K)(value, index);
  478. if (result == undefined || value < result)
  479. result = value;
  480. });
  481. return result;
  482. },
  483. partition: function(iterator) {
  484. var trues = [], falses = [];
  485. this.each(function(value, index) {
  486. ((iterator || Prototype.K)(value, index) ?
  487. trues : falses).push(value);
  488. });
  489. return [trues, falses];
  490. },
  491. pluck: function(property) {
  492. var results = [];
  493. this.each(function(value, index) {
  494. results.push(value[property]);
  495. });
  496. return results;
  497. },
  498. reject: function(iterator) {
  499. var results = [];
  500. this.each(function(value, index) {
  501. if (!iterator(value, index))
  502. results.push(value);
  503. });
  504. return results;
  505. },
  506. sortBy: function(iterator) {
  507. return this.map(function(value, index) {
  508. return {value: value, criteria: iterator(value, index)};
  509. }).sort(function(left, right) {
  510. var a = left.criteria, b = right.criteria;
  511. return a < b ? -1 : a > b ? 1 : 0;
  512. }).pluck('value');
  513. },
  514. toArray: function() {
  515. return this.map();
  516. },
  517. zip: function() {
  518. var iterator = Prototype.K, args = $A(arguments);
  519. if (typeof args.last() == 'function')
  520. iterator = args.pop();
  521. var collections = [this].concat(args).map($A);
  522. return this.map(function(value, index) {
  523. return iterator(collections.pluck(index));
  524. });
  525. },
  526. size: function() {
  527. return this.toArray().length;
  528. },
  529. inspect: function() {
  530. return '#<Enumerable:' + this.toArray().inspect() + '>';
  531. }
  532. }
  533. Object.extend(Enumerable, {
  534. map: Enumerable.collect,
  535. find: Enumerable.detect,
  536. select: Enumerable.findAll,
  537. member: Enumerable.include,
  538. entries: Enumerable.toArray
  539. });
  540. var $A = Array.from = function(iterable) {
  541. if (!iterable) return [];
  542. if (iterable.toArray) {
  543. return iterable.toArray();
  544. } else {
  545. var results = [];
  546. for (var i = 0, length = iterable.length; i < length; i++)
  547. results.push(iterable[i]);
  548. return results;
  549. }
  550. }
  551. if (Prototype.Browser.WebKit) {
  552. $A = Array.from = function(iterable) {
  553. if (!iterable) return [];
  554. if (!(typeof iterable == 'function' && iterable == '[object NodeList]') &&
  555. iterable.toArray) {
  556. return iterable.toArray();
  557. } else {
  558. var results = [];
  559. for (var i = 0, length = iterable.length; i < length; i++)
  560. results.push(iterable[i]);
  561. return results;
  562. }
  563. }
  564. }
  565. Object.extend(Array.prototype, Enumerable);
  566. if (!Array.prototype._reverse)
  567. Array.prototype._reverse = Array.prototype.reverse;
  568. Object.extend(Array.prototype, {
  569. _each: function(iterator) {
  570. for (var i = 0, length = this.length; i < length; i++)
  571. iterator(this[i]);
  572. },
  573. clear: function() {
  574. this.length = 0;
  575. return this;
  576. },
  577. first: function() {
  578. return this[0];
  579. },
  580. last: function() {
  581. return this[this.length - 1];
  582. },
  583. compact: function() {
  584. return this.select(function(value) {
  585. return value != null;
  586. });
  587. },
  588. flatten: function() {
  589. return this.inject([], function(array, value) {
  590. return array.concat(value && value.constructor == Array ?
  591. value.flatten() : [value]);
  592. });
  593. },
  594. without: function() {
  595. var values = $A(arguments);
  596. return this.select(function(value) {
  597. return !values.include(value);
  598. });
  599. },
  600. indexOf: function(object) {
  601. for (var i = 0, length = this.length; i < length; i++)
  602. if (this[i] == object) return i;
  603. return -1;
  604. },
  605. reverse: function(inline) {
  606. return (inline !== false ? this : this.toArray())._reverse();
  607. },
  608. reduce: function() {
  609. return this.length > 1 ? this : this[0];
  610. },
  611. uniq: function(sorted) {
  612. return this.inject([], function(array, value, index) {
  613. if (0 == index || (sorted ? array.last() != value : !array.include(value)))
  614. array.push(value);
  615. return array;
  616. });
  617. },
  618. clone: function() {
  619. return [].concat(this);
  620. },
  621. size: function() {
  622. return this.length;
  623. },
  624. inspect: function() {
  625. return '[' + this.map(Object.inspect).join(', ') + ']';
  626. },
  627. toJSON: function() {
  628. var results = [];
  629. this.each(function(object) {
  630. var value = Object.toJSON(object);
  631. if (value !== undefined) results.push(value);
  632. });
  633. return '[' + results.join(', ') + ']';
  634. }
  635. });
  636. Array.prototype.toArray = Array.prototype.clone;
  637. function $w(string) {
  638. string = string.strip();
  639. return string ? string.split(/\s+/) : [];
  640. }
  641. if (Prototype.Browser.Opera){
  642. Array.prototype.concat = function() {
  643. var array = [];
  644. for (var i = 0, length = this.length; i < length; i++) array.push(this[i]);
  645. for (var i = 0, length = arguments.length; i < length; i++) {
  646. if (arguments[i].constructor == Array) {
  647. for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)
  648. array.push(arguments[i][j]);
  649. } else {
  650. array.push(arguments[i]);
  651. }
  652. }
  653. return array;
  654. }
  655. }
  656. var Hash = function(object) {
  657. if (object instanceof Hash) this.merge(object);
  658. else Object.extend(this, object || {});
  659. };
  660. Object.extend(Hash, {
  661. toQueryString: function(obj) {
  662. var parts = [];
  663. parts.add = arguments.callee.addPair;
  664. this.prototype._each.call(obj, function(pair) {
  665. if (!pair.key) return;
  666. var value = pair.value;
  667. if (value && typeof value == 'object') {
  668. if (value.constructor == Array) value.each(function(value) {
  669. parts.add(pair.key, value);
  670. });
  671. return;
  672. }
  673. parts.add(pair.key, value);
  674. });
  675. return parts.join('&');
  676. },
  677. toJSON: function(object) {
  678. var results = [];
  679. this.prototype._each.call(object, function(pair) {
  680. var value = Object.toJSON(pair.value);
  681. if (value !== undefined) results.push(pair.key.toJSON() + ': ' + value);
  682. });
  683. return '{' + results.join(', ') + '}';
  684. }
  685. });
  686. Hash.toQueryString.addPair = function(key, value, prefix) {
  687. key = encodeURIComponent(key);
  688. if (value === undefined) this.push(key);
  689. else this.push(key + '=' + (value == null ? '' : encodeURIComponent(value)));
  690. }
  691. Object.extend(Hash.prototype, Enumerable);
  692. Object.extend(Hash.prototype, {
  693. _each: function(iterator) {
  694. for (var key in this) {
  695. var value = this[key];
  696. if (value && value == Hash.prototype[key]) continue;
  697. var pair = [key, value];
  698. pair.key = key;
  699. pair.value = value;
  700. iterator(pair);
  701. }
  702. },
  703. keys: function() {
  704. return this.pluck('key');
  705. },
  706. values: function() {
  707. return this.pluck('value');
  708. },
  709. merge: function(hash) {
  710. return $H(hash).inject(this, function(mergedHash, pair) {
  711. mergedHash[pair.key] = pair.value;
  712. return mergedHash;
  713. });
  714. },
  715. remove: function() {
  716. var result;
  717. for(var i = 0, length = arguments.length; i < length; i++) {
  718. var value = this[arguments[i]];
  719. if (value !== undefined){
  720. if (result === undefined) result = value;
  721. else {
  722. if (result.constructor != Array) result = [result];
  723. result.push(value)
  724. }
  725. }
  726. delete this[arguments[i]];
  727. }
  728. return result;
  729. },
  730. toQueryString: function() {
  731. return Hash.toQueryString(this);
  732. },
  733. inspect: function() {
  734. return '#<Hash:{' + this.map(function(pair) {
  735. return pair.map(Object.inspect).join(': ');
  736. }).join(', ') + '}>';
  737. },
  738. toJSON: function() {
  739. return Hash.toJSON(this);
  740. }
  741. });
  742. function $H(object) {
  743. if (object instanceof Hash) return object;
  744. return new Hash(object);
  745. };
  746. // Safari iterates over shadowed properties
  747. if (function() {
  748. var i = 0, Test = function(value) { this.key = value };
  749. Test.prototype.key = 'foo';
  750. for (var property in new Test('bar')) i++;
  751. return i > 1;
  752. }()) Hash.prototype._each = function(iterator) {
  753. var cache = [];
  754. for (var key in this) {
  755. var value = this[key];
  756. if ((value && value == Hash.prototype[key]) || cache.include(key)) continue;
  757. cache.push(key);
  758. var pair = [key, value];
  759. pair.key = key;
  760. pair.value = value;
  761. iterator(pair);
  762. }
  763. };
  764. ObjectRange = Class.create();
  765. Object.extend(ObjectRange.prototype, Enumerable);
  766. Object.extend(ObjectRange.prototype, {
  767. initialize: function(start, end, exclusive) {
  768. this.start = start;
  769. this.end = end;
  770. this.exclusive = exclusive;
  771. },
  772. _each: function(iterator) {
  773. var value = this.start;
  774. while (this.include(value)) {
  775. iterator(value);
  776. value = value.succ();
  777. }
  778. },
  779. include: function(value) {
  780. if (value < this.start)
  781. return false;
  782. if (this.exclusive)
  783. return value < this.end;
  784. return value <= this.end;
  785. }
  786. });
  787. var $R = function(start, end, exclusive) {
  788. return new ObjectRange(start, end, exclusive);
  789. }
  790. var Ajax = {
  791. getTransport: function() {
  792. return Try.these(
  793. function() {return new XMLHttpRequest()},
  794. function() {return new ActiveXObject('Msxml2.XMLHTTP')},
  795. function() {return new ActiveXObject('Microsoft.XMLHTTP')}
  796. ) || false;
  797. },
  798. activeRequestCount: 0
  799. }
  800. Ajax.Responders = {
  801. responders: [],
  802. _each: function(iterator) {
  803. this.responders._each(iterator);
  804. },
  805. register: function(responder) {
  806. if (!this.include(responder))
  807. this.responders.push(responder);
  808. },
  809. unregister: function(responder) {
  810. this.responders = this.responders.without(responder);
  811. },
  812. dispatch: function(callback, request, transport, json) {
  813. this.each(function(responder) {
  814. if (typeof responder[callback] == 'function') {
  815. try {
  816. responder[callback].apply(responder, [request, transport, json]);
  817. } catch (e) {}
  818. }
  819. });
  820. }
  821. };
  822. Object.extend(Ajax.Responders, Enumerable);
  823. Ajax.Responders.register({
  824. onCreate: function() {
  825. Ajax.activeRequestCount++;
  826. },
  827. onComplete: function() {
  828. Ajax.activeRequestCount--;
  829. }
  830. });
  831. Ajax.Base = function() {};
  832. Ajax.Base.prototype = {
  833. setOptions: function(options) {
  834. this.options = {
  835. method: 'post',
  836. asynchronous: true,
  837. contentType: 'application/x-www-form-urlencoded',
  838. encoding: 'UTF-8',
  839. parameters: ''
  840. }
  841. Object.extend(this.options, options || {});
  842. this.options.method = this.options.method.toLowerCase();
  843. if (typeof this.options.parameters == 'string')
  844. this.options.parameters = this.options.parameters.toQueryParams();
  845. }
  846. }
  847. Ajax.Request = Class.create();
  848. Ajax.Request.Events =
  849. ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
  850. Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
  851. _complete: false,
  852. initialize: function(url, options) {
  853. this.transport = Ajax.getTransport();
  854. this.setOptions(options);
  855. this.request(url);
  856. },
  857. request: function(url) {
  858. this.url = url;
  859. this.method = this.options.method;
  860. var params = Object.clone(this.options.parameters);
  861. if (!['get', 'post'].include(this.method)) {
  862. // simulate other verbs over post
  863. params['_method'] = this.method;
  864. this.method = 'post';
  865. }
  866. this.parameters = params;
  867. if (params = Hash.toQueryString(params)) {
  868. // when GET, append parameters to URL
  869. if (this.method == 'get')
  870. this.url += (this.url.include('?') ? '&' : '?') + params;
  871. else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))
  872. params += '&_=';
  873. }
  874. try {
  875. if (this.options.onCreate) this.options.onCreate(this.transport);
  876. Ajax.Responders.dispatch('onCreate', this, this.transport);
  877. this.transport.open(this.method.toUpperCase(), this.url,
  878. this.options.asynchronous);
  879. if (this.options.asynchronous)
  880. setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10);
  881. this.transport.onreadystatechange = this.onStateChange.bind(this);
  882. this.setRequestHeaders();
  883. this.body = this.method == 'post' ? (this.options.postBody || params) : null;
  884. this.transport.send(this.body);
  885. /* Force Firefox to handle ready state 4 for synchronous requests */
  886. if (!this.options.asynchronous && this.transport.overrideMimeType)
  887. this.onStateChange();
  888. }
  889. catch (e) {
  890. this.dispatchException(e);
  891. }
  892. },
  893. onStateChange: function() {
  894. var readyState = this.transport.readyState;
  895. if (readyState > 1 && !((readyState == 4) && this._complete))
  896. this.respondToReadyState(this.transport.readyState);
  897. },
  898. setRequestHeaders: function() {
  899. var headers = {
  900. 'X-Requested-With': 'XMLHttpRequest',
  901. 'X-Prototype-Version': Prototype.Version,
  902. 'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
  903. };
  904. if (this.method == 'post') {
  905. headers['Content-type'] = this.options.contentType +
  906. (this.options.encoding ? '; charset=' + this.options.encoding : '');
  907. /* Force "Connection: close" for older Mozilla browsers to work
  908. * around a bug where XMLHttpRequest sends an incorrect
  909. * Content-length header. See Mozilla Bugzilla #246651.
  910. */
  911. if (this.transport.overrideMimeType &&
  912. (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
  913. headers['Connection'] = 'close';
  914. }
  915. // user-defined headers
  916. if (typeof this.options.requestHeaders == 'object') {
  917. var extras = this.options.requestHeaders;
  918. if (typeof extras.push == 'function')
  919. for (var i = 0, length = extras.length; i < length; i += 2)
  920. headers[extras[i]] = extras[i+1];
  921. else
  922. $H(extras).each(function(pair) { headers[pair.key] = pair.value });
  923. }
  924. for (var name in headers)
  925. this.transport.setRequestHeader(name, headers[name]);
  926. },
  927. success: function() {
  928. return !this.transport.status
  929. || (this.transport.status >= 200 && this.transport.status < 300);
  930. },
  931. respondToReadyState: function(readyState) {
  932. var state = Ajax.Request.Events[readyState];
  933. var transport = this.transport, json = this.evalJSON();
  934. if (state == 'Complete') {
  935. try {
  936. this._complete = true;
  937. (this.options['on' + this.transport.status]
  938. || this.options['on' + (this.success() ? 'Success' : 'Failure')]
  939. || Prototype.emptyFunction)(transport, json);
  940. } catch (e) {
  941. this.dispatchException(e);
  942. }
  943. var contentType = this.getHeader('Content-type');
  944. if (contentType && contentType.strip().
  945. match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i))
  946. this.evalResponse();
  947. }
  948. try {
  949. (this.options['on' + state] || Prototype.emptyFunction)(transport, json);
  950. Ajax.Responders.dispatch('on' + state, this, transport, json);
  951. } catch (e) {
  952. this.dispatchException(e);
  953. }
  954. if (state == 'Complete') {
  955. // avoid memory leak in MSIE: clean up
  956. this.transport.onreadystatechange = Prototype.emptyFunction;
  957. }
  958. },
  959. getHeader: function(name) {
  960. try {
  961. return this.transport.getResponseHeader(name);
  962. } catch (e) { return null }
  963. },
  964. evalJSON: function() {
  965. try {
  966. var json = this.getHeader('X-JSON');
  967. return json ? json.evalJSON() : null;
  968. } catch (e) { return null }
  969. },
  970. evalResponse: function() {
  971. try {
  972. return eval((this.transport.responseText || '').unfilterJSON());
  973. } catch (e) {
  974. this.dispatchException(e);
  975. }
  976. },
  977. dispatchException: function(exception) {
  978. (this.options.onException || Prototype.emptyFunction)(this, exception);
  979. Ajax.Responders.dispatch('onException', this, exception);
  980. }
  981. });
  982. Ajax.Updater = Class.create();
  983. Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
  984. initialize: function(container, url, options) {
  985. this.container = {
  986. success: (container.success || container),
  987. failure: (container.failure || (container.success ? null : container))
  988. }
  989. this.transport = Ajax.getTransport();
  990. this.setOptions(options);
  991. var onComplete = this.options.onComplete || Prototype.emptyFunction;
  992. this.options.onComplete = (function(transport, param) {
  993. this.updateContent();
  994. onComplete(transport, param);
  995. }).bind(this);
  996. this.request(url);
  997. },
  998. updateContent: function() {
  999. var receiver = this.container[this.success() ? 'success' : 'failure'];
  1000. var response = this.transport.responseText;
  1001. if (!this.options.evalScripts) response = response.stripScripts();
  1002. if (receiver = $prototypeFE(receiver)) {
  1003. if (this.options.insertion)
  1004. new this.options.insertion(receiver, response);
  1005. else
  1006. receiver.update(response);
  1007. }
  1008. if (this.success()) {
  1009. if (this.onComplete)
  1010. setTimeout(this.onComplete.bind(this), 10);
  1011. }
  1012. }
  1013. });
  1014. Ajax.PeriodicalUpdater = Class.create();
  1015. Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), {
  1016. initialize: function(container, url, options) {
  1017. this.setOptions(options);
  1018. this.onComplete = this.options.onComplete;
  1019. this.frequency = (this.options.frequency || 2);
  1020. this.decay = (this.options.decay || 1);
  1021. this.updater = {};
  1022. this.container = container;
  1023. this.url = url;
  1024. this.start();
  1025. },
  1026. start: function() {
  1027. this.options.onComplete = this.updateComplete.bind(this);
  1028. this.onTimerEvent();
  1029. },
  1030. stop: function() {
  1031. this.updater.options.onComplete = undefined;
  1032. clearTimeout(this.timer);
  1033. (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
  1034. },
  1035. updateComplete: function(request) {
  1036. if (this.options.decay) {
  1037. this.decay = (request.responseText == this.lastText ?
  1038. this.decay * this.options.decay : 1);
  1039. this.lastText = request.responseText;
  1040. }
  1041. this.timer = setTimeout(this.onTimerEvent.bind(this),
  1042. this.decay * this.frequency * 1000);
  1043. },
  1044. onTimerEvent: function() {
  1045. this.updater = new Ajax.Updater(this.container, this.url, this.options);
  1046. }
  1047. });
  1048. function $prototypeFE(element) {
  1049. if (arguments.length > 1) {
  1050. for (var i = 0, elements = [], length = arguments.length; i < length; i++)
  1051. elements.push($prototypeFE(arguments[i]));
  1052. return elements;
  1053. }
  1054. if (typeof element == 'string')
  1055. element = document.getElementById(element);
  1056. return Element.extend(element);
  1057. }
  1058. if (Prototype.BrowserFeatures.XPath) {
  1059. document._getElementsByXPath = function(expression, parentElement) {
  1060. var results = [];
  1061. var query = document.evaluate(expression, $prototypeFE(parentElement) || document,
  1062. null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1063. for (var i = 0, length = query.snapshotLength; i < length; i++)
  1064. results.push(query.snapshotItem(i));
  1065. return results;
  1066. };
  1067. document.getElementsByClassName = function(className, parentElement) {
  1068. var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";
  1069. return document._getElementsByXPath(q, parentElement);
  1070. }
  1071. } else document.getElementsByClassName = function(className, parentElement) {
  1072. var children = ($prototypeFE(parentElement) || document.body).getElementsByTagName('*');
  1073. var elements = [], child;
  1074. for (var i = 0, length = children.length; i < length; i++) {
  1075. child = children[i];
  1076. if (Element.hasClassName(child, className))
  1077. elements.push(Element.extend(child));
  1078. }
  1079. return elements;
  1080. };
  1081. /*--------------------------------------------------------------------------*/
  1082. if (!window.Element) var Element = {};
  1083. Element.extend = function(element) {
  1084. var F = Prototype.BrowserFeatures;
  1085. if (!element || !element.tagName || element.nodeType == 3 ||
  1086. element._extended || F.SpecificElementExtensions || element == window)
  1087. return element;
  1088. var methods = {}, tagName = element.tagName, cache = Element.extend.cache,
  1089. T = Element.Methods.ByTag;
  1090. // extend methods for all tags (Safari doesn't need this)
  1091. if (!F.ElementExtensions) {
  1092. Object.extend(methods, Element.Methods),
  1093. Object.extend(methods, Element.Methods.Simulated);
  1094. }
  1095. // extend methods for specific tags
  1096. if (T[tagName]) Object.extend(methods, T[tagName]);
  1097. for (var property in methods) {
  1098. var value = methods[property];
  1099. if (typeof value == 'function' && !(property in element))
  1100. element[property] = cache.findOrStore(value);
  1101. }
  1102. element._extended = Prototype.emptyFunction;
  1103. return element;
  1104. };
  1105. Element.extend.cache = {
  1106. findOrStore: function(value) {
  1107. return this[value] = this[value] || function() {
  1108. return value.apply(null, [this].concat($A(arguments)));
  1109. }
  1110. }
  1111. };
  1112. Element.Methods = {
  1113. visible: function(element) {
  1114. return $prototypeFE(element).style.display != 'none';
  1115. },
  1116. toggle: function(element) {
  1117. element = $prototypeFE(element);
  1118. Element[Element.visible(element) ? 'hide' : 'show'](element);
  1119. return element;
  1120. },
  1121. hide: function(element) {
  1122. $prototypeFE(element).style.display = 'none';
  1123. return element;
  1124. },
  1125. show: function(element) {
  1126. $prototypeFE(element).style.display = '';
  1127. return element;
  1128. },
  1129. remove: function(element) {
  1130. element = $prototypeFE(element);
  1131. element.parentNode.removeChild(element);
  1132. return element;
  1133. },
  1134. update: function(element, html) {
  1135. html = typeof html == 'undefined' ? '' : html.toString();
  1136. $prototypeFE(element).innerHTML = html.stripScripts();
  1137. setTimeout(function() {html.evalScripts()}, 10);
  1138. return element;
  1139. },
  1140. replace: function(element, html) {
  1141. element = $prototypeFE(element);
  1142. html = typeof html == 'undefined' ? '' : html.toString();
  1143. if (element.outerHTML) {
  1144. element.outerHTML = html.stripScripts();
  1145. } else {
  1146. var range = element.ownerDocument.createRange();
  1147. range.selectNodeContents(element);
  1148. element.parentNode.replaceChild(
  1149. range.createContextualFragment(html.stripScripts()), element);
  1150. }
  1151. setTimeout(function() {html.evalScripts()}, 10);
  1152. return element;
  1153. },
  1154. inspect: function(element) {
  1155. element = $prototypeFE(element);
  1156. var result = '<' + element.tagName.toLowerCase();
  1157. $H({'id': 'id', 'className': 'class'}).each(function(pair) {
  1158. var property = pair.first(), attribute = pair.last();
  1159. var value = (element[property] || '').toString();
  1160. if (value) result += ' ' + attribute + '=' + value.inspect(true);
  1161. });
  1162. return result + '>';
  1163. },
  1164. recursivelyCollect: function(element, property) {
  1165. element = $prototypeFE(element);
  1166. var elements = [];
  1167. while (element = element[property])
  1168. if (element.nodeType == 1)
  1169. elements.push(Element.extend(element));
  1170. return elements;
  1171. },
  1172. ancestors: function(element) {
  1173. return $prototypeFE(element).recursivelyCollect('parentNode');
  1174. },
  1175. descendants: function(element) {
  1176. return $A($prototypeFE(element).getElementsByTagName('*')).each(Element.extend);
  1177. },
  1178. firstDescendant: function(element) {
  1179. element = $prototypeFE(element).firstChild;
  1180. while (element && element.nodeType != 1) element = element.nextSibling;
  1181. return $prototypeFE(element);
  1182. },
  1183. immediateDescendants: function(element) {
  1184. if (!(element = $prototypeFE(element).firstChild)) return [];
  1185. while (element && element.nodeType != 1) element = element.nextSibling;
  1186. if (element) return [element].concat($prototypeFE(element).nextSiblings());
  1187. return [];
  1188. },
  1189. previousSiblings: function(element) {
  1190. return $prototypeFE(element).recursivelyCollect('previousSibling');
  1191. },
  1192. nextSiblings: function(element) {
  1193. return $prototypeFE(element).recursivelyCollect('nextSibling');
  1194. },
  1195. siblings: function(element) {
  1196. element = $prototypeFE(element);
  1197. return element.previousSiblings().reverse().concat(element.nextSiblings());
  1198. },
  1199. match: function(element, selector) {
  1200. if (typeof selector == 'string')
  1201. selector = new Selector(selector);
  1202. return selector.match($prototypeFE(element));
  1203. },
  1204. up: function(element, expression, index) {
  1205. element = $prototypeFE(element);
  1206. if (arguments.length == 1) return $prototypeFE(element.parentNode);
  1207. var ancestors = element.ancestors();
  1208. return expression ? Selector.findElement(ancestors, expression, index) :
  1209. ancestors[index || 0];
  1210. },
  1211. down: function(element, expression, index) {
  1212. element = $prototypeFE(element);
  1213. if (arguments.length == 1) return element.firstDescendant();
  1214. var descendants = element.descendants();
  1215. return expression ? Selector.findElement(descendants, expression, index) :
  1216. descendants[index || 0];
  1217. },
  1218. previous: function(element, expression, index) {
  1219. element = $prototypeFE(element);
  1220. if (arguments.length == 1) return $prototypeFE(Selector.handlers.previousElementSibling(element));
  1221. var previousSiblings = element.previousSiblings();
  1222. return expression ? Selector.findElement(previousSiblings, expression, index) :
  1223. previousSiblings[index || 0];
  1224. },
  1225. next: function(element, expression, index) {
  1226. element = $prototypeFE(element);
  1227. if (arguments.length == 1) return $prototypeFE(Selector.handlers.nextElementSibling(element));
  1228. var nextSiblings = element.nextSiblings();
  1229. return expression ? Selector.findElement(nextSiblings, expression, index) :
  1230. nextSiblings[index || 0];
  1231. },
  1232. getElementsBySelector: function() {
  1233. var args = $A(arguments), element = $prototypeFE(args.shift());
  1234. return Selector.findChildElements(element, args);
  1235. },
  1236. getElementsByClassName: function(element, className) {
  1237. return document.getElementsByClassName(className, element);
  1238. },
  1239. readAttribute: function(element, name) {
  1240. element = $prototypeFE(element);
  1241. if (Prototype.Browser.IE) {
  1242. if (!element.attributes) return null;
  1243. var t = Element._attributeTranslations;
  1244. if (t.values[name]) return t.values[name](element, name);
  1245. if (t.names[name]) name = t.names[name];
  1246. var attribute = element.attributes[name];
  1247. return attribute ? attribute.nodeValue : null;
  1248. }
  1249. return element.getAttribute(name);
  1250. },
  1251. getHeight: function(element) {
  1252. return $prototypeFE(element).getDimensions().height;
  1253. },
  1254. getWidth: function(element) {
  1255. return $prototypeFE(element).getDimensions().width;
  1256. },
  1257. classNames: function(element) {
  1258. return new Element.ClassNames(element);
  1259. },
  1260. hasClassName: function(element, className) {
  1261. if (!(element = $prototypeFE(element))) return;
  1262. var elementClassName = element.className;
  1263. if (elementClassName.length == 0) return false;
  1264. if (elementClassName == className ||
  1265. elementClassName.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
  1266. return true;
  1267. return false;
  1268. },
  1269. addClassName: function(element, className) {
  1270. if (!(element = $prototypeFE(element))) return;
  1271. Element.classNames(element).add(className);
  1272. return element;
  1273. },
  1274. removeClassName: function(element, className) {
  1275. if (!(element = $prototypeFE(element))) return;
  1276. Element.classNames(element).remove(className);
  1277. return element;
  1278. },
  1279. toggleClassName: function(element, className) {
  1280. if (!(element = $prototypeFE(element))) return;
  1281. Element.classNames(element)[element.hasClassName(className) ? 'remove' : 'add'](className);
  1282. return element;
  1283. },
  1284. observe: function() {
  1285. Event.observe.apply(Event, arguments);
  1286. return $A(arguments).first();
  1287. },
  1288. stopObserving: function() {
  1289. Event.stopObserving.apply(Event, arguments);
  1290. return $A(arguments).first();
  1291. },
  1292. // removes whitespace-only text node children
  1293. cleanWhitespace: function(element) {
  1294. element = $prototypeFE(element);
  1295. var node = element.firstChild;
  1296. while (node) {
  1297. var nextNode = node.nextSibling;
  1298. if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
  1299. element.removeChild(node);
  1300. node = nextNode;
  1301. }
  1302. return element;
  1303. },
  1304. empty: function(element) {
  1305. return $prototypeFE(element).innerHTML.blank();
  1306. },
  1307. descendantOf: function(element, ancestor) {
  1308. element = $prototypeFE(element), ancestor = $prototypeFE(ancestor);
  1309. while (element = element.parentNode)
  1310. if (element == ancestor) return true;
  1311. return false;
  1312. },
  1313. scrollTo: function(element) {
  1314. element = $prototypeFE(element);
  1315. var pos = Position.cumulativeOffset(element);
  1316. window.scrollTo(pos[0], pos[1]);
  1317. return element;
  1318. },
  1319. getStyle: function(element, style) {
  1320. element = $prototypeFE(element);
  1321. style = style == 'float' ? 'cssFloat' : style.camelize();
  1322. var value = element.style[style];
  1323. if (!value) {
  1324. var css = document.defaultView.getComputedStyle(element, null);
  1325. value = css ? css[style] : null;
  1326. }
  1327. if (style == 'opacity') return value ? parseFloat(value) : 1.0;
  1328. return value == 'auto' ? null : value;
  1329. },
  1330. getOpacity: function(element) {
  1331. return $prototypeFE(element).getStyle('opacity');
  1332. },
  1333. setStyle: function(element, styles, camelized) {
  1334. element = $prototypeFE(element);
  1335. var elementStyle = element.style;
  1336. for (var property in styles)
  1337. if (property == 'opacity') element.setOpacity(styles[property])
  1338. else
  1339. elementStyle[(property == 'float' || property == 'cssFloat') ?
  1340. (elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') :
  1341. (camelized ? property : property.camelize())] = styles[property];
  1342. return element;
  1343. },
  1344. setOpacity: function(element, value) {
  1345. element = $prototypeFE(element);
  1346. element.style.opacity = (value == 1 || value === '') ? '' :
  1347. (value < 0.00001) ? 0 : value;
  1348. return element;
  1349. },
  1350. getDimensions: function(element) {
  1351. element = $prototypeFE(element);
  1352. var display = $prototypeFE(element).getStyle('display');
  1353. if (display != 'none' && display != null) // Safari bug
  1354. return {width: element.offsetWidth, height: element.offsetHeight};
  1355. // All *Width and *Height properties give 0 on elements with display none,
  1356. // so enable the element temporarily
  1357. var els = element.style;
  1358. var originalVisibility = els.visibility;
  1359. var originalPosition = els.position;
  1360. var originalDisplay = els.display;
  1361. els.visibility = 'hidden';
  1362. els.position = 'absolute';
  1363. els.display = 'block';
  1364. var originalWidth = element.clientWidth;
  1365. var originalHeight = element.clientHeight;
  1366. els.display = originalDisplay;
  1367. els.position = originalPosition;
  1368. els.visibility = originalVisibility;
  1369. return {width: originalWidth, height: originalHeight};
  1370. },
  1371. makePositioned: function(element) {
  1372. element = $prototypeFE(element);
  1373. var pos = Element.getStyle(element, 'position');
  1374. if (pos == 'static' || !pos) {
  1375. element._madePositioned = true;
  1376. element.style.position = 'relative';
  1377. // Opera returns the offset relative to the positioning context, when an
  1378. // element is position relative but top and left have not been defined
  1379. if (window.opera) {
  1380. element.style.top = 0;
  1381. element.style.left = 0;
  1382. }
  1383. }
  1384. return element;
  1385. },
  1386. undoPositioned: function(element) {
  1387. element = $prototypeFE(element);
  1388. if (element._madePositioned) {
  1389. element._madePositioned = undefined;
  1390. element.style.position =
  1391. element.style.top =
  1392. element.style.left =
  1393. element.style.bottom =
  1394. element.style.right = '';
  1395. }
  1396. return element;
  1397. },
  1398. makeClipping: function(element) {
  1399. element = $prototypeFE(element);
  1400. if (element._overflow) return element;
  1401. element._overflow = element.style.overflow || 'auto';
  1402. if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden')
  1403. element.style.overflow = 'hidden';
  1404. return element;
  1405. },
  1406. undoClipping: function(element) {
  1407. element = $prototypeFE(element);
  1408. if (!element._overflow) return element;
  1409. element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
  1410. element._overflow = null;
  1411. return element;
  1412. }
  1413. };
  1414. Object.extend(Element.Methods, {
  1415. childOf: Element.Methods.descendantOf,
  1416. childElements: Element.Methods.immediateDescendants
  1417. });
  1418. if (Prototype.Browser.Opera) {
  1419. Element.Methods._getStyle = Element.Methods.getStyle;
  1420. Element.Methods.getStyle = function(element, style) {
  1421. switch(style) {
  1422. case 'left':
  1423. case 'top':
  1424. case 'right':
  1425. case 'bottom':
  1426. if (Element._getStyle(element, 'position') == 'static') return null;
  1427. default: return Element._getStyle(element, style);
  1428. }
  1429. };
  1430. }
  1431. else if (Prototype.Browser.IE) {
  1432. Element.Methods.getStyle = function(element, style) {
  1433. element = $prototypeFE(element);
  1434. style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
  1435. var value = element.style[style];
  1436. if (!value && element.currentStyle) value = element.currentStyle[style];
  1437. if (style == 'opacity') {
  1438. if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
  1439. if (value[1]) return parseFloat(value[1]) / 100;
  1440. return 1.0;
  1441. }
  1442. if (value == 'auto') {
  1443. if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
  1444. return element['offset'+style.capitalize()] + 'px';
  1445. return null;
  1446. }
  1447. return value;
  1448. };
  1449. Element.Methods.setOpacity = function(element, value) {
  1450. element = $prototypeFE(element);
  1451. var filter = element.getStyle('filter'), style = element.style;
  1452. if (value == 1 || value === '') {
  1453. style.filter = filter.replace(/alpha\([^\)]*\)/gi,'');
  1454. return element;
  1455. } else if (value < 0.00001) value = 0;
  1456. style.filter = filter.replace(/alpha\([^\)]*\)/gi, '') +
  1457. 'alpha(opacity=' + (value * 100) + ')';
  1458. return element;
  1459. };
  1460. // IE is missing .innerHTML support for TABLE-related elements
  1461. Element.Methods.update = function(element, html) {
  1462. element = $prototypeFE(element);
  1463. html = typeof html == 'undefined' ? '' : html.toString();
  1464. var tagName = element.tagName.toUpperCase();
  1465. if (['THEAD','TBODY','TR','TD'].include(tagName)) {
  1466. var div = document.createElement('div');
  1467. switch (tagName) {
  1468. case 'THEAD':
  1469. case 'TBODY':
  1470. div.innerHTML = '<table><tbody>' + html.stripScripts() + '</tbody></table>';
  1471. depth = 2;
  1472. break;
  1473. case 'TR':
  1474. div.innerHTML = '<table><tbody><tr>' + html.stripScripts() + '</tr></tbody></table>';
  1475. depth = 3;
  1476. break;
  1477. case 'TD':
  1478. div.innerHTML = '<table><tbody><tr><td>' + html.stripScripts() + '</td></tr></tbody></table>';
  1479. depth = 4;
  1480. }
  1481. $A(element.childNodes).each(function(node) { element.removeChild(node) });
  1482. depth.times(function() { div = div.firstChild });
  1483. $A(div.childNodes).each(function(node) { element.appendChild(node) });
  1484. } else {
  1485. element.innerHTML = html.stripScripts();
  1486. }
  1487. setTimeout(function() { html.evalScripts() }, 10);
  1488. return element;
  1489. }
  1490. }
  1491. else if (Prototype.Browser.Gecko) {
  1492. Element.Methods.setOpacity = function(element, value) {
  1493. element = $prototypeFE(element);
  1494. element.style.opacity = (value == 1) ? 0.999999 :
  1495. (value === '') ? '' : (value < 0.00001) ? 0 : value;
  1496. return element;
  1497. };
  1498. }
  1499. Element._attributeTranslations = {
  1500. names: {
  1501. colspan: "colSpan",
  1502. rowspan: "rowSpan",
  1503. valign: "vAlign",
  1504. datetime: "dateTime",
  1505. accesskey: "accessKey",
  1506. tabindex: "tabIndex",
  1507. enctype: "encType",
  1508. maxlength: "maxLength",
  1509. readonly: "readOnly",
  1510. longdesc: "longDesc"
  1511. },
  1512. values: {
  1513. _getAttr: function(element, attribute) {
  1514. return element.getAttribute(attribute, 2);
  1515. },
  1516. _flag: function(element, attribute) {
  1517. return $prototypeFE(element).h