Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created February 24, 2020 04:37
Show Gist options
  • Save jsmanifest/8ede3a994c225ed3d45ef009f7ca9563 to your computer and use it in GitHub Desktop.
Save jsmanifest/8ede3a994c225ed3d45ef009f7ca9563 to your computer and use it in GitHub Desktop.
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