From 784d449e33903930d19c65f43d4a6c0b46d32530 Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Tue, 19 Nov 2024 10:35:27 +0000 Subject: [PATCH] Make the 'all feeds' checkbox affect local storage Fixes #58 Add functionality to update and check the "all-feeds" key in local storage. * Add code to update the "all-feeds" key in local storage when the "all feeds" checkbox is clicked. * Add code to check local storage for the "all-feeds" key value on page load and set the "all feeds" checkbox accordingly. * Add code to use the "all-feeds" key in local storage to determine the display of individual feeds on page load. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/PerlToolsTeam/planetperl/issues/58?shareId=XXXX-XXXX-XXXX-XXXX). --- docs/script.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/script.js b/docs/script.js index 7f85b518..2ff3d940 100644 --- a/docs/script.js +++ b/docs/script.js @@ -84,12 +84,25 @@ $(document).ready(function() { } }); - // Set the "All Feeds" checkbox to checked when the page loads - $('#all-feeds').prop('checked', true); + // Check localStorage for the "all-feeds" key value on page load + var allFeedsValue = localStorage.getItem('all-feeds'); + if (allFeedsValue === "true") { + $('#all-feeds').prop('checked', true); + } else if (allFeedsValue === "false") { + $('#all-feeds').prop('checked', false); + checkboxes.each(function() { + $(this).prop('checked', false); + $('.' + $(this).attr('id')).hide(); + }); + } else { + localStorage.setItem('all-feeds', "true"); + $('#all-feeds').prop('checked', true); + } // Add event listener for "All Feeds" checkbox $('#all-feeds').click(function() { var isChecked = $(this).prop('checked'); + localStorage.setItem('all-feeds', isChecked); $('.feed-checkbox').each(function() { $(this).prop('checked', isChecked); if (isChecked) {