Skip to content

Commit

Permalink
shorter alpha opacity filter, more tests, case-insensitive background…
Browse files Browse the repository at this point in the history
…-position replace
  • Loading branch information
stoyan committed May 15, 2010
1 parent 77b9f9d commit 81e1d7f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ports/js/cssmin.js
Expand Up @@ -52,6 +52,10 @@ YAHOO.compressor.cssmin = function (css, linebreakpos) {
match = match.replace("___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_" + i + "___", comments[i]);
}
}

// minify alpha opacity in filter strings
match = match.replace(/progid:DXImageTransform\.Microsoft\.Alpha\(Opacity=/gi, "alpha(opacity=");

preservedTokens.push(match);
return quote + "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.length - 1) + "___" + quote;
});
Expand Down Expand Up @@ -161,6 +165,8 @@ YAHOO.compressor.cssmin = function (css, linebreakpos) {
}
});

// shorter opacity IE filter
css = css.replace(/progid:DXImageTransform\.Microsoft\.Alpha\(Opacity=/gi, "alpha(opacity=");

// Remove empty rules.
css = css.replace(/[^\};\{\/]+\{\}/g, "");
Expand Down
8 changes: 7 additions & 1 deletion src/com/yahoo/platform/yui/compressor/CssCompressor.java
Expand Up @@ -78,6 +78,9 @@ public void compress(Writer out, int linebreakpos)
}
}

// minify alpha opacity in filter strings
token = token.replaceAll("(?i)progid:DXImageTransform.Microsoft.Alpha\\(Opacity=", "alpha(opacity=");

preservedTokens.add(token);
String preserver = quote + "___YUICSSMIN_PRESERVED_TOKEN_" + (preservedTokens.size() - 1) + "___" + quote;
m.appendReplacement(sb, preserver);
Expand Down Expand Up @@ -163,7 +166,7 @@ public void compress(Writer out, int linebreakpos)
css = css.replaceAll(":0 0 0(;|})", ":0$1");
css = css.replaceAll(":0 0(;|})", ":0$1");
// Replace background-position:0; with background-position:0 0;
css = css.replaceAll("background-position:0(;|})", "background-position:0 0$1");
css = css.replaceAll("(?i)background-position:0(;|})", "background-position:0 0$1");

// Replace 0.6 to .6, but only when preceded by : or a white-space
css = css.replaceAll("(:|\\s)0+\\.(\\d+)", "$1.$2");
Expand Down Expand Up @@ -210,6 +213,9 @@ public void compress(Writer out, int linebreakpos)
m.appendTail(sb);
css = sb.toString();

// shorter opacity IE filter
css = css.replaceAll("(?i)progid:DXImageTransform.Microsoft.Alpha\\(Opacity=", "alpha(opacity=");

// Remove empty rules.
css = css.replaceAll("[^\\}\\{/;]+\\{\\}", "");

Expand Down
2 changes: 2 additions & 0 deletions tests/background-position.css
@@ -0,0 +1,2 @@
a {background-position: 0 0 0 0;}
b {BACKGROUND-POSITION: 0 0;}
1 change: 1 addition & 0 deletions tests/background-position.css.min
@@ -0,0 +1 @@
a{background-position:0 0}b{background-position:0 0}
14 changes: 14 additions & 0 deletions tests/opacity-filter.css
@@ -0,0 +1,14 @@
/* example from https://developer.mozilla.org/en/CSS/opacity */
pre { /* make the box translucent (80% opaque) */
border: solid red;
opacity: 0.8; /* Firefox, Safari(WebKit), Opera */
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)"; /* IE 8 */
filter: PROGID:DXImageTransform.Microsoft.Alpha(Opacity=80); /* IE 4-7 */
zoom: 1; /* set "zoom", "width" or "height" to trigger "hasLayout" in IE 7 and lower */
}

/** and again */
code {
-ms-filter: "PROGID:DXImageTransform.Microsoft.Alpha(Opacity=80)"; /* IE 8 */
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80); /* IE 4-7 */
}
1 change: 1 addition & 0 deletions tests/opacity-filter.css.min
@@ -0,0 +1 @@
pre{border:solid red;opacity:.8;-ms-filter:"alpha(opacity=80)";filter:alpha(opacity=80);zoom:1}code{-ms-filter:"alpha(opacity=80)";filter:alpha(opacity=80)}

0 comments on commit 81e1d7f

Please sign in to comment.