Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5991

Show
Ignore:
Timestamp:
01/18/07 22:15:19 (2 years ago)
Author:
madrobby
Message:

script.aculo.us: update to Prototype 1.5.0 final

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/scriptaculous/CHANGELOG

    r5949 r5991  
    11*SVN* 
     2 
     3* Update to Prototype 1.5.0 final 
    24 
    35* New option keepBackgroundImage: true for Effect.Highlight, fixes #5037 [docwhat, tomg] 
  • spinoffs/scriptaculous/lib/prototype.js

    r5850 r5991  
    1 /*  Prototype JavaScript framework, version 1.5.0_rc2 
     1/*  Prototype JavaScript framework, version 1.5.0 
    22 *  (c) 2005-2007 Sam Stephenson 
    33 * 
     
    88 
    99var Prototype = { 
    10   Version: '1.5.0_rc2', 
     10  Version: '1.5.0', 
    1111  BrowserFeatures: { 
    1212    XPath: !!document.evaluate 
     
    630630  } 
    631631} 
    632 var Hash = { 
     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, { 
    633665  _each: function(iterator) { 
    634666    for (var key in this) { 
    635667      var value = this[key]; 
    636       if (typeof value == 'function') continue; 
     668      if (value && value == Hash.prototype[key]) continue; 
    637669 
    638670      var pair = [key, value]; 
     
    658690  }, 
    659691 
    660   toQueryString: function() { 
    661     return this.map(function(pair) { 
    662       if (!pair.key) return null; 
    663  
    664       if (pair.value && pair.value.constructor == Array) { 
    665         pair.value = pair.value.compact(); 
    666  
    667         if (pair.value.length < 2) { 
    668           pair.value = pair.value.reduce(); 
    669         } else { 
    670           var key = encodeURIComponent(pair.key); 
    671           return pair.value.map(function(value) { 
    672             return key + '=' + encodeURIComponent(value); 
    673                           }).join('&'); 
     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) 
    674701        } 
    675702      } 
    676  
    677       if (pair.value == undefined) pair[1] = ''; 
    678       return pair.map(encodeURIComponent).join('='); 
    679     }).join('&'); 
     703      delete this[arguments[i]]; 
     704    } 
     705    return result; 
     706  }, 
     707 
     708  toQueryString: function() { 
     709    return Hash.toQueryString(this); 
    680710  }, 
    681711 
     
    685715    }).join(', ') + '}>'; 
    686716  } 
    687 } 
     717}); 
    688718 
    689719function $H(object) { 
    690   var hash = Object.extend({}, object || {}); 
    691   Object.extend(hash, Enumerable); 
    692   Object.extend(hash, Hash); 
    693   return hash; 
    694 
     720  if (object && object.constructor == Hash) return object; 
     721  return new Hash(object); 
     722}; 
    695723ObjectRange = Class.create(); 
    696724Object.extend(ObjectRange.prototype, Enumerable); 
     
    786814 
    787815    this.options.method = this.options.method.toLowerCase(); 
    788     this.options.parameters = $H(typeof this.options.parameters == 'string' ? 
    789       this.options.parameters.toQueryParams() : this.options.parameters); 
     816    if (typeof this.options.parameters == 'string') 
     817      this.options.parameters = this.options.parameters.toQueryParams(); 
    790818  } 
    791819} 
     
    805833 
    806834  request: function(url) { 
     835    this.url = url; 
     836    this.method = this.options.method; 
    807837    var params = this.options.parameters; 
    808     if (params.any()) params['_'] = ''; 
    809  
    810     if (!['get', 'post'].include(this.options.method)) { 
     838 
     839    if (!['get', 'post'].include(this.method)) { 
    811840      // simulate other verbs over post 
    812       params['_method'] = this.options.method; 
    813       this.options.method = 'post'; 
    814     } 
    815  
    816     this.url = url; 
     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 += '&_=' 
    817847 
    818848    // when GET, append parameters to URL 
    819     if (this.options.method == 'get' && params.any()) 
    820       this.url += (this.url.indexOf('?') >= 0 ? '&' : '?') + 
    821         params.toQueryString(); 
     849    if (this.method == 'get' && params) 
     850      this.url += (this.url.indexOf('?') > -1 ? '&' : '?') + params; 
    822851 
    823852    try { 
    824853      Ajax.Responders.dispatch('onCreate', this, this.transport); 
    825854 
    826       this.transport.open(this.options.method.toUpperCase(), this.url, 
     855      this.transport.open(this.method.toUpperCase(), this.url, 
    827856        this.options.asynchronous); 
    828857 
     
    833862      this.setRequestHeaders(); 
    834863 
    835       var body = this.options.method == 'post' ? 
    836         (this.options.postBody || params.toQueryString()) : null; 
     864      var body = this.method == 'post' ? (this.options.postBody || params) : null; 
    837865 
    838866      this.transport.send(body); 
     
    861889    }; 
    862890 
    863     if (this.options.method == 'post') { 
     891    if (this.method == 'post') { 
    864892      headers['Content-type'] = this.options.contentType + 
    865893        (this.options.encoding ? '; charset=' + this.options.encoding : ''); 
     
    10551083      results.push(query.snapshotItem(i)); 
    10561084    return results; 
    1057   } 
     1085  }; 
    10581086} 
    10591087 
     
    10721100    return elements; 
    10731101  } 
    1074 } 
     1102}; 
    10751103 
    10761104/*--------------------------------------------------------------------------*/ 
     
    11011129  element._extended = true; 
    11021130  return element; 
    1103 } 
     1131}; 
    11041132 
    11051133Element.extend.cache = { 
     
    11091137    } 
    11101138  } 
    1111 } 
     1139}; 
    11121140 
    11131141Element.Methods = { 
     
    11471175  replace: function(element, html) { 
    11481176    element = $(element); 
     1177    html = typeof html == 'undefined' ? '' : html.toString(); 
    11491178    if (element.outerHTML) { 
    11501179      element.outerHTML = html.stripScripts(); 
     
    12391268 
    12401269  readAttribute: function(element, name) { 
    1241     return $(element).getAttribute(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); 
    12421279  }, 
    12431280 
    12441281  getHeight: function(element) { 
    1245     return $(element).offsetHeight; 
     1282    return $(element).getDimensions().height; 
     1283  }, 
     1284 
     1285  getWidth: function(element) { 
     1286    return $(element).getDimensions().width; 
    12461287  }, 
    12471288 
     
    13051346  }, 
    13061347 
    1307   childOf: function(element, ancestor) { 
     1348  descendantOf: function(element, ancestor) { 
    13081349    element = $(element), ancestor = $(ancestor); 
    13091350    while (element = element.parentNode) 
     
    13211362  getStyle: function(element, style) { 
    13221363    element = $(element); 
    1323     var camelizedStyle = (style == 'float' ? 
    1324       (typeof element.style.styleFloat != 'undefined' ? 'styleFloat' : 'cssFloat') : style).camelize(); 
    1325     var value = element.style[camelizedStyle]; 
     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]; 
    13261368    if (!value) { 
    13271369      if (document.defaultView && document.defaultView.getComputedStyle) { 
    13281370        var css = document.defaultView.getComputedStyle(element, null); 
    1329         value = css ? css[camelizedStyle] : null; 
     1371        value = css ? css[style] : null; 
    13301372      } else if (element.currentStyle) { 
    1331         value = element.currentStyle[camelizedStyle]; 
     1373        value = element.currentStyle[style]; 
    13321374      } 
    13331375    } 
     
    13571399          if(/MSIE/.test(navigator.userAgent) && !window.opera) 
    13581400            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,''); 
    13591404        } else { 
    13601405          if(value < 0.00001) value = 0; 
     
    13631408              'alpha(opacity='+value*100+')'; 
    13641409        } 
    1365       } else if(name == 'float') name = (typeof element.style.styleFloat != 'undefined') ? 'styleFloat' : 'cssFloat'; 
     1410      } else if(['float','cssFloat'].include(name)) name = (typeof element.style.styleFloat != 'undefined') ? 'styleFloat' : 'cssFloat'; 
    13661411      element.style[name.camelize()] = value; 
    13671412    } 
     
    13711416  getDimensions: function(element) { 
    13721417    element = $(element); 
    1373     if (Element.getStyle(element, 'display') != 'none') 
     1418    var display = $(element).getStyle('display'); 
     1419    if (display != 'none' && display != null) // Safari bug 
    13741420      return {width: element.offsetWidth, height: element.offsetHeight}; 
    13751421 
     
    13791425    var originalVisibility = els.visibility; 
    13801426    var originalPosition = els.position; 
     1427    var originalDisplay = els.display; 
    13811428    els.visibility = 'hidden'; 
    13821429    els.position = 'absolute'; 
    1383     els.display = ''; 
     1430    els.display = 'block'; 
    13841431    var originalWidth = element.clientWidth; 
    13851432    var originalHeight = element.clientHeight; 
    1386     els.display = 'none'
     1433    els.display = originalDisplay
    13871434    els.position = originalPosition; 
    13881435    els.visibility = originalVisibility; 
     
    14351482    return element; 
    14361483  } 
    1437 
     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}); 
    14381530 
    14391531Element.Methods.Simulated = { 
    14401532  hasAttribute: function(element, attribute) { 
     1533    var t = Element._attributeTranslations; 
     1534    attribute = t.names[attribute] || attribute; 
    14411535    return $(element).getAttributeNode(attribute).specified; 
    14421536  } 
    1443 } 
     1537}; 
    14441538 
    14451539// IE is missing .innerHTML support for TABLE-related elements 
    1446 if(document.all){ 
     1540if (document.all && !window.opera){ 
    14471541  Element.Methods.update = function(element, html) { 
    14481542    element = $(element); 
     
    14781572    return element; 
    14791573  } 
    1480 } 
     1574}; 
    14811575 
    14821576Object.extend(Element, Element.Methods); 
     
    16451739    return $A(this).join(' '); 
    16461740  } 
    1647 } 
     1741}; 
    16481742 
    16491743Object.extend(Element.ClassNames.prototype, Enumerable); 
     
    16921786      conditions.push('true'); 
    16931787    if (clause = params.id) 
    1694       conditions.push('element.getAttribute("id") == ' + clause.inspect()); 
     1788      conditions.push('element.readAttribute("id") == ' + clause.inspect()); 
    16951789    if (clause = params.tagName) 
    16961790      conditions.push('element.tagName.toUpperCase() == ' + clause.inspect()); 
    16971791    if ((clause = params.classNames).length > 0) 
    16981792      for (var i = 0, length = clause.length; i < length; i++) 
    1699         conditions.push('Element.hasClassName(element, ' + clause[i].inspect() + ')'); 
     1793        conditions.push('element.hasClassName(' + clause[i].inspect() + ')'); 
    17001794    if (clause = params.attributes) { 
    17011795      clause.each(function(attribute) { 
    1702         var value = 'element.getAttribute(' + attribute.name.inspect() + ')'; 
     1796        var value = 'element.readAttribute(' + attribute.name.inspect() + ')'; 
    17031797        var splitValueBy = function(delimiter) { 
    17041798          return value + ' && ' + value + '.split(' + delimiter.inspect() + ')'; 
     
    17131807          case '!=':      conditions.push(value + ' != ' + attribute.value.inspect()); break; 
    17141808          case '': 
    1715           case undefined: conditions.push(value + ' != null'); break; 
     1809          case undefined: conditions.push('element.hasAttribute(' + attribute.name.inspect() + ')'); break; 
    17161810          default:        throw 'Unknown operator ' + attribute.operator + ' in selector'; 
    17171811        } 
     
    17241818  compileMatcher: function() { 
    17251819    this.match = new Function('element', 'if (!element.tagName) return false; \ 
     1820      element = $(element); \ 
    17261821      return ' + this.buildMatchExpression()); 
    17271822  }, 
     
    17631858  findChildElements: function(element, expressions) { 
    17641859    return expressions.map(function(expression) { 
    1765       return expression.strip().split(/\s+/).inject([null], function(results, expr) { 
     1860      return expression.match(/[^\s"]+(?:"[^"]*"[^\s"]+)*/g).inject([null], function(results, expr) { 
    17661861        var selector = new Selector(expr); 
    17671862        return results.inject([], function(elements, result) { 
     
    17821877  }, 
    17831878 
    1784   serializeElements: function(elements) { 
    1785     return elements.inject([], function(queryComponents, element) { 
    1786       var queryComponent = Form.Element.serialize(element); 
    1787       if (queryComponent) queryComponents.push(queryComponent); 
    1788       return queryComponents; 
    1789     }).join('&'); 
     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); 
    17901895  } 
    17911896}; 
    17921897 
    17931898Form.Methods = { 
    1794   serialize: function(form) { 
    1795     return Form.serializeElements(Form.getElements(form)); 
     1899  serialize: function(form, getHash) { 
     1900    return Form.serializeElements(Form.getElements(form), getHash); 
    17961901  }, 
    17971902 
     
    18081913  getInputs: function(form, typeName, name) { 
    18091914    form = $(form); 
    1810     var inputs = form.getElementsByTagName('input'), matchingInputs = []; 
    1811  
    1812     if (!typeName && !name) 
    1813       return $A(inputs).map(Element.extend); 
    1814  
    1815     for (var i = 0, length = inputs.length; i < length; i++) { 
     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++) { 
    18161920      var input = inputs[i]; 
    1817       if ((typeName && input.type != typeName) || 
    1818           (name && input.name != name)) 
     1921      if ((typeName && input.type != typeName) || (name && input.name != name)) 
    18191922        continue; 
    18201923      matchingInputs.push(Element.extend(input)); 
     
    18741977  serialize: function(element) { 
    18751978    element = $(element); 
    1876     if (element.disabled) return ''; 
    1877     var method = element.tagName.toLowerCase(); 
    1878     var parameter = Form.Element.Serializers[method](element); 
    1879  
    1880     if (parameter) { 
    1881       var key = encodeURIComponent(parameter[0]); 
    1882       if (key.length == 0) return; 
    1883  
    1884       if (parameter[1].constructor != Array) 
    1885         parameter[1] = [parameter[1]]; 
    1886  
    1887       return parameter[1].map(function(value) { 
    1888         return key + '=' + encodeURIComponent(value); 
    1889       }).join('&'); 
    1890     } 
     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 ''; 
    18911988  }, 
    18921989 
     
    18941991    element = $(element); 
    18951992    var method = element.tagName.toLowerCase(); 
    1896     var parameter = Form.Element.Serializers[method](element); 
    1897  
    1898     if (parameter) 
    1899       return parameter[1]; 
     1993    return Form.Element.Serializers[method](element); 
    19001994  }, 
    19011995 
     
    19342028Object.extend(Form.Element, Form.Element.Methods); 
    19352029var Field = Form.Element; 
     2030var $F = Form.Element.getValue; 
    19362031 
    19372032/*--------------------------------------------------------------------------*/ 
     
    19462041        return Form.Element.Serializers.textarea(element); 
    19472042    } 
    1948     return false; 
    19492043  }, 
    19502044 
    19512045  inputSelector: function(element) { 
    1952     if (element.checked) 
    1953       return [element.name, element.value]; 
     2046    return element.checked ? element.value : null; 
    19542047  }, 
    19552048 
    19562049  textarea: function(element) { 
    1957     return [element.name, element.value]
     2050    return element.value
    19582051  }, 
    19592052 
    19602053  select: function(element) { 
    1961     return Form.Element.Serializers[element.type == 'select-one' ? 
     2054    return this[element.type == 'select-one' ? 
    19622055      'selectOne' : 'selectMany'](element); 
    19632056  }, 
    19642057 
    19652058  selectOne: function(element) { 
    1966     var value = '', opt, index = element.selectedIndex; 
    1967     if (index >= 0) { 
    1968       opt = Element.extend(element.options[index]); 
    1969       // Uses the new potential extension if hasAttribute isn't native. 
    1970       value = opt.hasAttribute('value') ? opt.value : opt.text; 
    1971     } 
    1972     return [element.name, value]; 
     2059    var index = element.selectedIndex; 
     2060    return index >= 0 ? this.optionValue(element.options[index]) : null; 
    19732061  }, 
    19742062 
    19752063  selectMany: function(element) { 
    1976     var value = []; 
    1977     for (var i = 0, length = element.length; i < length; i++) { 
    1978       var opt = Element.extend(element.options[i]); 
    1979       if (opt.selected) 
    1980         // Uses the new potential extension if hasAttribute isn't native. 
    1981         value.push(opt.hasAttribute('value') ? opt.value : opt.text); 
    1982     } 
    1983     return [element.name, value]; 
    1984   } 
    1985 
    1986  
    1987 /*--------------------------------------------------------------------------*/ 
    1988  
    1989 var $F = Form.Element.getValue; 
     2064    var values, length = element.length; 
     2065    if (!length) return null; 
     2066 
     2067    for (var i = 0, values = []; i < length; i++) { 
     2068      var opt = element.options[i]; 
     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
    19902079 
    19912080/*--------------------------------------------------------------------------*/ 
     
    23832472 
    23842473    element.style.position = 'absolute'; 
    2385     element.style.top    = top + 'px';; 
    2386     element.style.left   = left + 'px';; 
    2387     element.style.width  = width + 'px';; 
    2388     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'; 
    23892478  }, 
    23902479