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

Changeset 7846

Show
Ignore:
Timestamp:
10/12/07 17:28:50 (1 year ago)
Author:
madrobby
Message:

script.aculo.us: Update to new Class.create syntax in Prototype 1.6; update to latest Prototype 1.6 trunk.

Files:

Legend:

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

    r7642 r7846  
    11*SVN* 
     2 
     3* Update to new Class.create syntax in Prototype 1.6; update to latest Prototype 1.6 trunk. 
    24 
    35* Fix bottom CSS property reassignment and initialization in queues for Effect#SlideUp.  Closes #7412, #7761. 
  • spinoffs/scriptaculous/lib/prototype.js

    r7349 r7846  
    1515    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1, 
    1616    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1, 
    17     MobileSafari: !!navigator.userAgent.match(/iPhone.*Mobile.*Safari/) 
     17    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/) 
    1818  }, 
    1919 
     
    3838/* Based on Alex Arnell's inheritance implementation. */ 
    3939var Class = { 
    40   create: (function() { 
    41     var extending = { }; 
    42  
    43     return function(parent, properties) { 
    44       if (arguments.length == 1 && !Object.isFunction(parent)) 
    45         properties = parent, parent = null; 
    46  
    47       function klass() { 
    48         if (arguments[0] !== extending) 
    49           this.initialize.apply(this, arguments); 
    50       } 
    51  
    52       klass.superclass = parent; 
    53       klass.subclasses = []; 
    54  
    55       if (parent) { 
    56         klass.prototype = new parent(extending); 
    57         parent.subclasses.push(klass); 
    58       } 
    59  
    60       if (properties) Class.extend(klass, properties); 
    61       klass.prototype.constructor = klass; 
    62  
    63       return klass; 
    64     }; 
    65   })(), 
    66  
    67   extend: function(destination, source) { 
    68     var ancestor = destination.superclass && destination.superclass.prototype; 
     40  create: function() { 
     41    var parent = null, properties = $A(arguments); 
     42    if (Object.isFunction(properties[0])) 
     43      parent = properties.shift(); 
     44 
     45    function klass() { 
     46      this.initialize.apply(this, arguments); 
     47    } 
     48 
     49    Object.extend(klass, Class.Methods); 
     50    klass.superclass = parent; 
     51    klass.subclasses = []; 
     52 
     53    if (parent) { 
     54      var subclass = function() { }; 
     55      subclass.prototype = parent.prototype; 
     56      klass.prototype = new subclass; 
     57      parent.subclasses.push(klass); 
     58    } 
     59 
     60    for (var i = 0; i < properties.length; i++) 
     61      klass.addMethods(properties[i]); 
     62 
     63    if (!klass.prototype.initialize) 
     64      klass.prototype.initialize = Prototype.emptyFunction; 
     65 
     66    klass.prototype.constructor = klass; 
     67 
     68    return klass; 
     69  } 
     70}; 
     71 
     72Class.Methods = { 
     73  addMethods: function(source) { 
     74    var ancestor = this.superclass && this.superclass.prototype; 
    6975 
    7076    for (var property in source) { 
     
    7985        }); 
    8086      } 
    81       destination.prototype[property] = value; 
    82     } 
    83  
    84     return destination; 
    85   }, 
    86  
    87   mixin: function(destination, source) { 
    88     return Object.extend(destination.prototype, source); 
     87      this.prototype[property] = value; 
     88    } 
     89 
     90    return this; 
    8991  } 
    9092}; 
     
    235237 
    236238Date.prototype.toJSON = function() { 
    237   return '"' + this.getFullYear() + '-' + 
    238     (this.getMonth() + 1).toPaddedString(2) + '-' + 
    239     this.getDate().toPaddedString(2) + 'T' + 
    240     this.getHours().toPaddedString(2) + ':' + 
    241     this.getMinutes().toPaddedString(2) + ':' + 
    242     this.getSeconds().toPaddedString(2) + '"'; 
     239  return '"' + this.getUTCFullYear() + '-' + 
     240    (this.getUTCMonth() + 1).toPaddedString(2) + '-' + 
     241    this.getUTCDate().toPaddedString(2) + 'T' + 
     242    this.getUTCHours().toPaddedString(2) + ':' + 
     243    this.getUTCMinutes().toPaddedString(2) + ':' + 
     244    this.getUTCSeconds().toPaddedString(2) + 'Z"'; 
    243245}; 
    244246 
     
    14961498  }, 
    14971499 
    1498   updateComplete: function(responseText) { 
     1500  updateComplete: function(response) { 
    14991501    if (this.options.decay) { 
    1500       this.decay = (responseText == this.lastText ? 
     1502      this.decay = (response.responseText == this.lastText ? 
    15011503        this.decay * this.options.decay : 1); 
    15021504 
    1503       this.lastText = responseText; 
     1505      this.lastText = response.responseText; 
    15041506    } 
    15051507    this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency); 
     
    15271529      null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 
    15281530    for (var i = 0, length = query.snapshotLength; i < length; i++) 
    1529       results.push(query.snapshotItem(i)); 
     1531      results.push(Element.extend(query.snapshotItem(i))); 
    15301532    return results; 
    15311533  }; 
     
    16651667      element.parentNode.replaceChild(wrapper, element); 
    16661668    wrapper.appendChild(element); 
    1667     return element
     1669    return wrapper
    16681670  }, 
    16691671 
     
    21452147Element.Methods.identify.counter = 1; 
    21462148 
    2147 if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){ 
    2148   function iter(name) { 
    2149     return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]"; 
    2150   } 
    2151  
    2152   instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ? 
    2153   function(element, className) { 
    2154     className = className.toString().strip(); 
    2155     var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className); 
    2156     return cond ? document._getElementsByXPath('.//*' + cond, element) : []; 
    2157   } : function(element, className) { 
    2158     className = className.toString().strip(); 
    2159     var elements = [], classNames = (/\s/.test(className) ? $w(className) : null); 
    2160     if (!classNames && !className) return elements; 
    2161  
    2162     var nodes = $(element).getElementsByTagName('*'); 
    2163     className = ' ' + className + ' '; 
    2164  
    2165     for (var i = 0, child, cn; child = nodes[i]; i++) { 
    2166       if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) || 
    2167           (classNames && classNames.all(function(name) { 
    2168             return !name.toString().blank() && cn.include(' ' + name + ' '); 
    2169           })))) 
    2170         elements.push(Element.extend(child)); 
    2171     } 
    2172     return elements; 
    2173   }; 
    2174  
    2175   return function(className, parentElement) { 
    2176     return $(parentElement || document.body).getElementsByClassName(className); 
    2177   }; 
    2178 }(Element.Methods); 
    2179  
    21802149Object.extend(Element.Methods, { 
    21812150  getElementsBySelector: Element.Methods.select, 
     
    22922261    } 
    22932262    element = $(element); 
     2263    if (!element.currentStyle.hasLayout) element.style.zoom = 1; 
    22942264    var filter = element.getStyle('filter'), style = element.style; 
    22952265    if (value == 1 || value === '') { 
     
    30363006      if (reverse) { 
    30373007        for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) { 
    3038           node = nodes[i]; 
     3008          var node = nodes[i]; 
    30393009          if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; 
    30403010        } 
     
    37133683  KEY_INSERT:   45, 
    37143684 
    3715   DOMEvents: ['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 
    3716               'mousemove', 'mouseout', 'keypress', 'keydown', 'keyup', 
    3717               'load', 'unload', 'abort', 'error', 'resize', 'scroll', 
    3718               'select', 'change', 'submit', 'reset', 'focus', 'blur', 
    3719               'contextmenu'], 
    3720  
    37213685  cache: { }, 
    37223686 
     
    38113775 
    38123776  function getDOMEventName(eventName) { 
    3813     if (!Event.DOMEvents.include(eventName)) return "dataavailable"; 
     3777    if (eventName && eventName.match(/:/)) return "dataavailable"; 
    38143778    return { keypress: "keydown" }[eventName] || eventName; 
    38153779  } 
     
    39613925    if (fired) return; 
    39623926    if (timer) window.clearInterval(timer); 
    3963     document.fire("contentloaded"); 
     3927    document.fire("dom:loaded"); 
    39643928    fired = true; 
    39653929  } 
     
    39803944 
    39813945  } else { 
    3982     document.write("<script id=__onDOMContentLoaded defer " + 
    3983       "src='://javascript:void(0)'><\/script>"); 
    3984  
     3946    document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>"); 
    39853947    $("__onDOMContentLoaded").onreadystatechange = function() { 
    39863948      if (this.readyState == "complete") { 
     
    41064068/*--------------------------------------------------------------------------*/ 
    41074069 
     4070if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){ 
     4071  function iter(name) { 
     4072    return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]"; 
     4073  } 
     4074 
     4075  instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ? 
     4076  function(element, className) { 
     4077    className = className.toString().strip(); 
     4078    var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className); 
     4079    return cond ? document._getElementsByXPath('.//*' + cond, element) : []; 
     4080  } : function(element, className) { 
     4081    className = className.toString().strip(); 
     4082    var elements = [], classNames = (/\s/.test(className) ? $w(className) : null); 
     4083    if (!classNames && !className) return elements; 
     4084 
     4085    var nodes = $(element).getElementsByTagName('*'); 
     4086    className = ' ' + className + ' '; 
     4087 
     4088    for (var i = 0, child, cn; child = nodes[i]; i++) { 
     4089      if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) || 
     4090          (classNames && classNames.all(function(name) { 
     4091            return !name.toString().blank() && cn.include(' ' + name + ' '); 
     4092          })))) 
     4093        elements.push(Element.extend(child)); 
     4094    } 
     4095    return elements; 
     4096  }; 
     4097 
     4098  return function(className, parentElement) { 
     4099    return $(parentElement || document.body).getElementsByClassName(className); 
     4100  }; 
     4101}(Element.Methods); 
     4102 
     4103/*--------------------------------------------------------------------------*/ 
     4104 
    41084105Element.ClassNames = Class.create(); 
    41094106Element.ClassNames.prototype = { 
  • spinoffs/scriptaculous/src/effects.js

    r7642 r7846  
    218218      this.effects[i] && this.effects[i].loop(timePos); 
    219219  } 
    220 }); 
    221 Class.mixin(Effect.ScopedQueue, Enumerable); 
     220}, Effect.ScopedQueue, Enumerable); 
    222221 
    223222Effect.Queues = { 
  • spinoffs/scriptaculous/test/unit/slider_test.html

    r6387 r7846  
    8686      var slider = new Control.Slider('handle1', 'track1'); 
    8787      assertInstanceOf(Control.Slider, slider); 
    88       assertEqual(Prototype.Browser.IE ? 5 : 4, Event.observers.length); 
    8988       
    9089      assertEqual('horizontal', slider.axis);