Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. function Toggler(button, toggleElement) {
  2. this.toggleElement = toggleElement;
  3. this.showing = true;
  4. button.addEventListener('click', this.onToggleButtonClick.bind(this), false);
  5. }
  6.  
  7. Toggler.prototype.onToggleButtonClick = function(e) {
  8. this.toggle();
  9. }
  10.  
  11. Toggle.prototype.toggle = function() {
  12. if(this.showing) {
  13. this.hide();
  14. } else {
  15. this.show();
  16. }
  17. }
  18.  
  19. Toggle.prototype.show = function() {
  20. this.toggleElement.classList.remove('hide');
  21. this.showing = true;
  22. }
  23.  
  24. Toggle.prototype.hide = function() {
  25. this.toggleElement.classList.add('hide');
  26. this.showing = false;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement