Last active
March 4, 2021 14:56
-
-
Save mythz/db1996b4b87942fab84997dff73a702d to your computer and use it in GitHub Desktop.
Revisions
-
mythz revised this gist
Mar 3, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ let $ = (sel, el) => typeof sel === "string" ? (el || document).querySelector(sel) : sel || null, $$ = (sel, el) => Array.prototype.slice.call((el || document).querySelectorAll(sel)); function on(sel, handlers) { $$(sel).forEach(e => { -
mythz created this gist
Jan 19, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ let $ = sel => document.querySelector(sel), $$ = sel => document.querySelectorAll(sel); function on(sel, handlers) { $$(sel).forEach(e => { Object.keys(handlers).forEach(function (evt) { let fn = handlers[evt]; if (typeof evt === 'string' && typeof fn === 'function') { e.addEventListener(evt, fn.bind(e)); } }) }); } /* Usage Examples: */ $("#preview").innerHTML = "..."; $$(`a[href="${hash}"]`).forEach(el => el.classList.add('active')); on('.hero .tab', { click: function(evt) { this.classList.toggle('active') } }) on('form input', { keyup: function(evt) { } }) on('.menu select', { change: function(evt) { } })