-
-
Save carbone/2849bf2d92dbb91351dc852c54b3d8a1 to your computer and use it in GitHub Desktop.
Add this to custom-fields-accordions.js
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
// See https://customfields.zendesk.com/hc/en-us/articles/360000919672 | |
jQuery(document).ready(function() { | |
// Close the panel and remove all classes when called. | |
function close_accordion_section() { | |
jQuery('#custom-fields-accordion .accordion-section').removeClass('active'); | |
jQuery('#custom-fields-accordion .accordion-section-title').removeClass('active'); | |
jQuery('#custom-fields-accordion .accordion-section-content').slideUp(300).removeClass('open'); | |
} | |
jQuery('.accordion-section-title').click(function(e) { | |
// Store the clicked link | |
var currentAttrValue = jQuery(this).attr('href'); | |
// If open when clicked, close it. | |
if(jQuery(e.target).is('.active')) { | |
close_accordion_section(); | |
} | |
else { | |
// If closed, clear all classes. | |
close_accordion_section(); | |
// Add active class to section title | |
jQuery(this).addClass('active'); | |
// Open up the hidden content panel | |
jQuery('#custom-fields-accordion ' + currentAttrValue).slideDown(300).addClass('open'); | |
} | |
// Add an active classs to the whole wrapper. Not used by default, | |
// but added for convenience. | |
jQuery(this).closest('.accordion-section').addClass('active'); | |
// Don't try to follow the link. | |
e.preventDefault(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment