Changeset 6512

Show
Ignore:
Timestamp:
12/28/07 19:17:21 (1 year ago)
Author:
ryan
Message:

Prototype 1.6.0 and script.aculo.us 1.8.0. fixes #5543

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-includes/js/prototype.js

    r5743 r6512  
    1 /*  Prototype JavaScript framework, version 1.5.1.1 
     1/*  Prototype JavaScript framework, version 1.6.0 
    22 *  (c) 2005-2007 Sam Stephenson 
    33 * 
     
    55 *  For details, see the Prototype web site: http://www.prototypejs.org/ 
    66 * 
    7 /*--------------------------------------------------------------------------*/ 
     7 *--------------------------------------------------------------------------*/ 
    88 
    99var Prototype = { 
    10   Version: '1.5.1.1', 
     10  Version: '1.6.0', 
    1111 
    1212  Browser: { 
     
    1414    Opera:  !!window.opera, 
    1515    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1, 
    16     Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1 
     16    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1, 
     17    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/) 
    1718  }, 
    1819 
     
    2122    ElementExtensions: !!window.HTMLElement, 
    2223    SpecificElementExtensions: 
    23       (document.createElement('div').__proto__ !== 
    24        document.createElement('form').__proto__) 
     24      document.createElement('div').__proto__ && 
     25      document.createElement('div').__proto__ !== 
     26        document.createElement('form').__proto__ 
    2527  }, 
    2628 
     
    3032  emptyFunction: function() { }, 
    3133  K: function(x) { return x } 
    32 
    33  
     34}; 
     35 
     36if (Prototype.Browser.MobileSafari) 
     37  Prototype.BrowserFeatures.SpecificElementExtensions = false; 
     38 
     39if (Prototype.Browser.WebKit) 
     40  Prototype.BrowserFeatures.XPath = false; 
     41 
     42/* Based on Alex Arnell's inheritance implementation. */ 
    3443var Class = { 
    3544  create: function() { 
    36     return function() { 
     45    var parent = null, properties = $A(arguments); 
     46    if (Object.isFunction(properties[0])) 
     47      parent = properties.shift(); 
     48 
     49    function klass() { 
    3750      this.initialize.apply(this, arguments); 
    3851    } 
    39   } 
    40 
    41  
    42 var Abstract = new Object(); 
     52 
     53    Object.extend(klass, Class.Methods); 
     54    klass.superclass = parent; 
     55    klass.subclasses = []; 
     56 
     57    if (parent) { 
     58      var subclass = function() { }; 
     59      subclass.prototype = parent.prototype; 
     60      klass.prototype = new subclass; 
     61      parent.subclasses.push(klass); 
     62    } 
     63 
     64    for (var i = 0; i < properties.length; i++) 
     65      klass.addMethods(properties[i]); 
     66 
     67    if (!klass.prototype.initialize) 
     68      klass.prototype.initialize = Prototype.emptyFunction; 
     69 
     70    klass.prototype.constructor = klass; 
     71 
     72    return klass; 
     73  } 
     74}; 
     75 
     76Class.Methods = { 
     77  addMethods: function(source) { 
     78    var ancestor   = this.superclass && this.superclass.prototype; 
     79    var properties = Object.keys(source); 
     80 
     81    if (!Object.keys({ toString: true }).length) 
     82      properties.push("toString", "valueOf"); 
     83 
     84    for (var i = 0, length = properties.length; i < length; i++) { 
     85      var property = properties[i], value = source[property]; 
     86      if (ancestor && Object.isFunction(value) && 
     87          value.argumentNames().first() == "$super") { 
     88        var method = value, value = Object.extend((function(m) { 
     89          return function() { return ancestor[m].apply(this, arguments) }; 
     90        })(property).wrap(method), { 
     91          valueOf:  function() { return method }, 
     92          toString: function() { return method.toString() } 
     93        }); 
     94      } 
     95      this.prototype[property] = value; 
     96    } 
     97 
     98    return this; 
     99  } 
     100}; 
     101 
     102var Abstract = { }; 
    43103 
    44104Object.extend = function(destination, source) { 
    45   for (var property in source) { 
     105  for (var property in source) 
    46106    destination[property] = source[property]; 
    47   } 
    48107  return destination; 
    49 } 
     108}; 
    50109 
    51110Object.extend(Object, { 
     
    63122  toJSON: function(object) { 
    64123    var type = typeof object; 
    65     switch(type) { 
     124    switch (type) { 
    66125      case 'undefined': 
    67126      case 'function': 
     
    69128      case 'boolean': return object.toString(); 
    70129    } 
     130 
    71131    if (object === null) return 'null'; 
    72132    if (object.toJSON) return object.toJSON(); 
    73     if (object.ownerDocument === document) return; 
     133    if (Object.isElement(object)) return; 
     134 
    74135    var results = []; 
    75136    for (var property in object) { 
     
    78139        results.push(property.toJSON() + ': ' + value); 
    79140    } 
     141 
    80142    return '{' + results.join(', ') + '}'; 
     143  }, 
     144 
     145  toQueryString: function(object) { 
     146    return $H(object).toQueryString(); 
     147  }, 
     148 
     149  toHTML: function(object) { 
     150    return object && object.toHTML ? object.toHTML() : String.interpret(object); 
    81151  }, 
    82152 
     
    96166 
    97167  clone: function(object) { 
    98     return Object.extend({}, object); 
     168    return Object.extend({ }, object); 
     169  }, 
     170 
     171  isElement: function(object) { 
     172    return object && object.nodeType == 1; 
     173  }, 
     174 
     175  isArray: function(object) { 
     176    return object && object.constructor === Array; 
     177  }, 
     178 
     179  isHash: function(object) { 
     180    return object instanceof Hash; 
     181  }, 
     182 
     183  isFunction: function(object) { 
     184    return typeof object == "function"; 
     185  }, 
     186 
     187  isString: function(object) { 
     188    return typeof object == "string"; 
     189  }, 
     190 
     191  isNumber: function(object) { 
     192    return typeof object == "number"; 
     193  }, 
     194 
     195  isUndefined: function(object) { 
     196    return typeof object == "undefined"; 
    99197  } 
    100198}); 
    101199 
    102 Function.prototype.bind = function() { 
    103   var __method = this, args = $A(arguments), object = args.shift(); 
    104   return function() { 
    105     return __method.apply(object, args.concat($A(arguments))); 
    106   } 
    107 
    108  
    109 Function.prototype.bindAsEventListener = function(object) { 
    110   var __method = this, args = $A(arguments), object = args.shift(); 
    111   return function(event) { 
    112     return __method.apply(object, [event || window.event].concat(args)); 
    113   } 
    114 
    115  
    116 Object.extend(Number.prototype, { 
    117   toColorPart: function() { 
    118     return this.toPaddedString(2, 16); 
    119   }, 
    120  
    121   succ: function() { 
    122     return this + 1; 
    123   }, 
    124  
    125   times: function(iterator) { 
    126     $R(0, this, true).each(iterator); 
    127     return this; 
    128   }, 
    129  
    130   toPaddedString: function(length, radix) { 
    131     var string = this.toString(radix || 10); 
    132     return '0'.times(length - string.length) + string; 
    133   }, 
    134  
    135   toJSON: function() { 
    136     return isFinite(this) ? this.toString() : 'null'; 
     200Object.extend(Function.prototype, { 
     201  argumentNames: function() { 
     202    var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip"); 
     203    return names.length == 1 && !names[0] ? [] : names; 
     204  }, 
     205 
     206  bind: function() { 
     207    if (arguments.length < 2 && arguments[0] === undefined) return this; 
     208    var __method = this, args = $A(arguments), object = args.shift(); 
     209    return function() { 
     210      return __method.apply(object, args.concat($A(arguments))); 
     211    } 
     212  }, 
     213 
     214  bindAsEventListener: function() { 
     215    var __method = this, args = $A(arguments), object = args.shift(); 
     216    return function(event) { 
     217      return __method.apply(object, [event || window.event].concat(args)); 
     218    } 
     219  }, 
     220 
     221  curry: function() { 
     222    if (!arguments.length) return this; 
     223    var __method = this, args = $A(arguments); 
     224    return function() { 
     225      return __method.apply(this, args.concat($A(arguments))); 
     226    } 
     227  }, 
     228 
     229  delay: function() { 
     230    var __method = this, args = $A(arguments), timeout = args.shift() * 1000; 
     231    return window.setTimeout(function() { 
     232      return __method.apply(__method, args); 
     233    }, timeout); 
     234  }, 
     235 
     236  wrap: function(wrapper) { 
     237    var __method = this; 
     238    return function() { 
     239      return wrapper.apply(this, [__method.bind(this)].concat($A(arguments))); 
     240    } 
     241  }, 
     242 
     243  methodize: function() { 
     244    if (this._methodized) return this._methodized; 
     245    var __method = this; 
     246    return this._methodized = function() { 
     247      return __method.apply(null, [this].concat($A(arguments))); 
     248    }; 
    137249  } 
    138250}); 
    139251 
     252Function.prototype.defer = Function.prototype.delay.curry(0.01); 
     253 
    140254Date.prototype.toJSON = function() { 
    141   return '"' + this.getFullYear() + '-' + 
    142     (this.getMonth() + 1).toPaddedString(2) + '-' + 
    143     this.getDate().toPaddedString(2) + 'T' + 
    144     this.getHours().toPaddedString(2) + ':' + 
    145     this.getMinutes().toPaddedString(2) + ':' + 
    146     this.getSeconds().toPaddedString(2) + '"'; 
     255  return '"' + this.getUTCFullYear() + '-' + 
     256    (this.getUTCMonth() + 1).toPaddedString(2) + '-' + 
     257    this.getUTCDate().toPaddedString(2) + 'T' + 
     258    this.getUTCHours().toPaddedString(2) + ':' + 
     259    this.getUTCMinutes().toPaddedString(2) + ':' + 
     260    this.getUTCSeconds().toPaddedString(2) + 'Z"'; 
    147261}; 
    148262 
     
    156270        returnValue = lambda(); 
    157271        break; 
    158       } catch (e) {
     272      } catch (e) {
    159273    } 
    160274 
    161275    return returnValue; 
    162276  } 
    163 
     277}; 
     278 
     279RegExp.prototype.match = RegExp.prototype.test; 
     280 
     281RegExp.escape = function(str) { 
     282  return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); 
     283}; 
    164284 
    165285/*--------------------------------------------------------------------------*/ 
    166286 
    167 var PeriodicalExecuter = Class.create(); 
    168 PeriodicalExecuter.prototype = { 
     287var PeriodicalExecuter = Class.create({ 
    169288  initialize: function(callback, frequency) { 
    170289    this.callback = callback; 
     
    179298  }, 
    180299 
     300  execute: function() { 
     301    this.callback(this); 
     302  }, 
     303 
    181304  stop: function() { 
    182305    if (!this.timer) return; 
     
    189312      try { 
    190313        this.currentlyExecuting = true; 
    191         this.callback(this); 
     314        this.execute(); 
    192315      } finally { 
    193316        this.currentlyExecuting = false; 
     
    195318    } 
    196319  } 
    197 } 
     320}); 
    198321Object.extend(String, { 
    199322  interpret: function(value) { 
     
    239362  scan: function(pattern, iterator) { 
    240363    this.gsub(pattern, iterator); 
    241     return this
     364    return String(this)
    242365  }, 
    243366 
     
    246369    truncation = truncation === undefined ? '...' : truncation; 
    247370    return this.length > length ? 
    248       this.slice(0, length - truncation.length) + truncation : this
     371      this.slice(0, length - truncation.length) + truncation : String(this)
    249372  }, 
    250373 
     
    280403 
    281404  unescapeHTML: function() { 
    282     var div = document.createElement('div'); 
     405    var div = new Element('div'); 
    283406    div.innerHTML = this.stripTags(); 
    284407    return div.childNodes[0] ? (div.childNodes.length > 1 ? 
     
    289412  toQueryParams: function(separator) { 
    290413    var match = this.strip().match(/([^?#]*)(#.*)?$/); 
    291     if (!match) return {}; 
    292  
    293     return match[1].split(separator || '&').inject({}, function(hash, pair) { 
     414    if (!match) return { }; 
     415 
     416    return match[1].split(separator || '&').inject({ }, function(hash, pair) { 
    294417      if ((pair = pair.split('='))[0]) { 
    295418        var key = decodeURIComponent(pair.shift()); 
     
    298421 
    299422        if (key in hash) { 
    300           if (hash[key].constructor != Array) hash[key] = [hash[key]]; 
     423          if (!Object.isArray(hash[key])) hash[key] = [hash[key]]; 
    301424          hash[key].push(value); 
    302425        } 
     
    317440 
    318441  times: function(count) { 
    319     var result = ''; 
    320     for (var i = 0; i < count; i++) result += this; 
    321     return result; 
     442    return count < 1 ? '' : new Array(count + 1).join(this); 
    322443  }, 
    323444 
     
    397518  blank: function() { 
    398519    return /^\s*$/.test(this); 
     520  }, 
     521 
     522  interpolate: function(object, pattern) { 
     523    return new Template(this, pattern).evaluate(object); 
    399524  } 
    400525}); 
     
    410535 
    411536String.prototype.gsub.prepareReplacement = function(replacement) { 
    412   if (typeof replacement == 'function') return replacement; 
     537  if (Object.isFunction(replacement)) return replacement; 
    413538  var template = new Template(replacement); 
    414539  return function(match) { return template.evaluate(match) }; 
    415 } 
     540}; 
    416541 
    417542String.prototype.parseQuery = String.prototype.toQueryParams; 
     
    424549with (String.prototype.escapeHTML) div.appendChild(text); 
    425550 
    426 var Template = Class.create(); 
    427 Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/; 
    428 Template.prototype = { 
     551var Template = Class.create({ 
    429552  initialize: function(template, pattern) { 
    430553    this.template = template.toString(); 
    431     this.pattern = pattern || Template.Pattern; 
     554    this.pattern = pattern || Template.Pattern; 
    432555  }, 
    433556 
    434557  evaluate: function(object) { 
     558    if (Object.isFunction(object.toTemplateReplacements)) 
     559      object = object.toTemplateReplacements(); 
     560 
    435561    return this.template.gsub(this.pattern, function(match) { 
    436       var before = match[1]; 
     562      if (object == null) return ''; 
     563 
     564      var before = match[1] || ''; 
    437565      if (before == '\\') return match[2]; 
    438       return before + String.interpret(object[match[3]]); 
    439     }); 
    440   } 
    441 
    442  
    443 var $break = {}, $continue = new Error('"throw $continue" is deprecated, use "return" instead'); 
     566 
     567      var ctx = object, expr = match[3]; 
     568      var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/, match = pattern.exec(expr); 
     569      if (match == null) return before; 
     570 
     571      while (match != null) { 
     572        var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1]; 
     573        ctx = ctx[comp]; 
     574        if (null == ctx || '' == match[3]) break; 
     575        expr = expr.substring('[' == match[3] ? match[1].length : match[0].length); 
     576        match = pattern.exec(expr); 
     577      } 
     578 
     579      return before + String.interpret(ctx); 
     580    }.bind(this)); 
     581  } 
     582}); 
     583Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/; 
     584 
     585var $break = { }; 
    444586 
    445587var Enumerable = { 
    446   each: function(iterator) { 
     588  each: function(iterator, context) { 
    447589    var index = 0; 
     590    iterator = iterator.bind(context); 
    448591    try { 
    449592      this._each(function(value) { 
     
    456599  }, 
    457600 
    458   eachSlice: function(number, iterator) { 
     601  eachSlice: function(number, iterator, context) { 
     602    iterator = iterator ? iterator.bind(context) : Prototype.K; 
    459603    var index = -number, slices = [], array = this.toArray(); 
    460604    while ((index += number) < array.length) 
    461605      slices.push(array.slice(index, index+number)); 
    462     return slices.map(iterator); 
    463   }, 
    464  
    465   all: function(iterator) { 
     606    return slices.collect(iterator, context); 
     607  }, 
     608 
     609  all: function(iterator, context) { 
     610    iterator = iterator ? iterator.bind(context) : Prototype.K; 
    466611    var result = true; 
    467612    this.each(function(value, index) { 
    468       result = result && !!(iterator || Prototype.K)(value, index); 
     613      result = result && !!iterator(value, index); 
    469614      if (!result) throw $break; 
    470615    }); 
     
    472617  }, 
    473618 
    474   any: function(iterator) { 
     619  any: function(iterator, context) { 
     620    iterator = iterator ? iterator.bind(context) : Prototype.K; 
    475621    var result = false; 
    476622    this.each(function(value, index) { 
    477       if (result = !!(iterator || Prototype.K)(value, index)) 
     623      if (result = !!iterator(value, index)) 
    478624        throw $break; 
    479625    }); 
     
    481627  }, 
    482628 
    483   collect: function(iterator) { 
     629  collect: function(iterator, context) { 
     630    iterator = iterator ? iterator.bind(context) : Prototype.K; 
    484631    var results = []; 
    485632    this.each(function(value, index) { 
    486       results.push((iterator || Prototype.K)(value, index)); 
     633      results.push(iterator(value, index)); 
    487634    }); 
    488635    return results; 
    489636  }, 
    490637 
    491   detect: function(iterator) { 
     638  detect: function(iterator, context) { 
     639    iterator = iterator.bind(context); 
    492640    var result; 
    493641    this.each(function(value, index) { 
     
    500648  }, 
    501649 
    502   findAll: function(iterator) { 
     650  findAll: function(iterator, context) { 
     651    iterator = iterator.bind(context); 
    503652    var results = []; 
    504653    this.each(function(value, index) { 
     
    509658  }, 
    510659 
    511   grep: function(pattern, iterator) { 
     660  grep: function(filter, iterator, context) { 
     661    iterator = iterator ? iterator.bind(context) : Prototype.K; 
    512662    var results = []; 
     663 
     664    if (Object.isString(filter)) 
     665      filter = new RegExp(filter); 
     666 
    513667    this.each(function(value, index) { 
    514       var stringValue = value.toString(); 
    515       if (stringValue.match(pattern)) 
    516         results.push((iterator || Prototype.K)(value, index)); 
    517     }) 
     668      if (filter.match(value)) 
     669        results.push(iterator(value, index)); 
     670    }); 
    518671    return results; 
    519672  }, 
    520673 
    521674  include: function(object) { 
     675    if (Object.isFunction(this.indexOf)) 
     676      if (this.indexOf(object) != -1) return true; 
     677 
    522678    var found = false; 
    523679    this.each(function(value) { 
     
    538694  }, 
    539695 
    540   inject: function(memo, iterator) { 
     696  inject: function(memo, iterator, context) { 
     697    iterator = iterator.bind(context); 
    541698    this.each(function(value, index) { 
    542699      memo = iterator(memo, value, index); 
     
    552709  }, 
    553710 
    554   max: function(iterator) { 
     711  max: function(iterator, context) { 
     712    iterator = iterator ? iterator.bind(context) : Prototype.K; 
    555713    var result; 
    556714    this.each(function(value, index) { 
    557       value = (iterator || Prototype.K)(value, index); 
     715      value = iterator(value, index); 
    558716      if (result == undefined || value >= result) 
    559717        result = value; 
     
    562720  }, 
    563721 
    564   min: function(iterator) { 
     722  min: function(iterator, context) { 
     723    iterator = iterator ? iterator.bind(context) : Prototype.K; 
    565724    var result; 
    566725    this.each(function(value, index) { 
    567       value = (iterator || Prototype.K)(value, index); 
     726      value = iterator(value, index); 
    568727      if (result == undefined || value < result) 
    569728        result = value; 
     
    572731  }, 
    573732 
    574   partition: function(iterator) { 
     733  partition: function(iterator, context) { 
     734    iterator = iterator ? iterator.bind(context) : Prototype.K; 
    575735    var trues = [], falses = []; 
    576736    this.each(function(value, index) { 
    577       ((iterator || Prototype.K)(value, index) ? 
     737      (iterator(value, index) ? 
    578738        trues : falses).push(value); 
    579739    }); 
     
    583743  pluck: function(property) { 
    584744    var results = []; 
    585     this.each(function(value, index) { 
     745    this.each(function(value) { 
    586746      results.push(value[property]); 
    587747    }); 
     
    589749  }, 
    590750 
    591   reject: function(iterator) { 
     751  reject: function(iterator, context) { 
     752    iterator = iterator.bind(context); 
    592753    var results = []; 
    593754    this.each(function(value, index) { 
     
    598759  }, 
    599760 
    600   sortBy: function(iterator) { 
     761  sortBy: function(iterator, context) { 
     762    iterator = iterator.bind(context); 
    601763    return this.map(function(value, index) { 
    602764      return {value: value, criteria: iterator(value, index)}; 
     
    613775  zip: function() { 
    614776    var iterator = Prototype.K, args = $A(arguments); 
    615     if (typeof args.last() == 'function'
     777    if (Object.isFunction(args.last())
    616778      iterator = args.pop(); 
    617779 
     
    629791    return '#<Enumerable:' + this.toArray().inspect() + '>'; 
    630792  } 
    631 } 
     793}; 
    632794 
    633795Object.extend(Enumerable, { 
     
    635797  find:    Enumerable.detect, 
    636798  select:  Enumerable.findAll, 
     799  filter:  Enumerable.findAll, 
    637800  member:  Enumerable.include, 
    638   entries: Enumerable.toArray 
     801  entries: Enumerable.toArray, 
     802  every:   Enumerable.all, 
     803  some:    Enumerable.any 
    639804}); 
    640 var $A = Array.from = function(iterable) { 
     805function $A(iterable) { 
    641806  if (!iterable) return []; 
    642   if (iterable.toArray) { 
    643     return iterable.toArray(); 
    644   } else { 
    645     var results = []; 
    646     for (var i = 0, length = iterable.length; i < length; i++) 
    647       results.push(iterable[i]); 
     807  if (iterable.toArray) return iterable.toArray(); 
     808  var length = iterable.length, results = new Array(length); 
     809  while (length--) results[length] = iterable[length]; 
     810  return results; 
     811
     812 
     813if (Prototype.Browser.WebKit) { 
     814  function $A(iterable) { 
     815    if (!iterable) return []; 
     816    if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') && 
     817        iterable.toArray) return iterable.toArray(); 
     818    var length = iterable.length, results = new Array(length); 
     819    while (length--) results[length] = iterable[length]; 
    648820    return results; 
    649821  } 
    650822} 
    651823 
    652 if (Prototype.Browser.WebKit) { 
    653   $A = Array.from = function(iterable) { 
    654     if (!iterable) return []; 
    655     if (!(typeof iterable == 'function' && iterable == '[object NodeList]') && 
    656       iterable.toArray) { 
    657       return iterable.toArray(); 
    658     } else { 
    659       var results = []; 
    660       for (var i = 0, length = iterable.length; i < length; i++) 
    661         results.push(iterable[i]); 
    662       return results; 
    663     } 
    664   } 
    665 
     824Array.from = $A; 
    666825 
    667826Object.extend(Array.prototype, Enumerable); 
    668827 
    669 if (!Array.prototype._reverse) 
    670   Array.prototype._reverse = Array.prototype.reverse; 
     828if (!Array.prototype._reverse) Array.prototype._reverse = Array.prototype.reverse; 
    671829 
    672830Object.extend(Array.prototype, { 
     
    697855  flatten: function() { 
    698856    return this.inject([], function(array, value) { 
    699       return array.concat(value && value.constructor == Array
     857      return array.concat(Object.isArray(value)
    700858        value.flatten() : [value]); 
    701859    }); 
     
    709867  }, 
    710868 
    711   indexOf: function(object) { 
    712     for (var i = 0, length = this.length; i < length; i++) 
    713       if (this[i] == object) return i; 
    714     return -1; 
    715   }, 
    716  
    717869  reverse: function(inline) { 
    718870    return (inline !== false ? this : this.toArray())._reverse(); 
     
    728880        array.push(value); 
    729881      return array; 
     882    }); 
     883  }, 
     884 
     885  intersect: function(array) { 
     886    return this.uniq().findAll(function(item) { 
     887      return array.detect(function(value) { return item === value }); 
    730888    }); 
    731889  }, 
     
    753911}); 
    754912 
     913// use native browser JS 1.6 implementation if available 
     914if (Object.isFunction(Array.prototype.forEach)) 
     915  Array.prototype._each = Array.prototype.forEach; 
     916 
     917if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) { 
     918  i || (i = 0); 
     919  var length = this.length; 
     920  if (i < 0) i = length + i; 
     921  for (; i < length; i++) 
     922    if (this[i] === item) return i; 
     923  return -1; 
     924}; 
     925 
     926if (!Array.prototype.lastIndexOf) Array.prototype.lastIndexOf = function(item, i) { 
     927  i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1; 
     928  var n = this.slice(0, i).reverse().indexOf(item); 
     929  return (n < 0) ? n : i - n - 1; 
     930}; 
     931 
    755932Array.prototype.toArray = Array.prototype.clone; 
    756933 
    757934function $w(string) { 
     935  if (!Object.isString(string)) return []; 
    758936  string = string.strip(); 
    759937  return string ? string.split(/\s+/) : []; 
     
    765943    for (var i = 0, length = this.length; i < length; i++) array.push(this[i]); 
    766944    for (var i = 0, length = arguments.length; i < length; i++) { 
    767       if (arguments[i].constructor == Array) { 
     945      if (Object.isArray(arguments[i])) { 
    768946        for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++) 
    769947          array.push(arguments[i][j]); 
     
    773951    } 
    774952    return array; 
    775   } 
     953  }; 
    776954} 
    777 var Hash = function(object) { 
    778   if (object instanceof Hash) this.merge(object); 
    779   else Object.extend(this, object || {}); 
    780 }; 
    781  
    782 Object.extend(Hash, { 
    783   toQueryString: function(obj) { 
    784     var parts = []; 
    785     parts.add = arguments.callee.addPair; 
    786  
    787     this.prototype._each.call(obj, function(pair) { 
    788       if (!pair.key) return; 
    789       var value = pair.value; 
    790  
    791       if (value && typeof value == 'object') { 
    792         if (value.constructor == Array) value.each(function(value) { 
    793           parts.add(pair.key, value); 
    794         }); 
    795         return; 
    796       } 
    797       parts.add(pair.key, value); 
    798     }); 
    799  
    800     return parts.join('&'); 
    801   }, 
    802  
    803   toJSON: function(object) { 
    804     var results = []; 
    805     this.prototype._each.call(object, function(pair) { 
    806       var value = Object.toJSON(pair.value); 
    807       if (value !== undefined) results.push(pair.key.toJSON() + ': ' + value); 
    808     }); 
    809     return '{' + results.join(', ') + '}'; 
     955Object.extend(Number.prototype, { 
     956  toColorPart: function() { 
     957    return this.toPaddedString(2, 16); 
     958  }, 
     959 
     960  succ: function() { 
     961    return this + 1; 
     962  }, 
     963 
     964  times: function(iterator) { 
     965    $R(0, this, true).each(iterator); 
     966    return this; 
     967  }, 
     968 
     969  toPaddedString: function(length, radix) { 
     970    var string = this.toString(radix || 10); 
     971    return '0'.times(length - string.length) + string; 
     972  }, 
     973 
     974  toJSON: function() { 
     975    return isFinite(this) ? this.toString() : 'null'; 
    810976  } 
    811977}); 
    812978 
    813 Hash.toQueryString.addPair = function(key, value, prefix) { 
    814   key = encodeURIComponent(key); 
    815   if (value === undefined) this.push(key); 
    816   else this.push(key + '=' + (value == null ? '' : encodeURIComponent(value))); 
    817 
    818  
    819 Object.extend(Hash.prototype, Enumerable); 
    820 Object.extend(Hash.prototype, { 
    821   _each: function(iterator) { 
    822     for (var key in this) { 
    823       var value = this[key]; 
    824       if (value && value == Hash.prototype[key]) continue; 
    825  
    826       var pair = [key, value]; 
    827       pair.key = key; 
    828       pair.value = value; 
    829       iterator(pair); 
    830     } 
    831   }, 
    832  
    833   keys: function() { 
    834     return this.pluck('key'); 
    835   }, 
    836  
    837   values: function() { 
    838     return this.pluck('value'); 
    839   }, 
    840  
    841   merge: function(hash) { 
    842     return $H(hash).inject(this, function(mergedHash, pair) { 
    843       mergedHash[pair.key] = pair.value; 
    844       return mergedHash; 
    845     }); 
    846   }, 
    847  
    848   remove: function() { 
    849     var result; 
    850     for(var i = 0, length = arguments.length; i < length; i++) { 
    851       var value = this[arguments[i]]; 
    852       if (value !== undefined){ 
    853         if (result === undefined) result = value; 
    854         else { 
    855           if (result.constructor != Array) result = [result]; 
    856           result.push(value) 
    857         } 
    858       } 
    859       delete this[arguments[i]]; 
    860     } 
    861     return result; 
    862   }, 
    863  
    864   toQueryString: function() { 
    865     return Hash.toQueryString(this); 
    866   }, 
    867  
    868   inspect: function() { 
    869     return '#<Hash:{' + this.map(function(pair) { 
    870       return pair.map(Object.inspect).join(': '); 
    871     }).join(', ') + '}>'; 
    872   }, 
    873  
    874   toJSON: function() { 
    875     return Hash.toJSON(this); 
    876   } 
     979$w('abs round ceil floor').each(function(method){ 
     980  Number.prototype[method] = Math[method].methodize(); 
    877981}); 
    878  
    879982function $H(object) { 
    880   if (object instanceof Hash) return object; 
    881983  return new Hash(object); 
    882984}; 
    883985 
    884 // Safari iterates over shadowed properties 
    885 if (function() { 
    886   var i = 0, Test = function(value) { this.key = value }; 
    887   Test.prototype.key = 'foo'; 
    888   for (var property in new Test('bar')) i++; 
    889   return i > 1; 
    890 }()) Hash.prototype._each = function(iterator) { 
    891   var cache = []; 
    892   for (var key in this) { 
    893     var value = this[key]; 
    894     if ((value && value == Hash.prototype[key]) || cache.include(key)) continue; 
    895     cache.push(key); 
    896     var pair = [key, value]; 
    897     pair.key = key; 
    898     pair.value = value; 
    899     iterator(pair); 
    900   } 
    901 }; 
    902 ObjectRange = Class.create(); 
    903 Object.extend(ObjectRange.prototype, Enumerable); 
    904 Object.extend(ObjectRange.prototype, { 
     986var Hash = Class.create(Enumerable, (function() { 
     987  if (function() { 
     988    var i = 0, Test = function(value) { this.key = value }; 
     989    Test.prototype.key = 'foo'; 
     990    for (var property in new Test('bar')) i++; 
     991    return i > 1; 
     992  }()) { 
     993    function each(iterator) { 
     994      var cache = []; 
     995      for (var key in this._object) { 
     996        var value = this._object[key]; 
     997        if (cache.include(key)) continue; 
     998        cache.push(key); 
     999        var pair = [key, value]; 
     1000        pair.key = key; 
     1001        pair.value = value; 
     1002        iterator(pair); 
     1003      } 
     1004    } 
     1005  } else { 
     1006    function each(iterator) { 
     1007      for (var key in this._object) { 
     1008        var value = this._object[key], pair = [key, value]; 
     1009        pair.key = key; 
     1010        pair.value = value; 
     1011        iterator(pair); 
     1012      } 
     1013    } 
     1014  } 
     1015 
     1016  function toQueryPair(key, value) { 
     1017    if (Object.isUndefined(value)) return key; 
     1018    return key + '=' + encodeURIComponent(String.interpret(value)); 
     1019  } 
     1020 
     1021  return { 
     1022    initialize: function(object) { 
     1023      this._object = Object.isHash(object) ? object.toObject() : Object.clone(object); 
     1024    }, 
     1025 
     1026    _each: each, 
     1027 
     1028    set: function(key, value) { 
     1029      return this._object[key] = value; 
     1030    }, 
     1031 
     1032    get: function(key) { 
     1033      return this._object[key]; 
     1034    }, 
     1035 
     1036    unset: function(key) { 
     1037      var value = this._object[key]; 
     1038      delete this._object[key]; 
     1039      return value; 
     1040    }, 
     1041 
     1042    toObject: function() { 
     1043      return Object.clone(this._object); 
     1044    }, 
     1045 
     1046    keys: function() { 
     1047      return this.pluck('key'); 
     1048    }, 
     1049 
     1050    values: function() { 
     1051      return this.pluck('value'); 
     1052    }, 
     1053 
     1054    index: function(value) { 
     1055      var match = this.detect(function(pair) { 
     1056        return pair.value === value; 
     1057      }); 
     1058      return match && match.key; 
     1059    }, 
     1060 
     1061    merge: function(object) { 
     1062      return this.clone().update(object); 
     1063    }, 
     1064 
     1065    update: function(object) { 
     1066      return new Hash(object).inject(this, function(result, pair) { 
     1067        result.set(pair.key, pair.value); 
     1068        return result; 
     1069      }); 
     1070    }, 
     1071 
     1072    toQueryString: function() { 
     1073      return this.map(function(pair) { 
     1074        var key = encodeURIComponent(pair.key), values = pair.value; 
     1075 
     1076        if (values && typeof values == 'object') { 
     1077          if (Object.isArray(values)) 
     1078            return values.map(toQueryPair.curry(key)).join('&'); 
     1079        } 
     1080        return toQueryPair(key, values); 
     1081      }).join('&'); 
     1082    }, 
     1083 
     1084    inspect: function() { 
     1085      return '#<Hash:{' + this.map(function(pair) { 
     1086        return pair.map(Object.inspect).join(': '); 
     1087      }).join(', ') + '}>'; 
     1088    }, 
     1089 
     1090    toJSON: function() { 
     1091      return Object.toJSON(this.toObject()); 
     1092    }, 
     1093 
     1094    clone: function() { 
     1095      return new Hash(this); 
     1096    } 
     1097  } 
     1098})()); 
     1099 
     1100Hash.prototype.toTemplateReplacements = Hash.prototype.toObject; 
     1101Hash.from = $H; 
     1102var ObjectRange = Class.create(Enumerable, { 
    9051103  initialize: function(start, end, exclusive) { 
    9061104    this.start = start; 
     
    9281126var $R = function(start, end, exclusive) { 
    9291127  return new ObjectRange(start, end, exclusive); 
    930 } 
     1128}; 
    9311129 
    9321130var Ajax = { 
     
    9401138 
    9411139  activeRequestCount: 0 
    942 } 
     1140}; 
    9431141 
    9441142Ajax.Responders = { 
     
    9601158  dispatch: function(callback, request, transport, json) { 
    9611159    this.each(function(responder) { 
    962       if (typeof responder[callback] == 'function') { 
     1160      if (Object.isFunction(responder[callback])) { 
    9631161        try { 
    9641162          responder[callback].apply(responder, [request, transport, json]); 
    965         } catch (e) {
     1163        } catch (e) {
    9661164      } 
    9671165    }); 
     
    9721170 
    9731171Ajax.Responders.register({ 
    974   onCreate: function() { 
    975     Ajax.activeRequestCount++; 
    976   }, 
    977   onComplete: function() { 
    978     Ajax.activeRequestCount--; 
    979   } 
     1172  onCreate:   function() { Ajax.activeRequestCount++ }, 
     1173  onComplete: function() { Ajax.activeRequestCount-- } 
    9801174}); 
    9811175 
    982 Ajax.Base = function() {}; 
    983 Ajax.Base.prototype = { 
    984   setOptions: function(options) { 
     1176Ajax.Base = Class.create({ 
     1177  initialize: function(options) { 
    9851178    this.options = { 
    9861179      method:       'post', 
     
    9881181      contentType:  'application/x-www-form-urlencoded', 
    9891182      encoding:     'UTF-8', 
    990       parameters:   '' 
    991     } 
    992     Object.extend(this.options, options || {}); 
     1183      parameters:   '', 
     1184      evalJSON:     true, 
     1185      evalJS:       true 
     1186    }; 
     1187    Object.extend(this.options, options || { }); 
    9931188 
    9941189    this.options.method = this.options.method.toLowerCase(); 
    995     if (typeof this.options.parameters == 'string'
     1190    if (Object.isString(this.options.parameters)
    9961191      this.options.parameters = this.options.parameters.toQueryParams(); 
    9971192  } 
    998 
    999  
    1000 Ajax.Request = Class.create(); 
    1001 Ajax.Request.Events = 
    1002   ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete']; 
    1003  
    1004 Ajax.Request.prototype = Object.extend(new Ajax.Base(), { 
     1193}); 
     1194 
     1195Ajax.Request = Class.create(Ajax.Base, { 
    10051196  _complete: false, 
    10061197 
    1007   initialize: function(url, options) { 
     1198  initialize: function($super, url, options) { 
     1199    $super(options); 
    10081200    this.transport = Ajax.getTransport(); 
    1009     this.setOptions(options); 
    10101201    this.request(url); 
    10111202  }, 
     
    10241215    this.parameters = params; 
    10251216 
    1026     if (params = Hash.toQueryString(params)) { 
     1217    if (params = Object.toQueryString(params)) { 
    10271218      // when GET, append parameters to URL 
    10281219      if (this.method == 'get') 
     
    10331224 
    10341225    try { 
    1035       if (this.options.onCreate) this.options.onCreate(this.transport); 
    1036       Ajax.Responders.dispatch('onCreate', this, this.transport); 
     1226      var response = new Ajax.Response(this); 
     1227      if (this.options.onCreate) this.options.onCreate(response);&nbs