mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-24 10:37:20 +00:00
Added function to dynamically apply stylesheets
This commit is contained in:
parent
9ec268cd2f
commit
441479f1b4
21
js/Utils.js
21
js/Utils.js
@ -270,4 +270,25 @@ utils.toggleClass = function(el,className,status) {
|
||||
}
|
||||
};
|
||||
|
||||
utils.applyStyleSheet = function(id,css) {
|
||||
var el = document.getElementById(id);
|
||||
if(document.createStyleSheet) { // Older versions of IE
|
||||
if(el) {
|
||||
el.parentNode.removeChild(el);
|
||||
}
|
||||
doc.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd",
|
||||
' <style id="' + id + '" type="text/css">' + css + '</style>'); // fails without
|
||||
} else { // Modern browsers
|
||||
if(el) {
|
||||
el.replaceChild(document.createTextNode(css), el.firstChild);
|
||||
} else {
|
||||
el = document.createElement("style");
|
||||
el.type = "text/css";
|
||||
el.id = id;
|
||||
el.appendChild(document.createTextNode(css));
|
||||
document.getElementsByTagName("head")[0].appendChild(el);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user