-
- /**
- * @param $out - the tmp html content
- *
- */
- function interpritAppendedStylesheet ($out) {
- var stylesheet = $out[0].styleSheets[0]; // first stylesheet
- for(r in stylesheet.cssRules){
- try{
- var rule = stylesheet.cssRules[r];
- if(!isNaN(rule))break; // make sure the rule exists
- var $destObj = $out.find(rule.selectorText);
- var obj = rule.cssText.replace(rule.selectorText, '');
- obj = obj.replace('{','').replace('}',''); // clean up the { and }'s
- var styles = obj.split(";"); // separate each
- $destObj.css(createCSSRuleObject(styles)); // do the inline styling
- } catch (e) { }
- }
- };
-
-
- function isPatternRelevant (newHTML, pattern, relevantPatterns) {
- if( newHTML.indexOf(pattern) > -1 )
- relevantPatterns.push(new RegExp(pattern,"i"));
- };
-
- /**
- * The main method - inflinify
- * this utilizes two text areas and a div for final output -
- * (1) css input textarea for the css to apply
- * (2) html content for the css to apply TO
- */
- function inlinify (input) {
- var tmpWindow = window.open("", "tmpHtml", "width=0,height=0");
- window.blur(); // re focus on main window
- var tmpDoc = tmpWindow.document; // create a window that we can use
- var $tmpDoc = jQuery(tmpDoc); // jquerify the temp window
-
- tmpDoc.write(input); // write the HTML out to a new window doc
- interpritAppendedStylesheet($tmpDoc); // apply styles to the document just created
- $tmpDoc.find("style").remove(); // sanitize all style tags present prior to the transformation
-
- var newHTML = $tmpDoc.find("html").html();
- tmpWindow.close();
-
- var relevantPatterns = [];
- isPatternRelevant(newHTML, "href=\"", relevantPatterns);
- isPatternRelevant(newHTML, "src=\"", relevantPatterns);
- return sanitize( newHTML, relevantPatterns );
- };