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

Changeset 6286

Show
Ignore:
Timestamp:
03/02/07 13:22:19 (1 year ago)
Author:
mislav
Message:

reverting [6285], unnecessary merge from trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/branches/event/CHANGELOG

    r6285 r6286  
    11*SVN* 
    2  
    3 * Add optional third parameter "camlized" to Element.setStyle, for optimized performance if style names are known to be camelCased.  [Thomas Fuchs] 
    4  
    5 * Fix a bug in the simulated hasAttribute for IE due to getAttributeNode sometimes returning null.  [sam] 
    6  
    7 * Optimize Element.getStyle and add new Element.getOpacity method. Special case IE and Opera getStyle methods.  Closes #7648.  [Tobie Langel, Thomas Fuchs] 
    8  
    9 * Optimize Element.setStyle and add new Element.setOpacity method, special case IE and Gecko opacity methods.  Closes #7585.  [savetheclocktower] 
    102 
    113* Add unified Browser detection by providing Prototype.Browser.(IE|Gecko|WebKit|Opera) booleans.  Closes #6800.  [savetheclocktower] 
  • spinoffs/prototype/branches/event/src/dom.js

    r6285 r6286  
    302302  getStyle: function(element, style) { 
    303303    element = $(element); 
    304     style = style == 'float' ? 'cssFloat' : style.camelize(); 
     304    if (['float','cssFloat'].include(style)) 
     305      style = (typeof element.style.styleFloat != 'undefined' ? 'styleFloat' : 'cssFloat'); 
     306    style = style.camelize(); 
    305307    var value = element.style[style]; 
    306308    if (!value) { 
    307       var css = document.defaultView.getComputedStyle(element, null); 
    308       value = css ? css[style] : null; 
    309     } 
    310     if (style == 'opacity') return value ? parseFloat(value) : 1.0; 
     309      if (document.defaultView && document.defaultView.getComputedStyle) { 
     310        var css = document.defaultView.getComputedStyle(element, null); 
     311        value = css ? css[style] : null; 
     312      } else if (element.currentStyle) { 
     313        value = element.currentStyle[style]; 
     314      } 
     315    } 
     316     
     317    if((value == 'auto') && ['width','height'].include(style) && (element.getStyle('display') != 'none')) 
     318      value = element['offset'+style.capitalize()] + 'px'; 
     319     
     320    if (window.opera && ['left', 'top', 'right', 'bottom'].include(style)) 
     321      if (Element.getStyle(element, 'position') == 'static') value = 'auto'; 
     322    if(style == 'opacity') { 
     323      if(value) return parseFloat(value); 
     324      if(value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))   
     325        if(value[1]) return parseFloat(value[1]) / 100;   
     326      return 1.0;  
     327    } 
    311328    return value == 'auto' ? null : value; 
    312329  }, 
    313330   
    314   getOpacity: function(element) { 
    315     return $(element).getStyle('opacity'); 
    316   }, 
    317    
    318   setStyle: function(element, styles, camelized) { 
    319     element = $(element); 
    320     var elementStyle = element.style; 
    321  
    322     for (var property in styles
    323       if (property == 'opacity') element.setOpacity(styles[property]) 
    324       else  
    325         elementStyle[(property == 'float' || property == 'cssFloat') ? 
    326           (elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') :  
    327           (camelized ? property : property.camelize())] = styles[property]; 
    328  
    329     return element; 
    330   }, 
    331    
    332   setOpacity: function(element, value) { 
    333     element = $(element)
    334     element.style.opacity = (value == 1 || value === '') ? '' :  
    335       (value < 0.00001) ? 0 : value; 
     331  setStyle: function(element, style) { 
     332    element = $(element); 
     333    for (var name in style) { 
     334      var value = style[name]; 
     335      if(name == 'opacity') { 
     336        if (value == 1) { 
     337          value = (/Gecko/.test(navigator.userAgent) && 
     338            !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 0.999999 : 1.0; 
     339          if(/MSIE/.test(navigator.userAgent) && !window.opera
     340            element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,''); 
     341        } else if(value === '') { 
     342          if(/MSIE/.test(navigator.userAgent) && !window.opera) 
     343            element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,''); 
     344        } else { 
     345          if(value < 0.00001) value = 0;   
     346          if(/MSIE/.test(navigator.userAgent) && !window.opera) 
     347            element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'') + 
     348              'alpha(opacity='+value*100+')'; 
     349        } 
     350      } else if(['float','cssFloat'].include(name)) name = (typeof element.style.styleFloat != 'undefined') ? 'styleFloat' : 'cssFloat'
     351      element.style[name.camelize()] = value; 
     352    } 
    336353    return element; 
    337354  }, 
     
    409426Object.extend(Element.Methods, {childOf: Element.Methods.descendantOf}); 
    410427 
    411 if (Prototype.Browser.Opera) {  
    412   Element.Methods._getStyle = Element.Methods.getStyle;  
    413   Element.Methods.getStyle = function(element, style) {  
    414     switch(style) {  
    415       case 'left':  
    416       case 'top':  
    417       case 'right':  
    418       case 'bottom':  
    419         if(Element._getStyle(element, 'position') == 'static') return null;  
    420       default: return Element._getStyle(element, style);  
    421     }  
    422   };  
    423 } 
    424  
    425 if (Prototype.Browser.IE) { 
    426   Element.Methods.getStyle = function(element, style) { 
    427     element = $(element); 
    428     style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize(); 
    429     var value = element.style[style]; 
    430     if (!value && element.currentStyle) value = element.currentStyle[style]; 
    431  
    432     if (style == 'opacity') { 
    433       if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/)) 
    434         if (value[1]) return parseFloat(value[1]) / 100; 
    435       return 1.0; 
    436     } 
    437  
    438     if (value == 'auto') { 
    439       if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none')) 
    440         return element['offset'+style.capitalize()] + 'px'; 
    441       return null; 
    442     } 
    443     return value; 
    444   }; 
    445    
    446   Element.Methods.setOpacity = function(element, value) { 
    447     element = $(element); 
    448     var filter = element.getStyle('filter'), style = element.style; 
    449     if (value == 1 || value === '') { 
    450       style.filter = filter.replace(/alpha\([^\)]*\)/gi,''); 
    451       return element; 
    452     } else if (value < 0.00001) value = 0; 
    453     style.filter = filter.replace(/alpha\([^\)]*\)/gi, '') + 
    454       'alpha(opacity=' + (value * 100) + ')'; 
    455     return element;    
    456   }; 
    457 } 
    458  
    459 if (Prototype.Browser.Gecko) { 
    460   Element.Methods.setOpacity = function(element, value) { 
    461     element = $(element); 
    462     element.style.opacity = (value == 1) ? 0.999999 :  
    463       (value === '') ? '' : (value < 0.00001) ? 0 : value; 
    464     return element; 
    465   }; 
    466 } 
    467  
    468428Element._attributeTranslations = {}; 
    469429 
     
    511471Element.Methods.Simulated = { 
    512472  hasAttribute: function(element, attribute) { 
    513     var t = Element._attributeTranslations, node
     473    var t = Element._attributeTranslations
    514474    attribute = t.names[attribute] || attribute; 
    515     node = $(element).getAttributeNode(attribute); 
    516     return node && node.specified; 
     475    return $(element).getAttributeNode(attribute).specified; 
    517476  } 
    518477}; 
  • spinoffs/prototype/branches/event/test/unit/dom.html

    r6285 r6286  
    631631    }}, 
    632632     
    633     testElementSetStyleCamelized: function() { with(this) { 
    634       $('style_test_3').setStyle({ marginTop: '30px'}, true); 
    635       assertEqual('30px', $('style_test_3').style.marginTop); 
    636        
    637       // This would work if camelized parameter is false 
    638       $('style_test_3').setStyle({ 'margin-top': '20px'}, true); 
    639       assertEqual('30px', $('style_test_3').style.marginTop); 
    640     }}, 
    641      
    642     testElementSetOpacity: function() { with(this) { 
    643       [0,0.1,0.5,0.999].each(function(opacity){ 
    644         $('style_test_3').setOpacity(opacity); 
    645         // b/c of rounding issues on IE special case 
    646         assert($('style_test_3').getStyle('opacity').toString().startsWith(opacity)); 
    647       }); 
    648        
    649       assertEqual(0, 
    650         $('style_test_3').setOpacity(0.0000001).getStyle('opacity')); 
    651        
    652       // for Firefox, we don't set to 1, because of flickering 
    653       assert( 
    654         $('style_test_3').setOpacity(0.9999999).getStyle('opacity') > 0.999 
    655       ); 
    656     }}, 
    657      
    658633    testElementGetStyle: function() { with(this) { 
    659634      assertEqual("none", 
     
    707682      assertEqual(0.3, $('op3').getStyle('opacity')); 
    708683       
    709       $('op3').setStyle({opacity: 0}); 
    710       assertEqual(0, $('op3').getStyle('opacity')); 
    711        
    712684      if(navigator.appVersion.match(/MSIE/)) { 
    713685        assertEqual('alpha(opacity=30)', $('op1').getStyle('filter')); 
    714686        assertEqual('progid:DXImageTransform.Microsoft.Blur(strength=10)alpha(opacity=30)', $('op2').getStyle('filter')); 
    715         $('op2').setStyle({opacity:''}); 
    716         assertEqual('progid:DXImageTransform.Microsoft.Blur(strength=10)', $('op2').getStyle('filter')); 
    717         assertEqual('alpha(opacity=0)', $('op3').getStyle('filter')); 
     687        assertEqual('alpha(opacity=30)', $('op3').getStyle('filter')); 
    718688        assertEqual(0.3, $('op4-ie').getStyle('opacity')); 
    719689      } 
     
    722692      // which expected non-camelized strings) 
    723693      assertEqual("12px", $('style_test_1').getStyle('fontSize')); 
    724     }}, 
    725      
    726     testElementGetOpacity: function() {with(this) { 
    727       assertEqual(0.45, $('op1').setOpacity(0.45).getOpacity()); 
    728694    }}, 
    729695