Created
February 12, 2026 10:17
-
-
Save Firsh/ec12afc83547d13b4113ed6273a9e95e to your computer and use it in GitHub Desktop.
Simple JIG deeplinking for the filtering feature
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
| jQuery(document).ready(function($) { | |
| // Prevent auto-scrolling when hash changes | |
| if (window.location.hash) { | |
| setTimeout(function() { | |
| window.scrollTo(0, 0); | |
| }, 1); | |
| } | |
| // Function to activate filter based on hash | |
| function activateFilterFromHash() { | |
| var hash = window.location.hash.substring(1); // Remove the # symbol | |
| if (hash) { | |
| var $targetButton = $('.jig-filterButton[data-filter-slug="' + hash + '"]'); | |
| if ($targetButton.length > 0) { | |
| // Trigger click on the matching filter button | |
| $targetButton.trigger('click'); | |
| } | |
| } | |
| } | |
| // Activate filter on page load if hash exists | |
| activateFilterFromHash(); | |
| // Delegated click handler for filter buttons | |
| $(document).on('click', '.jig-filterButton', function() { | |
| var filterSlug = $(this).attr('data-filter-slug'); | |
| if (filterSlug) { | |
| // Update URL hash without scrolling | |
| if (history.replaceState) { | |
| // Use replaceState initially to prevent adding to history on first click | |
| // Then use regular hash update for subsequent clicks | |
| window.location.hash = filterSlug; | |
| } else { | |
| // Fallback for older browsers | |
| window.location.hash = filterSlug; | |
| } | |
| // Prevent any potential scrolling | |
| return false; | |
| } | |
| }); | |
| // Handle browser back/forward buttons | |
| $(window).on('hashchange', function() { | |
| activateFilterFromHash(); | |
| // Prevent scrolling on hash change | |
| window.scrollTo(0, $(window).scrollTop()); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment