Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Node.js support, and be smarter about the YAHOO global in a browser.

commit 89883187a787f90bc26cf409a94d24826c528ace 1 parent 8a6d59e
@cpanel cpanel authored
Showing with 23 additions and 4 deletions.
  1. +23 −4 ports/js/cssmin.js
View
27 ports/js/cssmin.js
@@ -15,9 +15,8 @@
* The copyrights embodied in the content of this file are licensed
* by Yahoo! Inc. under the BSD (revised) open source license.
*/
-var YAHOO = YAHOO || {};
-YAHOO.compressor = YAHOO.compressor || {};
-YAHOO.compressor.cssmin = function (css, linebreakpos){
+( function() {
+var cssmin = function (css, linebreakpos) {
var startIndex = 0,
endIndex = 0,
@@ -178,4 +177,24 @@ YAHOO.compressor.cssmin = function (css, linebreakpos){
return css;
-};
+};
+
+//Node.js
+if ( typeof module === "object" && typeof exports === "object" && module.exports === exports ) {
+ exports.cssmin = cssmin;
+}
+
+//web browser
+else if ( typeof window === "object" ) {
+ if ( typeof YAHOO !== "object" ) {
+ YAHOO = { compressor: { cssmin:cssmin } };
+ }
+ else if ( typeof YAHOO.compressor !== "object" ) {
+ YAHOO.compressor = { cssmin:cssmin };
+ }
+ else {
+ YAHOO.compressor.cssmin = cssmin;
+ }
+}
+
+})();

2 comments on commit 8988318

@cdata

For even more awesome Node support, add a package.json and publish this bad boy to NPM. I was very excited to discover this, and I know others would be as well!

@au-phiware

This breaks the tests!!!

(It seems there is no window object in rhino.)

Please sign in to comment.
Something went wrong with that request. Please try again.