Permalink
Browse files

Add opacity for IE8/9

Perhaps a hasLayout hack would be good for IE8 as well, lest people think it doesn't work?
What's the safest way?
  • Loading branch information...
1 parent f2c144b commit 7d2a1ba1e5f7edca1ad72db0355d2af6c2fecfe2 Hari Karam Singh committed Nov 3, 2011
Showing with 37 additions and 0 deletions.
  1. +4 −0 CssCrush.plugins
  2. +33 −0 plugins/ie-opacity.php
View
@@ -14,8 +14,12 @@ plugins[] = ie-clip.php
; IE filter shorthand
plugins[] = ie-filter.php
+; Add filter and other ie8/9 code for opacity
+plugins[] = ie-opacity.php
+
; Opaque fallback colors for clients that don't support RGBA
plugins[] = rgba-fallback.php
; HSL shim - converts HSL values to hex codes
plugins[] = hsl-to-hex.php
+
View
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Add opacity for IE8/9
+ *
+ * Before:
+ * opacity: 0.45;
+ *
+ * After:
+ * opacity: 0.45;
+ * -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=45);
+ * filter: alpha(opacity=45);
+ */
+
+CssCrush::addRuleMacro( 'csscrush_opacity' );
+
+function csscrush_opacity ( CssCrush_Rule $rule ) {
+ if ( $rule->propertyCount( 'opacity' ) < 1 ) {
+ return;
+ }
+ $new_set = array();
+ foreach ( $rule as $declaration ) {
+ $new_set[] = $declaration;
+ if ($declaration->property != 'opacity') {
+ continue;
+ }
+
+ $opacity = (float)$declaration->value;
+ $opacityX100 = round( $opacity * 100 );
+ $new_set[] = $rule->createDeclaration( '-ms-filter', '"progid:DXImageTransform.Microsoft.Alpha(Opacity='.$opacityX100.')"' );
+ $new_set[] = $rule->createDeclaration( 'filter', 'alpha(opacity='.$opacityX100.')' );
+ }
+ $rule->declarations = $new_set;
+}

0 comments on commit 7d2a1ba

Please sign in to comment.