This function simply converts your ordinary external stylesheet setting to an inline setting, saving you valuable seconds of your time.
A form to do the work for you is available at
klenwell sos.
// css_inliner
/*____________________________________________________________________________*/
function css_inliner(string)
{
// *** DATA
// Debug
var _debug = 0;
// Regex
var re_replace = /(\n|\/\*.*\*\/)/igm;
var re_deshell = /\{(.*)\}/i;
var re_tidy = /(\;\s+)/;
// Internal
var _contents = '';
// Return
var inline_css = '';
// *** MANIPULATE
// debug
if ( _debug ) alert("input: " + string);
// remove newlines
string = string.replace(re_replace, ' ');
if ( _debug ) alert("single line: " + string);
// deshell brackets
matched = string.match(re_deshell);
if ( matched == null )
{
alert('no result: make sure your input was in the proper .class { rule:value;... } format');
return 'invalid format';
}
else
{
string = matched[1];
}
if ( _debug ) alert("deshelled: " + string);
// tidy inline
inline = string.replace(re_tidy, '; ');
if ( _debug ) alert("tidy: " + string);
// sanity check
if ( inline == '' || inline == null )
{
alert('no result: make sure your input was in the proper .class { rule:value;... } format');
return 'invalid format';
}
inline = 'style="' + js_trim(inline) + '"';
// *** RETURN
return inline;
} // end Fx
/*____________________________________________________________________________*/