Moey extras
Pull to refresh
Pull down at the top of a list to load what's new — the gesture every phone app has. The content follows your finger, an arrow turns when you've pulled far enough, and a spinner stays until your data has arrived.
- AKOrder #104301 items
- BKOrder #104292 items
- CKOrder #104283 items
- DKOrder #104271 items
- EKOrder #104262 items
- FKOrder #104253 items
- GKOrder #104241 items
- HKOrder #104232 items
- IKOrder #104223 items
- JKOrder #104211 items
- KKOrder #104202 items
- LKOrder #104193 items
Today
The panel below scrolls on its own
- AKOrder #104301 items
- BKOrder #104292 items
- CKOrder #104283 items
- DKOrder #104271 items
- EKOrder #104262 items
- FKOrder #104253 items
- GKOrder #104241 items
- HKOrder #104232 items
- IKOrder #104223 items
- JKOrder #104211 items
Touch screens only: on a phone pull with your finger; on a computer use your browser's device mode (touch) — or the button below.
<main data-moey-refresh>
<ul class="list-group">…</ul>
</main>
<script>
const list = document.querySelector('main');
list.addEventListener('moey:refresh', (e) => {
e.detail.waitUntil(loadNewOrders()); // a promise: the spinner stays until it settles
});
</script>
Add it, step by step
- Put
data-moey-refreshon what scrolls. If the page itself scrolls, put it on your main content (or<body>). If a panel scrolls on its own (overflow-y-autowith a height), put it on that panel. - Load in
moey:refreshand hand the promise toe.detail.waitUntil(). The spinner stays while it runs, then everything slides back. WithoutwaitUntilit finishes after a short moment. - Update the list when your data arrives — add the new items, replace the old ones, whatever fits.
- Give computers a button. A mouse can't pull, so add a refresh button (it is good for keyboard users too) that calls
Moey.refresh(el)— the same spinner and event.
Loading data
list.addEventListener('moey:refresh', (e) => {
e.detail.waitUntil(
fetch('/api/orders?since=' + newest)
.then((r) => r.json())
.then((orders) => orders.forEach(addOrderOnTop))
.catch(() => Moey.toast({ message: "Couldn't refresh — check your connection", type: 'danger' }))
);
});
list.addEventListener('moey:refreshed', () => { /* the spinner is gone */ });
With a refresh button
On a computer, the button runs the same refresh — try it:
Orders
- AKOrder #104301 items
- BKOrder #104292 items
- CKOrder #104283 items
- DKOrder #104271 items
- EKOrder #104262 items
- FKOrder #104253 items
<button class="btn btn-sm" onclick="Moey.refresh('#orders')">
<i class="mi mi-refresh-cw"></i>Refresh
</button>
Good to know
- It only starts at the very top, and only when pulling down — normal scrolling never changes.
- The phone browser's own pull-to-reload is switched off where Moey's is used, so the two never fight (and an installed web app has none anyway).
- Rows you can swipe sideways (Swipe actions), Kanban boards and sliders don't start a pull.
- Screen readers hear "Refreshing…" and "Updated"; the list is
aria-busywhile it loads.
Reference
| Attribute / API | What it does |
|---|---|
data-moey-refresh | Pull to refresh on this element (the page's content, or a panel that scrolls itself) |
Event moey:refresh | Pulled far enough: e.detail.waitUntil(promise) keeps the spinner until it settles |
Event moey:refreshed | Done; everything slid back |
Moey.refresh(el) | Refresh from code or a button (returns a promise) |
.is-pulling · .is-ready · .is-refreshing | The states, for your own styling |
--mo-refresh-pull | How far it is pulled right now (px) |