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

Use style sheet, remove URL rewriting #58

Merged
merged 1 commit into from
Jun 29, 2020
Merged
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
34 changes: 11 additions & 23 deletions ie11CustomProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,25 @@
//const regHasVar = /var\(/;
var regPseudos = /:(hover|active|focus|target|visited|link|:before|:after|:first-letter|:first-line)/;

onElement('link[rel="stylesheet"]', function (el) {
fetchCss(el.href, function (css) {
var newCss = rewriteCss(css);
if (css === newCss) return;
newCss = relToAbs(el.href, newCss);
el.disabled = true;
var style = document.createElement('style');
if (el.media) style.setAttribute('media', el.media);
el.parentNode.insertBefore(style, el);
activateStyleElement(style, newCss);
});
});

function foundStyle(el){
if (el.ieCP_polyfilled) return;
if (el.ieCP_elementSheet) return;
if (!el.sheet) return;
if (el.href) {
return fetchCss(el.href, function (css) {
var newCss = rewriteCss(css);
if (css === newCss) return;
activateStyleElement(el, newCss);
});
}

var css = el.innerHTML;
var newCss = rewriteCss(css);
if (css === newCss) return;
activateStyleElement(el, newCss);
}
onElement('style', foundStyle);
onElement('link[rel="stylesheet"]', foundStyle);
// immediate, to pass w3c-tests, bud its a bad idea
// addEventListener('DOMNodeInserted',function(e){ e.target.tagName === 'STYLE' && foundStyle(e.target); });

Expand All @@ -148,15 +145,6 @@
if (found.setters) addSetterElement(el, found.setters);
});

function relToAbs(base, css) {
return css.replace(/url\(([^)]+)\)/g, function($0, $1){
$1 = $1.trim().replace(/(^['"]|['"]$)/g,'');
if ($1.match(/^([a-z]+:|\/)/)) return $0;
base = base.replace(/\?.*/,'');
return 'url('+ base + './../' + $1 +')';
});
}

// ie has a bug, where unknown properties at pseudo-selectors are computed at the element
// #el::after { -content:'x'; } => getComputedStyle(el)['-content'] == 'x'
// should we add something like -ieVar-pseudo_after-content:'x'?
Expand Down Expand Up @@ -229,7 +217,7 @@
return {getters:getters, setters:setters};
}
function activateStyleElement(style, css) {
style.innerHTML = css;
style.sheet.cssText = css;
style.ieCP_polyfilled = true;
var rules = style.sheet.rules, i=0, rule; // cssRules = CSSRuleList, rules = MSCSSRuleList
while (rule = rules[i++]) {
Expand Down