Make WordPress Core

Changeset 4813


Ignore:
Timestamp:
01/26/2007 03:41:17 AM (18 years ago)
Author:
ryan
Message:

Update to prototype 1.5.0 and scriptaculous 1.7.0. Fix some AJAXy bits. Props mdawaffe. fixes #3645 #3676 #3519

Location:
trunk/wp-includes
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/list-manipulation-js.php

    r4768 r4813  
    3333        if ( ajaxAdd.notInitialized() )
    3434            return true;
    35         ajaxAdd.options.parameters += '&action=' + ( update ? 'update-' : 'add-' ) + what + '&' + this.grabInputs( where, ajaxAdd ) + this.inputData;
     35        var action = ( update ? 'update-' : 'add-' ) + what;
     36        ajaxAdd.options.parameters = $H(ajaxAdd.options.parameters).merge({action: action}).merge(this.inputData.toQueryParams()).merge(this.grabInputs( where, ajaxAdd ).toQueryParams());
     37
    3638        var tempObj=this;
    3739        ajaxAdd.addOnComplete( function(transport) {
     
    8082            return true;
    8183        var tempObj = this;
    82         var action = 'delete-' + what + '&id=' + id;
     84        var action = 'delete-' + what;
     85        var actionId = action + '&id=' + id;
    8386        var idName = what.replace('-as-spam','') + '-' + id;
    8487        ajaxDel.addOnComplete( function(transport) {
    8588            Element.update(ajaxDel.myResponseElement,'');
    86             tempObj.destore(action);
     89            tempObj.destore(actionId);
    8790            if( tempObj.delComplete && typeof tempObj.delComplete == 'function' )
    8891                tempObj.delComplete( what, id, transport );
    8992        });
    90         ajaxDel.addOnWPError( function(transport) { tempObj.restore(action, true); });
    91         ajaxDel.options.parameters += '&action=' + action + this.inputData;
     93        ajaxDel.addOnWPError( function(transport) { tempObj.restore(actionId, true); });
     94        ajaxDel.options.parameters = $H(ajaxDel.options.parameters).merge({action: action, id: id}).merge(this.inputData.toQueryParams());
    9295        ajaxDel.request(ajaxDel.url);
    93         this.store(action, idName);
     96        this.store(actionId, idName);
    9497        tempObj.removeListItem( idName );
    9598        return false;
     
    103106            return true;
    104107        var tempObj = this;
    105         var action = 'dim-' + what + '&id=' + id;
     108        var action = 'dim-' + what;
     109        var actionId = action + '&id=' + id;
    106110        var idName = what + '-' + id;
    107111        ajaxDim.addOnComplete( function(transport) {
    108112            Element.update(ajaxDim.myResponseElement,'');
    109             tempObj.destore(action);
     113            tempObj.destore(actionId);
    110114            if ( tempObj.dimComplete && typeof tempObj.dimComplete == 'function' )
    111115                tempObj.dimComplete( what, id, dimClass, transport );
    112116        });
    113         ajaxDim.addOnWPError( function(transport) { tempObj.restore(action, true); });
    114         ajaxDim.options.parameters += '&action=' + action + this.inputData;
     117        ajaxDim.addOnWPError( function(transport) { tempObj.restore(actionId, true); });
     118        ajaxDim.options.parameters = $H(ajaxDim.options.parameters).merge({action: action, id: id}).merge(this.inputData.toQueryParams());
    115119        ajaxDim.request(ajaxDim.url);
    116         this.store(action, idName);
     120        this.store(actionId, idName);
    117121        this.dimItem( idName, dimClass );
    118122        return false;
  • trunk/wp-includes/js/prototype.js

    r4082 r4813  
    1 /*  Prototype JavaScript framework, version 1.5.0_rc0
    2  *  (c) 2005 Sam Stephenson <sam@conio.net>
     1/*  Prototype JavaScript framework, version 1.5.0
     2 *  (c) 2005-2007 Sam Stephenson
    33 *
    44 *  Prototype is freely distributable under the terms of an MIT-style license.
     
    88
    99var Prototype = {
    10   Version: '1.5.0_rc0',
     10  Version: '1.5.0',
     11  BrowserFeatures: {
     12    XPath: !!document.evaluate
     13  },
     14
    1115  ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',
    12 
    1316  emptyFunction: function() {},
    14   K: function(x) {return x}
     17  K: function(x) { return x }
    1518}
    1619
     
    3235}
    3336
    34 Object.inspect = function(object) {
    35   try {
    36     if (object == undefined) return 'undefined';
    37     if (object == null) return 'null';
    38     return object.inspect ? object.inspect() : object.toString();
    39   } catch (e) {
    40     if (e instanceof RangeError) return '...';
    41     throw e;
    42   }
    43 }
     37Object.extend(Object, {
     38  inspect: function(object) {
     39    try {
     40      if (object === undefined) return 'undefined';
     41      if (object === null) return 'null';
     42      return object.inspect ? object.inspect() : object.toString();
     43    } catch (e) {
     44      if (e instanceof RangeError) return '...';
     45      throw e;
     46    }
     47  },
     48
     49  keys: function(object) {
     50    var keys = [];
     51    for (var property in object)
     52      keys.push(property);
     53    return keys;
     54  },
     55
     56  values: function(object) {
     57    var values = [];
     58    for (var property in object)
     59      values.push(object[property]);
     60    return values;
     61  },
     62
     63  clone: function(object) {
     64    return Object.extend({}, object);
     65  }
     66});
    4467
    4568Function.prototype.bind = function() {
     
    5174
    5275Function.prototype.bindAsEventListener = function(object) {
    53   var __method = this;
     76  var __method = this, args = $A(arguments), object = args.shift();
    5477  return function(event) {
    55     return __method.call(object, event || window.event);
     78    return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments)));
    5679  }
    5780}
     
    78101    var returnValue;
    79102
    80     for (var i = 0; i < arguments.length; i++) {
     103    for (var i = 0, length = arguments.length; i < length; i++) {
    81104      var lambda = arguments[i];
    82105      try {
     
    103126
    104127  registerCallback: function() {
    105     setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
     128    this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
     129  },
     130
     131  stop: function() {
     132    if (!this.timer) return;
     133    clearInterval(this.timer);
     134    this.timer = null;
    106135  },
    107136
     
    110139      try {
    111140        this.currentlyExecuting = true;
    112         this.callback();
     141        this.callback(this);
    113142      } finally {
    114143        this.currentlyExecuting = false;
     
    117146  }
    118147}
     148String.interpret = function(value){
     149  return value == null ? '' : String(value);
     150}
     151
    119152Object.extend(String.prototype, {
    120153  gsub: function(pattern, replacement) {
     
    125158      if (match = source.match(pattern)) {
    126159        result += source.slice(0, match.index);
    127         result += (replacement(match) || '').toString();
     160        result += String.interpret(replacement(match));
    128161        source  = source.slice(match.index + match[0].length);
    129162      } else {
     
    190223    var div = document.createElement('div');
    191224    div.innerHTML = this.stripTags();
    192     return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
    193   },
    194 
    195   toQueryParams: function() {
    196     var pairs = this.match(/^\??(.*)$/)[1].split('&');
    197     return pairs.inject({}, function(params, pairString) {
    198       var pair = pairString.split('=');
    199       params[pair[0]] = pair[1];
    200       return params;
     225    return div.childNodes[0] ? (div.childNodes.length > 1 ?
     226      $A(div.childNodes).inject('',function(memo,node){ return memo+node.nodeValue }) :
     227      div.childNodes[0].nodeValue) : '';
     228  },
     229
     230  toQueryParams: function(separator) {
     231    var match = this.strip().match(/([^?#]*)(#.*)?$/);
     232    if (!match) return {};
     233
     234    return match[1].split(separator || '&').inject({}, function(hash, pair) {
     235      if ((pair = pair.split('='))[0]) {
     236        var name = decodeURIComponent(pair[0]);
     237        var value = pair[1] ? decodeURIComponent(pair[1]) : undefined;
     238
     239        if (hash[name] !== undefined) {
     240          if (hash[name].constructor != Array)
     241            hash[name] = [hash[name]];
     242          if (value) hash[name].push(value);
     243        }
     244        else hash[name] = value;
     245      }
     246      return hash;
    201247    });
    202248  },
     
    206252  },
    207253
     254  succ: function() {
     255    return this.slice(0, this.length - 1) +
     256      String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
     257  },
     258
    208259  camelize: function() {
    209     var oStringList = this.split('-');
    210     if (oStringList.length == 1) return oStringList[0];
    211 
    212     var camelizedString = this.indexOf('-') == 0
    213       ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1)
    214       : oStringList[0];
    215 
    216     for (var i = 1, len = oStringList.length; i < len; i++) {
    217       var s = oStringList[i];
    218       camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
    219     }
    220 
    221     return camelizedString;
    222   },
    223 
    224   inspect: function() {
    225     return "'" + this.replace(/\\/g, '\\\\').replace(/'/g, '\\\'') + "'";
     260    var parts = this.split('-'), len = parts.length;
     261    if (len == 1) return parts[0];
     262
     263    var camelized = this.charAt(0) == '-'
     264      ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
     265      : parts[0];
     266
     267    for (var i = 1; i < len; i++)
     268      camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
     269
     270    return camelized;
     271  },
     272
     273  capitalize: function(){
     274    return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
     275  },
     276
     277  underscore: function() {
     278    return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();
     279  },
     280
     281  dasherize: function() {
     282    return this.gsub(/_/,'-');
     283  },
     284
     285  inspect: function(useDoubleQuotes) {
     286    var escapedString = this.replace(/\\/g, '\\\\');
     287    if (useDoubleQuotes)
     288      return '"' + escapedString.replace(/"/g, '\\"') + '"';
     289    else
     290      return "'" + escapedString.replace(/'/g, '\\\'') + "'";
    226291  }
    227292});
     
    247312      var before = match[1];
    248313      if (before == '\\') return match[2];
    249       return before + (object[match[3]] || '').toString();
     314      return before + String.interpret(object[match[3]]);
    250315    });
    251316  }
     
    269334      if (e != $break) throw e;
    270335    }
     336    return this;
     337  },
     338
     339  eachSlice: function(number, iterator) {
     340    var index = -number, slices = [], array = this.toArray();
     341    while ((index += number) < array.length)
     342      slices.push(array.slice(index, index+number));
     343    return slices.map(iterator);
    271344  },
    272345
     
    281354
    282355  any: function(iterator) {
    283     var result = true;
     356    var result = false;
    284357    this.each(function(value, index) {
    285358      if (result = !!(iterator || Prototype.K)(value, index))
     
    292365    var results = [];
    293366    this.each(function(value, index) {
    294       results.push(iterator(value, index));
     367      results.push((iterator || Prototype.K)(value, index));
    295368    });
    296369    return results;
    297370  },
    298371
    299   detect: function (iterator) {
     372  detect: function(iterator) {
    300373    var result;
    301374    this.each(function(value, index) {
     
    338411  },
    339412
     413  inGroupsOf: function(number, fillWith) {
     414    fillWith = fillWith === undefined ? null : fillWith;
     415    return this.eachSlice(number, function(slice) {
     416      while(slice.length < number) slice.push(fillWith);
     417      return slice;
     418    });
     419  },
     420
    340421  inject: function(memo, iterator) {
    341422    this.each(function(value, index) {
     
    347428  invoke: function(method) {
    348429    var args = $A(arguments).slice(1);
    349     return this.collect(function(value) {
     430    return this.map(function(value) {
    350431      return value[method].apply(value, args);
    351432    });
     
    399480
    400481  sortBy: function(iterator) {
    401     return this.collect(function(value, index) {
     482    return this.map(function(value, index) {
    402483      return {value: value, criteria: iterator(value, index)};
    403484    }).sort(function(left, right) {
     
    408489
    409490  toArray: function() {
    410     return this.collect(Prototype.K);
     491    return this.map();
    411492  },
    412493
     
    420501      return iterator(collections.pluck(index));
    421502    });
     503  },
     504
     505  size: function() {
     506    return this.toArray().length;
    422507  },
    423508
     
    440525  } else {
    441526    var results = [];
    442     for (var i = 0; i < iterable.length; i++)
     527    for (var i = 0, length = iterable.length; i < length; i++)
    443528      results.push(iterable[i]);
    444529    return results;
     
    453538Object.extend(Array.prototype, {
    454539  _each: function(iterator) {
    455     for (var i = 0; i < this.length; i++)
     540    for (var i = 0, length = this.length; i < length; i++)
    456541      iterator(this[i]);
    457542  },
     
    472557  compact: function() {
    473558    return this.select(function(value) {
    474       return value != undefined || value != null;
     559      return value != null;
    475560    });
    476561  },
     
    491576
    492577  indexOf: function(object) {
    493     for (var i = 0; i < this.length; i++)
     578    for (var i = 0, length = this.length; i < length; i++)
    494579      if (this[i] == object) return i;
    495580    return -1;
     
    500585  },
    501586
     587  reduce: function() {
     588    return this.length > 1 ? this : this[0];
     589  },
     590
     591  uniq: function() {
     592    return this.inject([], function(array, value) {
     593      return array.include(value) ? array : array.concat([value]);
     594    });
     595  },
     596
     597  clone: function() {
     598    return [].concat(this);
     599  },
     600
     601  size: function() {
     602    return this.length;
     603  },
     604
    502605  inspect: function() {
    503606    return '[' + this.map(Object.inspect).join(', ') + ']';
    504607  }
    505608});
    506 var Hash = {
     609
     610Array.prototype.toArray = Array.prototype.clone;
     611
     612function $w(string){
     613  string = string.strip();
     614  return string ? string.split(/\s+/) : [];
     615}
     616
     617if(window.opera){
     618  Array.prototype.concat = function(){
     619    var array = [];
     620    for(var i = 0, length = this.length; i < length; i++) array.push(this[i]);
     621    for(var i = 0, length = arguments.length; i < length; i++) {
     622      if(arguments[i].constructor == Array) {
     623        for(var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)
     624          array.push(arguments[i][j]);
     625      } else {
     626        array.push(arguments[i]);
     627      }
     628    }
     629    return array;
     630  }
     631}
     632var Hash = function(obj) {
     633  Object.extend(this, obj || {});
     634};
     635
     636Object.extend(Hash, {
     637  toQueryString: function(obj) {
     638    var parts = [];
     639
     640      this.prototype._each.call(obj, function(pair) {
     641      if (!pair.key) return;
     642
     643      if (pair.value && pair.value.constructor == Array) {
     644        var values = pair.value.compact();
     645        if (values.length < 2) pair.value = values.reduce();
     646        else {
     647            key = encodeURIComponent(pair.key);
     648          values.each(function(value) {
     649            value = value != undefined ? encodeURIComponent(value) : '';
     650            parts.push(key + '=' + encodeURIComponent(value));
     651          });
     652          return;
     653        }
     654      }
     655      if (pair.value == undefined) pair[1] = '';
     656      parts.push(pair.map(encodeURIComponent).join('='));
     657      });
     658
     659    return parts.join('&');
     660  }
     661});
     662
     663Object.extend(Hash.prototype, Enumerable);
     664Object.extend(Hash.prototype, {
    507665  _each: function(iterator) {
    508666    for (var key in this) {
    509667      var value = this[key];
    510       if (typeof value == 'function') continue;
     668      if (value && value == Hash.prototype[key]) continue;
    511669
    512670      var pair = [key, value];
     
    526684
    527685  merge: function(hash) {
    528     return $H(hash).inject($H(this), function(mergedHash, pair) {
     686    return $H(hash).inject(this, function(mergedHash, pair) {
    529687      mergedHash[pair.key] = pair.value;
    530688      return mergedHash;
     
    532690  },
    533691
     692  remove: function() {
     693    var result;
     694    for(var i = 0, length = arguments.length; i < length; i++) {
     695      var value = this[arguments[i]];
     696      if (value !== undefined){
     697        if (result === undefined) result = value;
     698        else {
     699          if (result.constructor != Array) result = [result];
     700          result.push(value)
     701        }
     702      }
     703      delete this[arguments[i]];
     704    }
     705    return result;
     706  },
     707
    534708  toQueryString: function() {
    535     return this.map(function(pair) {
    536       return pair.map(encodeURIComponent).join('=');
    537     }).join('&');
     709    return Hash.toQueryString(this);
    538710  },
    539711
     
    543715    }).join(', ') + '}>';
    544716  }
    545 }
     717});
    546718
    547719function $H(object) {
    548   var hash = Object.extend({}, object || {});
    549   Object.extend(hash, Enumerable);
    550   Object.extend(hash, Hash);
    551   return hash;
    552 }
     720  if (object && object.constructor == Hash) return object;
     721  return new Hash(object);
     722};
    553723ObjectRange = Class.create();
    554724Object.extend(ObjectRange.prototype, Enumerable);
     
    562732  _each: function(iterator) {
    563733    var value = this.start;
    564     do {
     734    while (this.include(value)) {
    565735      iterator(value);
    566736      value = value.succ();
    567     } while (this.include(value));
     737    }
    568738  },
    569739
     
    600770  },
    601771
    602   register: function(responderToAdd) {
    603     if (!this.include(responderToAdd))
    604       this.responders.push(responderToAdd);
    605   },
    606 
    607   unregister: function(responderToRemove) {
    608     this.responders = this.responders.without(responderToRemove);
     772  register: function(responder) {
     773    if (!this.include(responder))
     774      this.responders.push(responder);
     775  },
     776
     777  unregister: function(responder) {
     778    this.responders = this.responders.without(responder);
    609779  },
    610780
    611781  dispatch: function(callback, request, transport, json) {
    612782    this.each(function(responder) {
    613       if (responder[callback] && typeof responder[callback] == 'function') {
     783      if (typeof responder[callback] == 'function') {
    614784        try {
    615785          responder[callback].apply(responder, [request, transport, json]);
     
    626796    Ajax.activeRequestCount++;
    627797  },
    628 
    629798  onComplete: function() {
    630799    Ajax.activeRequestCount--;
     
    639808      asynchronous: true,
    640809      contentType:  'application/x-www-form-urlencoded',
     810      encoding:     'UTF-8',
    641811      parameters:   ''
    642812    }
    643813    Object.extend(this.options, options || {});
    644   },
    645 
    646   responseIsSuccess: function() {
    647     return this.transport.status == undefined
    648         || this.transport.status == 0
    649         || (this.transport.status >= 200 && this.transport.status < 300);
    650   },
    651 
    652   responseIsFailure: function() {
    653     return !this.responseIsSuccess();
     814
     815    this.options.method = this.options.method.toLowerCase();
     816    if (typeof this.options.parameters == 'string')
     817      this.options.parameters = this.options.parameters.toQueryParams();
    654818  }
    655819}
     
    660824
    661825Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
     826  _complete: false,
     827
    662828  initialize: function(url, options) {
    663829    this.transport = Ajax.getTransport();
     
    667833
    668834  request: function(url) {
    669     var parameters = this.options.parameters || '';
    670     if (parameters.length > 0) parameters += '&_=';
     835    this.url = url;
     836    this.method = this.options.method;
     837    var params = this.options.parameters;
     838
     839    if (!['get', 'post'].include(this.method)) {
     840      // simulate other verbs over post
     841      params['_method'] = this.method;
     842      this.method = 'post';
     843    }
     844
     845    params = Hash.toQueryString(params);
     846    if (params && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) params += '&_='
     847
     848    // when GET, append parameters to URL
     849    if (this.method == 'get' && params)
     850      this.url += (this.url.indexOf('?') > -1 ? '&' : '?') + params;
    671851
    672852    try {
    673       this.url = url;
    674       if (this.options.method == 'get' && parameters.length > 0)
    675         this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;
    676 
    677853      Ajax.Responders.dispatch('onCreate', this, this.transport);
    678854
    679       this.transport.open(this.options.method, this.url,
     855      this.transport.open(this.method.toUpperCase(), this.url,
    680856        this.options.asynchronous);
    681857
    682       if (this.options.asynchronous) {
    683         this.transport.onreadystatechange = this.onStateChange.bind(this);
    684         setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10);
     858      if (this.options.asynchronous)
     859        setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10);
     860
     861      this.transport.onreadystatechange = this.onStateChange.bind(this);
     862      this.setRequestHeaders();
     863
     864      var body = this.method == 'post' ? (this.options.postBody || params) : null;
     865
     866      this.transport.send(body);
     867
     868      /* Force Firefox to handle ready state 4 for synchronous requests */
     869      if (!this.options.asynchronous && this.transport.overrideMimeType)
     870        this.onStateChange();
     871
     872    }
     873    catch (e) {
     874      this.dispatchException(e);
     875    }
     876  },
     877
     878  onStateChange: function() {
     879    var readyState = this.transport.readyState;
     880    if (readyState > 1 && !((readyState == 4) && this._complete))
     881      this.respondToReadyState(this.transport.readyState);
     882  },
     883
     884  setRequestHeaders: function() {
     885    var headers = {
     886      'X-Requested-With': 'XMLHttpRequest',
     887      'X-Prototype-Version': Prototype.Version,
     888      'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
     889    };
     890
     891    if (this.method == 'post') {
     892      headers['Content-type'] = this.options.contentType +
     893        (this.options.encoding ? '; charset=' + this.options.encoding : '');
     894
     895      /* Force "Connection: close" for older Mozilla browsers to work
     896       * around a bug where XMLHttpRequest sends an incorrect
     897       * Content-length header. See Mozilla Bugzilla #246651.
     898       */
     899      if (this.transport.overrideMimeType &&
     900          (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
     901            headers['Connection'] = 'close';
     902    }
     903
     904    // user-defined headers
     905    if (typeof this.options.requestHeaders == 'object') {
     906      var extras = this.options.requestHeaders;
     907
     908      if (typeof extras.push == 'function')
     909        for (var i = 0, length = extras.length; i < length; i += 2)
     910          headers[extras[i]] = extras[i+1];
     911      else
     912        $H(extras).each(function(pair) { headers[pair.key] = pair.value });
     913    }
     914
     915    for (var name in headers)
     916      this.transport.setRequestHeader(name, headers[name]);
     917  },
     918
     919  success: function() {
     920    return !this.transport.status
     921        || (this.transport.status >= 200 && this.transport.status < 300);
     922  },
     923
     924  respondToReadyState: function(readyState) {
     925    var state = Ajax.Request.Events[readyState];
     926    var transport = this.transport, json = this.evalJSON();
     927
     928    if (state == 'Complete') {
     929      try {
     930        this._complete = true;
     931        (this.options['on' + this.transport.status]
     932         || this.options['on' + (this.success() ? 'Success' : 'Failure')]
     933         || Prototype.emptyFunction)(transport, json);
     934      } catch (e) {
     935        this.dispatchException(e);
    685936      }
    686937
    687       this.setRequestHeaders();
    688 
    689       var body = this.options.postBody ? this.options.postBody : parameters;
    690       this.transport.send(this.options.method == 'post' ? body : null);
    691 
     938      if ((this.getHeader('Content-type') || 'text/javascript').strip().
     939        match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i))
     940          this.evalResponse();
     941    }
     942
     943    try {
     944      (this.options['on' + state] || Prototype.emptyFunction)(transport, json);
     945      Ajax.Responders.dispatch('on' + state, this, transport, json);
    692946    } catch (e) {
    693947      this.dispatchException(e);
    694948    }
    695   },
    696 
    697   setRequestHeaders: function() {
    698     var requestHeaders =
    699       ['X-Requested-With', 'XMLHttpRequest',
    700        'X-Prototype-Version', Prototype.Version,
    701        'Accept', 'text/javascript, text/html, application/xml, text/xml, */*'];
    702 
    703     if (this.options.method == 'post') {
    704       requestHeaders.push('Content-type', this.options.contentType);
    705 
    706       /* Force "Connection: close" for Mozilla browsers to work around
    707        * a bug where XMLHttpReqeuest sends an incorrect Content-length
    708        * header. See Mozilla Bugzilla #246651.
    709        */
    710       if (this.transport.overrideMimeType)
    711         requestHeaders.push('Connection', 'close');
    712     }
    713 
    714     if (this.options.requestHeaders)
    715       requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);
    716 
    717     for (var i = 0; i < requestHeaders.length; i += 2)
    718       this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
    719   },
    720 
    721   onStateChange: function() {
    722     var readyState = this.transport.readyState;
    723     if (readyState != 1)
    724       this.respondToReadyState(this.transport.readyState);
    725   },
    726 
    727   header: function(name) {
     949
     950    if (state == 'Complete') {
     951      // avoid memory leak in MSIE: clean up
     952      this.transport.onreadystatechange = Prototype.emptyFunction;
     953    }
     954  },
     955
     956  getHeader: function(name) {
    728957    try {
    729958      return this.transport.getResponseHeader(name);
    730     } catch (e) {}
     959    } catch (e) { return null }
    731960  },
    732961
    733962  evalJSON: function() {
    734963    try {
    735       return eval('(' + this.header('X-JSON') + ')');
    736     } catch (e) {}
     964      var json = this.getHeader('X-JSON');
     965      return json ? eval('(' + json + ')') : null;
     966    } catch (e) { return null }
    737967  },
    738968
     
    745975  },
    746976
    747   respondToReadyState: function(readyState) {
    748     var event = Ajax.Request.Events[readyState];
    749     var transport = this.transport, json = this.evalJSON();
    750 
    751     if (event == 'Complete') {
    752       try {
    753         (this.options['on' + this.transport.status]
    754          || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
    755          || Prototype.emptyFunction)(transport, json);
    756       } catch (e) {
    757         this.dispatchException(e);
    758       }
    759 
    760       if ((this.header('Content-type') || '').match(/^text\/javascript/i))
    761         this.evalResponse();
    762     }
    763 
    764     try {
    765       (this.options['on' + event] || Prototype.emptyFunction)(transport, json);
    766       Ajax.Responders.dispatch('on' + event, this, transport, json);
    767     } catch (e) {
    768       this.dispatchException(e);
    769     }
    770 
    771     /* Avoid memory leak in MSIE: clean up the oncomplete event handler */
    772     if (event == 'Complete')
    773       this.transport.onreadystatechange = Prototype.emptyFunction;
    774   },
    775 
    776977  dispatchException: function(exception) {
    777978    (this.options.onException || Prototype.emptyFunction)(this, exception);
     
    784985Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
    785986  initialize: function(container, url, options) {
    786     this.containers = {
    787       success: container.success ? $(container.success) : $(container),
    788       failure: container.failure ? $(container.failure) :
    789         (container.success ? null : $(container))
     987    this.container = {
     988      success: (container.success || container),
     989      failure: (container.failure || (container.success ? null : container))
    790990    }
    791991
     
    794994
    795995    var onComplete = this.options.onComplete || Prototype.emptyFunction;
    796     this.options.onComplete = (function(transport, object) {
     996    this.options.onComplete = (function(transport, param) {
    797997      this.updateContent();
    798       onComplete(transport, object);
     998      onComplete(transport, param);
    799999    }).bind(this);
    8001000
     
    8031003
    8041004  updateContent: function() {
    805     var receiver = this.responseIsSuccess() ?
    806       this.containers.success : this.containers.failure;
     1005    var receiver = this.container[this.success() ? 'success' : 'failure'];
    8071006    var response = this.transport.responseText;
    8081007
    809     if (!this.options.evalScripts)
    810       response = response.stripScripts();
    811 
    812     if (receiver) {
    813       if (this.options.insertion) {
     1008    if (!this.options.evalScripts) response = response.stripScripts();
     1009
     1010    if (receiver = $(receiver)) {
     1011      if (this.options.insertion)
    8141012        new this.options.insertion(receiver, response);
    815       } else {
    816         Element.update(receiver, response);
    817       }
    818     }
    819 
    820     if (this.responseIsSuccess()) {
     1013      else
     1014        receiver.update(response);
     1015    }
     1016
     1017    if (this.success()) {
    8211018      if (this.onComplete)
    8221019        setTimeout(this.onComplete.bind(this), 10);
     
    8471044
    8481045  stop: function() {
    849     this.updater.onComplete = undefined;
     1046    this.updater.options.onComplete = undefined;
    8501047    clearTimeout(this.timer);
    8511048    (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
     
    8671064  }
    8681065});
    869 function $() {
    870   var results = [], element;
    871   for (var i = 0; i < arguments.length; i++) {
    872     element = arguments[i];
    873     if (typeof element == 'string')
    874       element = document.getElementById(element);
    875     results.push(Element.extend(element));
    876   }
    877   return results.length < 2 ? results[0] : results;
     1066function $(element) {
     1067  if (arguments.length > 1) {
     1068    for (var i = 0, elements = [], length = arguments.length; i < length; i++)
     1069      elements.push($(arguments[i]));
     1070    return elements;
     1071  }
     1072  if (typeof element == 'string')
     1073    element = document.getElementById(element);
     1074  return Element.extend(element);
     1075}
     1076
     1077if (Prototype.BrowserFeatures.XPath) {
     1078  document._getElementsByXPath = function(expression, parentElement) {
     1079    var results = [];
     1080    var query = document.evaluate(expression, $(parentElement) || document,
     1081      null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
     1082    for (var i = 0, length = query.snapshotLength; i < length; i++)
     1083      results.push(query.snapshotItem(i));
     1084    return results;
     1085  };
    8781086}
    8791087
    8801088document.getElementsByClassName = function(className, parentElement) {
    881   var children = ($(parentElement) || document.body).getElementsByTagName('*');
    882   return $A(children).inject([], function(elements, child) {
    883     if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
    884       elements.push(Element.extend(child));
     1089  if (Prototype.BrowserFeatures.XPath) {
     1090    var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";
     1091    return document._getElementsByXPath(q, parentElement);
     1092  } else {
     1093    var children = ($(parentElement) || document.body).getElementsByTagName('*');
     1094    var elements = [], child;
     1095    for (var i = 0, length = children.length; i < length; i++) {
     1096      child = children[i];
     1097      if (Element.hasClassName(child, className))
     1098        elements.push(Element.extend(child));
     1099    }
    8851100    return elements;
    886   });
    887 }
     1101  }
     1102};
    8881103
    8891104/*--------------------------------------------------------------------------*/
     
    8931108
    8941109Element.extend = function(element) {
    895   if (!element) return;
    896   if (_nativeExtensions) return element;
     1110  if (!element || _nativeExtensions || element.nodeType == 3) return element;
    8971111
    8981112  if (!element._extended && element.tagName && element != window) {
    899     var methods = Element.Methods, cache = Element.extend.cache;
    900     for (property in methods) {
     1113    var methods = Object.clone(Element.Methods), cache = Element.extend.cache;
     1114
     1115    if (element.tagName == 'FORM')
     1116      Object.extend(methods, Form.Methods);
     1117    if (['INPUT', 'TEXTAREA', 'SELECT'].include(element.tagName))
     1118      Object.extend(methods, Form.Element.Methods);
     1119
     1120    Object.extend(methods, Element.Methods.Simulated);
     1121
     1122    for (var property in methods) {
    9011123      var value = methods[property];
    902       if (typeof value == 'function')
     1124      if (typeof value == 'function' && !(property in element))
    9031125        element[property] = cache.findOrStore(value);
    9041126    }
     
    9071129  element._extended = true;
    9081130  return element;
    909 }
     1131};
    9101132
    9111133Element.extend.cache = {
     
    9151137    }
    9161138  }
    917 }
     1139};
    9181140
    9191141Element.Methods = {
     
    9221144  },
    9231145
    924   toggle: function() {
    925     for (var i = 0; i < arguments.length; i++) {
    926       var element = $(arguments[i]);
    927       Element[Element.visible(element) ? 'hide' : 'show'](element);
    928     }
    929   },
    930 
    931   hide: function() {
    932     for (var i = 0; i < arguments.length; i++) {
    933       var element = $(arguments[i]);
    934       element.style.display = 'none';
    935     }
    936   },
    937 
    938   show: function() {
    939     for (var i = 0; i < arguments.length; i++) {
    940       var element = $(arguments[i]);
    941       element.style.display = '';
    942     }
     1146  toggle: function(element) {
     1147    element = $(element);
     1148    Element[Element.visible(element) ? 'hide' : 'show'](element);
     1149    return element;
     1150  },
     1151
     1152  hide: function(element) {
     1153    $(element).style.display = 'none';
     1154    return element;
     1155  },
     1156
     1157  show: function(element) {
     1158    $(element).style.display = '';
     1159    return element;
    9431160  },
    9441161
     
    9461163    element = $(element);
    9471164    element.parentNode.removeChild(element);
     1165    return element;
    9481166  },
    9491167
    9501168  update: function(element, html) {
     1169    html = typeof html == 'undefined' ? '' : html.toString();
    9511170    $(element).innerHTML = html.stripScripts();
    9521171    setTimeout(function() {html.evalScripts()}, 10);
     1172    return element;
    9531173  },
    9541174
    9551175  replace: function(element, html) {
    9561176    element = $(element);
     1177    html = typeof html == 'undefined' ? '' : html.toString();
    9571178    if (element.outerHTML) {
    9581179      element.outerHTML = html.stripScripts();
     
    9641185    }
    9651186    setTimeout(function() {html.evalScripts()}, 10);
     1187    return element;
     1188  },
     1189
     1190  inspect: function(element) {
     1191    element = $(element);
     1192    var result = '<' + element.tagName.toLowerCase();
     1193    $H({'id': 'id', 'className': 'class'}).each(function(pair) {
     1194      var property = pair.first(), attribute = pair.last();
     1195      var value = (element[property] || '').toString();
     1196      if (value) result += ' ' + attribute + '=' + value.inspect(true);
     1197    });
     1198    return result + '>';
     1199  },
     1200
     1201  recursivelyCollect: function(element, property) {
     1202    element = $(element);
     1203    var elements = [];
     1204    while (element = element[property])
     1205      if (element.nodeType == 1)
     1206        elements.push(Element.extend(element));
     1207    return elements;
     1208  },
     1209
     1210  ancestors: function(element) {
     1211    return $(element).recursivelyCollect('parentNode');
     1212  },
     1213
     1214  descendants: function(element) {
     1215    return $A($(element).getElementsByTagName('*'));
     1216  },
     1217
     1218  immediateDescendants: function(element) {
     1219    if (!(element = $(element).firstChild)) return [];
     1220    while (element && element.nodeType != 1) element = element.nextSibling;
     1221    if (element) return [element].concat($(element).nextSiblings());
     1222    return [];
     1223  },
     1224
     1225  previousSiblings: function(element) {
     1226    return $(element).recursivelyCollect('previousSibling');
     1227  },
     1228
     1229  nextSiblings: function(element) {
     1230    return $(element).recursivelyCollect('nextSibling');
     1231  },
     1232
     1233  siblings: function(element) {
     1234    element = $(element);
     1235    return element.previousSiblings().reverse().concat(element.nextSiblings());
     1236  },
     1237
     1238  match: function(element, selector) {
     1239    if (typeof selector == 'string')
     1240      selector = new Selector(selector);
     1241    return selector.match($(element));
     1242  },
     1243
     1244  up: function(element, expression, index) {
     1245    return Selector.findElement($(element).ancestors(), expression, index);
     1246  },
     1247
     1248  down: function(element, expression, index) {
     1249    return Selector.findElement($(element).descendants(), expression, index);
     1250  },
     1251
     1252  previous: function(element, expression, index) {
     1253    return Selector.findElement($(element).previousSiblings(), expression, index);
     1254  },
     1255
     1256  next: function(element, expression, index) {
     1257    return Selector.findElement($(element).nextSiblings(), expression, index);
     1258  },
     1259
     1260  getElementsBySelector: function() {
     1261    var args = $A(arguments), element = $(args.shift());
     1262    return Selector.findChildElements(element, args);
     1263  },
     1264
     1265  getElementsByClassName: function(element, className) {
     1266    return document.getElementsByClassName(className, element);
     1267  },
     1268
     1269  readAttribute: function(element, name) {
     1270    element = $(element);
     1271    if (document.all && !window.opera) {
     1272      var t = Element._attributeTranslations;
     1273      if (t.values[name]) return t.values[name](element, name);
     1274      if (t.names[name])  name = t.names[name];
     1275      var attribute = element.attributes[name];
     1276      if(attribute) return attribute.nodeValue;
     1277    }
     1278    return element.getAttribute(name);
    9661279  },
    9671280
    9681281  getHeight: function(element) {
    969     element = $(element);
    970     return element.offsetHeight;
     1282    return $(element).getDimensions().height;
     1283  },
     1284
     1285  getWidth: function(element) {
     1286    return $(element).getDimensions().width;
    9711287  },
    9721288
     
    9771293  hasClassName: function(element, className) {
    9781294    if (!(element = $(element))) return;
    979     return Element.classNames(element).include(className);
     1295    var elementClassName = element.className;
     1296    if (elementClassName.length == 0) return false;
     1297    if (elementClassName == className ||
     1298        elementClassName.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
     1299      return true;
     1300    return false;
    9801301  },
    9811302
    9821303  addClassName: function(element, className) {
    9831304    if (!(element = $(element))) return;
    984     return Element.classNames(element).add(className);
     1305    Element.classNames(element).add(className);
     1306    return element;
    9851307  },
    9861308
    9871309  removeClassName: function(element, className) {
    9881310    if (!(element = $(element))) return;
    989     return Element.classNames(element).remove(className);
     1311    Element.classNames(element).remove(className);
     1312    return element;
     1313  },
     1314
     1315  toggleClassName: function(element, className) {
     1316    if (!(element = $(element))) return;
     1317    Element.classNames(element)[element.hasClassName(className) ? 'remove' : 'add'](className);
     1318    return element;
     1319  },
     1320
     1321  observe: function() {
     1322    Event.observe.apply(Event, arguments);
     1323    return $A(arguments).first();
     1324  },
     1325
     1326  stopObserving: function() {
     1327    Event.stopObserving.apply(Event, arguments);
     1328    return $A(arguments).first();
    9901329  },
    9911330
     
    9931332  cleanWhitespace: function(element) {
    9941333    element = $(element);
    995     for (var i = 0; i < element.childNodes.length; i++) {
    996       var node = element.childNodes[i];
     1334    var node = element.firstChild;
     1335    while (node) {
     1336      var nextNode = node.nextSibling;
    9971337      if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
    998         Element.remove(node);
    999     }
     1338        element.removeChild(node);
     1339      node = nextNode;
     1340    }
     1341    return element;
    10001342  },
    10011343
     
    10041346  },
    10051347
    1006   childOf: function(element, ancestor) {
     1348  descendantOf: function(element, ancestor) {
    10071349    element = $(element), ancestor = $(ancestor);
    10081350    while (element = element.parentNode)
     
    10131355  scrollTo: function(element) {
    10141356    element = $(element);
    1015     var x = element.x ? element.x : element.offsetLeft,
    1016         y = element.y ? element.y : element.offsetTop;
    1017     window.scrollTo(x, y);
     1357    var pos = Position.cumulativeOffset(element);
     1358    window.scrollTo(pos[0], pos[1]);
     1359    return element;
    10181360  },
    10191361
    10201362  getStyle: function(element, style) {
    10211363    element = $(element);
    1022     var value = element.style[style.camelize()];
     1364    if (['float','cssFloat'].include(style))
     1365      style = (typeof element.style.styleFloat != 'undefined' ? 'styleFloat' : 'cssFloat');
     1366    style = style.camelize();
     1367    var value = element.style[style];
    10231368    if (!value) {
    10241369      if (document.defaultView && document.defaultView.getComputedStyle) {
    10251370        var css = document.defaultView.getComputedStyle(element, null);
    1026         value = css ? css.getPropertyValue(style) : null;
     1371        value = css ? css[style] : null;
    10271372      } else if (element.currentStyle) {
    1028         value = element.currentStyle[style.camelize()];
     1373        value = element.currentStyle[style];
    10291374      }
    10301375    }
     1376
     1377    if((value == 'auto') && ['width','height'].include(style) && (element.getStyle('display') != 'none'))
     1378      value = element['offset'+style.capitalize()] + 'px';
    10311379
    10321380    if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
    10331381      if (Element.getStyle(element, 'position') == 'static') value = 'auto';
    1034 
     1382    if(style == 'opacity') {
     1383      if(value) return parseFloat(value);
     1384      if(value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
     1385        if(value[1]) return parseFloat(value[1]) / 100;
     1386      return 1.0;
     1387    }
    10351388    return value == 'auto' ? null : value;
    10361389  },
     
    10381391  setStyle: function(element, style) {
    10391392    element = $(element);
    1040     for (var name in style)
    1041       element.style[name.camelize()] = style[name];
     1393    for (var name in style) {
     1394      var value = style[name];
     1395      if(name == 'opacity') {
     1396        if (value == 1) {
     1397          value = (/Gecko/.test(navigator.userAgent) &&
     1398            !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 0.999999 : 1.0;
     1399          if(/MSIE/.test(navigator.userAgent) && !window.opera)
     1400            element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'');
     1401        } else if(value == '') {
     1402          if(/MSIE/.test(navigator.userAgent) && !window.opera)
     1403            element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'');
     1404        } else {
     1405          if(value < 0.00001) value = 0;
     1406          if(/MSIE/.test(navigator.userAgent) && !window.opera)
     1407            element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'') +
     1408              'alpha(opacity='+value*100+')';
     1409        }
     1410      } else if(['float','cssFloat'].include(name)) name = (typeof element.style.styleFloat != 'undefined') ? 'styleFloat' : 'cssFloat';
     1411      element.style[name.camelize()] = value;
     1412    }
     1413    return element;
    10421414  },
    10431415
    10441416  getDimensions: function(element) {
    10451417    element = $(element);
    1046     if (Element.getStyle(element, 'display') != 'none')
     1418    var display = $(element).getStyle('display');
     1419    if (display != 'none' && display != null) // Safari bug
    10471420      return {width: element.offsetWidth, height: element.offsetHeight};
    10481421
     
    10521425    var originalVisibility = els.visibility;
    10531426    var originalPosition = els.position;
     1427    var originalDisplay = els.display;
    10541428    els.visibility = 'hidden';
    10551429    els.position = 'absolute';
    1056     els.display = '';
     1430    els.display = 'block';
    10571431    var originalWidth = element.clientWidth;
    10581432    var originalHeight = element.clientHeight;
    1059     els.display = 'none';
     1433    els.display = originalDisplay;
    10601434    els.position = originalPosition;
    10611435    els.visibility = originalVisibility;
     
    10761450      }
    10771451    }
     1452    return element;
    10781453  },
    10791454
     
    10881463        element.style.right = '';
    10891464    }
     1465    return element;
    10901466  },
    10911467
    10921468  makeClipping: function(element) {
    10931469    element = $(element);
    1094     if (element._overflow) return;
    1095     element._overflow = element.style.overflow;
     1470    if (element._overflow) return element;
     1471    element._overflow = element.style.overflow || 'auto';
    10961472    if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden')
    10971473      element.style.overflow = 'hidden';
     1474    return element;
    10981475  },
    10991476
    11001477  undoClipping: function(element) {
    11011478    element = $(element);
    1102     if (element._overflow) return;
    1103     element.style.overflow = element._overflow;
    1104     element._overflow = undefined;
    1105   }
    1106 }
     1479    if (!element._overflow) return element;
     1480    element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
     1481    element._overflow = null;
     1482    return element;
     1483  }
     1484};
     1485
     1486Object.extend(Element.Methods, {childOf: Element.Methods.descendantOf});
     1487
     1488Element._attributeTranslations = {};
     1489
     1490Element._attributeTranslations.names = {
     1491  colspan:   "colSpan",
     1492  rowspan:   "rowSpan",
     1493  valign:    "vAlign",
     1494  datetime:  "dateTime",
     1495  accesskey: "accessKey",
     1496  tabindex:  "tabIndex",
     1497  enctype:   "encType",
     1498  maxlength: "maxLength",
     1499  readonly:  "readOnly",
     1500  longdesc:  "longDesc"
     1501};
     1502
     1503Element._attributeTranslations.values = {
     1504  _getAttr: function(element, attribute) {
     1505    return element.getAttribute(attribute, 2);
     1506  },
     1507
     1508  _flag: function(element, attribute) {
     1509    return $(element).hasAttribute(attribute) ? attribute : null;
     1510  },
     1511
     1512  style: function(element) {
     1513    return element.style.cssText.toLowerCase();
     1514  },
     1515
     1516  title: function(element) {
     1517    var node = element.getAttributeNode('title');
     1518    return node.specified ? node.nodeValue : null;
     1519  }
     1520};
     1521
     1522Object.extend(Element._attributeTranslations.values, {
     1523  href: Element._attributeTranslations.values._getAttr,
     1524  src:  Element._attributeTranslations.values._getAttr,
     1525  disabled: Element._attributeTranslations.values._flag,
     1526  checked:  Element._attributeTranslations.values._flag,
     1527  readonly: Element._attributeTranslations.values._flag,
     1528  multiple: Element._attributeTranslations.values._flag
     1529});
     1530
     1531Element.Methods.Simulated = {
     1532  hasAttribute: function(element, attribute) {
     1533    var t = Element._attributeTranslations;
     1534    attribute = t.names[attribute] || attribute;
     1535    return $(element).getAttributeNode(attribute).specified;
     1536  }
     1537};
     1538
     1539// IE is missing .innerHTML support for TABLE-related elements
     1540if (document.all && !window.opera){
     1541  Element.Methods.update = function(element, html) {
     1542    element = $(element);
     1543    html = typeof html == 'undefined' ? '' : html.toString();
     1544    var tagName = element.tagName.toUpperCase();
     1545    if (['THEAD','TBODY','TR','TD'].include(tagName)) {
     1546      var div = document.createElement('div');
     1547      switch (tagName) {
     1548        case 'THEAD':
     1549        case 'TBODY':
     1550          div.innerHTML = '<table><tbody>' +  html.stripScripts() + '</tbody></table>';
     1551          depth = 2;
     1552          break;
     1553        case 'TR':
     1554          div.innerHTML = '<table><tbody><tr>' +  html.stripScripts() + '</tr></tbody></table>';
     1555          depth = 3;
     1556          break;
     1557        case 'TD':
     1558          div.innerHTML = '<table><tbody><tr><td>' +  html.stripScripts() + '</td></tr></tbody></table>';
     1559          depth = 4;
     1560      }
     1561      $A(element.childNodes).each(function(node){
     1562        element.removeChild(node)
     1563      });
     1564      depth.times(function(){ div = div.firstChild });
     1565
     1566      $A(div.childNodes).each(
     1567        function(node){ element.appendChild(node) });
     1568    } else {
     1569      element.innerHTML = html.stripScripts();
     1570    }
     1571    setTimeout(function() {html.evalScripts()}, 10);
     1572    return element;
     1573  }
     1574};
    11071575
    11081576Object.extend(Element, Element.Methods);
     
    11101578var _nativeExtensions = false;
    11111579
    1112 if(!HTMLElement && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) {
    1113   var HTMLElement = {}
    1114   HTMLElement.prototype = document.createElement('div').__proto__;
    1115 }
     1580if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
     1581  ['', 'Form', 'Input', 'TextArea', 'Select'].each(function(tag) {
     1582    var className = 'HTML' + tag + 'Element';
     1583    if(window[className]) return;
     1584    var klass = window[className] = {};
     1585    klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__;
     1586  });
    11161587
    11171588Element.addMethods = function(methods) {
    11181589  Object.extend(Element.Methods, methods || {});
    11191590
    1120   if(typeof HTMLElement != 'undefined') {
    1121     var methods = Element.Methods, cache = Element.extend.cache;
    1122     for (property in methods) {
     1591  function copy(methods, destination, onlyIfAbsent) {
     1592    onlyIfAbsent = onlyIfAbsent || false;
     1593    var cache = Element.extend.cache;
     1594    for (var property in methods) {
    11231595      var value = methods[property];
    1124       if (typeof value == 'function')
    1125         HTMLElement.prototype[property] = cache.findOrStore(value);
    1126     }
     1596      if (!onlyIfAbsent || !(property in destination))
     1597        destination[property] = cache.findOrStore(value);
     1598    }
     1599  }
     1600
     1601  if (typeof HTMLElement != 'undefined') {
     1602    copy(Element.Methods, HTMLElement.prototype);
     1603    copy(Element.Methods.Simulated, HTMLElement.prototype, true);
     1604    copy(Form.Methods, HTMLFormElement.prototype);
     1605    [HTMLInputElement, HTMLTextAreaElement, HTMLSelectElement].each(function(klass) {
     1606      copy(Form.Element.Methods, klass.prototype);
     1607    });
    11271608    _nativeExtensions = true;
    11281609  }
    11291610}
    1130 
    1131 Element.addMethods();
    11321611
    11331612var Toggle = new Object();
     
    11491628        this.element.insertAdjacentHTML(this.adjacency, this.content);
    11501629      } catch (e) {
    1151         var tagName = this.element.tagName.toLowerCase();
    1152         if (tagName == 'tbody' || tagName == 'tr') {
     1630        var tagName = this.element.tagName.toUpperCase();
     1631        if (['TBODY', 'TR'].include(tagName)) {
    11531632          this.insertContent(this.contentFromAnonymousTable());
    11541633        } else {
     
    12491728  add: function(classNameToAdd) {
    12501729    if (this.include(classNameToAdd)) return;
    1251     this.set(this.toArray().concat(classNameToAdd).join(' '));
     1730    this.set($A(this).concat(classNameToAdd).join(' '));
    12521731  },
    12531732
    12541733  remove: function(classNameToRemove) {
    12551734    if (!this.include(classNameToRemove)) return;
    1256     this.set(this.select(function(className) {
    1257       return className != classNameToRemove;
    1258     }).join(' '));
     1735    this.set($A(this).without(classNameToRemove).join(' '));
    12591736  },
    12601737
    12611738  toString: function() {
    1262     return this.toArray().join(' ');
    1263   }
    1264 }
     1739    return $A(this).join(' ');
     1740  }
     1741};
    12651742
    12661743Object.extend(Element.ClassNames.prototype, Enumerable);
     
    13091786      conditions.push('true');
    13101787    if (clause = params.id)
    1311       conditions.push('element.id == ' + clause.inspect());
     1788      conditions.push('element.readAttribute("id") == ' + clause.inspect());
    13121789    if (clause = params.tagName)
    13131790      conditions.push('element.tagName.toUpperCase() == ' + clause.inspect());
    13141791    if ((clause = params.classNames).length > 0)
    1315       for (var i = 0; i < clause.length; i++)
    1316         conditions.push('Element.hasClassName(element, ' + clause[i].inspect() + ')');
     1792      for (var i = 0, length = clause.length; i < length; i++)
     1793        conditions.push('element.hasClassName(' + clause[i].inspect() + ')');
    13171794    if (clause = params.attributes) {
    13181795      clause.each(function(attribute) {
    1319         var value = 'element.getAttribute(' + attribute.name.inspect() + ')';
     1796        var value = 'element.readAttribute(' + attribute.name.inspect() + ')';
    13201797        var splitValueBy = function(delimiter) {
    13211798          return value + ' && ' + value + '.split(' + delimiter.inspect() + ')';
     
    13301807          case '!=':      conditions.push(value + ' != ' + attribute.value.inspect()); break;
    13311808          case '':
    1332           case undefined: conditions.push(value + ' != null'); break;
     1809          case undefined: conditions.push('element.hasAttribute(' + attribute.name.inspect() + ')'); break;
    13331810          default:        throw 'Unknown operator ' + attribute.operator + ' in selector';
    13341811        }
     
    13411818  compileMatcher: function() {
    13421819    this.match = new Function('element', 'if (!element.tagName) return false; \
     1820      element = $(element); \
    13431821      return ' + this.buildMatchExpression());
    13441822  },
     
    13551833
    13561834    var results = [];
    1357     for (var i = 0; i < scope.length; i++)
     1835    for (var i = 0, length = scope.length; i < length; i++)
    13581836      if (this.match(element = scope[i]))
    13591837        results.push(Element.extend(element));
     
    13671845}
    13681846
     1847Object.extend(Selector, {
     1848  matchElements: function(elements, expression) {
     1849    var selector = new Selector(expression);
     1850    return elements.select(selector.match.bind(selector)).map(Element.extend);
     1851  },
     1852
     1853  findElement: function(elements, expression, index) {
     1854    if (typeof expression == 'number') index = expression, expression = false;
     1855    return Selector.matchElements(elements, expression || '*')[index || 0];
     1856  },
     1857
     1858  findChildElements: function(element, expressions) {
     1859    return expressions.map(function(expression) {
     1860      return expression.match(/[^\s"]+(?:"[^"]*"[^\s"]+)*/g).inject([null], function(results, expr) {
     1861        var selector = new Selector(expr);
     1862        return results.inject([], function(elements, result) {
     1863          return elements.concat(selector.findElements(result || element));
     1864        });
     1865      });
     1866    }).flatten();
     1867  }
     1868});
     1869
    13691870function $$() {
    1370   return $A(arguments).map(function(expression) {
    1371     return expression.strip().split(/\s+/).inject([null], function(results, expr) {
    1372       var selector = new Selector(expr);
    1373       return results.map(selector.findElements.bind(selector)).flatten();
    1374     });
    1375   }).flatten();
    1376 }
    1377 var Field = {
    1378   clear: function() {
    1379     for (var i = 0; i < arguments.length; i++)
    1380       $(arguments[i]).value = '';
    1381   },
    1382 
     1871  return Selector.findChildElements(document, $A(arguments));
     1872}
     1873var Form = {
     1874  reset: function(form) {
     1875    $(form).reset();
     1876    return form;
     1877  },
     1878
     1879  serializeElements: function(elements, getHash) {
     1880    var data = elements.inject({}, function(result, element) {
     1881      if (!element.disabled && element.name) {
     1882        var key = element.name, value = $(element).getValue();
     1883        if (value != undefined) {
     1884          if (result[key]) {
     1885            if (result[key].constructor != Array) result[key] = [result[key]];
     1886            result[key].push(value);
     1887          }
     1888          else result[key] = value;
     1889        }
     1890      }
     1891      return result;
     1892    });
     1893
     1894    return getHash ? data : Hash.toQueryString(data);
     1895  }
     1896};
     1897
     1898Form.Methods = {
     1899  serialize: function(form, getHash) {
     1900    return Form.serializeElements(Form.getElements(form), getHash);
     1901  },
     1902
     1903  getElements: function(form) {
     1904    return $A($(form).getElementsByTagName('*')).inject([],
     1905      function(elements, child) {
     1906        if (Form.Element.Serializers[child.tagName.toLowerCase()])
     1907          elements.push(Element.extend(child));
     1908        return elements;
     1909      }
     1910    );
     1911  },
     1912
     1913  getInputs: function(form, typeName, name) {
     1914    form = $(form);
     1915    var inputs = form.getElementsByTagName('input');
     1916
     1917    if (!typeName && !name) return $A(inputs).map(Element.extend);
     1918
     1919    for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
     1920      var input = inputs[i];
     1921      if ((typeName && input.type != typeName) || (name && input.name != name))
     1922        continue;
     1923      matchingInputs.push(Element.extend(input));
     1924    }
     1925
     1926    return matchingInputs;
     1927  },
     1928
     1929  disable: function(form) {
     1930    form = $(form);
     1931    form.getElements().each(function(element) {
     1932      element.blur();
     1933      element.disabled = 'true';
     1934    });
     1935    return form;
     1936  },
     1937
     1938  enable: function(form) {
     1939    form = $(form);
     1940    form.getElements().each(function(element) {
     1941      element.disabled = '';
     1942    });
     1943    return form;
     1944  },
     1945
     1946  findFirstElement: function(form) {
     1947    return $(form).getElements().find(function(element) {
     1948      return element.type != 'hidden' && !element.disabled &&
     1949        ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
     1950    });
     1951  },
     1952
     1953  focusFirstElement: function(form) {
     1954    form = $(form);
     1955    form.findFirstElement().activate();
     1956    return form;
     1957  }
     1958}
     1959
     1960Object.extend(Form, Form.Methods);
     1961
     1962/*--------------------------------------------------------------------------*/
     1963
     1964Form.Element = {
    13831965  focus: function(element) {
    13841966    $(element).focus();
    1385   },
    1386 
    1387   present: function() {
    1388     for (var i = 0; i < arguments.length; i++)
    1389       if ($(arguments[i]).value == '') return false;
    1390     return true;
     1967    return element;
    13911968  },
    13921969
    13931970  select: function(element) {
    13941971    $(element).select();
     1972    return element;
     1973  }
     1974}
     1975
     1976Form.Element.Methods = {
     1977  serialize: function(element) {
     1978    element = $(element);
     1979    if (!element.disabled && element.name) {
     1980      var value = element.getValue();
     1981      if (value != undefined) {
     1982        var pair = {};
     1983        pair[element.name] = value;
     1984        return Hash.toQueryString(pair);
     1985      }
     1986    }
     1987    return '';
     1988  },
     1989
     1990  getValue: function(element) {
     1991    element = $(element);
     1992    var method = element.tagName.toLowerCase();
     1993    return Form.Element.Serializers[method](element);
     1994  },
     1995
     1996  clear: function(element) {
     1997    $(element).value = '';
     1998    return element;
     1999  },
     2000
     2001  present: function(element) {
     2002    return $(element).value != '';
    13952003  },
    13962004
     
    13982006    element = $(element);
    13992007    element.focus();
    1400     if (element.select)
     2008    if (element.select && ( element.tagName.toLowerCase() != 'input' ||
     2009      !['button', 'reset', 'submit'].include(element.type) ) )
    14012010      element.select();
    1402   }
    1403 }
     2011    return element;
     2012  },
     2013
     2014  disable: function(element) {
     2015    element = $(element);
     2016    element.disabled = true;
     2017    return element;
     2018  },
     2019
     2020  enable: function(element) {
     2021    element = $(element);
     2022    element.blur();
     2023    element.disabled = false;
     2024    return element;
     2025  }
     2026}
     2027
     2028Object.extend(Form.Element, Form.Element.Methods);
     2029var Field = Form.Element;
     2030var $F = Form.Element.getValue;
    14042031
    14052032/*--------------------------------------------------------------------------*/
    1406 
    1407 var Form = {
    1408   serialize: function(form) {
    1409     var elements = Form.getElements($(form));
    1410     var queryComponents = new Array();
    1411 
    1412     for (var i = 0; i < elements.length; i++) {
    1413       var queryComponent = Form.Element.serialize(elements[i]);
    1414       if (queryComponent)
    1415         queryComponents.push(queryComponent);
    1416     }
    1417 
    1418     return queryComponents.join('&');
    1419   },
    1420 
    1421   getElements: function(form) {
    1422     form = $(form);
    1423     var elements = new Array();
    1424 
    1425     for (var tagName in Form.Element.Serializers) {
    1426       var tagElements = form.getElementsByTagName(tagName);
    1427       for (var j = 0; j < tagElements.length; j++)
    1428         elements.push(tagElements[j]);
    1429     }
    1430     return elements;
    1431   },
    1432 
    1433   getInputs: function(form, typeName, name) {
    1434     form = $(form);
    1435     var inputs = form.getElementsByTagName('input');
    1436 
    1437     if (!typeName && !name)
    1438       return inputs;
    1439 
    1440     var matchingInputs = new Array();
    1441     for (var i = 0; i < inputs.length; i++) {
    1442       var input = inputs[i];
    1443       if ((typeName && input.type != typeName) ||
    1444           (name && input.name != name))
    1445         continue;
    1446       matchingInputs.push(input);
    1447     }
    1448 
    1449     return matchingInputs;
    1450   },
    1451 
    1452   disable: function(form) {
    1453     var elements = Form.getElements(form);
    1454     for (var i = 0; i < elements.length; i++) {
    1455       var element = elements[i];
    1456       element.blur();
    1457       element.disabled = 'true';
    1458     }
    1459   },
    1460 
    1461   enable: function(form) {
    1462     var elements = Form.getElements(form);
    1463     for (var i = 0; i < elements.length; i++) {
    1464       var element = elements[i];
    1465       element.disabled = '';
    1466     }
    1467   },
    1468 
    1469   findFirstElement: function(form) {
    1470     return Form.getElements(form).find(function(element) {
    1471       return element.type != 'hidden' && !element.disabled &&
    1472         ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
    1473     });
    1474   },
    1475 
    1476   focusFirstElement: function(form) {
    1477     Field.activate(Form.findFirstElement(form));
    1478   },
    1479 
    1480   reset: function(form) {
    1481     $(form).reset();
    1482   }
    1483 }
    1484 
    1485 Form.Element = {
    1486   serialize: function(element) {
    1487     element = $(element);
    1488     var method = element.tagName.toLowerCase();
    1489     var parameter = Form.Element.Serializers[method](element);
    1490 
    1491     if (parameter) {
    1492       var key = encodeURIComponent(parameter[0]);
    1493       if (key.length == 0) return;
    1494 
    1495       if (parameter[1].constructor != Array)
    1496         parameter[1] = [parameter[1]];
    1497 
    1498       return parameter[1].map(function(value) {
    1499         return key + '=' + encodeURIComponent(value);
    1500       }).join('&');
    1501     }
    1502   },
    1503 
    1504   getValue: function(element) {
    1505     element = $(element);
    1506     var method = element.tagName.toLowerCase();
    1507     var parameter = Form.Element.Serializers[method](element);
    1508 
    1509     if (parameter)
    1510       return parameter[1];
    1511   }
    1512 }
    15132033
    15142034Form.Element.Serializers = {
    15152035  input: function(element) {
    15162036    switch (element.type.toLowerCase()) {
    1517       case 'submit':
    1518       case 'hidden':
    1519       case 'password':
    1520       case 'text':
    1521         return Form.Element.Serializers.textarea(element);
    15222037      case 'checkbox':
    15232038      case 'radio':
    15242039        return Form.Element.Serializers.inputSelector(element);
    1525     }
    1526     return false;
     2040      default:
     2041        return Form.Element.Serializers.textarea(element);
     2042    }
    15272043  },
    15282044
    15292045  inputSelector: function(element) {
    1530     if (element.checked)
    1531       return [element.name, element.value];
     2046    return element.checked ? element.value : null;
    15322047  },
    15332048
    15342049  textarea: function(element) {
    1535     return [element.name, element.value];
     2050    return element.value;
    15362051  },
    15372052
    15382053  select: function(element) {
    1539     return Form.Element.Serializers[element.type == 'select-one' ?
     2054    return this[element.type == 'select-one' ?
    15402055      'selectOne' : 'selectMany'](element);
    15412056  },
    15422057
    15432058  selectOne: function(element) {
    1544     var value = '', opt, index = element.selectedIndex;
    1545     if (index >= 0) {
    1546       opt = element.options[index];
    1547       value = opt.value || opt.text;
    1548     }
    1549     return [element.name, value];
     2059    var index = element.selectedIndex;
     2060    return index >= 0 ? this.optionValue(element.options[index]) : null;
    15502061  },
    15512062
    15522063  selectMany: function(element) {
    1553     var value = [];
    1554     for (var i = 0; i < element.length; i++) {
     2064    var values, length = element.length;
     2065    if (!length) return null;
     2066
     2067    for (var i = 0, values = []; i < length; i++) {
    15552068      var opt = element.options[i];
    1556       if (opt.selected)
    1557         value.push(opt.value || opt.text);
    1558     }
    1559     return [element.name, value];
    1560   }
    1561 }
    1562 
    1563 /*--------------------------------------------------------------------------*/
    1564 
    1565 var $F = Form.Element.getValue;
     2069      if (opt.selected) values.push(this.optionValue(opt));
     2070    }
     2071    return values;
     2072  },
     2073
     2074  optionValue: function(opt) {
     2075    // extend element because hasAttribute may not be native
     2076    return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text;
     2077  }
     2078}
    15662079
    15672080/*--------------------------------------------------------------------------*/
     
    15842097  onTimerEvent: function() {
    15852098    var value = this.getValue();
    1586     if (this.lastValue != value) {
     2099    var changed = ('string' == typeof this.lastValue && 'string' == typeof value
     2100      ? this.lastValue != value : String(this.lastValue) != String(value));
     2101    if (changed) {
    15872102      this.callback(this.element, value);
    15882103      this.lastValue = value;
     
    16292144
    16302145  registerFormCallbacks: function() {
    1631     var elements = Form.getElements(this.element);
    1632     for (var i = 0; i < elements.length; i++)
    1633       this.registerCallback(elements[i]);
     2146    Form.getElements(this.element).each(this.registerCallback.bind(this));
    16342147  },
    16352148
     
    16412154          Event.observe(element, 'click', this.onElementEvent.bind(this));
    16422155          break;
    1643         case 'password':
    1644         case 'text':
    1645         case 'textarea':
    1646         case 'select-one':
    1647         case 'select-multiple':
     2156        default:
    16482157          Event.observe(element, 'change', this.onElementEvent.bind(this));
    16492158          break;
     
    16802189  KEY_DOWN:     40,
    16812190  KEY_DELETE:   46,
     2191  KEY_HOME:     36,
     2192  KEY_END:      35,
     2193  KEY_PAGEUP:   33,
     2194  KEY_PAGEDOWN: 34,
    16822195
    16832196  element: function(event) {
     
    17352248  unloadCache: function() {
    17362249    if (!Event.observers) return;
    1737     for (var i = 0; i < Event.observers.length; i++) {
     2250    for (var i = 0, length = Event.observers.length; i < length; i++) {
    17382251      Event.stopObserving.apply(this, Event.observers[i]);
    17392252      Event.observers[i][0] = null;
     
    17432256
    17442257  observe: function(element, name, observer, useCapture) {
    1745     var element = $(element);
     2258    element = $(element);
    17462259    useCapture = useCapture || false;
    17472260
     
    17512264      name = 'keydown';
    17522265
    1753     this._observeAndCache(element, name, observer, useCapture);
     2266    Event._observeAndCache(element, name, observer, useCapture);
    17542267  },
    17552268
    17562269  stopObserving: function(element, name, observer, useCapture) {
    1757     var element = $(element);
     2270    element = $(element);
    17582271    useCapture = useCapture || false;
    17592272
     
    18222335      element = element.offsetParent;
    18232336      if (element) {
    1824         p = Element.getStyle(element, 'position');
     2337        if(element.tagName=='BODY') break;
     2338        var p = Element.getStyle(element, 'position');
    18252339        if (p == 'relative' || p == 'absolute') break;
    18262340      }
     
    18782392  },
    18792393
    1880   clone: function(source, target) {
    1881     source = $(source);
    1882     target = $(target);
    1883     target.style.position = 'absolute';
    1884     var offsets = this.cumulativeOffset(source);
    1885     target.style.top    = offsets[1] + 'px';
    1886     target.style.left   = offsets[0] + 'px';
    1887     target.style.width  = source.offsetWidth + 'px';
    1888     target.style.height = source.offsetHeight + 'px';
    1889   },
    1890 
    18912394  page: function(forElement) {
    18922395    var valueT = 0, valueL = 0;
     
    19052408    element = forElement;
    19062409    do {
    1907       valueT -= element.scrollTop  || 0;
    1908       valueL -= element.scrollLeft || 0;
     2410      if (!window.opera || element.tagName=='BODY') {
     2411        valueT -= element.scrollTop  || 0;
     2412        valueL -= element.scrollLeft || 0;
     2413      }
    19092414    } while (element = element.parentNode);
    19102415
     
    19672472
    19682473    element.style.position = 'absolute';
    1969     element.style.top    = top + 'px';;
    1970     element.style.left   = left + 'px';;
    1971     element.style.width  = width + 'px';;
    1972     element.style.height = height + 'px';;
     2474    element.style.top    = top + 'px';
     2475    element.style.left   = left + 'px';
     2476    element.style.width  = width + 'px';
     2477    element.style.height = height + 'px';
    19732478  },
    19742479
     
    20072512  }
    20082513}
     2514
     2515Element.addMethods();
  • trunk/wp-includes/js/scriptaculous/MIT-LICENSE

    r4629 r4813  
    1 Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
     1Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
    22
    33Permission is hereby granted, free of charge, to any person obtaining
  • trunk/wp-includes/js/scriptaculous/builder.js

    r4629 r4813  
    1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
     1// script.aculo.us builder.js v1.7.0, Fri Jan 19 19:16:36 CET 2007
     2
     3// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
    24//
    3 // See scriptaculous.js for full license.
     5// script.aculo.us is freely distributable under the terms of an MIT-style license.
     6// For details, see the script.aculo.us web site: http://script.aculo.us/
    47
    58var Builder = {
     
    3437     
    3538    // see if browser added wrapping tags
    36     if(element && (element.tagName != elementName))
     39    if(element && (element.tagName.toUpperCase() != elementName))
    3740      element = element.getElementsByTagName(elementName)[0];
    3841   
     
    6265                element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
    6366            }
    64             if(element.tagName != elementName)
     67            if(element.tagName.toUpperCase() != elementName)
    6568              element = parentElement.getElementsByTagName(elementName)[0];
    6669            }
     
    7679     return document.createTextNode(text);
    7780  },
     81
     82  ATTR_MAP: {
     83    'className': 'class',
     84    'htmlFor': 'for'
     85  },
     86
    7887  _attributes: function(attributes) {
    7988    var attrs = [];
    8089    for(attribute in attributes)
    81       attrs.push((attribute=='className' ? 'class' : attribute) +
     90      attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) +
    8291          '="' + attributes[attribute].toString().escapeHTML() + '"');
    8392    return attrs.join(" ");
     
    98107  _isStringOrNumber: function(param) {
    99108    return(typeof param=='string' || typeof param=='number');
     109  },
     110  build: function(html) {
     111    var element = this.node('div');
     112    $(element).update(html.strip());
     113    return element.down();
     114  },
     115  dump: function(scope) {
     116    if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
     117 
     118    var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
     119      "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
     120      "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
     121      "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
     122      "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
     123      "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
     124 
     125    tags.each( function(tag){
     126      scope[tag] = function() {
     127        return Builder.node.apply(Builder, [tag].concat($A(arguments))); 
     128      }
     129    });
    100130  }
    101131}
  • trunk/wp-includes/js/scriptaculous/controls.js

    r4629 r4813  
    1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
    2 //           (c) 2005 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
    3 //           (c) 2005 Jon Tirsen (http://www.tirsen.com)
     1// script.aculo.us controls.js v1.7.0, Fri Jan 19 19:16:36 CET 2007
     2
     3// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
     4//           (c) 2005, 2006 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
     5//           (c) 2005, 2006 Jon Tirsen (http://www.tirsen.com)
    46// Contributors:
    57//  Richard Livsey
     
    79//  Rob Wills
    810//
    9 // See scriptaculous.js for full license.
     11// script.aculo.us is freely distributable under the terms of an MIT-style license.
     12// For details, see the script.aculo.us web site: http://script.aculo.us/
    1013
    1114// Autocompleter.Base handles all the autocompletion functionality
     
    3336// useful when one of the tokens is \n (a newline), as it
    3437// allows smart autocompletion after linebreaks.
     38
     39if(typeof Effect == 'undefined')
     40  throw("controls.js requires including script.aculo.us' effects.js library");
    3541
    3642var Autocompleter = {}
     
    4652    this.entryCount  = 0;
    4753
    48     if (this.setOptions)
     54    if(this.setOptions)
    4955      this.setOptions(options);
    5056    else
     
    5662    this.options.minChars     = this.options.minChars || 1;
    5763    this.options.onShow       = this.options.onShow ||
    58     function(element, update){
    59       if(!update.style.position || update.style.position=='absolute') {
    60         update.style.position = 'absolute';
    61         Position.clone(element, update, {setHeight: false, offsetTop: element.offsetHeight});
    62       }
    63       Effect.Appear(update,{duration:0.15});
    64     };
     64      function(element, update){
     65        if(!update.style.position || update.style.position=='absolute') {
     66          update.style.position = 'absolute';
     67          Position.clone(element, update, {
     68            setHeight: false,
     69            offsetTop: element.offsetHeight
     70          });
     71        }
     72        Effect.Appear(update,{duration:0.15});
     73      };
    6574    this.options.onHide = this.options.onHide ||
    66     function(element, update){ new Effect.Fade(update,{duration:0.15}) };
    67 
    68     if (typeof(this.options.tokens) == 'string')
     75      function(element, update){ new Effect.Fade(update,{duration:0.15}) };
     76
     77    if(typeof(this.options.tokens) == 'string')
    6978      this.options.tokens = new Array(this.options.tokens);
    7079
     
    95104 
    96105  fixIEOverlapping: function() {
    97     Position.clone(this.update, this.iefix);
     106    Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
    98107    this.iefix.style.zIndex = 1;
    99108    this.update.style.zIndex = 2;
     
    203212    if(this.index > 0) this.index--
    204213      else this.index = this.entryCount-1;
     214    this.getEntry(this.index).scrollIntoView(true);
    205215  },
    206216 
     
    208218    if(this.index < this.entryCount-1) this.index++
    209219      else this.index = 0;
     220    this.getEntry(this.index).scrollIntoView(false);
    210221  },
    211222 
     
    255266      this.update.innerHTML = choices;
    256267      Element.cleanWhitespace(this.update);
    257       Element.cleanWhitespace(this.update.firstChild);
    258 
    259       if(this.update.firstChild && this.update.firstChild.childNodes) {
     268      Element.cleanWhitespace(this.update.down());
     269
     270      if(this.update.firstChild && this.update.down().childNodes) {
    260271        this.entryCount =
    261           this.update.firstChild.childNodes.length;
     272          this.update.down().childNodes.length;
    262273        for (var i = 0; i < this.entryCount; i++) {
    263274          var entry = this.getEntry(i);
     
    270281
    271282      this.stopIndicator();
    272 
    273283      this.index = 0;
    274       this.render();
     284     
     285      if(this.entryCount==1 && this.options.autoSelect) {
     286        this.selectEntry();
     287        this.hide();
     288      } else {
     289        this.render();
     290      }
    275291    }
    276292  },
     
    460476
    461477    this.options = Object.extend({
     478      paramName: "value",
    462479      okButton: true,
    463480      okText: "ok",
     
    532549    this.createForm();
    533550    this.element.parentNode.insertBefore(this.form, this.element);
    534     Field.scrollFreeActivate(this.editField);
     551    if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField);
    535552    // stop the event to avoid a page refresh in Safari
    536553    if (evt) {
     
    591608      textField.obj = this;
    592609      textField.type = "text";
    593       textField.name = "value";
     610      textField.name = this.options.paramName;
    594611      textField.value = text;
    595612      textField.style.backgroundColor = this.options.highlightcolor;
     
    604621      var textArea = document.createElement("textarea");
    605622      textArea.obj = this;
    606       textArea.name = "value";
     623      textArea.name = this.options.paramName;
    607624      textArea.value = this.convertHTMLLineBreaks(text);
    608625      textArea.rows = this.options.rows;
     
    637654    this.editField.disabled = false;
    638655    this.editField.value = transport.responseText.stripTags();
     656    Field.scrollFreeActivate(this.editField);
    639657  },
    640658  onclickCancel: function() {
     
    773791        optionTag = document.createElement("option");
    774792        optionTag.value = (e instanceof Array) ? e[0] : e;
     793        if((typeof this.options.value == 'undefined') &&
     794          ((e instanceof Array) ? this.element.innerHTML == e[1] : e == optionTag.value)) optionTag.selected = true;
    775795        if(this.options.value==optionTag.value) optionTag.selected = true;
    776796        optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e));
  • trunk/wp-includes/js/scriptaculous/dragdrop.js

    r4629 r4813  
    1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
    2 //           (c) 2005 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
     1// script.aculo.us dragdrop.js v1.7.0, Fri Jan 19 19:16:36 CET 2007
     2
     3// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
     4//           (c) 2005, 2006 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
    35//
    4 // See scriptaculous.js for full license.
    5 
    6 /*--------------------------------------------------------------------------*/
     6// script.aculo.us is freely distributable under the terms of an MIT-style license.
     7// For details, see the script.aculo.us web site: http://script.aculo.us/
     8
     9if(typeof Effect == 'undefined')
     10  throw("dragdrop.js requires including script.aculo.us' effects.js library");
    711
    812var Droppables = {
     
    146150 
    147151  activate: function(draggable) {
    148     window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
    149     this.activeDraggable = draggable;
     152    if(draggable.options.delay) {
     153      this._timeout = setTimeout(function() {
     154        Draggables._timeout = null;
     155        window.focus();
     156        Draggables.activeDraggable = draggable;
     157      }.bind(this), draggable.options.delay);
     158    } else {
     159      window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
     160      this.activeDraggable = draggable;
     161    }
    150162  },
    151163 
     
    161173    if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return;
    162174    this._lastPointer = pointer;
     175   
    163176    this.activeDraggable.updateDrag(event, pointer);
    164177  },
    165178 
    166179  endDrag: function(event) {
     180    if(this._timeout) {
     181      clearTimeout(this._timeout);
     182      this._timeout = null;
     183    }
    167184    if(!this.activeDraggable) return;
    168185    this._lastPointer = null;
     
    191208        if(o[eventName]) o[eventName](eventName, draggable, event);
    192209      });
     210    if(draggable.options[eventName]) draggable.options[eventName](draggable, event);
    193211  },
    194212 
     
    205223
    206224var Draggable = Class.create();
     225Draggable._dragging    = {};
     226
    207227Draggable.prototype = {
    208228  initialize: function(element) {
    209     var options = Object.extend({
     229    var defaults = {
    210230      handle: false,
    211       starteffect: function(element) {
    212         element._opacity = Element.getOpacity(element);
    213         new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
    214       },
    215231      reverteffect: function(element, top_offset, left_offset) {
    216232        var dur = Math.sqrt(Math.abs(top_offset^2)+Math.abs(left_offset^2))*0.02;
    217         element._revert = new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur});
     233        new Effect.Move(element, { x: -left_offset, y: -top_offset, duration: dur,
     234          queue: {scope:'_draggable', position:'end'}
     235        });
    218236      },
    219237      endeffect: function(element) {
    220         var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0
    221         new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity});
     238        var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0;
     239        new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
     240          queue: {scope:'_draggable', position:'end'},
     241          afterFinish: function(){
     242            Draggable._dragging[element] = false
     243          }
     244        });
    222245      },
    223246      zindex: 1000,
     
    226249      scrollSensitivity: 20,
    227250      scrollSpeed: 15,
    228       snap: false   // false, or xy or [x,y] or function(x,y){ return [x,y] }
    229     }, arguments[1] || {});
     251      snap: false,  // false, or xy or [x,y] or function(x,y){ return [x,y] }
     252      delay: 0
     253    };
     254   
     255    if(!arguments[1] || typeof arguments[1].endeffect == 'undefined')
     256      Object.extend(defaults, {
     257        starteffect: function(element) {
     258          element._opacity = Element.getOpacity(element);
     259          Draggable._dragging[element] = true;
     260          new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
     261        }
     262      });
     263   
     264    var options = Object.extend(defaults, arguments[1] || {});
    230265
    231266    this.element = $(element);
    232267   
    233     if(options.handle && (typeof options.handle == 'string')) {
    234       var h = Element.childrenWithClassName(this.element, options.handle, true);
    235       if(h.length>0) this.handle = h[0];
    236     }
     268    if(options.handle && (typeof options.handle == 'string'))
     269      this.handle = this.element.down('.'+options.handle, 0);
     270   
    237271    if(!this.handle) this.handle = $(options.handle);
    238272    if(!this.handle) this.handle = this.element;
    239273   
    240     if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML)
     274    if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) {
    241275      options.scroll = $(options.scroll);
     276      this._isScrollChild = Element.childOf(this.element, options.scroll);
     277    }
    242278
    243279    Element.makePositioned(this.element); // fix IE   
     
    265301 
    266302  initDrag: function(event) {
     303    if(typeof Draggable._dragging[this.element] != 'undefined' &&
     304      Draggable._dragging[this.element]) return;
    267305    if(Event.isLeftClick(event)) {   
    268306      // abort on form elements, fixes a Firefox issue
    269307      var src = Event.element(event);
    270       if(src.tagName && (
    271         src.tagName=='INPUT' ||
    272         src.tagName=='SELECT' ||
    273         src.tagName=='OPTION' ||
    274         src.tagName=='BUTTON' ||
    275         src.tagName=='TEXTAREA')) return;
     308      if((tag_name = src.tagName.toUpperCase()) && (
     309        tag_name=='INPUT' ||
     310        tag_name=='SELECT' ||
     311        tag_name=='OPTION' ||
     312        tag_name=='BUTTON' ||
     313        tag_name=='TEXTAREA')) return;
    276314       
    277       if(this.element._revert) {
    278         this.element._revert.cancel();
    279         this.element._revert = null;
    280       }
    281      
    282315      var pointer = [Event.pointerX(event), Event.pointerY(event)];
    283316      var pos     = Position.cumulativeOffset(this.element);
     
    315348   
    316349    Draggables.notify('onStart', this, event);
     350       
    317351    if(this.options.starteffect) this.options.starteffect(this.element);
    318352  },
     
    323357    Droppables.show(pointer, this.element);
    324358    Draggables.notify('onDrag', this, event);
     359   
    325360    this.draw(pointer);
    326361    if(this.options.change) this.options.change(this);
     
    334369      } else {
    335370        p = Position.page(this.options.scroll);
    336         p[0] += this.options.scroll.scrollLeft;
    337         p[1] += this.options.scroll.scrollTop;
     371        p[0] += this.options.scroll.scrollLeft + Position.deltaX;
     372        p[1] += this.options.scroll.scrollTop + Position.deltaY;
    338373        p.push(p[0]+this.options.scroll.offsetWidth);
    339374        p.push(p[1]+this.options.scroll.offsetHeight);
     
    381416    if(this.options.endeffect)
    382417      this.options.endeffect(this.element);
    383 
     418     
    384419    Draggables.deactivate(this);
    385420    Droppables.reset();
     
    401436  draw: function(point) {
    402437    var pos = Position.cumulativeOffset(this.element);
     438    if(this.options.ghosting) {
     439      var r   = Position.realOffset(this.element);
     440      pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY;
     441    }
     442   
    403443    var d = this.currentDelta();
    404444    pos[0] -= d[0]; pos[1] -= d[1];
    405445   
    406     if(this.options.scroll && (this.options.scroll != window)) {
     446    if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) {
    407447      pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
    408448      pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
     
    431471    if((!this.options.constraint) || (this.options.constraint=='vertical'))
    432472      style.top  = p[1] + "px";
     473   
    433474    if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
    434475  },
     
    443484 
    444485  startScrolling: function(speed) {
     486    if(!(speed[0] || speed[1])) return;
    445487    this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed];
    446488    this.lastScrolled = new Date();
     
    467509    Droppables.show(Draggables._lastPointer, this.element);
    468510    Draggables.notify('onDrag', this);
    469     Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer);
    470     Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000;
    471     Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000;
    472     if (Draggables._lastScrollPointer[0] < 0)
    473       Draggables._lastScrollPointer[0] = 0;
    474     if (Draggables._lastScrollPointer[1] < 0)
    475       Draggables._lastScrollPointer[1] = 0;
    476     this.draw(Draggables._lastScrollPointer);
     511    if (this._isScrollChild) {
     512      Draggables._lastScrollPointer = Draggables._lastScrollPointer || $A(Draggables._lastPointer);
     513      Draggables._lastScrollPointer[0] += this.scrollSpeed[0] * delta / 1000;
     514      Draggables._lastScrollPointer[1] += this.scrollSpeed[1] * delta / 1000;
     515      if (Draggables._lastScrollPointer[0] < 0)
     516        Draggables._lastScrollPointer[0] = 0;
     517      if (Draggables._lastScrollPointer[1] < 0)
     518        Draggables._lastScrollPointer[1] = 0;
     519      this.draw(Draggables._lastScrollPointer);
     520    }
    477521   
    478522    if(this.options.change) this.options.change(this);
     
    526570
    527571var Sortable = {
     572  SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/,
     573 
    528574  sortables: {},
    529575 
    530576  _findRootElement: function(element) {
    531     while (element.tagName != "BODY") { 
     577    while (element.tagName.toUpperCase() != "BODY") { 
    532578      if(element.id && Sortable.sortables[element.id]) return element;
    533579      element = element.parentNode;
     
    566612      handle:      false,      // or a CSS class
    567613      only:        false,
     614      delay:       0,
    568615      hoverclass:  null,
    569616      ghosting:    false,
     
    571618      scrollSensitivity: 20,
    572619      scrollSpeed: 15,
    573       format:      /^[^_]*_(.*)$/,
     620      format:      this.SERIALIZE_RULE,
    574621      onChange:    Prototype.emptyFunction,
    575622      onUpdate:    Prototype.emptyFunction
     
    585632      scrollSpeed: options.scrollSpeed,
    586633      scrollSensitivity: options.scrollSensitivity,
     634      delay:       options.delay,
    587635      ghosting:    options.ghosting,
    588636      constraint:  options.constraint,
     
    613661      hoverclass:  options.hoverclass,
    614662      onHover:     Sortable.onHover
    615       //greedy:      !options.dropOnEmpty
    616663    }
    617664   
     
    638685      // handles are per-draggable
    639686      var handle = options.handle ?
    640         Element.childrenWithClassName(e, options.handle)[0] : e;   
     687        $(e).down('.'+options.handle,0) : e;   
    641688      options.draggables.push(
    642689        new Draggable(e, Object.extend(options_for_draggable, { handle: handle })));
     
    709756      var index;
    710757     
    711       var children = Sortable.findElements(dropon, {tag: droponOptions.tag});
     758      var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only});
    712759      var child = null;
    713760           
     
    736783
    737784  unmark: function() {
    738     if(Sortable._marker) Element.hide(Sortable._marker);
     785    if(Sortable._marker) Sortable._marker.hide();
    739786  },
    740787
     
    745792
    746793    if(!Sortable._marker) {
    747       Sortable._marker = $('dropmarker') || document.createElement('DIV');
    748       Element.hide(Sortable._marker);
    749       Element.addClassName(Sortable._marker, 'dropmarker');
    750       Sortable._marker.style.position = 'absolute';
     794      Sortable._marker =
     795        ($('dropmarker') || Element.extend(document.createElement('DIV'))).
     796          hide().addClassName('dropmarker').setStyle({position:'absolute'});
    751797      document.getElementsByTagName("body").item(0).appendChild(Sortable._marker);
    752798    }   
    753799    var offsets = Position.cumulativeOffset(dropon);
    754     Sortable._marker.style.left = offsets[0] + 'px';
    755     Sortable._marker.style.top = offsets[1] + 'px';
     800    Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'});
    756801   
    757802    if(position=='after')
    758803      if(sortable.overlap == 'horizontal')
    759         Sortable._marker.style.left = (offsets[0]+dropon.clientWidth) + 'px';
     804        Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'});
    760805      else
    761         Sortable._marker.style.top = (offsets[1]+dropon.clientHeight) + 'px';
    762    
    763     Element.show(Sortable._marker);
     806        Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'});
     807   
     808    Sortable._marker.show();
    764809  },
    765810 
     
    776821        element: element,
    777822        parent: parent,
    778         children: new Array,
     823        children: [],
    779824        position: parent.children.length,
    780         container: Sortable._findChildrenElement(children[i], options.treeTag.toUpperCase())
     825        container: $(children[i]).down(options.treeTag)
    781826      }
    782827     
     
    789834
    790835    return parent;
    791   },
    792 
    793   /* Finds the first element of the given tag type within a parent element.
    794     Used for finding the first LI[ST] within a L[IST]I[TEM].*/
    795   _findChildrenElement: function (element, containerTag) {
    796     if (element && element.hasChildNodes)
    797       for (var i = 0; i < element.childNodes.length; ++i)
    798         if (element.childNodes[i].tagName == containerTag)
    799           return element.childNodes[i];
    800  
    801     return null;
    802836  },
    803837
     
    816850      id: null,
    817851      parent: null,
    818       children: new Array,
     852      children: [],
    819853      container: element,
    820854      position: 0
    821855    }
    822856   
    823     return Sortable._tree (element, options, root);
     857    return Sortable._tree(element, options, root);
    824858  },
    825859
     
    870904    if (options.tree) {
    871905      return Sortable.tree(element, arguments[1]).children.map( function (item) {
    872         return [name + Sortable._constructIndex(item) + "=" +
     906        return [name + Sortable._constructIndex(item) + "[id]=" +
    873907                encodeURIComponent(item.id)].concat(item.children.map(arguments.callee));
    874908      }).flatten().join('&');
     
    881915}
    882916
    883 /* Returns true if child is contained within element */
     917// Returns true if child is contained within element
    884918Element.isParent = function(child, element) {
    885919  if (!child.parentNode || child == element) return false;
    886 
    887920  if (child.parentNode == element) return true;
    888 
    889921  return Element.isParent(child.parentNode, element);
    890922}
     
    909941
    910942Element.offsetSize = function (element, type) {
    911   if (type == 'vertical' || type == 'height')
    912     return element.offsetHeight;
    913   else
    914     return element.offsetWidth;
     943  return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')];
    915944}
  • trunk/wp-includes/js/scriptaculous/effects.js

    r4629 r4813  
    1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
     1// script.aculo.us effects.js v1.7.0, Fri Jan 19 19:16:36 CET 2007
     2
     3// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
    24// Contributors:
    35//  Justin Palmer (http://encytemedia.com/)
     
    57//  Martin Bialasinki
    68//
    7 // See scriptaculous.js for full license. 
     9// script.aculo.us is freely distributable under the terms of an MIT-style license.
     10// For details, see the script.aculo.us web site: http://script.aculo.us/
    811
    912// converts rgb() and #xxx to #xxxxxx format, 
    1013// returns self (or first argument) if not convertable 
    1114String.prototype.parseColor = function() { 
    12   var color = '#'; 
     15  var color = '#';
    1316  if(this.slice(0,4) == 'rgb(') { 
    1417    var cols = this.slice(4,this.length-1).split(','); 
     
    4245Element.setContentZoom = function(element, percent) {
    4346  element = $(element); 
    44   Element.setStyle(element, {fontSize: (percent/100) + 'em'});   
     47  element.setStyle({fontSize: (percent/100) + 'em'});   
    4548  if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
    46 }
    47 
    48 Element.getOpacity = function(element){ 
    49   var opacity;
    50   if (opacity = Element.getStyle(element, 'opacity')) 
    51     return parseFloat(opacity); 
    52   if (opacity = (Element.getStyle(element, 'filter') || '').match(/alpha\(opacity=(.*)\)/)) 
    53     if(opacity[1]) return parseFloat(opacity[1]) / 100; 
    54   return 1.0; 
    55 }
    56 
    57 Element.setOpacity = function(element, value){ 
    58   element= $(element); 
    59   if (value == 1){
    60     Element.setStyle(element, { opacity:
    61       (/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ?
    62       0.999999 : null });
    63     if(/MSIE/.test(navigator.userAgent)) 
    64       Element.setStyle(element, {filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'')}); 
    65   } else { 
    66     if(value < 0.00001) value = 0; 
    67     Element.setStyle(element, {opacity: value});
    68     if(/MSIE/.test(navigator.userAgent)) 
    69      Element.setStyle(element,
    70        { filter: Element.getStyle(element,'filter').replace(/alpha\([^\)]*\)/gi,'') +
    71                  'alpha(opacity='+value*100+')' }); 
    72   }
    73 
    74  
    75 Element.getInlineOpacity = function(element){ 
     49  return element;
     50}
     51
     52Element.getOpacity = function(element){
     53  return $(element).getStyle('opacity');
     54}
     55
     56Element.setOpacity = function(element, value){
     57  return $(element).setStyle({opacity:value});
     58}
     59
     60Element.getInlineOpacity = function(element){
    7661  return $(element).style.opacity || '';
    77 
    78 
    79 Element.childrenWithClassName = function(element, className, findFirst) {
    80   var classNameRegExp = new RegExp("(^|\\s)" + className + "(\\s|$)");
    81   var results = $A($(element).getElementsByTagName('*'))[findFirst ? 'detect' : 'select']( function(c) {
    82     return (c.className && c.className.match(classNameRegExp));
    83   });
    84   if(!results) results = [];
    85   return results;
    8662}
    8763
     
    10581
    10682var Effect = {
     83  _elementDoesNotExistError: {
     84    name: 'ElementDoesNotExistError',
     85    message: 'The specified DOM element does not exist, but is required for this effect to operate'
     86  },
    10787  tagifyText: function(element) {
     88    if(typeof Builder == 'undefined')
     89      throw("Effect.tagifyText requires including script.aculo.us' builder.js library");
     90     
    10891    var tagifyStyle = 'position:relative';
    109     if(/MSIE/.test(navigator.userAgent)) tagifyStyle += ';zoom:1';
     92    if(/MSIE/.test(navigator.userAgent) && !window.opera) tagifyStyle += ';zoom:1';
     93   
    11094    element = $(element);
    11195    $A(element.childNodes).each( function(child) {
     
    160144/* ------------- transitions ------------- */
    161145
    162 Effect.Transitions = {}
    163 
    164 Effect.Transitions.linear = function(pos) {
    165   return pos;
    166 }
    167 Effect.Transitions.sinoidal = function(pos) {
    168   return (-Math.cos(pos*Math.PI)/2) + 0.5;
    169 }
    170 Effect.Transitions.reverse  = function(pos) {
    171   return 1-pos;
    172 }
    173 Effect.Transitions.flicker = function(pos) {
    174   return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4;
    175 }
    176 Effect.Transitions.wobble = function(pos) {
    177   return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
    178 }
    179 Effect.Transitions.pulse = function(pos) {
    180   return (Math.floor(pos*10) % 2 == 0 ?
    181     (pos*10-Math.floor(pos*10)) : 1-(pos*10-Math.floor(pos*10)));
    182 }
    183 Effect.Transitions.none = function(pos) {
    184   return 0;
    185 }
    186 Effect.Transitions.full = function(pos) {
    187   return 1;
    188 }
     146Effect.Transitions = {
     147  linear: Prototype.K,
     148  sinoidal: function(pos) {
     149    return (-Math.cos(pos*Math.PI)/2) + 0.5;
     150  },
     151  reverse: function(pos) {
     152    return 1-pos;
     153  },
     154  flicker: function(pos) {
     155    return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4;
     156  },
     157  wobble: function(pos) {
     158    return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
     159  },
     160  pulse: function(pos, pulses) {
     161    pulses = pulses || 5;
     162    return (
     163      Math.round((pos % (1/pulses)) * pulses) == 0 ?
     164            ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) :
     165        1 - ((pos * pulses * 2) - Math.floor(pos * pulses * 2))
     166      );
     167  },
     168  none: function(pos) {
     169    return 0;
     170  },
     171  full: function(pos) {
     172    return 1;
     173  }
     174};
    189175
    190176/* ------------- core effects ------------- */
     
    213199          });
    214200        break;
     201      case 'with-last':
     202        timestamp = this.effects.pluck('startOn').max() || timestamp;
     203        break;
    215204      case 'end':
    216205        // start effect after last queued effect has finished
     
    226215   
    227216    if(!this.interval)
    228       this.interval = setInterval(this.loop.bind(this), 40);
     217      this.interval = setInterval(this.loop.bind(this), 15);
    229218  },
    230219  remove: function(effect) {
     
    237226  loop: function() {
    238227    var timePos = new Date().getTime();
    239     this.effects.invoke('loop', timePos);
     228    for(var i=0, len=this.effects.length;i<len;i++)
     229      if(this.effects[i]) this.effects[i].loop(timePos);
    240230  }
    241231});
     
    257247  transition: Effect.Transitions.sinoidal,
    258248  duration:   1.0,   // seconds
    259   fps:        25.0,  // max. 25fps due to Effect.Queue implementation
     249  fps:        60.0,  // max. 60fps due to Effect.Queue implementation
    260250  sync:       false, // true for combining
    261251  from:       0.0,
     
    325315  },
    326316  inspect: function() {
    327     return '#<Effect:' + $H(this).inspect() + ',options:' + $H(this.options).inspect() + '>';
     317    var data = $H();
     318    for(property in this)
     319      if(typeof this[property] != 'function') data[property] = this[property];
     320    return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>';
    328321  }
    329322}
     
    349342});
    350343
     344Effect.Event = Class.create();
     345Object.extend(Object.extend(Effect.Event.prototype, Effect.Base.prototype), {
     346  initialize: function() {
     347    var options = Object.extend({
     348      duration: 0
     349    }, arguments[0] || {});
     350    this.start(options);
     351  },
     352  update: Prototype.emptyFunction
     353});
     354
    351355Effect.Opacity = Class.create();
    352356Object.extend(Object.extend(Effect.Opacity.prototype, Effect.Base.prototype), {
    353357  initialize: function(element) {
    354358    this.element = $(element);
     359    if(!this.element) throw(Effect._elementDoesNotExistError);
    355360    // make this work on IE on elements without 'layout'
    356     if(/MSIE/.test(navigator.userAgent) && (!this.element.hasLayout))
     361    if(/MSIE/.test(navigator.userAgent) && !window.opera && (!this.element.currentStyle.hasLayout))
    357362      this.element.setStyle({zoom: 1});
    358363    var options = Object.extend({
     
    371376  initialize: function(element) {
    372377    this.element = $(element);
     378    if(!this.element) throw(Effect._elementDoesNotExistError);
    373379    var options = Object.extend({
    374380      x:    0,
     
    394400  update: function(position) {
    395401    this.element.setStyle({
    396       left: this.options.x  * position + this.originalLeft + 'px',
    397       top:  this.options.y  * position + this.originalTop  + 'px'
     402      left: Math.round(this.options.x  * position + this.originalLeft) + 'px',
     403      top:  Math.round(this.options.y  * position + this.originalTop)  + 'px'
    398404    });
    399405  }
     
    409415Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), {
    410416  initialize: function(element, percent) {
    411     this.element = $(element)
     417    this.element = $(element);
     418    if(!this.element) throw(Effect._elementDoesNotExistError);
    412419    var options = Object.extend({
    413420      scaleX: true,
     
    434441   
    435442    var fontSize = this.element.getStyle('font-size') || '100%';
    436     ['em','px','%'].each( function(fontSizeType) {
     443    ['em','px','%','pt'].each( function(fontSizeType) {
    437444      if(fontSize.indexOf(fontSizeType)>0) {
    438445        this.fontSize     = parseFloat(fontSize);
     
    459466  },
    460467  finish: function(position) {
    461     if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
     468    if(this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
    462469  },
    463470  setDimensions: function(height, width) {
    464471    var d = {};
    465     if(this.options.scaleX) d.width = width + 'px';
    466     if(this.options.scaleY) d.height = height + 'px';
     472    if(this.options.scaleX) d.width = Math.round(width) + 'px';
     473    if(this.options.scaleY) d.height = Math.round(height) + 'px';
    467474    if(this.options.scaleFromCenter) {
    468475      var topd  = (height - this.dims[0])/2;
     
    484491  initialize: function(element) {
    485492    this.element = $(element);
     493    if(!this.element) throw(Effect._elementDoesNotExistError);
    486494    var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {});
    487495    this.start(options);
     
    491499    if(this.element.getStyle('display')=='none') { this.cancel(); return; }
    492500    // Disable background image during the effect
    493     this.oldStyle = {
    494       backgroundImage: this.element.getStyle('background-image') };
    495     this.element.setStyle({backgroundImage: 'none'});
     501    this.oldStyle = {};
     502    if (!this.options.keepBackgroundImage) {
     503      this.oldStyle.backgroundImage = this.element.getStyle('background-image');
     504      this.element.setStyle({backgroundImage: 'none'});
     505    }
    496506    if(!this.options.endcolor)
    497507      this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff');
     
    548558  afterFinishInternal: function(effect) {
    549559    if(effect.options.to!=0) return;
    550     effect.element.hide();
    551     effect.element.setStyle({opacity: oldOpacity});
     560    effect.element.hide().setStyle({opacity: oldOpacity});
    552561  }}, arguments[1] || {});
    553562  return new Effect.Opacity(element,options);
     
    564573  },
    565574  beforeSetup: function(effect) {
    566     effect.element.setOpacity(effect.options.from);
    567     effect.element.show();
     575    effect.element.setOpacity(effect.options.from).show();
    568576  }}, arguments[1] || {});
    569577  return new Effect.Opacity(element,options);
     
    572580Effect.Puff = function(element) {
    573581  element = $(element);
    574   var oldStyle = { opacity: element.getInlineOpacity(), position: element.getStyle('position') };
     582  var oldStyle = {
     583    opacity: element.getInlineOpacity(),
     584    position: element.getStyle('position'),
     585    top:  element.style.top,
     586    left: element.style.left,
     587    width: element.style.width,
     588    height: element.style.height
     589  };
    575590  return new Effect.Parallel(
    576591   [ new Effect.Scale(element, 200,
     
    579594     Object.extend({ duration: 1.0,
    580595      beforeSetupInternal: function(effect) {
    581         effect.effects[0].element.setStyle({position: 'absolute'}); },
     596        Position.absolutize(effect.effects[0].element)
     597      },
    582598      afterFinishInternal: function(effect) {
    583          effect.effects[0].element.hide();
    584          effect.effects[0].element.setStyle(oldStyle); }
     599         effect.effects[0].element.hide().setStyle(oldStyle); }
    585600     }, arguments[1] || {})
    586601   );
     
    590605  element = $(element);
    591606  element.makeClipping();
    592   return new Effect.Scale(element, 0, 
     607  return new Effect.Scale(element, 0,
    593608    Object.extend({ scaleContent: false,
    594609      scaleX: false,
    595610      restoreAfterFinish: true,
    596611      afterFinishInternal: function(effect) {
    597         effect.element.hide();
    598         effect.element.undoClipping();
     612        effect.element.hide().undoClipping();
    599613      }
    600614    }, arguments[1] || {})
     
    605619  element = $(element);
    606620  var elementDimensions = element.getDimensions();
    607   return new Effect.Scale(element, 100,
    608     Object.extend({ scaleContent: false,
    609       scaleX: false,
    610       scaleFrom: 0,
    611       scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    612       restoreAfterFinish: true,
    613       afterSetup: function(effect) {
    614         effect.element.makeClipping();
    615         effect.element.setStyle({height: '0px'});
    616         effect.element.show();
    617       }, 
    618       afterFinishInternal: function(effect) {
    619         effect.element.undoClipping();
    620       }
    621     }, arguments[1] || {})
    622   );
     621  return new Effect.Scale(element, 100, Object.extend({
     622    scaleContent: false,
     623    scaleX: false,
     624    scaleFrom: 0,
     625    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
     626    restoreAfterFinish: true,
     627    afterSetup: function(effect) {
     628      effect.element.makeClipping().setStyle({height: '0px'}).show();
     629    }, 
     630    afterFinishInternal: function(effect) {
     631      effect.element.undoClipping();
     632    }
     633  }, arguments[1] || {}));
    623634}
    624635
     
    626637  element = $(element);
    627638  var oldOpacity = element.getInlineOpacity();
    628   return new Effect.Appear(element, {
     639  return new Effect.Appear(element, Object.extend({
    629640    duration: 0.4,
    630641    from: 0,
     
    635646        scaleX: false, scaleContent: false, restoreAfterFinish: true,
    636647        beforeSetup: function(effect) {
    637           effect.element.makePositioned();
    638           effect.element.makeClipping();
     648          effect.element.makePositioned().makeClipping();
    639649        },
    640650        afterFinishInternal: function(effect) {
    641           effect.element.hide();
    642           effect.element.undoClipping();
    643           effect.element.undoPositioned();
    644           effect.element.setStyle({opacity: oldOpacity});
     651          effect.element.hide().undoClipping().undoPositioned().setStyle({opacity: oldOpacity});
    645652        }
    646653      })
    647654    }
    648   });
     655  }, arguments[1] || {}));
    649656}
    650657
     
    664671        },
    665672        afterFinishInternal: function(effect) {
    666           effect.effects[0].element.hide();
    667           effect.effects[0].element.undoPositioned();
    668           effect.effects[0].element.setStyle(oldStyle);
     673          effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle);
    669674        }
    670675      }, arguments[1] || {}));
     
    688693    new Effect.Move(effect.element,
    689694      { x: -20, y: 0, duration: 0.05, afterFinishInternal: function(effect) {
    690         effect.element.undoPositioned();
    691         effect.element.setStyle(oldStyle);
     695        effect.element.undoPositioned().setStyle(oldStyle);
    692696  }}) }}) }}) }}) }}) }});
    693697}
    694698
    695699Effect.SlideDown = function(element) {
    696   element = $(element);
    697   element.cleanWhitespace();
     700  element = $(element).cleanWhitespace();
    698701  // SlideDown need to have the content of the element wrapped in a container element with fixed height!
    699   var oldInnerBottom = $(element.firstChild).getStyle('bottom');
     702  var oldInnerBottom = element.down().getStyle('bottom');
    700703  var elementDimensions = element.getDimensions();
    701704  return new Effect.Scale(element, 100, Object.extend({
     
    707710    afterSetup: function(effect) {
    708711      effect.element.makePositioned();
    709       effect.element.firstChild.makePositioned();
     712      effect.element.down().makePositioned();
    710713      if(window.opera) effect.element.setStyle({top: ''});
    711       effect.element.makeClipping();
    712       effect.element.setStyle({height: '0px'});
    713       effect.element.show(); },
     714      effect.element.makeClipping().setStyle({height: '0px'}).show();
     715    },
    714716    afterUpdateInternal: function(effect) {
    715       effect.element.firstChild.setStyle({bottom:
     717      effect.element.down().setStyle({bottom:
    716718        (effect.dims[0] - effect.element.clientHeight) + 'px' });
    717719    },
    718720    afterFinishInternal: function(effect) {
    719       effect.element.undoClipping();
    720       // IE will crash if child is undoPositioned first
    721       if(/MSIE/.test(navigator.userAgent)){
    722         effect.element.undoPositioned();
    723         effect.element.firstChild.undoPositioned();
    724       }else{
    725         effect.element.firstChild.undoPositioned();
    726         effect.element.undoPositioned();
    727       }
    728       effect.element.firstChild.setStyle({bottom: oldInnerBottom}); }
     721      effect.element.undoClipping().undoPositioned();
     722      effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom}); }
    729723    }, arguments[1] || {})
    730724  );
    731725}
    732  
     726
    733727Effect.SlideUp = function(element) {
    734   element = $(element);
    735   element.cleanWhitespace();
    736   var oldInnerBottom = $(element.firstChild).getStyle('bottom');
     728  element = $(element).cleanWhitespace();
     729  var oldInnerBottom = element.down().getStyle('bottom');
    737730  return new Effect.Scale(element, window.opera ? 0 : 1,
    738731   Object.extend({ scaleContent: false,
     
    743736    beforeStartInternal: function(effect) {
    744737      effect.element.makePositioned();
    745       effect.element.firstChild.makePositioned();
     738      effect.element.down().makePositioned();
    746739      if(window.opera) effect.element.setStyle({top: ''});
    747       effect.element.makeClipping();
    748       effect.element.show(); }, 
     740      effect.element.makeClipping().show();
     741    }, 
    749742    afterUpdateInternal: function(effect) {
    750       effect.element.firstChild.setStyle({bottom:
    751         (effect.dims[0] - effect.element.clientHeight) + 'px' }); },
     743      effect.element.down().setStyle({bottom:
     744        (effect.dims[0] - effect.element.clientHeight) + 'px' });
     745    },
    752746    afterFinishInternal: function(effect) {
    753       effect.element.hide();
    754       effect.element.undoClipping();
    755       effect.element.firstChild.undoPositioned();
    756       effect.element.undoPositioned();
    757       effect.element.setStyle({bottom: oldInnerBottom}); }
     747      effect.element.hide().undoClipping().undoPositioned().setStyle({bottom: oldInnerBottom});
     748      effect.element.down().undoPositioned();
     749    }
    758750   }, arguments[1] || {})
    759751  );
     
    762754// Bug in opera makes the TD containing this element expand for a instance after finish
    763755Effect.Squish = function(element) {
    764   return new Effect.Scale(element, window.opera ? 1 : 0,
    765     { restoreAfterFinish: true,
    766       beforeSetup: function(effect) {
    767         effect.element.makeClipping(effect.element); }, 
    768       afterFinishInternal: function(effect) {
    769         effect.element.hide(effect.element);
    770         effect.element.undoClipping(effect.element); }
     756  return new Effect.Scale(element, window.opera ? 1 : 0, {
     757    restoreAfterFinish: true,
     758    beforeSetup: function(effect) {
     759      effect.element.makeClipping();
     760    }, 
     761    afterFinishInternal: function(effect) {
     762      effect.element.hide().undoClipping();
     763    }
    771764  });
    772765}
     
    824817    duration: 0.01,
    825818    beforeSetup: function(effect) {
    826       effect.element.hide();
    827       effect.element.makeClipping();
    828       effect.element.makePositioned();
     819      effect.element.hide().makeClipping().makePositioned();
    829820    },
    830821    afterFinishInternal: function(effect) {
     
    837828        ], Object.extend({
    838829             beforeSetup: function(effect) {
    839                effect.effects[0].element.setStyle({height: '0px'});
    840                effect.effects[0].element.show();
     830               effect.effects[0].element.setStyle({height: '0px'}).show();
    841831             },
    842832             afterFinishInternal: function(effect) {
    843                effect.effects[0].element.undoClipping();
    844                effect.effects[0].element.undoPositioned();
    845                effect.effects[0].element.setStyle(oldStyle);
     833               effect.effects[0].element.undoClipping().undoPositioned().setStyle(oldStyle);
    846834             }
    847835           }, options)
     
    897885    ], Object.extend({           
    898886         beforeStartInternal: function(effect) {
    899            effect.effects[0].element.makePositioned();
    900            effect.effects[0].element.makeClipping(); },
     887           effect.effects[0].element.makePositioned().makeClipping();
     888         },
    901889         afterFinishInternal: function(effect) {
    902            effect.effects[0].element.hide();
    903            effect.effects[0].element.undoClipping();
    904            effect.effects[0].element.undoPositioned();
    905            effect.effects[0].element.setStyle(oldStyle); }
     890           effect.effects[0].element.hide().undoClipping().undoPositioned().setStyle(oldStyle); }
    906891       }, options)
    907892  );
     
    913898  var oldOpacity = element.getInlineOpacity();
    914899  var transition = options.transition || Effect.Transitions.sinoidal;
    915   var reverser   = function(pos){ return transition(1-Effect.Transitions.pulse(pos)) };
     900  var reverser   = function(pos){ return transition(1-Effect.Transitions.pulse(pos, options.pulses)) };
    916901  reverser.bind(transition);
    917902  return new Effect.Opacity(element,
    918     Object.extend(Object.extend({  duration: 3.0, from: 0,
     903    Object.extend(Object.extend({  duration: 2.0, from: 0,
    919904      afterFinishInternal: function(effect) { effect.element.setStyle({opacity: oldOpacity}); }
    920905    }, options), {transition: reverser}));
     
    928913    width: element.style.width,
    929914    height: element.style.height };
    930   Element.makeClipping(element);
     915  element.makeClipping();
    931916  return new Effect.Scale(element, 5, Object.extend({   
    932917    scaleContent: false,
     
    937922      scaleY: false,
    938923      afterFinishInternal: function(effect) {
    939         effect.element.hide();
    940         effect.element.undoClipping();
    941         effect.element.setStyle(oldStyle);
     924        effect.element.hide().undoClipping().setStyle(oldStyle);
    942925      } });
    943926  }}, arguments[1] || {}));
    944927};
    945928
     929Effect.Morph = Class.create();
     930Object.extend(Object.extend(Effect.Morph.prototype, Effect.Base.prototype), {
     931  initialize: function(element) {
     932    this.element = $(element);
     933    if(!this.element) throw(Effect._elementDoesNotExistError);
     934    var options = Object.extend({
     935      style: {}
     936    }, arguments[1] || {});
     937    if (typeof options.style == 'string') {
     938      if(options.style.indexOf(':') == -1) {
     939        var cssText = '', selector = '.' + options.style;
     940        $A(document.styleSheets).reverse().each(function(styleSheet) {
     941          if (styleSheet.cssRules) cssRules = styleSheet.cssRules;
     942          else if (styleSheet.rules) cssRules = styleSheet.rules;
     943          $A(cssRules).reverse().each(function(rule) {
     944            if (selector == rule.selectorText) {
     945              cssText = rule.style.cssText;
     946              throw $break;
     947            }
     948          });
     949          if (cssText) throw $break;
     950        });
     951        this.style = cssText.parseStyle();
     952        options.afterFinishInternal = function(effect){
     953          effect.element.addClassName(effect.options.style);
     954          effect.transforms.each(function(transform) {
     955            if(transform.style != 'opacity')
     956              effect.element.style[transform.style.camelize()] = '';
     957          });
     958        }
     959      } else this.style = options.style.parseStyle();
     960    } else this.style = $H(options.style)
     961    this.start(options);
     962  },
     963  setup: function(){
     964    function parseColor(color){
     965      if(!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) color = '#ffffff';
     966      color = color.parseColor();
     967      return $R(0,2).map(function(i){
     968        return parseInt( color.slice(i*2+1,i*2+3), 16 )
     969      });
     970    }
     971    this.transforms = this.style.map(function(pair){
     972      var property = pair[0].underscore().dasherize(), value = pair[1], unit = null;
     973
     974      if(value.parseColor('#zzzzzz') != '#zzzzzz') {
     975        value = value.parseColor();
     976        unit  = 'color';
     977      } else if(property == 'opacity') {
     978        value = parseFloat(value);
     979        if(/MSIE/.test(navigator.userAgent) && !window.opera && (!this.element.currentStyle.hasLayout))
     980          this.element.setStyle({zoom: 1});
     981      } else if(Element.CSS_LENGTH.test(value))
     982        var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/),
     983          value = parseFloat(components[1]), unit = (components.length == 3) ? components[2] : null;
     984
     985      var originalValue = this.element.getStyle(property);
     986      return $H({
     987        style: property,
     988        originalValue: unit=='color' ? parseColor(originalValue) : parseFloat(originalValue || 0),
     989        targetValue: unit=='color' ? parseColor(value) : value,
     990        unit: unit
     991      });
     992    }.bind(this)).reject(function(transform){
     993      return (
     994        (transform.originalValue == transform.targetValue) ||
     995        (
     996          transform.unit != 'color' &&
     997          (isNaN(transform.originalValue) || isNaN(transform.targetValue))
     998        )
     999      )
     1000    });
     1001  },
     1002  update: function(position) {
     1003    var style = $H(), value = null;
     1004    this.transforms.each(function(transform){
     1005      value = transform.unit=='color' ?
     1006        $R(0,2).inject('#',function(m,v,i){
     1007          return m+(Math.round(transform.originalValue[i]+
     1008            (transform.targetValue[i] - transform.originalValue[i])*position)).toColorPart() }) :
     1009        transform.originalValue + Math.round(
     1010          ((transform.targetValue - transform.originalValue) * position) * 1000)/1000 + transform.unit;
     1011      style[transform.style] = value;
     1012    });
     1013    this.element.setStyle(style);
     1014  }
     1015});
     1016
     1017Effect.Transform = Class.create();
     1018Object.extend(Effect.Transform.prototype, {
     1019  initialize: function(tracks){
     1020    this.tracks  = [];
     1021    this.options = arguments[1] || {};
     1022    this.addTracks(tracks);
     1023  },
     1024  addTracks: function(tracks){
     1025    tracks.each(function(track){
     1026      var data = $H(track).values().first();
     1027      this.tracks.push($H({
     1028        ids:     $H(track).keys().first(),
     1029        effect:  Effect.Morph,
     1030        options: { style: data }
     1031      }));
     1032    }.bind(this));
     1033    return this;
     1034  },
     1035  play: function(){
     1036    return new Effect.Parallel(
     1037      this.tracks.map(function(track){
     1038        var elements = [$(track.ids) || $$(track.ids)].flatten();
     1039        return elements.map(function(e){ return new track.effect(e, Object.extend({ sync:true }, track.options)) });
     1040      }).flatten(),
     1041      this.options
     1042    );
     1043  }
     1044});
     1045
     1046Element.CSS_PROPERTIES = $w(
     1047  'backgroundColor backgroundPosition borderBottomColor borderBottomStyle ' +
     1048  'borderBottomWidth borderLeftColor borderLeftStyle borderLeftWidth ' +
     1049  'borderRightColor borderRightStyle borderRightWidth borderSpacing ' +
     1050  'borderTopColor borderTopStyle borderTopWidth bottom clip color ' +
     1051  'fontSize fontWeight height left letterSpacing lineHeight ' +
     1052  'marginBottom marginLeft marginRight marginTop markerOffset maxHeight '+
     1053  'maxWidth minHeight minWidth opacity outlineColor outlineOffset ' +
     1054  'outlineWidth paddingBottom paddingLeft paddingRight paddingTop ' +
     1055  'right textIndent top width wordSpacing zIndex');
     1056 
     1057Element.CSS_LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/;
     1058
     1059String.prototype.parseStyle = function(){
     1060  var element = Element.extend(document.createElement('div'));
     1061  element.innerHTML = '<div style="' + this + '"></div>';
     1062  var style = element.down().style, styleRules = $H();
     1063 
     1064  Element.CSS_PROPERTIES.each(function(property){
     1065    if(style[property]) styleRules[property] = style[property];
     1066  });
     1067  if(/MSIE/.test(navigator.userAgent) && !window.opera && this.indexOf('opacity') > -1) {
     1068    styleRules.opacity = this.match(/opacity:\s*((?:0|1)?(?:\.\d*)?)/)[1];
     1069  }
     1070  return styleRules;
     1071};
     1072
     1073Element.morph = function(element, style) {
     1074  new Effect.Morph(element, Object.extend({ style: style }, arguments[2] || {}));
     1075  return element;
     1076};
     1077
    9461078['setOpacity','getOpacity','getInlineOpacity','forceRerendering','setContentZoom',
    947  'collectTextNodes','collectTextNodesIgnoreClass','childrenWithClassName'].each(
     1079 'collectTextNodes','collectTextNodesIgnoreClass','morph'].each(
    9481080  function(f) { Element.Methods[f] = Element[f]; }
    9491081);
  • trunk/wp-includes/js/scriptaculous/prototype.js

    r4629 r4813  
    1 /*  Prototype JavaScript framework, version 1.5.0_rc0
    2  *  (c) 2005 Sam Stephenson <sam@conio.net>
     1/*  Prototype JavaScript framework, version 1.5.0
     2 *  (c) 2005-2007 Sam Stephenson
    33 *
    44 *  Prototype is freely distributable under the terms of an MIT-style license.
     
    88
    99var Prototype = {
    10   Version: '1.5.0_rc0',
     10  Version: '1.5.0',
     11  BrowserFeatures: {
     12    XPath: !!document.evaluate
     13  },
     14
    1115  ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',
    12 
    1316  emptyFunction: function() {},
    14   K: function(x) {return x}
     17  K: function(x) { return x }
    1518}
    1619
     
    3235}
    3336
    34 Object.inspect = function(object) {
    35   try {
    36     if (object == undefined) return 'undefined';
    37     if (object == null) return 'null';
    38     return object.inspect ? object.inspect() : object.toString();
    39   } catch (e) {
    40     if (e instanceof RangeError) return '...';
    41     throw e;
    42   }
    43 }
     37Object.extend(Object, {
     38  inspect: function(object) {
     39    try {
     40      if (object === undefined) return 'undefined';
     41      if (object === null) return 'null';
     42      return object.inspect ? object.inspect() : object.toString();
     43    } catch (e) {
     44      if (e instanceof RangeError) return '...';
     45      throw e;
     46    }
     47  },
     48
     49  keys: function(object) {
     50    var keys = [];
     51    for (var property in object)
     52      keys.push(property);
     53    return keys;
     54  },
     55
     56  values: function(object) {
     57    var values = [];
     58    for (var property in object)
     59      values.push(object[property]);
     60    return values;
     61  },
     62
     63  clone: function(object) {
     64    return Object.extend({}, object);
     65  }
     66});
    4467
    4568Function.prototype.bind = function() {
     
    5174
    5275Function.prototype.bindAsEventListener = function(object) {
    53   var __method = this;
     76  var __method = this, args = $A(arguments), object = args.shift();
    5477  return function(event) {
    55     return __method.call(object, event || window.event);
     78    return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments)));
    5679  }
    5780}
     
    78101    var returnValue;
    79102
    80     for (var i = 0; i < arguments.length; i++) {
     103    for (var i = 0, length = arguments.length; i < length; i++) {
    81104      var lambda = arguments[i];
    82105      try {
     
    103126
    104127  registerCallback: function() {
    105     setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
     128    this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
     129  },
     130
     131  stop: function() {
     132    if (!this.timer) return;
     133    clearInterval(this.timer);
     134    this.timer = null;
    106135  },
    107136
     
    110139      try {
    111140        this.currentlyExecuting = true;
    112         this.callback();
     141        this.callback(this);
    113142      } finally {
    114143        this.currentlyExecuting = false;
     
    117146  }
    118147}
     148String.interpret = function(value){
     149  return value == null ? '' : String(value);
     150}
     151
    119152Object.extend(String.prototype, {
    120153  gsub: function(pattern, replacement) {
     
    125158      if (match = source.match(pattern)) {
    126159        result += source.slice(0, match.index);
    127         result += (replacement(match) || '').toString();
     160        result += String.interpret(replacement(match));
    128161        source  = source.slice(match.index + match[0].length);
    129162      } else {
     
    190223    var div = document.createElement('div');
    191224    div.innerHTML = this.stripTags();
    192     return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
    193   },
    194 
    195   toQueryParams: function() {
    196     var pairs = this.match(/^\??(.*)$/)[1].split('&');
    197     return pairs.inject({}, function(params, pairString) {
    198       var pair = pairString.split('=');
    199       params[pair[0]] = pair[1];
    200       return params;
     225    return div.childNodes[0] ? (div.childNodes.length > 1 ?
     226      $A(div.childNodes).inject('',function(memo,node){ return memo+node.nodeValue }) :
     227      div.childNodes[0].nodeValue) : '';
     228  },
     229
     230  toQueryParams: function(separator) {
     231    var match = this.strip().match(/([^?#]*)(#.*)?$/);
     232    if (!match) return {};
     233
     234    return match[1].split(separator || '&').inject({}, function(hash, pair) {
     235      if ((pair = pair.split('='))[0]) {
     236        var name = decodeURIComponent(pair[0]);
     237        var value = pair[1] ? decodeURIComponent(pair[1]) : undefined;
     238
     239        if (hash[name] !== undefined) {
     240          if (hash[name].constructor != Array)
     241            hash[name] = [hash[name]];
     242          if (value) hash[name].push(value);
     243        }
     244        else hash[name] = value;
     245      }
     246      return hash;
    201247    });
    202248  },
     
    206252  },
    207253
     254  succ: function() {
     255    return this.slice(0, this.length - 1) +
     256      String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
     257  },
     258
    208259  camelize: function() {
    209     var oStringList = this.split('-');
    210     if (oStringList.length == 1) return oStringList[0];
    211 
    212     var camelizedString = this.indexOf('-') == 0
    213       ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1)
    214       : oStringList[0];
    215 
    216     for (var i = 1, len = oStringList.length; i < len; i++) {
    217       var s = oStringList[i];
    218       camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
    219     }
    220 
    221     return camelizedString;
    222   },
    223 
    224   inspect: function() {
    225     return "'" + this.replace(/\\/g, '\\\\').replace(/'/g, '\\\'') + "'";
     260    var parts = this.split('-'), len = parts.length;
     261    if (len == 1) return parts[0];
     262
     263    var camelized = this.charAt(0) == '-'
     264      ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
     265      : parts[0];
     266
     267    for (var i = 1; i < len; i++)
     268      camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
     269
     270    return camelized;
     271  },
     272
     273  capitalize: function(){
     274    return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
     275  },
     276
     277  underscore: function() {
     278    return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();
     279  },
     280
     281  dasherize: function() {
     282    return this.gsub(/_/,'-');
     283  },
     284
     285  inspect: function(useDoubleQuotes) {
     286    var escapedString = this.replace(/\\/g, '\\\\');
     287    if (useDoubleQuotes)
     288      return '"' + escapedString.replace(/"/g, '\\"') + '"';
     289    else
     290      return "'" + escapedString.replace(/'/g, '\\\'') + "'";
    226291  }
    227292});
     
    247312      var before = match[1];
    248313      if (before == '\\') return match[2];
    249       return before + (object[match[3]] || '').toString();
     314      return before + String.interpret(object[match[3]]);
    250315    });
    251316  }
     
    269334      if (e != $break) throw e;
    270335    }
     336    return this;
     337  },
     338
     339  eachSlice: function(number, iterator) {
     340    var index = -number, slices = [], array = this.toArray();
     341    while ((index += number) < array.length)
     342      slices.push(array.slice(index, index+number));
     343    return slices.map(iterator);
    271344  },
    272345
     
    281354
    282355  any: function(iterator) {
    283     var result = true;
     356    var result = false;
    284357    this.each(function(value, index) {
    285358      if (result = !!(iterator || Prototype.K)(value, index))
     
    292365    var results = [];
    293366    this.each(function(value, index) {
    294       results.push(iterator(value, index));
     367      results.push((iterator || Prototype.K)(value, index));
    295368    });
    296369    return results;
    297370  },
    298371
    299   detect: function (iterator) {
     372  detect: function(iterator) {
    300373    var result;
    301374    this.each(function(value, index) {
     
    338411  },
    339412
     413  inGroupsOf: function(number, fillWith) {
     414    fillWith = fillWith === undefined ? null : fillWith;
     415    return this.eachSlice(number, function(slice) {
     416      while(slice.length < number) slice.push(fillWith);
     417      return slice;
     418    });
     419  },
     420
    340421  inject: function(memo, iterator) {
    341422    this.each(function(value, index) {
     
    347428  invoke: function(method) {
    348429    var args = $A(arguments).slice(1);
    349     return this.collect(function(value) {
     430    return this.map(function(value) {
    350431      return value[method].apply(value, args);
    351432    });
     
    399480
    400481  sortBy: function(iterator) {
    401     return this.collect(function(value, index) {
     482    return this.map(function(value, index) {
    402483      return {value: value, criteria: iterator(value, index)};
    403484    }).sort(function(left, right) {
     
    408489
    409490  toArray: function() {
    410     return this.collect(Prototype.K);
     491    return this.map();
    411492  },
    412493
     
    420501      return iterator(collections.pluck(index));
    421502    });
     503  },
     504
     505  size: function() {
     506    return this.toArray().length;
    422507  },
    423508
     
    440525  } else {
    441526    var results = [];
    442     for (var i = 0; i < iterable.length; i++)
     527    for (var i = 0, length = iterable.length; i < length; i++)
    443528      results.push(iterable[i]);
    444529    return results;
     
    453538Object.extend(Array.prototype, {
    454539  _each: function(iterator) {
    455     for (var i = 0; i < this.length; i++)
     540    for (var i = 0, length = this.length; i < length; i++)
    456541      iterator(this[i]);
    457542  },
     
    472557  compact: function() {
    473558    return this.select(function(value) {
    474       return value != undefined || value != null;
     559      return value != null;
    475560    });
    476561  },
     
    491576
    492577  indexOf: function(object) {
    493     for (var i = 0; i < this.length; i++)
     578    for (var i = 0, length = this.length; i < length; i++)
    494579      if (this[i] == object) return i;
    495580    return -1;
     
    500585  },
    501586
     587  reduce: function() {
     588    return this.length > 1 ? this : this[0];
     589  },
     590
     591  uniq: function() {
     592    return this.inject([], function(array, value) {
     593      return array.include(value) ? array : array.concat([value]);
     594    });
     595  },
     596
     597  clone: function() {
     598    return [].concat(this);
     599  },
     600
     601  size: function() {
     602    return this.length;
     603  },
     604
    502605  inspect: function() {
    503606    return '[' + this.map(Object.inspect).join(', ') + ']';
    504607  }
    505608});
    506 var Hash = {
     609
     610Array.prototype.toArray = Array.prototype.clone;
     611
     612function $w(string){
     613  string = string.strip();
     614  return string ? string.split(/\s+/) : [];
     615}
     616
     617if(window.opera){
     618  Array.prototype.concat = function(){
     619    var array = [];
     620    for(var i = 0, length = this.length; i < length; i++) array.push(this[i]);
     621    for(var i = 0, length = arguments.length; i < length; i++) {
     622      if(arguments[i].constructor == Array) {
     623        for(var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)
     624          array.push(arguments[i][j]);
     625      } else {
     626        array.push(arguments[i]);
     627      }
     628    }
     629    return array;
     630  }
     631}
     632var Hash = function(obj) {
     633  Object.extend(this, obj || {});
     634};
     635
     636Object.extend(Hash, {
     637  toQueryString: function(obj) {
     638    var parts = [];
     639
     640      this.prototype._each.call(obj, function(pair) {
     641      if (!pair.key) return;
     642
     643      if (pair.value && pair.value.constructor == Array) {
     644        var values = pair.value.compact();
     645        if (values.length < 2) pair.value = values.reduce();
     646        else {
     647            key = encodeURIComponent(pair.key);
     648          values.each(function(value) {
     649            value = value != undefined ? encodeURIComponent(value) : '';
     650            parts.push(key + '=' + encodeURIComponent(value));
     651          });
     652          return;
     653        }
     654      }
     655      if (pair.value == undefined) pair[1] = '';
     656      parts.push(pair.map(encodeURIComponent).join('='));
     657      });
     658
     659    return parts.join('&');
     660  }
     661});
     662
     663Object.extend(Hash.prototype, Enumerable);
     664Object.extend(Hash.prototype, {
    507665  _each: function(iterator) {
    508666    for (var key in this) {
    509667      var value = this[key];
    510       if (typeof value == 'function') continue;
     668      if (value && value == Hash.prototype[key]) continue;
    511669
    512670      var pair = [key, value];
     
    526684
    527685  merge: function(hash) {
    528     return $H(hash).inject($H(this), function(mergedHash, pair) {
     686    return $H(hash).inject(this, function(mergedHash, pair) {
    529687      mergedHash[pair.key] = pair.value;
    530688      return mergedHash;
     
    532690  },
    533691
     692  remove: function() {
     693    var result;
     694    for(var i = 0, length = arguments.length; i < length; i++) {
     695      var value = this[arguments[i]];
     696      if (value !== undefined){
     697        if (result === undefined) result = value;
     698        else {
     699          if (result.constructor != Array) result = [result];
     700          result.push(value)
     701        }
     702      }
     703      delete this[arguments[i]];
     704    }
     705    return result;
     706  },
     707
    534708  toQueryString: function() {
    535     return this.map(function(pair) {
    536       return pair.map(encodeURIComponent).join('=');
    537     }).join('&');
     709    return Hash.toQueryString(this);
    538710  },
    539711
     
    543715    }).join(', ') + '}>';
    544716  }
    545 }
     717});
    546718
    547719function $H(object) {
    548   var hash = Object.extend({}, object || {});
    549   Object.extend(hash, Enumerable);
    550   Object.extend(hash, Hash);
    551   return hash;
    552 }
     720  if (object && object.constructor == Hash) return object;
     721  return new Hash(object);
     722};
    553723ObjectRange = Class.create();
    554724Object.extend(ObjectRange.prototype, Enumerable);
     
    562732  _each: function(iterator) {
    563733    var value = this.start;
    564     do {
     734    while (this.include(value)) {
    565735      iterator(value);
    566736      value = value.succ();
    567     } while (this.include(value));
     737    }
    568738  },
    569739
     
    600770  },
    601771
    602   register: function(responderToAdd) {
    603     if (!this.include(responderToAdd))
    604       this.responders.push(responderToAdd);
    605   },
    606 
    607   unregister: function(responderToRemove) {
    608     this.responders = this.responders.without(responderToRemove);
     772  register: function(responder) {
     773    if (!this.include(responder))
     774      this.responders.push(responder);
     775  },
     776
     777  unregister: function(responder) {
     778    this.responders = this.responders.without(responder);
    609779  },
    610780
    611781  dispatch: function(callback, request, transport, json) {
    612782    this.each(function(responder) {
    613       if (responder[callback] && typeof responder[callback] == 'function') {
     783      if (typeof responder[callback] == 'function') {
    614784        try {
    615785          responder[callback].apply(responder, [request, transport, json]);
     
    626796    Ajax.activeRequestCount++;
    627797  },
    628 
    629798  onComplete: function() {
    630799    Ajax.activeRequestCount--;
     
    639808      asynchronous: true,
    640809      contentType:  'application/x-www-form-urlencoded',
     810      encoding:     'UTF-8',
    641811      parameters:   ''
    642812    }
    643813    Object.extend(this.options, options || {});
    644   },
    645 
    646   responseIsSuccess: function() {
    647     return this.transport.status == undefined
    648         || this.transport.status == 0
    649         || (this.transport.status >= 200 && this.transport.status < 300);
    650   },
    651 
    652   responseIsFailure: function() {
    653     return !this.responseIsSuccess();
     814
     815    this.options.method = this.options.method.toLowerCase();
     816    if (typeof this.options.parameters == 'string')
     817      this.options.parameters = this.options.parameters.toQueryParams();
    654818  }
    655819}
     
    660824
    661825Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
     826  _complete: false,
     827
    662828  initialize: function(url, options) {
    663829    this.transport = Ajax.getTransport();
     
    667833
    668834  request: function(url) {
    669     var parameters = this.options.parameters || '';
    670     if (parameters.length > 0) parameters += '&_=';
     835    this.url = url;
     836    this.method = this.options.method;
     837    var params = this.options.parameters;
     838
     839    if (!['get', 'post'].include(this.method)) {
     840      // simulate other verbs over post
     841      params['_method'] = this.method;
     842      this.method = 'post';
     843    }
     844
     845    params = Hash.toQueryString(params);
     846    if (params && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) params += '&_='
     847
     848    // when GET, append parameters to URL
     849    if (this.method == 'get' && params)
     850      this.url += (this.url.indexOf('?') > -1 ? '&' : '?') + params;
    671851
    672852    try {
    673       this.url = url;
    674       if (this.options.method == 'get' && parameters.length > 0)
    675         this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;
    676 
    677853      Ajax.Responders.dispatch('onCreate', this, this.transport);
    678854
    679       this.transport.open(this.options.method, this.url,
     855      this.transport.open(this.method.toUpperCase(), this.url,
    680856        this.options.asynchronous);
    681857
    682       if (this.options.asynchronous) {
    683         this.transport.onreadystatechange = this.onStateChange.bind(this);
    684         setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10);
     858      if (this.options.asynchronous)
     859        setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10);
     860
     861      this.transport.onreadystatechange = this.onStateChange.bind(this);
     862      this.setRequestHeaders();
     863
     864      var body = this.method == 'post' ? (this.options.postBody || params) : null;
     865
     866      this.transport.send(body);
     867
     868      /* Force Firefox to handle ready state 4 for synchronous requests */
     869      if (!this.options.asynchronous && this.transport.overrideMimeType)
     870        this.onStateChange();
     871
     872    }
     873    catch (e) {
     874      this.dispatchException(e);
     875    }
     876  },
     877
     878  onStateChange: function() {
     879    var readyState = this.transport.readyState;
     880    if (readyState > 1 && !((readyState == 4) && this._complete))
     881      this.respondToReadyState(this.transport.readyState);
     882  },
     883
     884  setRequestHeaders: function() {
     885    var headers = {
     886      'X-Requested-With': 'XMLHttpRequest',
     887      'X-Prototype-Version': Prototype.Version,
     888      'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
     889    };
     890
     891    if (this.method == 'post') {
     892      headers['Content-type'] = this.options.contentType +
     893        (this.options.encoding ? '; charset=' + this.options.encoding : '');
     894
     895      /* Force "Connection: close" for older Mozilla browsers to work
     896       * around a bug where XMLHttpRequest sends an incorrect
     897       * Content-length header. See Mozilla Bugzilla #246651.
     898       */
     899      if (this.transport.overrideMimeType &&
     900          (navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
     901            headers['Connection'] = 'close';
     902    }
     903
     904    // user-defined headers
     905    if (typeof this.options.requestHeaders == 'object') {
     906      var extras = this.options.requestHeaders;
     907
     908      if (typeof extras.push == 'function')
     909        for (var i = 0, length = extras.length; i < length; i += 2)
     910          headers[extras[i]] = extras[i+1];
     911      else
     912        $H(extras).each(function(pair) { headers[pair.key] = pair.value });
     913    }
     914
     915    for (var name in headers)
     916      this.transport.setRequestHeader(name, headers[name]);
     917  },
     918
     919  success: function() {
     920    return !this.transport.status
     921        || (this.transport.status >= 200 && this.transport.status < 300);
     922  },
     923
     924  respondToReadyState: function(readyState) {
     925    var state = Ajax.Request.Events[readyState];
     926    var transport = this.transport, json = this.evalJSON();
     927
     928    if (state == 'Complete') {
     929      try {
     930        this._complete = true;
     931        (this.options['on' + this.transport.status]
     932         || this.options['on' + (this.success() ? 'Success' : 'Failure')]
     933         || Prototype.emptyFunction)(transport, json);
     934      } catch (e) {
     935        this.dispatchException(e);
    685936      }
    686937
    687       this.setRequestHeaders();
    688 
    689       var body = this.options.postBody ? this.options.postBody : parameters;
    690       this.transport.send(this.options.method == 'post' ? body : null);
    691 
     938      if ((this.getHeader('Content-type') || 'text/javascript').strip().
     939        match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i))
     940          this.evalResponse();
     941    }
     942
     943    try {
     944      (this.options['on' + state] || Prototype.emptyFunction)(transport, json);
     945      Ajax.Responders.dispatch('on' + state, this, transport, json);
    692946    } catch (e) {
    693947      this.dispatchException(e);
    694948    }
    695   },
    696 
    697   setRequestHeaders: function() {
    698     var requestHeaders =
    699       ['X-Requested-With', 'XMLHttpRequest',
    700        'X-Prototype-Version', Prototype.Version,
    701        'Accept', 'text/javascript, text/html, application/xml, text/xml, */*'];
    702 
    703     if (this.options.method == 'post') {
    704       requestHeaders.push('Content-type', this.options.contentType);
    705 
    706       /* Force "Connection: close" for Mozilla browsers to work around
    707        * a bug where XMLHttpReqeuest sends an incorrect Content-length
    708        * header. See Mozilla Bugzilla #246651.
    709        */
    710       if (this.transport.overrideMimeType)
    711         requestHeaders.push('Connection', 'close');
    712     }
    713 
    714     if (this.options.requestHeaders)
    715       requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);
    716 
    717     for (var i = 0; i < requestHeaders.length; i += 2)
    718       this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
    719   },
    720 
    721   onStateChange: function() {
    722     var readyState = this.transport.readyState;
    723     if (readyState != 1)
    724       this.respondToReadyState(this.transport.readyState);
    725   },
    726 
    727   header: function(name) {
     949
     950    if (state == 'Complete') {
     951      // avoid memory leak in MSIE: clean up
     952      this.transport.onreadystatechange = Prototype.emptyFunction;
     953    }
     954  },
     955
     956  getHeader: function(name) {
    728957    try {
    729958      return this.transport.getResponseHeader(name);
    730     } catch (e) {}
     959    } catch (e) { return null }
    731960  },
    732961
    733962  evalJSON: function() {
    734963    try {
    735       return eval('(' + this.header('X-JSON') + ')');
    736     } catch (e) {}
     964      var json = this.getHeader('X-JSON');
     965      return json ? eval('(' + json + ')') : null;
     966    } catch (e) { return null }
    737967  },
    738968
     
    745975  },
    746976
    747   respondToReadyState: function(readyState) {
    748     var event = Ajax.Request.Events[readyState];
    749     var transport = this.transport, json = this.evalJSON();
    750 
    751     if (event == 'Complete') {
    752       try {
    753         (this.options['on' + this.transport.status]
    754          || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
    755          || Prototype.emptyFunction)(transport, json);
    756       } catch (e) {
    757         this.dispatchException(e);
    758       }
    759 
    760       if ((this.header('Content-type') || '').match(/^text\/javascript/i))
    761         this.evalResponse();
    762     }
    763 
    764     try {
    765       (this.options['on' + event] || Prototype.emptyFunction)(transport, json);
    766       Ajax.Responders.dispatch('on' + event, this, transport, json);
    767     } catch (e) {
    768       this.dispatchException(e);
    769     }
    770 
    771     /* Avoid memory leak in MSIE: clean up the oncomplete event handler */
    772     if (event == 'Complete')
    773       this.transport.onreadystatechange = Prototype.emptyFunction;
    774   },
    775 
    776977  dispatchException: function(exception) {
    777978    (this.options.onException || Prototype.emptyFunction)(this, exception);
     
    784985Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
    785986  initialize: function(container, url, options) {
    786     this.containers = {
    787       success: container.success ? $(container.success) : $(container),
    788       failure: container.failure ? $(container.failure) :
    789         (container.success ? null : $(container))
     987    this.container = {
     988      success: (container.success || container),
     989      failure: (container.failure || (container.success ? null : container))
    790990    }
    791991
     
    794994
    795995    var onComplete = this.options.onComplete || Prototype.emptyFunction;
    796     this.options.onComplete = (function(transport, object) {
     996    this.options.onComplete = (function(transport, param) {
    797997      this.updateContent();
    798       onComplete(transport, object);
     998      onComplete(transport, param);
    799999    }).bind(this);
    8001000
     
    8031003
    8041004  updateContent: function() {
    805     var receiver = this.responseIsSuccess() ?
    806       this.containers.success : this.containers.failure;
     1005    var receiver = this.container[this.success() ? 'success' : 'failure'];
    8071006    var response = this.transport.responseText;
    8081007
    809     if (!this.options.evalScripts)
    810       response = response.stripScripts();
    811 
    812     if (receiver) {
    813       if (this.options.insertion) {
     1008    if (!this.options.evalScripts) response = response.stripScripts();
     1009
     1010    if (receiver = $(receiver)) {
     1011      if (this.options.insertion)
    8141012        new this.options.insertion(receiver, response);
    815       } else {
    816         Element.update(receiver, response);
    817       }
    818     }
    819 
    820     if (this.responseIsSuccess()) {
     1013      else
     1014        receiver.update(response);
     1015    }
     1016
     1017    if (this.success()) {
    8211018      if (this.onComplete)
    8221019        setTimeout(this.onComplete.bind(this), 10);
     
    8471044
    8481045  stop: function() {
    849     this.updater.onComplete = undefined;
     1046    this.updater.options.onComplete = undefined;
    8501047    clearTimeout(this.timer);
    8511048    (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
     
    8671064  }
    8681065});
    869 function $() {
    870   var results = [], element;
    871   for (var i = 0; i < arguments.length; i++) {
    872     element = arguments[i];
    873     if (typeof element == 'string')
    874       element = document.getElementById(element);
    875     results.push(Element.extend(element));
    876   }
    877   return results.length < 2 ? results[0] : results;
     1066function $(element) {
     1067  if (arguments.length > 1) {
     1068    for (var i = 0, elements = [], length = arguments.length; i < length; i++)
     1069      elements.push($(arguments[i]));
     1070    return elements;
     1071  }
     1072  if (typeof element == 'string')
     1073    element = document.getElementById(element);
     1074  return Element.extend(element);
     1075}
     1076
     1077if (Prototype.BrowserFeatures.XPath) {
     1078  document._getElementsByXPath = function(expression, parentElement) {
     1079    var results = [];
     1080    var query = document.evaluate(expression, $(parentElement) || document,
     1081      null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
     1082    for (var i = 0, length = query.snapshotLength; i < length; i++)
     1083      results.push(query.snapshotItem(i));
     1084    return results;
     1085  };
    8781086}
    8791087
    8801088document.getElementsByClassName = function(className, parentElement) {
    881   var children = ($(parentElement) || document.body).getElementsByTagName('*');
    882   return $A(children).inject([], function(elements, child) {
    883     if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
    884       elements.push(Element.extend(child));
     1089  if (Prototype.BrowserFeatures.XPath) {
     1090    var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";
     1091    return document._getElementsByXPath(q, parentElement);
     1092  } else {
     1093    var children = ($(parentElement) || document.body).getElementsByTagName('*');
     1094    var elements = [], child;
     1095    for (var i = 0, length = children.length; i < length; i++) {
     1096      child = children[i];
     1097      if (Element.hasClassName(child, className))
     1098        elements.push(Element.extend(child));
     1099    }
    8851100    return elements;
    886   });
    887 }
     1101  }
     1102};
    8881103
    8891104/*--------------------------------------------------------------------------*/
     
    8931108
    8941109Element.extend = function(element) {
    895   if (!element) return;
    896   if (_nativeExtensions) return element;
     1110  if (!element || _nativeExtensions || element.nodeType == 3) return element;
    8971111
    8981112  if (!element._extended && element.tagName && element != window) {
    899     var methods = Element.Methods, cache = Element.extend.cache;
    900     for (property in methods) {
     1113    var methods = Object.clone(Element.Methods), cache = Element.extend.cache;
     1114
     1115    if (element.tagName == 'FORM')
     1116      Object.extend(methods, Form.Methods);
     1117    if (['INPUT', 'TEXTAREA', 'SELECT'].include(element.tagName))
     1118      Object.extend(methods, Form.Element.Methods);
     1119
     1120    Object.extend(methods, Element.Methods.Simulated);
     1121
     1122    for (var property in methods) {
    9011123      var value = methods[property];
    902       if (typeof value == 'function')
     1124      if (typeof value == 'function' && !(property in element))
    9031125        element[property] = cache.findOrStore(value);
    9041126    }
     
    9071129  element._extended = true;
    9081130  return element;
    909 }
     1131};
    9101132
    9111133Element.extend.cache = {
     
    9151137    }
    9161138  }
    917 }
     1139};
    9181140
    9191141Element.Methods = {
     
    9221144  },
    9231145
    924   toggle: function() {
    925     for (var i = 0; i < arguments.length; i++) {
    926       var element = $(arguments[i]);
    927       Element[Element.visible(element) ? 'hide' : 'show'](element);
    928     }
    929   },
    930 
    931   hide: function() {
    932     for (var i = 0; i < arguments.length; i++) {
    933       var element = $(arguments[i]);
    934       element.style.display = 'none';
    935     }
    936   },
    937 
    938   show: function() {
    939     for (var i = 0; i < arguments.length; i++) {
    940       var element = $(arguments[i]);
    941       element.style.display = '';
    942     }
     1146  toggle: function(element) {
     1147    element = $(element);
     1148    Element[Element.visible(element) ? 'hide' : 'show'](element);
     1149    return element;
     1150  },
     1151
     1152  hide: function(element) {
     1153    $(element).style.display = 'none';
     1154    return element;
     1155  },
     1156
     1157  show: function(element) {
     1158    $(element).style.display = '';
     1159    return element;
    9431160  },
    9441161
     
    9461163    element = $(element);
    9471164    element.parentNode.removeChild(element);
     1165    return element;
    9481166  },
    9491167
    9501168  update: function(element, html) {
     1169    html = typeof html == 'undefined' ? '' : html.toString();
    9511170    $(element).innerHTML = html.stripScripts();
    9521171    setTimeout(function() {html.evalScripts()}, 10);
     1172    return element;
    9531173  },
    9541174
    9551175  replace: function(element, html) {
    9561176    element = $(element);
     1177    html = typeof html == 'undefined' ? '' : html.toString();
    9571178    if (element.outerHTML) {
    9581179      element.outerHTML = html.stripScripts();
     
    9641185    }
    9651186    setTimeout(function() {html.evalScripts()}, 10);
     1187    return element;
     1188  },
     1189
     1190  inspect: function(element) {
     1191    element = $(element);
     1192    var result = '<' + element.tagName.toLowerCase();
     1193    $H({'id': 'id', 'className': 'class'}).each(function(pair) {
     1194      var property = pair.first(), attribute = pair.last();
     1195      var value = (element[property] || '').toString();
     1196      if (value) result += ' ' + attribute + '=' + value.inspect(true);
     1197    });
     1198    return result + '>';
     1199  },
     1200
     1201  recursivelyCollect: function(element, property) {
     1202    element = $(element);
     1203    var elements = [];
     1204    while (element = element[property])
     1205      if (element.nodeType == 1)
     1206        elements.push(Element.extend(element));
     1207    return elements;
     1208  },
     1209
     1210  ancestors: function(element) {
     1211    return $(element).recursivelyCollect('parentNode');
     1212  },
     1213
     1214  descendants: function(element) {
     1215    return $A($(element).getElementsByTagName('*'));
     1216  },
     1217
     1218  immediateDescendants: function(element) {
     1219    if (!(element = $(element).firstChild)) return [];
     1220    while (element && element.nodeType != 1) element = element.nextSibling;
     1221    if (element) return [element].concat($(element).nextSiblings());
     1222    return [];
     1223  },
     1224
     1225  previousSiblings: function(element) {
     1226    return $(element).recursivelyCollect('previousSibling');
     1227  },
     1228
     1229  nextSiblings: function(element) {
     1230    return $(element).recursivelyCollect('nextSibling');
     1231  },
     1232
     1233  siblings: function(element) {
     1234    element = $(element);
     1235    return element.previousSiblings().reverse().concat(element.nextSiblings());
     1236  },
     1237
     1238  match: function(element, selector) {
     1239    if (typeof selector == 'string')
     1240      selector = new Selector(selector);
     1241    return selector.match($(element));
     1242  },
     1243
     1244  up: function(element, expression, index) {
     1245    return Selector.findElement($(element).ancestors(), expression, index);
     1246  },
     1247
     1248  down: function(element, expression, index) {
     1249    return Selector.findElement($(element).descendants(), expression, index);
     1250  },
     1251
     1252  previous: function(element, expression, index) {
     1253    return Selector.findElement($(element).previousSiblings(), expression, index);
     1254  },
     1255
     1256  next: function(element, expression, index) {
     1257    return Selector.findElement($(element).nextSiblings(), expression, index);
     1258  },
     1259
     1260  getElementsBySelector: function() {
     1261    var args = $A(arguments), element = $(args.shift());
     1262    return Selector.findChildElements(element, args);
     1263  },
     1264
     1265  getElementsByClassName: function(element, className) {
     1266    return document.getElementsByClassName(className, element);
     1267  },
     1268
     1269  readAttribute: function(element, name) {
     1270    element = $(element);
     1271    if (document.all && !window.opera) {
     1272      var t = Element._attributeTranslations;
     1273      if (t.values[name]) return t.values[name](element, name);
     1274      if (t.names[name])  name = t.names[name];
     1275      var attribute = element.attributes[name];
     1276      if(attribute) return attribute.nodeValue;
     1277    }
     1278    return element.getAttribute(name);
    9661279  },
    9671280
    9681281  getHeight: function(element) {
    969     element = $(element);
    970     return element.offsetHeight;
     1282    return $(element).getDimensions().height;
     1283  },
     1284
     1285  getWidth: function(element) {
     1286    return $(element).getDimensions().width;
    9711287  },
    9721288
     
    9771293  hasClassName: function(element, className) {
    9781294    if (!(element = $(element))) return;
    979     return Element.classNames(element).include(className);
     1295    var elementClassName = element.className;
     1296    if (elementClassName.length == 0) return false;
     1297    if (elementClassName == className ||
     1298        elementClassName.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
     1299      return true;
     1300    return false;
    9801301  },
    9811302
    9821303  addClassName: function(element, className) {
    9831304    if (!(element = $(element))) return;
    984     return Element.classNames(element).add(className);
     1305    Element.classNames(element).add(className);
     1306    return element;
    9851307  },
    9861308
    9871309  removeClassName: function(element, className) {
    9881310    if (!(element = $(element))) return;
    989     return Element.classNames(element).remove(className);
     1311    Element.classNames(element).remove(className);
     1312    return element;
     1313  },
     1314
     1315  toggleClassName: function(element, className) {
     1316    if (!(element = $(element))) return;
     1317    Element.classNames(element)[element.hasClassName(className) ? 'remove' : 'add'](className);
     1318    return element;
     1319  },
     1320
     1321  observe: function() {
     1322    Event.observe.apply(Event, arguments);
     1323    return $A(arguments).first();
     1324  },
     1325
     1326  stopObserving: function() {
     1327    Event.stopObserving.apply(Event, arguments);
     1328    return $A(arguments).first();
    9901329  },
    9911330
     
    9931332  cleanWhitespace: function(element) {
    9941333    element = $(element);
    995     for (var i = 0; i < element.childNodes.length; i++) {
    996       var node = element.childNodes[i];
     1334    var node = element.firstChild;
     1335    while (node) {
     1336      var nextNode = node.nextSibling;
    9971337      if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
    998         Element.remove(node);
    999     }
     1338        element.removeChild(node);
     1339      node = nextNode;
     1340    }
     1341    return element;
    10001342  },
    10011343
     
    10041346  },
    10051347
    1006   childOf: function(element, ancestor) {
     1348  descendantOf: function(element, ancestor) {
    10071349    element = $(element), ancestor = $(ancestor);
    10081350    while (element = element.parentNode)
     
    10131355  scrollTo: function(element) {
    10141356    element = $(element);
    1015     var x = element.x ? element.x : element.offsetLeft,
    1016         y = element.y ? element.y : element.offsetTop;
    1017     window.scrollTo(x, y);
     1357    var pos = Position.cumulativeOffset(element);
     1358    window.scrollTo(pos[0], pos[1]);
     1359    return element;
    10181360  },
    10191361
    10201362  getStyle: function(element, style) {
    10211363    element = $(element);
    1022     var value = element.style[style.camelize()];
     1364    if (['float','cssFloat'].include(style))
     1365      style = (typeof element.style.styleFloat != 'undefined' ? 'styleFloat' : 'cssFloat');
     1366    style = style.camelize();
     1367    var value = element.style[style];
    10231368    if (!value) {
    10241369      if (document.defaultView && document.defaultView.getComputedStyle) {
    10251370        var css = document.defaultView.getComputedStyle(element, null);
    1026         value = css ? css.getPropertyValue(style) : null;
     1371        value = css ? css[style] : null;
    10271372      } else if (element.currentStyle) {
    1028         value = element.currentStyle[style.camelize()];
     1373        value = element.currentStyle[style];
    10291374      }
    10301375    }
     1376
     1377    if((value == 'auto') && ['width','height'].include(style) && (element.getStyle('display') != 'none'))
     1378      value = element['offset'+style.capitalize()] + 'px';
    10311379
    10321380    if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
    10331381      if (Element.getStyle(element, 'position') == 'static') value = 'auto';
    1034 
     1382    if(style == 'opacity') {
     1383      if(value) return parseFloat(value);
     1384      if(value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
     1385        if(value[1]) return parseFloat(value[1]) / 100;
     1386      return 1.0;
     1387    }
    10351388    return value == 'auto' ? null : value;
    10361389  },
     
    10381391  setStyle: function(element, style) {
    10391392    element = $(element);
    1040     for (var name in style)
    1041       element.style[name.camelize()] = style[name];
     1393    for (var name in style) {
     1394      var value = style[name];
     1395      if(name == 'opacity') {
     1396        if (value == 1) {
     1397          value = (/Gecko/.test(navigator.userAgent) &&
     1398            !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 0.999999 : 1.0;
     1399          if(/MSIE/.test(navigator.userAgent) && !window.opera)
     1400            element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'');
     1401        } else if(value == '') {
     1402          if(/MSIE/.test(navigator.userAgent) && !window.opera)
     1403            element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'');
     1404        } else {
     1405          if(value < 0.00001) value = 0;
     1406          if(/MSIE/.test(navigator.userAgent) && !window.opera)
     1407            element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'') +
     1408              'alpha(opacity='+value*100+')';
     1409        }
     1410      } else if(['float','cssFloat'].include(name)) name = (typeof element.style.styleFloat != 'undefined') ? 'styleFloat' : 'cssFloat';
     1411      element.style[name.camelize()] = value;
     1412    }
     1413    return element;
    10421414  },
    10431415
    10441416  getDimensions: function(element) {
    10451417    element = $(element);
    1046     if (Element.getStyle(element, 'display') != 'none')
     1418    var display = $(element).getStyle('display');
     1419    if (display != 'none' && display != null) // Safari bug
    10471420      return {width: element.offsetWidth, height: element.offsetHeight};
    10481421
     
    10521425    var originalVisibility = els.visibility;
    10531426    var originalPosition = els.position;
     1427    var originalDisplay = els.display;
    10541428    els.visibility = 'hidden';
    10551429    els.position = 'absolute';
    1056     els.display = '';
     1430    els.display = 'block';
    10571431    var originalWidth = element.clientWidth;
    10581432    var originalHeight = element.clientHeight;
    1059     els.display = 'none';
     1433    els.display = originalDisplay;
    10601434    els.position = originalPosition;
    10611435    els.visibility = originalVisibility;
     
    10761450      }
    10771451    }
     1452    return element;
    10781453  },
    10791454
     
    10881463        element.style.right = '';
    10891464    }
     1465    return element;
    10901466  },
    10911467
    10921468  makeClipping: function(element) {
    10931469    element = $(element);
    1094     if (element._overflow) return;
    1095     element._overflow = element.style.overflow;
     1470    if (element._overflow) return element;
     1471    element._overflow = element.style.overflow || 'auto';
    10961472    if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden')
    10971473      element.style.overflow = 'hidden';
     1474    return element;
    10981475  },
    10991476
    11001477  undoClipping: function(element) {
    11011478    element = $(element);
    1102     if (element._overflow) return;
    1103     element.style.overflow = element._overflow;
    1104     element._overflow = undefined;
    1105   }
    1106 }
     1479    if (!element._overflow) return element;
     1480    element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
     1481    element._overflow = null;
     1482    return element;
     1483  }
     1484};
     1485
     1486Object.extend(Element.Methods, {childOf: Element.Methods.descendantOf});
     1487
     1488Element._attributeTranslations = {};
     1489
     1490Element._attributeTranslations.names = {
     1491  colspan:   "colSpan",
     1492  rowspan:   "rowSpan",
     1493  valign:    "vAlign",
     1494  datetime:  "dateTime",
     1495  accesskey: "accessKey",
     1496  tabindex:  "tabIndex",
     1497  enctype:   "encType",
     1498  maxlength: "maxLength",
     1499  readonly:  "readOnly",
     1500  longdesc:  "longDesc"
     1501};
     1502
     1503Element._attributeTranslations.values = {
     1504  _getAttr: function(element, attribute) {
     1505    return element.getAttribute(attribute, 2);
     1506  },
     1507
     1508  _flag: function(element, attribute) {
     1509    return $(element).hasAttribute(attribute) ? attribute : null;
     1510  },
     1511
     1512  style: function(element) {
     1513    return element.style.cssText.toLowerCase();
     1514  },
     1515
     1516  title: function(element) {
     1517    var node = element.getAttributeNode('title');
     1518    return node.specified ? node.nodeValue : null;
     1519  }
     1520};
     1521
     1522Object.extend(Element._attributeTranslations.values, {
     1523  href: Element._attributeTranslations.values._getAttr,
     1524  src:  Element._attributeTranslations.values._getAttr,
     1525  disabled: Element._attributeTranslations.values._flag,
     1526  checked:  Element._attributeTranslations.values._flag,
     1527  readonly: Element._attributeTranslations.values._flag,
     1528  multiple: Element._attributeTranslations.values._flag
     1529});
     1530
     1531Element.Methods.Simulated = {
     1532  hasAttribute: function(element, attribute) {
     1533    var t = Element._attributeTranslations;
     1534    attribute = t.names[attribute] || attribute;
     1535    return $(element).getAttributeNode(attribute).specified;
     1536  }
     1537};
     1538
     1539// IE is missing .innerHTML support for TABLE-related elements
     1540if (document.all && !window.opera){
     1541  Element.Methods.update = function(element, html) {
     1542    element = $(element);
     1543    html = typeof html == 'undefined' ? '' : html.toString();
     1544    var tagName = element.tagName.toUpperCase();
     1545    if (['THEAD','TBODY','TR','TD'].include(tagName)) {
     1546      var div = document.createElement('div');
     1547      switch (tagName) {
     1548        case 'THEAD':
     1549        case 'TBODY':
     1550          div.innerHTML = '<table><tbody>' +  html.stripScripts() + '</tbody></table>';
     1551          depth = 2;
     1552          break;
     1553        case 'TR':
     1554          div.innerHTML = '<table><tbody><tr>' +  html.stripScripts() + '</tr></tbody></table>';
     1555          depth = 3;
     1556          break;
     1557        case 'TD':
     1558          div.innerHTML = '<table><tbody><tr><td>' +  html.stripScripts() + '</td></tr></tbody></table>';
     1559          depth = 4;
     1560      }
     1561      $A(element.childNodes).each(function(node){
     1562        element.removeChild(node)
     1563      });
     1564      depth.times(function(){ div = div.firstChild });
     1565
     1566      $A(div.childNodes).each(
     1567        function(node){ element.appendChild(node) });
     1568    } else {
     1569      element.innerHTML = html.stripScripts();
     1570    }
     1571    setTimeout(function() {html.evalScripts()}, 10);
     1572    return element;
     1573  }
     1574};
    11071575
    11081576Object.extend(Element, Element.Methods);
     
    11101578var _nativeExtensions = false;
    11111579
    1112 if(!HTMLElement && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) {
    1113   var HTMLElement = {}
    1114   HTMLElement.prototype = document.createElement('div').__proto__;
    1115 }
     1580if(/Konqueror|Safari|KHTML/.test(navigator.userAgent))
     1581  ['', 'Form', 'Input', 'TextArea', 'Select'].each(function(tag) {
     1582    var className = 'HTML' + tag + 'Element';
     1583    if(window[className]) return;
     1584    var klass = window[className] = {};
     1585    klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__;
     1586  });
    11161587
    11171588Element.addMethods = function(methods) {
    11181589  Object.extend(Element.Methods, methods || {});
    11191590
    1120   if(typeof HTMLElement != 'undefined') {
    1121     var methods = Element.Methods, cache = Element.extend.cache;
    1122     for (property in methods) {
     1591  function copy(methods, destination, onlyIfAbsent) {
     1592    onlyIfAbsent = onlyIfAbsent || false;
     1593    var cache = Element.extend.cache;
     1594    for (var property in methods) {
    11231595      var value = methods[property];
    1124       if (typeof value == 'function')
    1125         HTMLElement.prototype[property] = cache.findOrStore(value);
    1126     }
     1596      if (!onlyIfAbsent || !(property in destination))
     1597        destination[property] = cache.findOrStore(value);
     1598    }
     1599  }
     1600
     1601  if (typeof HTMLElement != 'undefined') {
     1602    copy(Element.Methods, HTMLElement.prototype);
     1603    copy(Element.Methods.Simulated, HTMLElement.prototype, true);
     1604    copy(Form.Methods, HTMLFormElement.prototype);
     1605    [HTMLInputElement, HTMLTextAreaElement, HTMLSelectElement].each(function(klass) {
     1606      copy(Form.Element.Methods, klass.prototype);
     1607    });
    11271608    _nativeExtensions = true;
    11281609  }
    11291610}
    1130 
    1131 Element.addMethods();
    11321611
    11331612var Toggle = new Object();
     
    11491628        this.element.insertAdjacentHTML(this.adjacency, this.content);
    11501629      } catch (e) {
    1151         var tagName = this.element.tagName.toLowerCase();
    1152         if (tagName == 'tbody' || tagName == 'tr') {
     1630        var tagName = this.element.tagName.toUpperCase();
     1631        if (['TBODY', 'TR'].include(tagName)) {
    11531632          this.insertContent(this.contentFromAnonymousTable());
    11541633        } else {
     
    12491728  add: function(classNameToAdd) {
    12501729    if (this.include(classNameToAdd)) return;
    1251     this.set(this.toArray().concat(classNameToAdd).join(' '));
     1730    this.set($A(this).concat(classNameToAdd).join(' '));
    12521731  },
    12531732
    12541733  remove: function(classNameToRemove) {
    12551734    if (!this.include(classNameToRemove)) return;
    1256     this.set(this.select(function(className) {
    1257       return className != classNameToRemove;
    1258     }).join(' '));
     1735    this.set($A(this).without(classNameToRemove).join(' '));
    12591736  },
    12601737
    12611738  toString: function() {
    1262     return this.toArray().join(' ');
    1263   }
    1264 }
     1739    return $A(this).join(' ');
     1740  }
     1741};
    12651742
    12661743Object.extend(Element.ClassNames.prototype, Enumerable);
     
    13091786      conditions.push('true');
    13101787    if (clause = params.id)
    1311       conditions.push('element.id == ' + clause.inspect());
     1788      conditions.push('element.readAttribute("id") == ' + clause.inspect());
    13121789    if (clause = params.tagName)
    13131790      conditions.push('element.tagName.toUpperCase() == ' + clause.inspect());
    13141791    if ((clause = params.classNames).length > 0)
    1315       for (var i = 0; i < clause.length; i++)
    1316         conditions.push('Element.hasClassName(element, ' + clause[i].inspect() + ')');
     1792      for (var i = 0, length = clause.length; i < length; i++)
     1793        conditions.push('element.hasClassName(' + clause[i].inspect() + ')');
    13171794    if (clause = params.attributes) {
    13181795      clause.each(function(attribute) {
    1319         var value = 'element.getAttribute(' + attribute.name.inspect() + ')';
     1796        var value = 'element.readAttribute(' + attribute.name.inspect() + ')';
    13201797        var splitValueBy = function(delimiter) {
    13211798          return value + ' && ' + value + '.split(' + delimiter.inspect() + ')';
     
    13301807          case '!=':      conditions.push(value + ' != ' + attribute.value.inspect()); break;
    13311808          case '':
    1332           case undefined: conditions.push(value + ' != null'); break;
     1809          case undefined: conditions.push('element.hasAttribute(' + attribute.name.inspect() + ')'); break;
    13331810          default:        throw 'Unknown operator ' + attribute.operator + ' in selector';
    13341811        }
     
    13411818  compileMatcher: function() {
    13421819    this.match = new Function('element', 'if (!element.tagName) return false; \
     1820      element = $(element); \
    13431821      return ' + this.buildMatchExpression());
    13441822  },
     
    13551833
    13561834    var results = [];
    1357     for (var i = 0; i < scope.length; i++)
     1835    for (var i = 0, length = scope.length; i < length; i++)
    13581836      if (this.match(element = scope[i]))
    13591837        results.push(Element.extend(element));
     
    13671845}
    13681846
     1847Object.extend(Selector, {
     1848  matchElements: function(elements, expression) {
     1849    var selector = new Selector(expression);
     1850    return elements.select(selector.match.bind(selector)).map(Element.extend);
     1851  },
     1852
     1853  findElement: function(elements, expression, index) {
     1854    if (typeof expression == 'number') index = expression, expression = false;
     1855    return Selector.matchElements(elements, expression || '*')[index || 0];
     1856  },
     1857
     1858  findChildElements: function(element, expressions) {
     1859    return expressions.map(function(expression) {
     1860      return expression.match(/[^\s"]+(?:"[^"]*"[^\s"]+)*/g).inject([null], function(results, expr) {
     1861        var selector = new Selector(expr);
     1862        return results.inject([], function(elements, result) {
     1863          return elements.concat(selector.findElements(result || element));
     1864        });
     1865      });
     1866    }).flatten();
     1867  }
     1868});
     1869
    13691870function $$() {
    1370   return $A(arguments).map(function(expression) {
    1371     return expression.strip().split(/\s+/).inject([null], function(results, expr) {
    1372       var selector = new Selector(expr);
    1373       return results.map(selector.findElements.bind(selector)).flatten();
    1374     });
    1375   }).flatten();
    1376 }
    1377 var Field = {
    1378   clear: function() {
    1379     for (var i = 0; i < arguments.length; i++)
    1380       $(arguments[i]).value = '';
    1381   },
    1382 
     1871  return Selector.findChildElements(document, $A(arguments));
     1872}
     1873var Form = {
     1874  reset: function(form) {
     1875    $(form).reset();
     1876    return form;
     1877  },
     1878
     1879  serializeElements: function(elements, getHash) {
     1880    var data = elements.inject({}, function(result, element) {
     1881      if (!element.disabled && element.name) {
     1882        var key = element.name, value = $(element).getValue();
     1883        if (value != undefined) {
     1884          if (result[key]) {
     1885            if (result[key].constructor != Array) result[key] = [result[key]];
     1886            result[key].push(value);
     1887          }
     1888          else result[key] = value;
     1889        }
     1890      }
     1891      return result;
     1892    });
     1893
     1894    return getHash ? data : Hash.toQueryString(data);
     1895  }
     1896};
     1897
     1898Form.Methods = {
     1899  serialize: function(form, getHash) {
     1900    return Form.serializeElements(Form.getElements(form), getHash);
     1901  },
     1902
     1903  getElements: function(form) {
     1904    return $A($(form).getElementsByTagName('*')).inject([],
     1905      function(elements, child) {
     1906        if (Form.Element.Serializers[child.tagName.toLowerCase()])
     1907          elements.push(Element.extend(child));
     1908        return elements;
     1909      }
     1910    );
     1911  },
     1912
     1913  getInputs: function(form, typeName, name) {
     1914    form = $(form);
     1915    var inputs = form.getElementsByTagName('input');
     1916
     1917    if (!typeName && !name) return $A(inputs).map(Element.extend);
     1918
     1919    for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
     1920      var input = inputs[i];
     1921      if ((typeName && input.type != typeName) || (name && input.name != name))
     1922        continue;
     1923      matchingInputs.push(Element.extend(input));
     1924    }
     1925
     1926    return matchingInputs;
     1927  },
     1928
     1929  disable: function(form) {
     1930    form = $(form);
     1931    form.getElements().each(function(element) {
     1932      element.blur();
     1933      element.disabled = 'true';
     1934    });
     1935    return form;
     1936  },
     1937
     1938  enable: function(form) {
     1939    form = $(form);
     1940    form.getElements().each(function(element) {
     1941      element.disabled = '';
     1942    });
     1943    return form;
     1944  },
     1945
     1946  findFirstElement: function(form) {
     1947    return $(form).getElements().find(function(element) {
     1948      return element.type != 'hidden' && !element.disabled &&
     1949        ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
     1950    });
     1951  },
     1952
     1953  focusFirstElement: function(form) {
     1954    form = $(form);
     1955    form.findFirstElement().activate();
     1956    return form;
     1957  }
     1958}
     1959
     1960Object.extend(Form, Form.Methods);
     1961
     1962/*--------------------------------------------------------------------------*/
     1963
     1964Form.Element = {
    13831965  focus: function(element) {
    13841966    $(element).focus();
    1385   },
    1386 
    1387   present: function() {
    1388     for (var i = 0; i < arguments.length; i++)
    1389       if ($(arguments[i]).value == '') return false;
    1390     return true;
     1967    return element;
    13911968  },
    13921969
    13931970  select: function(element) {
    13941971    $(element).select();
     1972    return element;
     1973  }
     1974}
     1975
     1976Form.Element.Methods = {
     1977  serialize: function(element) {
     1978    element = $(element);
     1979    if (!element.disabled && element.name) {
     1980      var value = element.getValue();
     1981      if (value != undefined) {
     1982        var pair = {};
     1983        pair[element.name] = value;
     1984        return Hash.toQueryString(pair);
     1985      }
     1986    }
     1987    return '';
     1988  },
     1989
     1990  getValue: function(element) {
     1991    element = $(element);
     1992    var method = element.tagName.toLowerCase();
     1993    return Form.Element.Serializers[method](element);
     1994  },
     1995
     1996  clear: function(element) {
     1997    $(element).value = '';
     1998    return element;
     1999  },
     2000
     2001  present: function(element) {
     2002    return $(element).value != '';
    13952003  },
    13962004
     
    13982006    element = $(element);
    13992007    element.focus();
    1400     if (element.select)
     2008    if (element.select && ( element.tagName.toLowerCase() != 'input' ||
     2009      !['button', 'reset', 'submit'].include(element.type) ) )
    14012010      element.select();
    1402   }
    1403 }
     2011    return element;
     2012  },
     2013
     2014  disable: function(element) {
     2015    element = $(element);
     2016    element.disabled = true;
     2017    return element;
     2018  },
     2019
     2020  enable: function(element) {
     2021    element = $(element);
     2022    element.blur();
     2023    element.disabled = false;
     2024    return element;
     2025  }
     2026}
     2027
     2028Object.extend(Form.Element, Form.Element.Methods);
     2029var Field = Form.Element;
     2030var $F = Form.Element.getValue;
    14042031
    14052032/*--------------------------------------------------------------------------*/
    1406 
    1407 var Form = {
    1408   serialize: function(form) {
    1409     var elements = Form.getElements($(form));
    1410     var queryComponents = new Array();
    1411 
    1412     for (var i = 0; i < elements.length; i++) {
    1413       var queryComponent = Form.Element.serialize(elements[i]);
    1414       if (queryComponent)
    1415         queryComponents.push(queryComponent);
    1416     }
    1417 
    1418     return queryComponents.join('&');
    1419   },
    1420 
    1421   getElements: function(form) {
    1422     form = $(form);
    1423     var elements = new Array();
    1424 
    1425     for (var tagName in Form.Element.Serializers) {
    1426       var tagElements = form.getElementsByTagName(tagName);
    1427       for (var j = 0; j < tagElements.length; j++)
    1428         elements.push(tagElements[j]);
    1429     }
    1430     return elements;
    1431   },
    1432 
    1433   getInputs: function(form, typeName, name) {
    1434     form = $(form);
    1435     var inputs = form.getElementsByTagName('input');
    1436 
    1437     if (!typeName && !name)
    1438       return inputs;
    1439 
    1440     var matchingInputs = new Array();
    1441     for (var i = 0; i < inputs.length; i++) {
    1442       var input = inputs[i];
    1443       if ((typeName && input.type != typeName) ||
    1444           (name && input.name != name))
    1445         continue;
    1446       matchingInputs.push(input);
    1447     }
    1448 
    1449     return matchingInputs;
    1450   },
    1451 
    1452   disable: function(form) {
    1453     var elements = Form.getElements(form);
    1454     for (var i = 0; i < elements.length; i++) {
    1455       var element = elements[i];
    1456       element.blur();
    1457       element.disabled = 'true';
    1458     }
    1459   },
    1460 
    1461   enable: function(form) {
    1462     var elements = Form.getElements(form);
    1463     for (var i = 0; i < elements.length; i++) {
    1464       var element = elements[i];
    1465       element.disabled = '';
    1466     }
    1467   },
    1468 
    1469   findFirstElement: function(form) {
    1470     return Form.getElements(form).find(function(element) {
    1471       return element.type != 'hidden' && !element.disabled &&
    1472         ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
    1473     });
    1474   },
    1475 
    1476   focusFirstElement: function(form) {
    1477     Field.activate(Form.findFirstElement(form));
    1478   },
    1479 
    1480   reset: function(form) {
    1481     $(form).reset();
    1482   }
    1483 }
    1484 
    1485 Form.Element = {
    1486   serialize: function(element) {
    1487     element = $(element);
    1488     var method = element.tagName.toLowerCase();
    1489     var parameter = Form.Element.Serializers[method](element);
    1490 
    1491     if (parameter) {
    1492       var key = encodeURIComponent(parameter[0]);
    1493       if (key.length == 0) return;
    1494 
    1495       if (parameter[1].constructor != Array)
    1496         parameter[1] = [parameter[1]];
    1497 
    1498       return parameter[1].map(function(value) {
    1499         return key + '=' + encodeURIComponent(value);
    1500       }).join('&');
    1501     }
    1502   },
    1503 
    1504   getValue: function(element) {
    1505     element = $(element);
    1506     var method = element.tagName.toLowerCase();
    1507     var parameter = Form.Element.Serializers[method](element);
    1508 
    1509     if (parameter)
    1510       return parameter[1];
    1511   }
    1512 }
    15132033
    15142034Form.Element.Serializers = {
    15152035  input: function(element) {
    15162036    switch (element.type.toLowerCase()) {
    1517       case 'submit':
    1518       case 'hidden':
    1519       case 'password':
    1520       case 'text':
    1521         return Form.Element.Serializers.textarea(element);
    15222037      case 'checkbox':
    15232038      case 'radio':
    15242039        return Form.Element.Serializers.inputSelector(element);
    1525     }
    1526     return false;
     2040      default:
     2041        return Form.Element.Serializers.textarea(element);
     2042    }
    15272043  },
    15282044
    15292045  inputSelector: function(element) {
    1530     if (element.checked)
    1531       return [element.name, element.value];
     2046    return element.checked ? element.value : null;
    15322047  },
    15332048
    15342049  textarea: function(element) {
    1535     return [element.name, element.value];
     2050    return element.value;
    15362051  },
    15372052
    15382053  select: function(element) {
    1539     return Form.Element.Serializers[element.type == 'select-one' ?
     2054    return this[element.type == 'select-one' ?
    15402055      'selectOne' : 'selectMany'](element);
    15412056  },
    15422057
    15432058  selectOne: function(element) {
    1544     var value = '', opt, index = element.selectedIndex;
    1545     if (index >= 0) {
    1546       opt = element.options[index];
    1547       value = opt.value || opt.text;
    1548     }
    1549     return [element.name, value];
     2059    var index = element.selectedIndex;
     2060    return index >= 0 ? this.optionValue(element.options[index]) : null;
    15502061  },
    15512062
    15522063  selectMany: function(element) {
    1553     var value = [];
    1554     for (var i = 0; i < element.length; i++) {
     2064    var values, length = element.length;
     2065    if (!length) return null;
     2066
     2067    for (var i = 0, values = []; i < length; i++) {
    15552068      var opt = element.options[i];
    1556       if (opt.selected)
    1557         value.push(opt.value || opt.text);
    1558     }
    1559     return [element.name, value];
    1560   }
    1561 }
    1562 
    1563 /*--------------------------------------------------------------------------*/
    1564 
    1565 var $F = Form.Element.getValue;
     2069      if (opt.selected) values.push(this.optionValue(opt));
     2070    }
     2071    return values;
     2072  },
     2073
     2074  optionValue: function(opt) {
     2075    // extend element because hasAttribute may not be native
     2076    return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text;
     2077  }
     2078}
    15662079
    15672080/*--------------------------------------------------------------------------*/
     
    15842097  onTimerEvent: function() {
    15852098    var value = this.getValue();
    1586     if (this.lastValue != value) {
     2099    var changed = ('string' == typeof this.lastValue && 'string' == typeof value
     2100      ? this.lastValue != value : String(this.lastValue) != String(value));
     2101    if (changed) {
    15872102      this.callback(this.element, value);
    15882103      this.lastValue = value;
     
    16292144
    16302145  registerFormCallbacks: function() {
    1631     var elements = Form.getElements(this.element);
    1632     for (var i = 0; i < elements.length; i++)
    1633       this.registerCallback(elements[i]);
     2146    Form.getElements(this.element).each(this.registerCallback.bind(this));
    16342147  },
    16352148
     
    16412154          Event.observe(element, 'click', this.onElementEvent.bind(this));
    16422155          break;
    1643         case 'password':
    1644         case 'text':
    1645         case 'textarea':
    1646         case 'select-one':
    1647         case 'select-multiple':
     2156        default:
    16482157          Event.observe(element, 'change', this.onElementEvent.bind(this));
    16492158          break;
     
    16802189  KEY_DOWN:     40,
    16812190  KEY_DELETE:   46,
     2191  KEY_HOME:     36,
     2192  KEY_END:      35,
     2193  KEY_PAGEUP:   33,
     2194  KEY_PAGEDOWN: 34,
    16822195
    16832196  element: function(event) {
     
    17352248  unloadCache: function() {
    17362249    if (!Event.observers) return;
    1737     for (var i = 0; i < Event.observers.length; i++) {
     2250    for (var i = 0, length = Event.observers.length; i < length; i++) {
    17382251      Event.stopObserving.apply(this, Event.observers[i]);
    17392252      Event.observers[i][0] = null;
     
    17432256
    17442257  observe: function(element, name, observer, useCapture) {
    1745     var element = $(element);
     2258    element = $(element);
    17462259    useCapture = useCapture || false;
    17472260
     
    17512264      name = 'keydown';
    17522265
    1753     this._observeAndCache(element, name, observer, useCapture);
     2266    Event._observeAndCache(element, name, observer, useCapture);
    17542267  },
    17552268
    17562269  stopObserving: function(element, name, observer, useCapture) {
    1757     var element = $(element);
     2270    element = $(element);
    17582271    useCapture = useCapture || false;
    17592272
     
    18222335      element = element.offsetParent;
    18232336      if (element) {
    1824         p = Element.getStyle(element, 'position');
     2337        if(element.tagName=='BODY') break;
     2338        var p = Element.getStyle(element, 'position');
    18252339        if (p == 'relative' || p == 'absolute') break;
    18262340      }
     
    18782392  },
    18792393
    1880   clone: function(source, target) {
    1881     source = $(source);
    1882     target = $(target);
    1883     target.style.position = 'absolute';
    1884     var offsets = this.cumulativeOffset(source);
    1885     target.style.top    = offsets[1] + 'px';
    1886     target.style.left   = offsets[0] + 'px';
    1887     target.style.width  = source.offsetWidth + 'px';
    1888     target.style.height = source.offsetHeight + 'px';
    1889   },
    1890 
    18912394  page: function(forElement) {
    18922395    var valueT = 0, valueL = 0;
     
    19052408    element = forElement;
    19062409    do {
    1907       valueT -= element.scrollTop  || 0;
    1908       valueL -= element.scrollLeft || 0;
     2410      if (!window.opera || element.tagName=='BODY') {
     2411        valueT -= element.scrollTop  || 0;
     2412        valueL -= element.scrollLeft || 0;
     2413      }
    19092414    } while (element = element.parentNode);
    19102415
     
    19672472
    19682473    element.style.position = 'absolute';
    1969     element.style.top    = top + 'px';;
    1970     element.style.left   = left + 'px';;
    1971     element.style.width  = width + 'px';;
    1972     element.style.height = height + 'px';;
     2474    element.style.top    = top + 'px';
     2475    element.style.left   = left + 'px';
     2476    element.style.width  = width + 'px';
     2477    element.style.height = height + 'px';
    19732478  },
    19742479
     
    20072512  }
    20082513}
     2514
     2515Element.addMethods();
  • trunk/wp-includes/js/scriptaculous/scriptaculous.js

    r4629 r4813  
    1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
     1// script.aculo.us scriptaculous.js v1.7.0, Fri Jan 19 19:16:36 CET 2007
     2
     3// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
    24//
    35// Permission is hereby granted, free of charge, to any person obtaining
     
    1921// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    2022// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     23//
     24// For details, see the script.aculo.us web site: http://script.aculo.us/
    2125
    2226var Scriptaculous = {
    23   Version: '1.6.1',
     27  Version: '1.7.0',
    2428  require: function(libraryName) {
    2529    // inserting via DOM fails in Safari 2.0, so brute force approach
  • trunk/wp-includes/js/scriptaculous/slider.js

    r4629 r4813  
    1 // Copyright (c) 2005 Marty Haught, Thomas Fuchs
     1// script.aculo.us slider.js v1.7.0, Fri Jan 19 19:16:36 CET 2007
     2
     3// Copyright (c) 2005, 2006 Marty Haught, Thomas Fuchs
    24//
    3 // See http://script.aculo.us for more info
    4 //
    5 // Permission is hereby granted, free of charge, to any person obtaining
    6 // a copy of this software and associated documentation files (the
    7 // "Software"), to deal in the Software without restriction, including
    8 // without limitation the rights to use, copy, modify, merge, publish,
    9 // distribute, sublicense, and/or sell copies of the Software, and to
    10 // permit persons to whom the Software is furnished to do so, subject to
    11 // the following conditions:
    12 //
    13 // The above copyright notice and this permission notice shall be
    14 // included in all copies or substantial portions of the Software.
    15 //
    16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     5// script.aculo.us is freely distributable under the terms of an MIT-style license.
     6// For details, see the script.aculo.us web site: http://script.aculo.us/
    237
    248if(!Control) var Control = {};
     
    6549   
    6650    this.trackLength = this.maximumOffset() - this.minimumOffset();
    67     this.handleLength = this.isVertical() ? this.handles[0].offsetHeight : this.handles[0].offsetWidth;
     51
     52    this.handleLength = this.isVertical() ?
     53      (this.handles[0].offsetHeight != 0 ?
     54        this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) :
     55      (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth :
     56        this.handles[0].style.width.replace(/px$/,""));
    6857
    6958    this.active   = false;
     
    138127  setValue: function(sliderValue, handleIdx){
    139128    if(!this.active) {
    140       this.activeHandle    = this.handles[handleIdx];
    141       this.activeHandleIdx = handleIdx;
     129      this.activeHandleIdx = handleIdx || 0;
     130      this.activeHandle    = this.handles[this.activeHandleIdx];
    142131      this.updateStyles();
    143132    }
     
    181170  },
    182171  maximumOffset: function(){
    183     return(this.isVertical() ?
    184       this.track.offsetHeight - this.alignY : this.track.offsetWidth - this.alignX);
     172    return(this.isVertical() ?
     173      (this.track.offsetHeight != 0 ? this.track.offsetHeight :
     174        this.track.style.height.replace(/px$/,"")) - this.alignY :
     175      (this.track.offsetWidth != 0 ? this.track.offsetWidth :
     176        this.track.style.width.replace(/px$/,"")) - this.alignY);
    185177  }, 
    186178  isVertical:  function(){
     
    218210        var handle = Event.element(event);
    219211        var pointer  = [Event.pointerX(event), Event.pointerY(event)];
    220         if(handle==this.track) {
     212        var track = handle;
     213        if(track==this.track) {
    221214          var offsets  = Position.cumulativeOffset(this.track);
    222215          this.event = event;
     
    231224          while((this.handles.indexOf(handle) == -1) && handle.parentNode)
    232225            handle = handle.parentNode;
    233        
    234           this.activeHandle    = handle;
    235           this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
    236           this.updateStyles();
    237        
    238           var offsets  = Position.cumulativeOffset(this.activeHandle);
    239           this.offsetX = (pointer[0] - offsets[0]);
    240           this.offsetY = (pointer[1] - offsets[1]);
     226           
     227          if(this.handles.indexOf(handle)!=-1) {
     228            this.activeHandle    = handle;
     229            this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
     230            this.updateStyles();
     231           
     232            var offsets  = Position.cumulativeOffset(this.activeHandle);
     233            this.offsetX = (pointer[0] - offsets[0]);
     234            this.offsetY = (pointer[1] - offsets[1]);
     235          }
    241236        }
    242237      }
  • trunk/wp-includes/js/scriptaculous/unittest.js

    r4629 r4813  
    1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
    2 //           (c) 2005 Jon Tirsen (http://www.tirsen.com)
    3 //           (c) 2005 Michael Schuerig (http://www.schuerig.de/michael/)
     1// script.aculo.us unittest.js v1.7.0, Fri Jan 19 19:16:36 CET 2007
     2
     3// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
     4//           (c) 2005, 2006 Jon Tirsen (http://www.tirsen.com)
     5//           (c) 2005, 2006 Michael Schuerig (http://www.schuerig.de/michael/)
    46//
    5 // Permission is hereby granted, free of charge, to any person obtaining
    6 // a copy of this software and associated documentation files (the
    7 // "Software"), to deal in the Software without restriction, including
    8 // without limitation the rights to use, copy, modify, merge, publish,
    9 // distribute, sublicense, and/or sell copies of the Software, and to
    10 // permit persons to whom the Software is furnished to do so, subject to
    11 // the following conditions:
    12 //
    13 // The above copyright notice and this permission notice shall be
    14 // included in all copies or substantial portions of the Software.
    15 //
    16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    23 
     7// script.aculo.us is freely distributable under the terms of an MIT-style license.
     8// For details, see the script.aculo.us web site: http://script.aculo.us/
    249
    2510// experimental, Firefox-only
     
    2813    pointerX: 0,
    2914    pointerY: 0,
    30     buttons: 0
     15    buttons:  0,
     16    ctrlKey:  false,
     17    altKey:   false,
     18    shiftKey: false,
     19    metaKey:  false
    3120  }, arguments[2] || {});
    3221  var oEvent = document.createEvent("MouseEvents");
    3322  oEvent.initMouseEvent(eventName, true, true, document.defaultView,
    3423    options.buttons, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
    35     false, false, false, false, 0, $(element));
     24    options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, 0, $(element));
    3625 
    3726  if(this.mark) Element.remove(this.mark);
     
    9988    this.statusCell = document.createElement('td');
    10089    this.nameCell = document.createElement('td');
     90    this.nameCell.className = "nameCell";
    10191    this.nameCell.appendChild(document.createTextNode(testName));
    10292    this.messageCell = document.createElement('td');
     
    111101    this.statusCell.innerHTML = status;
    112102    this.messageCell.innerHTML = this._toHTML(summary);
     103    this.addLinksToResults();
    113104  },
    114105  message: function(message) {
     
    132123  _toHTML: function(txt) {
    133124    return txt.escapeHTML().replace(/\n/g,"<br/>");
     125  },
     126  addLinksToResults: function(){
     127    $$("tr.failed .nameCell").each( function(td){ // todo: limit to children of this.log
     128      td.title = "Run only this test"
     129      Event.observe(td, 'click', function(){ window.location.search = "?tests=" + td.innerHTML;});
     130    });
     131    $$("tr.passed .nameCell").each( function(td){ // todo: limit to children of this.log
     132      td.title = "Run all tests"
     133      Event.observe(td, 'click', function(){ window.location.search = "";});
     134    });
    134135  }
    135136}
     
    142143    }, arguments[1] || {});
    143144    this.options.resultsURL = this.parseResultsURLQueryParameter();
     145    this.options.tests      = this.parseTestsQueryParameter();
    144146    if (this.options.testLog) {
    145147      this.options.testLog = $(this.options.testLog) || null;
     
    159161        for(var testcase in testcases) {
    160162          if(/^test/.test(testcase)) {
    161             this.tests.push(new Test.Unit.Testcase(testcase, testcases[testcase], testcases["setup"], testcases["teardown"]));
     163            this.tests.push(
     164               new Test.Unit.Testcase(
     165                 this.options.context ? ' -> ' + this.options.titles[testcase] : testcase,
     166                 testcases[testcase], testcases["setup"], testcases["teardown"]
     167               ));
    162168          }
    163169        }
     
    170176  parseResultsURLQueryParameter: function() {
    171177    return window.location.search.parseQuery()["resultsURL"];
     178  },
     179  parseTestsQueryParameter: function(){
     180    if (window.location.search.parseQuery()["tests"]){
     181        return window.location.search.parseQuery()["tests"].split(',');
     182    };
    172183  },
    173184  // Returns:
     
    230241    }
    231242    return (
     243      (this.options.context ? this.options.context + ': ': '') +
    232244      this.tests.length + " tests, " +
    233245      assertions + " assertions, " +
     
    284296    catch(e) { this.error(e); }
    285297  },
     298  assertInspect: function(expected, actual) {
     299    var message = arguments[2] || "assertInspect";
     300    try { (expected == actual.inspect()) ? this.pass() :
     301      this.fail(message + ': expected "' + Test.Unit.inspect(expected) +
     302        '", actual "' + Test.Unit.inspect(actual) + '"'); }
     303    catch(e) { this.error(e); }
     304  },
    286305  assertEnumEqual: function(expected, actual) {
    287306    var message = arguments[2] || "assertEnumEqual";
     
    298317    catch(e) { this.error(e); }
    299318  },
     319  assertIdentical: function(expected, actual) {
     320    var message = arguments[2] || "assertIdentical";
     321    try { (expected === actual) ? this.pass() :
     322      this.fail(message + ': expected "' + Test.Unit.inspect(expected) + 
     323        '", actual "' + Test.Unit.inspect(actual) + '"'); }
     324    catch(e) { this.error(e); }
     325  },
     326  assertNotIdentical: function(expected, actual) {
     327    var message = arguments[2] || "assertNotIdentical";
     328    try { !(expected === actual) ? this.pass() :
     329      this.fail(message + ': expected "' + Test.Unit.inspect(expected) + 
     330        '", actual "' + Test.Unit.inspect(actual) + '"'); }
     331    catch(e) { this.error(e); }
     332  },
    300333  assertNull: function(obj) {
    301334    var message = arguments[1] || 'assertNull'
     
    304337    catch(e) { this.error(e); }
    305338  },
     339  assertMatch: function(expected, actual) {
     340    var message = arguments[2] || 'assertMatch';
     341    var regex = new RegExp(expected);
     342    try { (regex.exec(actual)) ? this.pass() :
     343      this.fail(message + ' : regex: "' +  Test.Unit.inspect(expected) + ' did not match: ' + Test.Unit.inspect(actual) + '"'); }
     344    catch(e) { this.error(e); }
     345  },
    306346  assertHidden: function(element) {
    307347    var message = arguments[1] || 'assertHidden';
     
    311351    var message = arguments[1] || 'assertNotNull';
    312352    this.assert(object != null, message);
     353  },
     354  assertType: function(expected, actual) {
     355    var message = arguments[2] || 'assertType';
     356    try {
     357      (actual.constructor == expected) ? this.pass() :
     358      this.fail(message + ': expected "' + Test.Unit.inspect(expected) + 
     359        '", actual "' + (actual.constructor) + '"'); }
     360    catch(e) { this.error(e); }
     361  },
     362  assertNotOfType: function(expected, actual) {
     363    var message = arguments[2] || 'assertNotOfType';
     364    try {
     365      (actual.constructor != expected) ? this.pass() :
     366      this.fail(message + ': expected "' + Test.Unit.inspect(expected) + 
     367        '", actual "' + (actual.constructor) + '"'); }
     368    catch(e) { this.error(e); }
    313369  },
    314370  assertInstanceOf: function(expected, actual) {
     
    325381      this.fail(message + ": object was an instance of the not expected type"); }
    326382    catch(e) { this.error(e); }
     383  },
     384  assertRespondsTo: function(method, obj) {
     385    var message = arguments[2] || 'assertRespondsTo';
     386    try {
     387      (obj[method] && typeof obj[method] == 'function') ? this.pass() :
     388      this.fail(message + ": object doesn't respond to [" + method + "]"); }
     389    catch(e) { this.error(e); }
     390  },
     391  assertReturnsTrue: function(method, obj) {
     392    var message = arguments[2] || 'assertReturnsTrue';
     393    try {
     394      var m = obj[method];
     395      if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
     396      m() ? this.pass() :
     397      this.fail(message + ": method returned false"); }
     398    catch(e) { this.error(e); }
     399  },
     400  assertReturnsFalse: function(method, obj) {
     401    var message = arguments[2] || 'assertReturnsFalse';
     402    try {
     403      var m = obj[method];
     404      if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
     405      !m() ? this.pass() :
     406      this.fail(message + ": method returned true"); }
     407    catch(e) { this.error(e); }
     408  },
     409  assertRaise: function(exceptionName, method) {
     410    var message = arguments[2] || 'assertRaise';
     411    try {
     412      method();
     413      this.fail(message + ": exception expected but none was raised"); }
     414    catch(e) {
     415      ((exceptionName == null) || (e.name==exceptionName)) ? this.pass() : this.error(e);
     416    }
     417  },
     418  assertElementsMatch: function() {
     419    var expressions = $A(arguments), elements = $A(expressions.shift());
     420    if (elements.length != expressions.length) {
     421      this.fail('assertElementsMatch: size mismatch: ' + elements.length + ' elements, ' + expressions.length + ' expressions');
     422      return false;
     423    }
     424    elements.zip(expressions).all(function(pair, index) {
     425      var element = $(pair.first()), expression = pair.last();
     426      if (element.match(expression)) return true;
     427      this.fail('assertElementsMatch: (in index ' + index + ') expected ' + expression.inspect() + ' but got ' + element.inspect());
     428    }.bind(this)) && this.pass();
     429  },
     430  assertElementMatches: function(element, expression) {
     431    this.assertElementsMatch([element], expression);
     432  },
     433  benchmark: function(operation, iterations) {
     434    var startAt = new Date();
     435    (iterations || 1).times(operation);
     436    var timeTaken = ((new Date())-startAt);
     437    this.info((arguments[2] || 'Operation') + ' finished ' +
     438       iterations + ' iterations in ' + (timeTaken/1000)+'s' );
     439    return timeTaken;
    327440  },
    328441  _isVisible: function(element) {
     
    356469    Test.Unit.Assertions.prototype.initialize.bind(this)();
    357470    this.name           = name;
    358     this.test           = test || function() {};
     471   
     472    if(typeof test == 'string') {
     473      test = test.gsub(/(\.should[^\(]+\()/,'#{0}this,');
     474      test = test.gsub(/(\.should[^\(]+)\(this,\)/,'#{1}(this)');
     475      this.test = function() {
     476        eval('with(this){'+test+'}');
     477      }
     478    } else {
     479      this.test = test || function() {};
     480    }
     481   
    359482    this.setup          = setup || function() {};
    360483    this.teardown       = teardown || function() {};
     
    382505  }
    383506});
     507
     508// *EXPERIMENTAL* BDD-style testing to please non-technical folk
     509// This draws many ideas from RSpec http://rspec.rubyforge.org/
     510
     511Test.setupBDDExtensionMethods = function(){
     512  var METHODMAP = {
     513    shouldEqual:     'assertEqual',
     514    shouldNotEqual:  'assertNotEqual',
     515    shouldEqualEnum: 'assertEnumEqual',
     516    shouldBeA:       'assertType',
     517    shouldNotBeA:    'assertNotOfType',
     518    shouldBeAn:      'assertType',
     519    shouldNotBeAn:   'assertNotOfType',
     520    shouldBeNull:    'assertNull',
     521    shouldNotBeNull: 'assertNotNull',
     522   
     523    shouldBe:        'assertReturnsTrue',
     524    shouldNotBe:     'assertReturnsFalse',
     525    shouldRespondTo: 'assertRespondsTo'
     526  };
     527  Test.BDDMethods = {};
     528  for(m in METHODMAP) {
     529    Test.BDDMethods[m] = eval(
     530      'function(){'+
     531      'var args = $A(arguments);'+
     532      'var scope = args.shift();'+
     533      'scope.'+METHODMAP[m]+'.apply(scope,(args || []).concat([this])); }');
     534  }
     535  [Array.prototype, String.prototype, Number.prototype].each(
     536    function(p){ Object.extend(p, Test.BDDMethods) }
     537  );
     538}
     539
     540Test.context = function(name, spec, log){
     541  Test.setupBDDExtensionMethods();
     542 
     543  var compiledSpec = {};
     544  var titles = {};
     545  for(specName in spec) {
     546    switch(specName){
     547      case "setup":
     548      case "teardown":
     549        compiledSpec[specName] = spec[specName];
     550        break;
     551      default:
     552        var testName = 'test'+specName.gsub(/\s+/,'-').camelize();
     553        var body = spec[specName].toString().split('\n').slice(1);
     554        if(/^\{/.test(body[0])) body = body.slice(1);
     555        body.pop();
     556        body = body.map(function(statement){
     557          return statement.strip()
     558        });
     559        compiledSpec[testName] = body.join('\n');
     560        titles[testName] = specName;
     561    }
     562  }
     563  new Test.Unit.Runner(compiledSpec, { titles: titles, testLog: log || 'testlog', context: name });
     564};
  • trunk/wp-includes/js/wp-ajax-js.php

    r4768 r4813  
    2424    },
    2525    addArg: function(key, value) {
    26         var a = $H(this.options.parameters.parseQuery());
     26        var a = [];
    2727        a[encodeURIComponent(key)] = encodeURIComponent(value);
    28         this.options.parameters = a.map(function(pair) {
    29             return pair.join('=');
    30         }).join('&');
     28        this.options.parameters = $H(this.options.parameters).merge($H(a));
    3129    },
    3230    getResponseElement: function(r) {
  • trunk/wp-includes/script-loader.php

    r4799 r4813  
    1919        $mce_config = apply_filters('tiny_mce_config_url', '/wp-includes/js/tinymce/tiny_mce_config.php');
    2020        $this->add( 'wp_tiny_mce', $mce_config, array('tiny_mce'), '20070124' );
    21         $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.5.0');
     21        $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.5.0-0');
    2222        $this->add( 'autosave', '/wp-includes/js/autosave-js.php', array('prototype', 'sack'), '20070116');
    2323        $this->add( 'wp-ajax', '/wp-includes/js/wp-ajax-js.php', array('prototype'), '20070118');
    2424        $this->add( 'listman', '/wp-includes/js/list-manipulation-js.php', array('wp-ajax', 'fat'), '20070118');
    25         $this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/wp-scriptaculous.js', array('prototype'), '1.6.1');
    26         $this->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.6.1');
    27         $this->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder'), '1.6.1');
    28         $this->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.6.1');
    29         $this->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.6.1');
    30         $this->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.6.1');
    31         $this->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.6.1');
     25        $this->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/wp-scriptaculous.js', array('prototype'), '1.7.0');
     26        $this->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.7.0');
     27        $this->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.7.0');
     28        $this->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.7.0');
     29        $this->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.7.0');
     30        $this->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.7.0');
     31        $this->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.7.0');
    3232        $this->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118');
    3333        if ( is_admin() ) {
Note: See TracChangeset for help on using the changeset viewer.