Last active
January 2, 2016 14:19
-
-
Save yratof/8315904 to your computer and use it in GitHub Desktop.
Function to add class to body depending on font-size
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
<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