Skip to content

Commit d2a289f

Browse files
committed
feat: getValue function and use element.save() to execute crud save
1 parent 3a130e3 commit d2a289f

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/index.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* SPDX-License-Identifier: MIT
66
********************************************************************************/
77
import observer from '@cocreate/observer';
8-
import crud from '@cocreate/crud-client';
8+
// import crud from '@cocreate/crud-client';
99
import localStorage from '@cocreate/local-storage';
1010

1111
const themes = ["light", "dark"];
@@ -42,6 +42,12 @@ function init(linkTag) {
4242

4343
if (parse == 'true') {
4444
parseLinkCSS();
45+
linkTag.getValue = () => {
46+
const onlyUnique = (value, index, self) => {
47+
return self.indexOf(value) === index;
48+
};
49+
return parsedCSS.concat(linkCSS).filter(onlyUnique)
50+
}
4551
let elements = document.querySelectorAll("[class]");
4652
initElements(elements);
4753
observerInit();
@@ -260,7 +266,8 @@ function addNewRules() {
260266
parsedCSS.splice(low, 0, rule);
261267
}
262268
if (tempStyleList.length > 0)
263-
save();
269+
if (linkTag.save)
270+
linkTag.save();
264271
tempStyleList = [];
265272
}
266273

@@ -269,13 +276,14 @@ function save() {
269276
if (linkTag && linkTag.hasAttribute('object') && linkTag.getAttribute('save') != 'false') {
270277
clearTimeout(delayTimer);
271278
delayTimer = setTimeout(function () {
272-
const onlyUnique = (value, index, self) => {
273-
return self.indexOf(value) === index;
274-
};
275-
276-
let css = parsedCSS.concat(linkCSS).filter(onlyUnique);
277-
crud.save(linkTag, css.join('\r\n'));
278-
}, 3000);
279+
linkTag.save();
280+
// const onlyUnique = (value, index, self) => {
281+
// return self.indexOf(value) === index;
282+
// };
283+
284+
// let css = parsedCSS.concat(linkCSS).filter(onlyUnique);
285+
// crud.save(linkTag, css.join('\r\n'));
286+
}, 5000);
279287
}
280288
}
281289

0 commit comments

Comments
 (0)