Skip to content

Instantly share code, notes, and snippets.

@yratof
Last active January 2, 2016 14:19
Show Gist options
  • Save yratof/8315904 to your computer and use it in GitHub Desktop.
Save yratof/8315904 to your computer and use it in GitHub Desktop.
Function to add class to body depending on font-size
<script>
// Check if localStorage is supported
if ('localStorage' in window && typeof localStorage == 'object') {
jQuery(document).ready(function($) {
// Set the class if black-white is set
// Note that localStorage saves everything as strings
if (localStorage["black-white"] == "1") {
$('html').addClass('black-white');
}
// Register click listener for the button
$('.black-white-button').click(function() {
// Toggle black-white on and off
if (localStorage["black-white"] != "1") {
$('html').addClass('black-white');
localStorage["black-white"] = "1";
}
else {
$('html').removeClass('black-white');
localStorage["black-white"] = "0";
}
}); // - button click
if (localStorage["font-size"] == "1") {
$('html').addClass('font-size');
}
// Register click listener for the button
$('.font-size-button').click(function() {
// Toggle black-white on and off
if (localStorage["font-size"] != "1") {
$('html').addClass('font-size');
localStorage["font-size"] = "1";
}
else {
$('html').removeClass('font-size');
localStorage["font-size"] = "0";
}
}); // - button click
}); // - doc ready
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment