Skip to content

Commit

Permalink
Cleanup, less wordy.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnat authored Jun 4, 2024
1 parent c955f19 commit a616504
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ For devs who love ergonomics! You may appreciate Surreal if:
* `me()` can be used directly as a single element (like `querySelector()` or `$()`)
* `any()` can use: `for` / `forEach` / `filter` / `map` (like `querySelectorAll()` or `$()`)
* πŸŒ— No forced style. Use: `classAdd` or `class_add` or `addClass` or `add_class`
* Use `camelCase` (Javascript) or `snake_case` (Python, Rust, PHP, Ruby, SQL, *CSS*).
* Use `camelCase` (Javascript) or `snake_case` (Python, Rust, PHP, Ruby, SQL, CSS).

### πŸ€” Why use `me()` / `any()` instead of `$()`
* πŸ’‘ Solves the classic jQuery bloat problem: Am I getting 1 element or an array of elements?
Expand Down Expand Up @@ -89,9 +89,9 @@ Or, 🌐 via CDN: `<script src="https://cdn.jsdelivr.net/gh/gnat/surreal@main/su
* `me("body")` Gets `<body>`
* `me(".button")` Gets the first `<div class="button">...</div>`. To get all of them use `any()`
* Select **one or more** elements as an array: `any(...)`
* Similar to `me()` but guaranteed to return an array (or empty array).
* `any(".foo")` Gets all matching elements, such as: `<div class="foo">...</div>`
* Feel free to convert between arrays of elements and single elements: `any(me())`, `me(any(".something"))`
* Like `me()` but guaranteed to return an array (or empty array).
* `any(".foo")` Get all matching elements, such as: `<div class="foo">...</div>`
* Convert between arrays of elements and single elements: `any(me())`, `me(any(".something"))`

### πŸ”₯ DOM Functions

Expand Down Expand Up @@ -202,26 +202,27 @@ Looking for stuff [we recommend doing in vanilla JS](#no-surreal)?
* πŸ”— `remove`
* ▢️ `me().remove()`
* ▢️ `any('button').remove()`
* πŸ”— `classAdd` πŸ” `class_add` πŸ” `addClass` πŸ” `add_class`
* πŸ”— `classAdd` πŸŒ— `class_add` πŸŒ— `addClass` πŸŒ— `add_class`
* ▢️ `me().classAdd('active')`
* Leading `.` is **optional**
* These are the same: `me().classAdd('active')` πŸ” `me().classAdd('.active')`
* πŸ”— `classRemove` πŸ” `class_remove` πŸ” `removeClass` πŸ” `remove_class`
* Same thing: `me().classAdd('active')` πŸŒ— `me().classAdd('.active')`
* πŸ”— `classRemove` πŸŒ— `class_remove` πŸŒ— `removeClass` πŸŒ— `remove_class`
* ▢️ `me().classRemove('active')`
* πŸ”— `classToggle` πŸ” `class_toggle` πŸ” `toggleClass` πŸ” `toggle_class`
* πŸ”— `classToggle` πŸŒ— `class_toggle` πŸŒ— `toggleClass` πŸŒ— `toggle_class`
* ▢️ `me().classToggle('active')`
* πŸ”— `styles`
* ▢️ `me().styles('color: red')` Add style.
* ▢️ `me().styles({ 'color':'red', 'background':'blue' })` Add multiple styles.
* ▢️ `me().styles({ 'background':null })` Remove style.
* πŸ”— `attribute` πŸ” `attributes` πŸ” `attr`
* πŸ”— `attribute` πŸŒ— `attributes` πŸŒ— `attr`
* Get: ▢️ `me().attribute('data-x')`
* Get is only for single elements. For many, wrap the call in `any(...).run(...)` or `any(...).forEach(...)`.
* For single elements.
* For many elements, wrap it in: `any(...).run(...)` or `any(...).forEach(...)`
* Set: ▢️`me().attribute('data-x', true)`
* Set multiple: ▢️ `me().attribute({ 'data-x':'yes', 'data-y':'no' })`
* Remove: ▢️ `me().attribute('data-x', null)`
* Remove multiple: ▢️ `me().attribute({ 'data-x': null, 'data-y':null })`
* πŸ”— `send` πŸ” `trigger`
* πŸ”— `send` πŸŒ— `trigger`
* ▢️ `me().send('change')`
* ▢️ `me().send('change', {'data':'thing'})`
* Wraps `dispatchEvent`
Expand Down Expand Up @@ -259,10 +260,10 @@ Looking for stuff [we recommend doing in vanilla JS](#no-surreal)?
* ▢️ `halt(event)`
* Prevent default browser behaviors.
* Wrapper for [preventDefault](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
* 🌐 `createElement` πŸ” `create_element`
* 🌐 `createElement` πŸŒ— `create_element`
* ▢️ `e_new = createElement("div"); me().prepend(e_new)`
* Alias of vanilla `document.createElement`
* 🌐 `onloadAdd` πŸ” `onload_add` πŸ” `addOnload` πŸ” `add_onload`
* 🌐 `onloadAdd` πŸŒ— `onload_add` πŸŒ— `addOnload` πŸŒ— `add_onload`
* ▢️ `onloadAdd(_ => { alert("loaded!"); })`
* Execute after the DOM is ready. Similar to jquery `ready()`
* Queues functions onto `window.onload`
Expand All @@ -279,13 +280,13 @@ Build effects with `me().styles({...})` with timelines using [CSS transitioned `

Common effects included:

* πŸ”— `fadeOut` πŸ” `fade_out`
* πŸ”— `fadeOut` πŸŒ— `fade_out`
* Fade out and remove element.
* Keep element with `remove=false`.
* ▢️ `me().fadeOut()`
* ▢️ `me().fadeOut(ev => { alert("Faded out!") }, 3000)` Over 3 seconds then call function.

* πŸ”— `fadeIn` πŸ” `fade_in`
* πŸ”— `fadeIn` πŸŒ— `fade_in`
* Fade in existing element which has `opacity: 0`
* ▢️ `me().fadeIn()`
* ▢️ `me().fadeIn(ev => { alert("Faded in!") }, 3000)` Over 3 seconds then call function.
Expand Down Expand Up @@ -384,7 +385,7 @@ me().on("click", async event => {

## <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.
Feel free to edit Surreal directly- but if you prefer, you can use plugins to effortlessly merge with new versions.

```javascript
function pluginHello(e) {
Expand All @@ -399,10 +400,10 @@ function pluginHello(e) {
surreal.plugins.push(pluginHello)
```

You can now use it like: `me().hello("Internet")`
Now use your function like: `me().hello("Internet")`

* See the included `pluginEffects` for a more comprehensive example.
* Your functions will be added globally by `globalsAdd()` If you do not want this, add it to the restricted list.
* Your functions are added globally by `globalsAdd()` If you do not want this, add it to the `restricted` list.
* Refer to an existing function to see how to make yours work with 1 or many elements.

Make an [issue](https://github.com/gnat/surreal/issues) or [pull request](https://github.com/gnat/surreal/pulls) if you think people would like to use it! If it's useful enough we'll want it in core.
Expand Down

0 comments on commit a616504

Please sign in to comment.