Skip to content

Commit 52888c7

Browse files
committed
Add static method, dataset and options to local stylesheets
1 parent 9d301ec commit 52888c7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

CSSObject/CSSObject.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,31 @@ import Stylesheet from "./parser/Stylesheet.js"
4949
return this
5050
}
5151

52+
/**
53+
* get static stylesheet
54+
* @param {string} string css text
55+
* @param {object} callback callback
56+
*/
57+
static(string, callback) {
58+
let style = new Stylesheet(string)
59+
return callback(style)
60+
}
61+
5262
/**
5363
* get local stylesheets
5464
* @param {object} callback callback function
5565
* @param {boolean} all return all stylesheets in callback
5666
*/
5767
local(callback, all = false) {
5868
let styles = []
59-
Object.values(document.styleSheets).forEach(sheet => {
69+
Object.values(document.styleSheets).forEach((sheet, index) => {
6070
if (sheet.ownerNode != null || sheet.ownerNode.childNodes.length > 0)
6171
if (sheet.ownerNode.innerText != "") {
62-
let style = new Stylesheet(sheet.ownerNode.innerText)
72+
let filename = sheet.ownerNode.dataset.name || null
73+
if (this._options.only_files.length == 0 && this._options.ignore_files.includes(filename)) return
74+
if (this._options.only_files.length > 0 && !this._options.only_files.includes(filename)) return
75+
76+
let style = new Stylesheet(sheet.ownerNode.innerText, filename)
6377
all ? styles.push(style) : callback(style)
6478
}
6579
})

0 commit comments

Comments
 (0)