PageRenderTime 84ms CodeModel.GetById 17ms app.highlight 53ms RepoModel.GetById 0ms app.codeStats 1ms

/Web/wp-includes/js/prototype.js

https://bitbucket.org/jimjenkins5/blog
JavaScript | 4874 lines | 4739 code | 127 blank | 8 comment | 120 complexity | 965fe52b851d8ff3c2b915ada9fb273f MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1

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

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

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