Created
February 27, 2012 18:26
-
-
Save beakr/1925986 to your computer and use it in GitHub Desktop.
A gist providing the code for handling and saving the statuses of checkboxes using localStorage.
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
$(function(){ | |
// Get settings from local storage | |
var settings_pronounceable = localStorage.getItem("settings_pronounceable") == "true"; | |
var settings_capitals = localStorage.getItem("settings_capitals") == "true"; | |
var settings_numbers = localStorage.getItem("settings_numbers") == "true"; | |
var settings_symbols = localStorage.getItem("settings_symbols") == "true"; | |
// Configure settings display with values from local storage, or use defaults | |
$("#settings_pronounceable").prop("checked", settings_pronounceable); | |
$("#settings_capitals").prop("checked", settings_capitals); | |
$("#settings_numbers").prop("checked", settings_numbers); | |
$("#settings_symbols").prop("checked", settings_symbols); | |
// Handle changes of settings | |
$("#settings_pronounceable").change(function() { | |
pronounceable = $(this).prop("checked"); | |
localStorage.setItem("settings_pronounceable", pronounceable); | |
}); | |
$("#settings_capitals").change(function() { | |
capitals = $(this).prop("checked"); | |
localStorage.setItem("settings_capitals", capitals); | |
}); | |
$("#settings_numbers").change(function() { | |
numbers = $(this).prop("checked"); | |
localStorage.setItem("settings_numbers", numbers); | |
}); | |
$("#settings_symbols").change(function() { | |
symbols = $(this).prop("checked"); | |
localStorage.setItem("settings_symbols", symbols); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment