Skip to content

Instantly share code, notes, and snippets.

@AlexMold
Created August 9, 2016 16:11
Show Gist options
  • Save AlexMold/1106223f7edf0cc18553582ae43155f3 to your computer and use it in GitHub Desktop.
Save AlexMold/1106223f7edf0cc18553582ae43155f3 to your computer and use it in GitHub Desktop.
class DropdownCabinet {
constructor(){
this.$toggler = $('.js-dropdown-toggler');
this.$list = $('.js-dropdown-list');
this.$html = $('html');
this.init();
}
init(){
this.bind();
}
toggler(){
this.$toggler.click(function(e){
var current = $(this).next('.js-dropdown-list');
current.toggleClass('is-open');
$('.js-dropdown-list').not(current).removeClass('is-open');
e.stopPropagation();
});
}
closeAll(){
let _this = this;
this.$html.click(function(){
if (_this.$list.hasClass('is-open')) {
_this.$list.removeClass('is-open');
}
});
this.$list.click(function(e){
e.stopPropagation();
});
}
bind(){
this.toggler();
this.closeAll();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment