From a6fea839b024433c1f0d1592c03ef9f09d357c96 Mon Sep 17 00:00:00 2001 From: Nathaniel Sabanski Date: Sun, 4 Feb 2024 17:56:51 -0800 Subject: [PATCH] Event passing examples. New disable/enable calls. --- README.md | 23 +++++++++++------- example.html | 62 +++++++++++++++++++++++++++++++++++++++++-------- package.json | 2 +- surreal.js | 34 ++++++++++++++++++++------- tests/reset.css | 25 ++++++++++++++++---- 5 files changed, 113 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index a9e7eb4..27605bd 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ Or, 🌐 use the CDN: ` @@ -230,6 +231,12 @@ Looking for stuff [we recommend doing in vanilla JS](#no-surreal)? * Wraps `removeEventListener` * 🔗 `offAll` * ▶️ `me().offAll()` +* 🔗 `disable` + * ▶️ `me().disable()` + * Easy alternative to `off()`. Disables click, key, submit events. +* 🔗 `enable` + * ▶️ `me().enable()` + * Opposite of `disable()` * 🌐 `sleep` * ▶️ `await sleep(1000, ev => { alert(ev) })` * `async` version of `setTimeout` @@ -318,7 +325,7 @@ Append / Prepend elements. ## 🔎 Technical FAQ * Can I locally scope functions to ` - + + + +
📭 I stay open because of stopPropagation() + +
📬 I close dramatically from a child button async event + + +
+
diff --git a/package.json b/package.json index fa349be..1e969bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "surreal", - "version": "1.0.1", + "version": "1.0.2", "description": "Surreal", "repository": { "type": "git", diff --git a/surreal.js b/surreal.js index 3594098..260a119 100644 --- a/surreal.js +++ b/surreal.js @@ -1,4 +1,4 @@ -// Welcome to Surreal 1.0.1 +// Welcome to Surreal 1.0.2 // Documentation: https://github.com/gnat/surreal // Locality of Behavior (LoB): https://htmx.org/essays/locality-of-behaviour/ var $ = { // You can use a different name than "$", but you must change the reference in any plugins you use! @@ -8,7 +8,7 @@ var $ = { // You can use a different name than "$", but you must change the refe // 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(`Cannot use "${e}". Missing a character?`) } + if (e == null) { console.warn(`Surreal: Cannot use "${e}". Missing a character?`) } // General e.run = (value) => { return $.run(e, value) } @@ -28,6 +28,8 @@ var $ = { // You can use a different name than "$", but you must change the refe e.off = (name, fn) => { return $.off(e, name, fn) } e.offAll = (name) => { return $.offAll(e, name) } e.off_all = e.offAll + e.disable = (name) => { return $.disable(e) } + e.enable = (name) => { return $.enable(e) } e.trigger = (name) => { return $.trigger(e, name) } e.halt = () => { return $.halt(e) } @@ -54,7 +56,7 @@ var $ = { // You can use a different name than "$", but you must change the refe // me(selector=null, start=document, warning=true) { if (selector == null) return $.sugar(start.currentScript.parentElement) // Just local me() in