Skip to content

Commit 510343b

Browse files
committed
fix: if parser not explicitly set to false observer will observe classes
1 parent f761027 commit 510343b

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/index.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,40 @@ function init(linkTag) {
3838
document.head.appendChild(styleEl);
3939
styleElSheet = styleEl.sheet;
4040

41+
// TODO get from @cocreate/config
4142
if (parse == undefined)
4243
parse = localStorage.getItem('cssParser')
44+
if (parse === 'false' || parse === false)
45+
return
4346

44-
if (parse == 'true') {
45-
parseLinkCSS();
46-
linkTag.getValue = () => {
47-
const onlyUnique = (value, index, self) => {
48-
return self.indexOf(value) === index;
49-
};
47+
parseLinkCSS();
5048

51-
const urlObject = new URL(linkTag.href);
52-
const pathParts = urlObject.pathname.split("/");
49+
linkTag.getValue = () => {
50+
const onlyUnique = (value, index, self) => {
51+
return self.indexOf(value) === index;
52+
};
5353

54-
let data = {}
55-
data.name = pathParts[pathParts.length - 1];
56-
data.path = urlObject.pathname.replace(data.name, '');
57-
data.pathname = urlObject.pathname;
58-
data.src = parsedCSS.concat(linkCSS).filter(onlyUnique).join('\r\n');
59-
data['content-type'] = 'text/css';
54+
const urlObject = new URL(linkTag.href);
55+
const pathParts = urlObject.pathname.split("/");
56+
57+
let data = {}
58+
data.name = pathParts[pathParts.length - 1];
59+
data.path = urlObject.pathname.replace(data.name, '');
60+
data.pathname = urlObject.pathname;
61+
data.src = parsedCSS.concat(linkCSS).filter(onlyUnique).join('\r\n');
62+
data['content-type'] = 'text/css';
63+
64+
return data
65+
}
66+
67+
if (parse === 'true' || parse === true) {
6068

61-
return data
62-
}
6369
let elements = document.querySelectorAll("[class]");
6470
initElements(elements);
65-
observerInit();
6671
}
6772

73+
observerInit();
74+
6875
}
6976
}
7077

0 commit comments

Comments
 (0)