Fixed two issues with IE 7 filters.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Mon, 18 Apr 2011 07:36:55 +0000 (09:36 +0200)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Mon, 18 Apr 2011 07:36:55 +0000 (09:36 +0200)
* Fixed issue with multiple IE filters (IE 7 couldn't handle them if shortened).
* Fixed issue with restoring spaces in all IE filters.

lib/clean.js
test/unit-test.js

index 818cf96..dcc83e9 100644 (file)
@@ -66,7 +66,7 @@ var CleanCSS = {
     replace(/\s+/g, ' ') // multiple whitespace
     replace(/ !important/g, '!important') // whitespace before !important
     replace(/[ ]?,[ ]?/g, ',') // space with a comma
-    replace(/progid:[^(]+\(([^\)]+)/, function(match, contents) { // restore spaces inside IE filters (IE 7 issue)
+    replace(/progid:[^(]+\(([^\)]+)/g, function(match, contents) { // restore spaces inside IE filters (IE 7 issue)
       return match.replace(/,/g, ', ');
     })
     replace(/ ([+~>]) /g, '$1') // replace spaces around selectors
@@ -99,8 +99,8 @@ var CleanCSS = {
       else if (weight == 'bold') return 'font-weight:700';
       else return match;
     })
-    replace(/progid:DXImageTransform\.Microsoft\.(Alpha|Chroma)/g, function(match, contents) { // IE shorter filters
-      return contents.toLowerCase();
+    replace(/progid:DXImageTransform\.Microsoft\.(Alpha|Chroma)(\([^\)]+\))([;}'"])/g, function(match, filter, args, suffix) { // IE shorter filters but only if single (IE 7 issue)
+      return filter.toLowerCase() + args + suffix;
     })
     replace(/(\s|:)0(px|em|ex|cm|mm|in|pt|pc|%)/g, '$1' + '0') // zero + unit to zero
     replace(/(border|border-top|border-right|border-bottom|border-left|outline|background):none/g, '$1:0') // none to 0
index fc28d8f..681715d 100644 (file)
@@ -235,11 +235,15 @@ vows.describe('clean-units').addBatch({
       "a{filter:alpha(Opacity=80);-ms-filter:'alpha(Opacity=50)'}"
     ],
     'short chroma': [
-      'progid:DXImageTransform.Microsoft.Chroma(color=#919191)', 'chroma(color=#919191)'
+      'a{filter:progid:DXImageTransform.Microsoft.Chroma(color=#919191)}', 'a{filter:chroma(color=#919191)}'
     ],
     'matrix filter spaces': [
-      "progid:DXImageTransform.Microsoft.Matrix(M11=0.984, M22=0.984, M12=0.17, M21=-0.17, SizingMethod='auto expand')",
-      "progid:DXImageTransform.Microsoft.Matrix(M11=.984, M22=.984, M12=.17, M21=-.17, SizingMethod='auto expand')"
+      "a{filter:progid:DXImageTransform.Microsoft.Matrix(M11=0.984, M22=0.984, M12=0.17, M21=-0.17, SizingMethod='auto expand')",
+      "a{filter:progid:DXImageTransform.Microsoft.Matrix(M11=.984, M22=.984, M12=.17, M21=-.17, SizingMethod='auto expand')"
+    ],
+    'multiple filters (IE7 issue)': [
+      "a{filter:progid:DXImageTransform.Microsoft.Chroma(color=#919191) progid:DXImageTransform.Microsoft.Matrix(M11=0.984, M22=0.984, M12=0.17, M21=-0.17, SizingMethod='auto expand')}",
+      "a{filter:progid:DXImageTransform.Microsoft.Chroma(color=#919191) progid:DXImageTransform.Microsoft.Matrix(M11=.984, M22=.984, M12=.17, M21=-.17, SizingMethod='auto expand')}"
     ]
   }),
   'charsets': cssContext({