Skip to content

Instantly share code, notes, and snippets.

@zdimaz
Last active September 2, 2019 10:23
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 zdimaz/373be229f95c5462add222ac74f2d801 to your computer and use it in GitHub Desktop.
Save zdimaz/373be229f95c5462add222ac74f2d801 to your computer and use it in GitHub Desktop.
accordion plugin jq
self.jqueryExtend();
/*
*
*
* Accordion
*
*/
jqueryExtend: function() {
$.fn.extend({
/**
** accordion plugin
** @param toggle - set to true, if need to be toggle
** @return jquery
**/
accordion: function(toggle) {
return this.each(function() {
var $this = $(this),
active = $this.children('.js_accordion_title.active').length ? $this.children('.js_accordion_title.active') : null;
$this.children('.js_accordion_title').not(active).next().hide();
$this.on('click', '.js_accordion_title', function() {
var $this = $(this);
if (!toggle) {
if ($(this).hasClass('active')) {
$(this).removeClass('active')
.siblings('.js_accordion_title')
.removeClass('active')
.end()
.siblings('.js_accordion_content')
.stop()
.slideUp();
} else {
$(this).addClass('active')
.siblings('.js_accordion_title')
.removeClass('active')
.end()
.next('.js_accordion_content')
.stop()
.slideDown(500)
.siblings('.js_accordion_content')
.stop()
.slideUp();
}
} else {
$(this).toggleclass('active').next().stop().slidetoggle();
}
});
});
}
});
},
if ($(".js_accordion").length) {
$(".js_accordion").accordion();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment