Created
February 24, 2020 04:37
-
-
Save jsmanifest/8ede3a994c225ed3d45ef009f7ca9563 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Theme() {} | |
Theme.prototype.createStylesheet = function() { | |
return { | |
header: { | |
color: '#333', | |
fontStyle: 'italic', | |
fontFamily: 'Roboto, sans-serif', | |
}, | |
background: { | |
backgroundColor: '#fff', | |
}, | |
button: { | |
backgroundColor: '#fff', | |
color: '#333', | |
}, | |
color: '#fff', | |
} | |
} | |
Theme.prototype.applyStylesheet = function(stylesheet) { | |
const bodyElem = document.querySelector('body') | |
const headerElem = document.getElementById('header') | |
const buttonElems = document.querySelectorAll('button') | |
this.applyStyles(bodyElem, stylesheet.background) | |
this.applyStyles(headerElem, stylesheet.header) | |
buttonElems.forEach((buttonElem) => { | |
this.applyStyles(buttonElem, stylesheet.button) | |
}) | |
} | |
Theme.prototype.applyStyles = function(elem, styles) { | |
for (let key in styles) { | |
if (styles.hasOwnProperty(key)) { | |
elem.style[key] = styles[key] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment