I feel like I'm not getting the concept promises here. I'm trying to get external css used in a file and append it to the html. Then I'd like to do something with that content. What all am I doing wrong here? This is where I'm at after flailing and reading the docs for longer than I'd like to admit.
<script type="text/javascript">
$(function() {
$.when(convertPageCssToInlineStyle()).then(
alert(document.documentElement.outerHTML)
);
});
var convertPageCssToInlineStyle = function() {
var links = $("html").find("link[rel=stylesheet]");
links.attr("href", function(i, value) {
if (!window.location.origin)
window.location.origin = window.location.protocol + "//" + window.location.host + value;
$.when(
$.get(window.location.origin, function(response) {
$('<style />').text(response).appendTo($('head'));
})
);
});
};
</script>