PageRenderTime 63ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/include/js/prototype.php

https://bitbucket.org/icarito/pmc
PHP | 8435 lines | 7033 code | 1055 blank | 347 comment | 1509 complexity | bb3bf7ccd5515ab5c045f0edbecf000b MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1

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

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

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