Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@klauskpm
Created June 2, 2017 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klauskpm/4aaec521cf83f72309293306c2b0b48d to your computer and use it in GitHub Desktop.
Save klauskpm/4aaec521cf83f72309293306c2b0b48d to your computer and use it in GitHub Desktop.
/**
* 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