Created
August 24, 2016 09:53
-
-
Save kvendrik/d2545924bd76edefff07e0819606ddfa to your computer and use it in GitHub Desktop.
dataToggle.js
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
| const dataToggle = { | |
| init(){ | |
| this._els = document.querySelectorAll('[data-toggle]') || []; | |
| this._bindEvents(); | |
| }, | |
| _bindEvents(){ | |
| [].forEach.call(this._els, (el) => { | |
| el.addEventListener('click', () => this._toggleTarget(el), false); | |
| }); | |
| }, | |
| _toggleTarget(el){ | |
| const targetSelector = el.getAttribute('data-toggle-target'); | |
| const className = el.getAttribute('data-toggle'); | |
| const targetEl = document.querySelector(targetSelector); | |
| targetEl.classList.toggle(className); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment