mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Implement serialized themes
This commit is contained in:
parent
f142a0b24a
commit
a7cd4f6791
2 changed files with 39 additions and 11 deletions
|
@ -676,6 +676,31 @@ class Contents {
|
|||
}.bind(this));
|
||||
}
|
||||
|
||||
_getStylesheetNode() {
|
||||
var styleEl;
|
||||
var key = "epubjs-inserted-css";
|
||||
|
||||
// Check if link already exists
|
||||
styleEl = this.document.getElementById("#"+key);
|
||||
if (!styleEl) {
|
||||
styleEl = this.document.createElement("style");
|
||||
styleEl.id = key;
|
||||
// Append style element to head
|
||||
this.document.head.appendChild(styleEl);
|
||||
}
|
||||
return styleEl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append stylesheet css
|
||||
* @param {string} serializedCss
|
||||
*/
|
||||
addStylesheetSerialized(serializedCss) {
|
||||
var styleEl;
|
||||
styleEl = this._getStylesheetNode();
|
||||
styleEl.innerText = serializedCss;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append stylesheet rules to a generate stylesheet
|
||||
* Array: https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule
|
||||
|
@ -685,19 +710,10 @@ class Contents {
|
|||
addStylesheetRules(rules) {
|
||||
var styleEl;
|
||||
var styleSheet;
|
||||
var key = "epubjs-inserted-css";
|
||||
|
||||
if(!this.document || !rules || rules.length === 0) return;
|
||||
|
||||
// Check if link already exists
|
||||
styleEl = this.document.getElementById("#"+key);
|
||||
if (!styleEl) {
|
||||
styleEl = this.document.createElement("style");
|
||||
styleEl.id = key;
|
||||
}
|
||||
|
||||
// Append style element to head
|
||||
this.document.head.appendChild(styleEl);
|
||||
styleEl = this._getStylesheetNode();
|
||||
|
||||
// Grab style sheet
|
||||
styleSheet = styleEl.sheet;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue