Last active
September 20, 2017 22:54
-
-
Save honewatson/742a3b10de0d1d501825567f4e8b9e1e to your computer and use it in GitHub Desktop.
Simple JS Class Toggle
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 eventManager = (listeners, app={}) => (eventData, listener) => { | |
| try { | |
| listeners[listener](eventData, app); | |
| } | |
| catch(e) { | |
| console.trace(e); | |
| } | |
| } | |
| const toggle = classElement => { | |
| const {element, cls} = classElement; | |
| element.classList.toggle(cls); | |
| } | |
| window.ev = eventManager({toggle}); |
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
| <li onclick="return ev({element: this, cls: 'make-awesome'}, 'toggle');">Hello</li> | |
| <!-- ->> <li onclick="return ev({element: this, cls: 'make-awesome'}, 'toggle');" class="make-awesome">Hello</li> --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment