Created
December 21, 2021 19:45
-
-
Save coulterpeterson/f5d91aead41819e59e77fdaab439bae3 to your computer and use it in GitHub Desktop.
Open Divi Toggle with Button Module OR With Direct Anchor Link to Page
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> | |
// What to do when the read more buttons are clicked (they're toggles now) | |
(function($) { | |
jQuery(document).ready(function() { | |
let menuLinks = jQuery('a.read-more'), | |
toggles = jQuery('.et_pb_toggle'); | |
menuLinks.each(function(){ | |
jQuery(this).click(function(){ | |
let clickedLinkTarget = jQuery(this).attr('href'); | |
if(jQuery( '.et_pb_toggle' + clickedLinkTarget ).hasClass('et_pb_toggle_close')) { | |
jQuery( '.et_pb_toggle' + clickedLinkTarget ) | |
.removeClass('et_pb_toggle_close') | |
.addClass('et_pb_toggle_open'); | |
} else { | |
jQuery( '.et_pb_toggle' + clickedLinkTarget ) | |
.removeClass('et_pb_toggle_open') | |
.addClass('et_pb_toggle_close'); | |
} | |
}) | |
}) | |
}); | |
})(jQuery); | |
// What to do when a story toggle link is taken to the page | |
(function($){ | |
jQuery(window).load(function(){ | |
let et_hash = window.location.hash; | |
if(window.location.hash) { | |
jQuery( '.et_pb_toggle' + et_hash ) | |
.removeClass('et_pb_toggle_close') | |
.addClass('et_pb_toggle_open'); | |
// Scroll up a tad | |
window.scrollBy(0, -120); | |
} | |
}); | |
})(jQuery); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment