Skip to content

Instantly share code, notes, and snippets.

@carbone
Last active February 14, 2018 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carbone/2849bf2d92dbb91351dc852c54b3d8a1 to your computer and use it in GitHub Desktop.
Save carbone/2849bf2d92dbb91351dc852c54b3d8a1 to your computer and use it in GitHub Desktop.
Add this to custom-fields-accordions.js
// 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