Last active
January 17, 2017 15:07
-
-
Save adamsilver/9184c0f3dac027b6714e3a9ccc9728bc to your computer and use it in GitHub Desktop.
Trying to make simple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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