Skip to content

Instantly share code, notes, and snippets.

@zaurmag
Last active July 13, 2017 20:29
Show Gist options
  • Save zaurmag/b430017b4ed40fa5c5c98922a720315a to your computer and use it in GitHub Desktop.
Save zaurmag/b430017b4ed40fa5c5c98922a720315a to your computer and use it in GitHub Desktop.
Плагин вертикальное меню аккордеон
// ======= Plugin Accordeon Vmenu =======
(function($) {
jQuery.fn.dropdownMenu = function(options) {
options = $.extend({
destroy: false
}, options);
var make = function() {
if (!options.destroy) {
$(this).find('.sub-menu').hide();
$(this).find('li.current-menu-parent .sub-menu').show();
$(this).find('li.menu-item-has-children > a').after('<a class="openLink" href="#"></a>');
}
$(this).find('li.menu-item-has-children .openLink').on('click', function() {
var checkElement = $(this).next();
if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
checkElement.slideUp(200);
$(this).parent().removeClass('open');
return false;
}
if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
$(this).parent().removeClass('open');
$(this).find('ul:visible').slideUp(200);
checkElement.slideDown(200);
$(this).parent().addClass('open');
return false;
}
});
}
if (options.destroy) {
$(this).find('.openLink').remove();
$(this).find('.sub-menu').css('display', '');
}
return this.each(make);
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment