Skip to content

Commit

Permalink
New shortcut previousElementSibling selector.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnat authored Feb 16, 2024
1 parent 09eee94 commit bee189b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,26 @@ me().on("click", async event => {

## 💎 Conventions & Tips

* Many ideas can be plain HTML / CSS (ex: dropdowns).
* Many ideas can be done in HTML / CSS (ex: dropdowns)
* Surreal only exists to help write shorter vanilla JS
* `_` = for temporary or unused variables. Keep it short and sweet!
* `e`, `el`, `elt` = element
* `e`, `ev`, `evt` = event
* `f`, `fn` = function
* Scoping functions inside `<script>` (..or anything not scoped by `me()`)
* ⭐ Inside a `me()` event: `me().on('click', ev => { /* add and call function here */ })`

#### Scope new functions inside `<script>`
* ⭐ Inside an event: `me().on('click', ev => { /* add and call function here */ })`
* Or, use an inline module: `<script type="module">`
* Note: `me()` will no longer see `parentElement` so explicit selectors are required: `me(".mybutton")`
* Or, use backend code to generate unique names for anything not scoped by `me()`

#### Select a void element (`<input type="text" />`)
* Use: `me('-')` or `me('prev')` or `me('previous')`
* Shorthand for `me(document.currentScript.previousElementSibling)`
* Or, use a relative start.
* `<input e1 type="text" /><script>me('[e1]', me()).value = "hello"</script>`
* Similar pattern can be seen Surreal's companion project: [css-scope-inline](https://github.com/gnat/css-scope-inline)

## <a name="plugins"></a>🔌 Your own plugin

Feel free to modify Surreal for a project any way you like- but you can use plugins to effortlessly merge functions with new versions.
Expand Down

0 comments on commit bee189b

Please sign in to comment.