Skip to content

Commit e429931

Browse files
authored
Create ES3-scoped-css.js
1 parent e639c05 commit e429931

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ES3-scoped-css.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// if you are supporting Opera 9 or lower, Internet Explorer 8 or lower, or older Safari version
2+
3+
function generate_scoped_styles(doc) {
4+
doc = doc || document
5+
/** @type {HTMLCollection} */
6+
var styles = doc.getElementsByTagName("style")
7+
for (var i = 0; i < styles.length; i++) {
8+
if (styles[i].className != "scoped") continue
9+
var style = styles[i]
10+
var parent_el = style.parentElement
11+
parent_el.id = parent_el.id || "i" + (Math.random() * 1e9 | 0) // .toString(16)
12+
style.innerHTML = style.innerHTML.split("\\\&").join("#" + parent_el.id)
13+
}
14+
}
15+
generate_scoped_styles()

0 commit comments

Comments
 (0)