Skip to content

Instantly share code, notes, and snippets.

@adamsilver
Last active January 17, 2017 15:07
Show Gist options
  • Save adamsilver/9184c0f3dac027b6714e3a9ccc9728bc to your computer and use it in GitHub Desktop.
Save adamsilver/9184c0f3dac027b6714e3a9ccc9728bc to your computer and use it in GitHub Desktop.
Trying to make simple
function Toggler(button, toggleElement) {
this.toggleElement = toggleElement;
this.showing = true;
button.addEventListener('click', this.onToggleButtonClick.bind(this), false);
}
Toggler.prototype.onToggleButtonClick = function(e) {
this.toggle();
}
Toggle.prototype.toggle = function() {
if(this.showing) {
this.hide();
} else {
this.show();
}
}
Toggle.prototype.show = function() {
this.toggleElement.classList.remove('hide');
this.showing = true;
}
Toggle.prototype.hide = function() {
this.toggleElement.classList.add('hide');
this.showing = false;
}
var button = document.querySelector('.button');
var toggleElement = document.querySelector('.toggleElement');
var myToggler = new Toggler(button, toggleElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment