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

Changeset 7209

Show
Ignore:
Timestamp:
07/22/07 20:01:24 (1 year ago)
Author:
madrobby
Message:

Add support for full CSS inheritance in Effect.Morph. Closes #9054. [Tobie]

Files:

Legend:

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

    r7198 r7209  
    11*SVN* 
     2 
     3* Add support for full CSS inheritance in Effect.Morph.  Closes #9054.  [Tobie] 
     4  IMPORTANT: Note that this could potentially change the outcome of classname-based morphs, so be sure to check your morph effects if you use this feature.  
     5  For this feature, the new method Element#getStyles is introduced, which returns an objects which properties correspond to the CSS properties found in Element.CSS_PROPERTIES. Note that this method doesn't work seemlessly across browsers for certain non-measurable CSS properties, such as float.   
    26 
    37* Add the externalControlOnly option to the in-place editors to allow for external controls to exclusively trigger the in-place editing.  Closes #9024.  [tdd] 
  • spinoffs/scriptaculous/src/effects.js

    r6984 r7209  
    936936      style: {} 
    937937    }, arguments[1] || {}); 
    938     if (typeof options.style == 'string') { 
    939       if(options.style.indexOf(':') == -1) { 
    940         var cssText = '', selector = '.' + options.style; 
    941         $A(document.styleSheets).reverse().each(function(styleSheet) { 
    942           if (styleSheet.cssRules) cssRules = styleSheet.cssRules; 
    943           else if (styleSheet.rules) cssRules = styleSheet.rules; 
    944           $A(cssRules).reverse().each(function(rule) { 
    945             if (selector == rule.selectorText) { 
    946               cssText = rule.style.cssText; 
    947               throw $break; 
    948             } 
    949           }); 
    950           if (cssText) throw $break; 
     938     
     939    if (typeof options.style != 'string') this.style = $H(options.style); 
     940    else { 
     941      if (options.style.include(':')) 
     942        this.style = options.style.parseStyle(); 
     943      else { 
     944        this.element.addClassName(options.style); 
     945        this.style = $H(this.element.getStyles()); 
     946        this.element.removeClassName(options.style); 
     947        var css = this.element.getStyles(); 
     948        this.style = this.style.reject(function(style) { 
     949          return style.value == css[style.key]; 
    951950        }); 
    952         this.style = cssText.parseStyle(); 
    953         options.afterFinishInternal = function(effect){ 
     951        options.afterFinishInternal = function(effect) { 
    954952          effect.element.addClassName(effect.options.style); 
    955953          effect.transforms.each(function(transform) { 
    956             if(transform.style != 'opacity') 
    957               effect.element.style[transform.style] = ''; 
     954            effect.element.style[transform.style] = ''; 
    958955          }); 
    959956        } 
    960       } else this.style = options.style.parseStyle(); 
    961     } else this.style = $H(options.style) 
     957      } 
     958    } 
    962959    this.start(options); 
    963960  }, 
     961   
    964962  setup: function(){ 
    965963    function parseColor(color){ 
     
    10711069  }); 
    10721070   
    1073   if(Prototype.Browser.IE && this.indexOf('opacity') > -1
     1071  if(Prototype.Browser.IE && this.include('opacity')
    10741072    styleRules.opacity = this.match(/opacity:\s*((?:0|1)?(?:\.\d*)?)/)[1]; 
    10751073 
    10761074  return styleRules; 
    10771075}; 
     1076 
     1077if (document.defaultView && document.defaultView.getComputedStyle) { 
     1078  Element.getStyles = function(element) { 
     1079    var css = document.defaultView.getComputedStyle($(element), null); 
     1080    return Element.CSS_PROPERTIES.inject({}, function(styles, property) { 
     1081      styles[property] = css[property]; 
     1082      return styles; 
     1083    }); 
     1084  }; 
     1085} else { 
     1086  Element.getStyles = function(element) { 
     1087    element = $(element); 
     1088    var css = element.currentStyle, styles; 
     1089    styles = Element.CSS_PROPERTIES.inject({}, function(hash, property) { 
     1090      hash[property] = css[property]; 
     1091      return hash; 
     1092    }); 
     1093    if (!styles.opacity) styles.opacity = element.getOpacity(); 
     1094    return styles; 
     1095  }; 
     1096} 
    10781097 
    10791098Effect.Methods = { 
     
    11071126); 
    11081127 
    1109 $w('getInlineOpacity forceRerendering setContentZoom collectTextNodes collectTextNodesIgnoreClass').each(  
     1128$w('getInlineOpacity forceRerendering setContentZoom collectTextNodes collectTextNodesIgnoreClass getStyles').each(  
    11101129  function(f) { Effect.Methods[f] = Element[f]; } 
    11111130); 
  • spinoffs/scriptaculous/test/unit/effects_test.html

    r6981 r7209  
    2222      color: #fff; 
    2323      font-style: italic; 
    24       font-size: 20px; 
    2524      background: #000; 
    2625      opacity: 0.5; 
     26    } 
     27    body div.final { 
     28      font-size: 20px; 
    2729    } 
    2830  </style> 
  • spinoffs/scriptaculous/test/unit/element_test.html

    r6387 r7209  
    1313    blah { color:rgb(0, 255, 0); } 
    1414    #op2 { opacity:0.5;filter:alpha(opacity=50)progid:DXImageTransform.Microsoft.Blur(strength=10);} 
     15    #allStyles_1 {font-size: 12px;} 
     16    #allStyles_2 {opacity:0.5; filter:alpha(opacity=50);} 
     17    #allStyles_3 {opacity:0.5;} 
    1518  </style> 
    1619</head> 
     
    5962 
    6063<div id="perftest1"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></div> 
    61  
     64<div id="allStyles_1"></div> 
     65<div id="allStyles_2"></div> 
     66<div id="allStyles_3"></div> 
    6267<!-- Tests follow --> 
    6368<script type="text/javascript" language="javascript" charset="utf-8"> 
     
    96101        "font:12px/15pt Verdana;opacity:0.4;border:4px dotted red".parseStyle(); 
    97102      },100); 
     103    }}, 
     104 
     105    testGetStyles: function() { with(this) { 
     106      assertEqual('12px', $('allStyles_1').getStyles().fontSize); 
     107      assertEqual(1, parseFloat($('allStyles_1').getStyles().opacity)); 
     108      assertEqual(0.5, parseFloat($('allStyles_2').getStyles().opacity)); 
     109      assertEqual(0.5, parseFloat($('allStyles_3').getStyles().opacity)); 
    98110    }} 
    99111