Messing with Anchors and LocalStorage for Options page
I'm trying to put together a chrome extension. The options page is really messy so far. Can somebody help me figure out what's going on?
The first time I load it, the links toggle like they're supposed to. But when I reload it, it fails to highlight the stuff localStorage was supposed to have remembered, and the anchors don't seem to be working. The problem might be with localStorage, which, I guess isn't jQuery... But I need help, and whoever is helping me needs to be able to read this stuff, so I figured this was the place to ask.
Do note that this only needs to run in Webkit. Yay for not worrying about IE6!
- <html>
- <head><title>Concerto for Chrome Options</title></head>
- <script type="text/javascript"
- src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
- </script>
- <style type="text/css">
- .feed {
- text-decoration: none;
- color: #DD0000;
- }
- .on {
- color: #00BB00;
- }
-
- #status{
- display:none;
- }
- </style>
- <script type="text/javascript">
- jQuery(document).ready(prepare_page);
- function prepare_page(){
- restore_options();
- jQuery(".feed").click(toggleFeed);
- }
- function toggleFeed(e) {
- e.preventDefault();
- $(this).toggleClass("on");
- }
- // Saves options to localStorage.
- function save_options() {
- var feeds = [];
- jQuery(".on").each(function() { feeds.push($(this).attr("id")); });
- localStorage.feeds = feeds;
-
- // Update status to let user know options were saved.
- $("#status").show();
- setTimeout(hideStatus, 800);
- function hideStatus() { $("#status").hide("fast"); }
- }
- // Restores select box state to saved value from localStorage.
- function restore_options() {
- var feeds = localStorage.feeds;
- if(!feeds) { return; }
- var count = 0;
- while (count < feeds.length) {
- jQuery("#"+feeds[count]).addClass("on");
- count = count+1;
- }
- }
- </script>
- <body>
- <p>Desired Feeds: <br/>
- <a href="" class="feed" id="feed1">Feed 1</a><br/>
- <a href="" class="feed" id="feed2">Feed 2</a><br/>
- <a href="" class="feed" id="feed3">Feed 3</a><br/>
- <a href="" class="feed" id="feed4">Feed 4</a><br/>
- <br/></p>
- <button onclick="save_options()">Save</button>
- <p id="status">Options Saved!</p>
- </body>
- </html>