Skip to content

Instantly share code, notes, and snippets.

@mrkrand
Last active April 5, 2016 14:44
Show Gist options
  • Save mrkrand/91fcf32088d81a00a4864606c1ac3797 to your computer and use it in GitHub Desktop.
Save mrkrand/91fcf32088d81a00a4864606c1ac3797 to your computer and use it in GitHub Desktop.
/* Generic dropdown script */
$.fn.edaDropdown = function() {
var dropDowns = this;
dropDowns.each(function( index, element ) {
jQuery(this).find('> span').click(function(e){
e.stopPropagation();
var currentOpen = false;
var a = jQuery(this);
if (a.parent().hasClass('open')) {
currentOpen = true;
}
dropDowns.removeClass('open');
if(!currentOpen) {
a.parent().addClass('open');
}
});
});
jQuery("body").click(function(){
dropDowns.removeClass('open');
});
};
/* Dropdown init */
jQuery('.dropdown').edaDropdown();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment