Created
June 2, 2017 16:01
-
-
Save klauskpm/4aaec521cf83f72309293306c2b0b48d to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Created by klauskpm | |
*/ | |
(function () { | |
'use strict'; | |
app | |
.factory('contrastService', ContrastService); | |
ContrastService.$inject = ['storageService']; | |
function ContrastService(storageService) { | |
var storage = 'contrastState'; | |
var cssClass = 'contrast'; | |
var service = { | |
currentState: null, | |
checkState: checkContrast, | |
getState: getContrastState, | |
setState: setContrastState, | |
toggleState: toggleContrast | |
}; | |
window.toggleContrast = function() { service.toggleState() }; | |
return service; | |
function checkContrast() { | |
this.currentState = this.getState(); | |
updateView(this.currentState); | |
} | |
function getContrastState() { | |
var state = storageService.get(storage); | |
return !(typeof state === 'undefined' || !state); | |
} | |
function setContrastState(state) { | |
storageService.set(storage, state); | |
this.currentState = state; | |
updateView(state); | |
} | |
function updateView(state) { | |
var body = document.getElementsByTagName('body')[0]; | |
if (state) | |
body.classList.add(cssClass); | |
else | |
body.classList.remove(cssClass); | |
} | |
function toggleContrast() { | |
this.setState(!this.currentState); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment