Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cssjanus.js work in a browser and compatible with closure compiler. #61

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions src/cssjanus.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function CSSJanus() {
* @param {boolean} [options.transformEdgeInUrl=false] Transform edges in URLs (e.g. 'left', 'right')
* @return {string} Transformed stylesheet
*/
transform: function ( css, options ) {
'transform': function ( css, options ) { // eslint-disable-line quote-props, (for closure compiler)
// Tokenizers
var noFlipSingleTokenizer = new Tokenizer( noFlipSingleRegExp, noFlipSingleToken ),
noFlipClassTokenizer = new Tokenizer( noFlipClassRegExp, noFlipClassToken ),
Expand Down Expand Up @@ -389,30 +389,35 @@ cssjanus = new CSSJanus();

/* Exports */

/**
* Transform a left-to-right stylesheet to right-to-left.
*
* This function is a static wrapper around the transform method of an instance of CSSJanus.
*
* @param {string} css Stylesheet to transform
* @param {Object|boolean} [options] Options object, or transformDirInUrl option (back-compat)
* @param {boolean} [options.transformDirInUrl=false] Transform directions in URLs (e.g. 'ltr', 'rtl')
* @param {boolean} [options.transformEdgeInUrl=false] Transform edges in URLs (e.g. 'left', 'right')
* @param {boolean} [transformEdgeInUrl] Back-compat parameter
* @return {string} Transformed stylesheet
*/
exports.transform = function ( css, options, transformEdgeInUrl ) {
var norm;
if ( typeof options === 'object' ) {
norm = options;
} else {
norm = {};
if ( typeof options === 'boolean' ) {
norm.transformDirInUrl = options;
}
if ( typeof transformEdgeInUrl === 'boolean' ) {
norm.transformEdgeInUrl = transformEdgeInUrl;
if ( typeof module !== 'undefined' && module.exports ) {
/**
* Transform a left-to-right stylesheet to right-to-left.
*
* This function is a static wrapper around the transform method of an instance of CSSJanus.
*
* @param {string} css Stylesheet to transform
* @param {Object|boolean} [options] Options object, or transformDirInUrl option (back-compat)
* @param {boolean} [options.transformDirInUrl=false] Transform directions in URLs (e.g. 'ltr', 'rtl')
* @param {boolean} [options.transformEdgeInUrl=false] Transform edges in URLs (e.g. 'left', 'right')
* @param {boolean} [transformEdgeInUrl] Back-compat parameter
* @return {string} Transformed stylesheet
*/
exports.transform = function ( css, options, transformEdgeInUrl ) {
var norm;
if ( typeof options === 'object' ) {
norm = options;
} else {
norm = {};
if ( typeof options === 'boolean' ) {
norm.transformDirInUrl = options;
}
if ( typeof transformEdgeInUrl === 'boolean' ) {
norm.transformEdgeInUrl = transformEdgeInUrl;
}
}
}
return cssjanus.transform( css, norm );
};
return cssjanus.transform( css, norm );
};
} else if ( typeof window !== 'undefined' ) {
// Allow cssjanus to be used in a browser.
window[ 'cssjanus' ] = cssjanus; // eslint-disable-line no-undef, dot-notation
}