From a53fdeb6a8e208fb5bc362286ab8457487d23714 Mon Sep 17 00:00:00 2001 From: Nathaniel Sabanski Date: Sun, 7 Jul 2024 14:44:35 -0700 Subject: [PATCH] More friendly any() with arrays. General cleanup. --- surreal.js | 66 +++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/surreal.js b/surreal.js index 5a40a8e..648e771 100644 --- a/surreal.js +++ b/surreal.js @@ -9,16 +9,17 @@ let $ = { // Convenience for internals. // Table of contents and convenient call chaining sugar. For a familiar "jQuery like" syntax. 🙂 // Check before adding new: https://youmightnotneedjquery.com/ sugar(e) { - if (e == null) { console.warn(`Surreal: Cannot use "${e}". Missing a character?`) } + if ($.isNodeList(e)) { e.forEach(_ => { $.sugar(_) }) } // Apply Surreal to nodes in array as well as the array. + if (!$.isNode(e) && !$.isNodeList(e)) { console.warn(`Surreal: Not a supported element / node / array of nodes "${e}"`); return e } if (e.hasOwnProperty('hasSurreal')) return e // Surreal already applied // General - e.run = (value) => { return $.run(e, value) } + e.run = (f) => { return $.run(e, f) } e.remove = () => { return $.remove(e) } // Classes and CSS. e.classAdd = (name) => { return $.classAdd(e, name) } - e.class_add = e.add_class = e.addClass = e.classAdd // Alias + e.class_add = e.add_class = e.addClass = e.classAdd // Alias e.classRemove = (name) => { return $.classRemove(e, name) } e.class_remove = e.remove_class = e.removeClass = e.classRemove // Alias e.classToggle = (name, force) => { return $.classToggle(e, name, force) } @@ -26,8 +27,8 @@ let $ = { // Convenience for internals. e.styles = (value) => { return $.styles(e, value) } // Events. - e.on = (name, fn) => { return $.on(e, name, fn) } - e.off = (name, fn) => { return $.off(e, name, fn) } + e.on = (name, f) => { return $.on(e, name, f) } + e.off = (name, f) => { return $.off(e, name, f) } e.offAll = (name) => { return $.offAll(e, name) } e.off_all = e.offAll // Alias e.disable = () => { return $.disable(e) } @@ -66,16 +67,17 @@ let $ = { // Convenience for internals. // Returns an Array of elements (so you can use methods like forEach/filter/map/reduce if you want). // Example: any('button') any(selector, start=document, warning=true) { - if (selector == null) return $.sugar([start.currentScript.parentElement]) // Just local me() in