# More (``) A feed's "load more" link. Without JS it is a link to the next page; with JS the next page loads into the list as the link nears the viewport, or when it is activated. Self-registering, light DOM, no words of its own. ```html
  1. …
  2. …
Voir plus ``` ## The markup | where | what | notes | |---|---|---| | host `for` | the id of the list to load into | without it: the previous sibling if it is `[data-feed-items]`, else the `[data-feed-items]` inside the previous sibling | | host `announce` | the live-region text after a load, `{n}` = items added | default `{n} more`: set it in the page's language (`{n} de plus`) | | `a[data-more]` | the link to the next page | its `href` is fetched | ## The endpoint `GET ` with `Accept: text/html` and `X-Fragment: 1` (cookies: `credentials: "same-origin"`). The answer is HTML: a fragment or a whole page, either works. The element reads two things from it: - `[data-feed-items]`: its children are appended to the page's list, in order; - `pebble-more a[data-more]`: the next link, which replaces the current one. No such link means the end of the feed. So the cheapest server answer for `X-Fragment: 1` is: ```html
  1. …
  2. …
Voir plus ``` A non-2xx answer, or one without `[data-feed-items]`, is a failure. ## Behavior - An IntersectionObserver watches the link with a 600 px root margin (`ROOT_MARGIN`); when it comes within reach, the next page loads. A page short enough to keep the new link within reach loads the one after at once. - Activating the link (click, tap, Enter) loads too, and cancels the navigation. A modified click (new tab) is the browser's. - One fetch at a time. While it runs the link is hidden and the host has `data-loading` (the sheet shows a spinner). - A failure shows the link again and marks the host `data-error`; the observer stops loading by itself until the link is activated by hand, so a failing server is not hammered. - The end of the feed removes the link and marks the host `data-done`. The host stays, empty but for its live region, so the last announcement is heard. - Each load writes the `announce` text into a polite live region (`role="status"`, visually hidden, part `status`); the same text twice in a row is still announced. - When the link had focus (a keyboard user), focus moves to the first new item (given `tabindex="-1"` if it has none). - The URL is never changed. - Scripts in the answer do not run (DOMParser documents never run them). Custom elements in it (a `` per item, say) upgrade as they are appended. ## State hooks On the host: `[data-loading]`, `[data-error]`, `[data-done]`. The link carries `hidden` while loading. ## CSS hooks The sheet ships as `more.css` (raw: `dist/more.css`, published as `@pebble/more/more.css`); the element adopts it when it upgrades. Dark defaults from `prefers-color-scheme`. `--pebble-more-ink` · `--pebble-more-surface` · `--pebble-more-border` · `--pebble-more-error` (the link's border after a failure) · `--pebble-more-focus` (falls back to `--accent`; also the spinner's arc) · `--pebble-more-padding` (1rem, above and below) · `--pebble-more-size` (44px: the link's minimum height) · `--pebble-more-max-width` (24rem) · `--pebble-more-radius` (999px) · `--pebble-more-spinner-size` (1.75rem) ## Exports `ROOT_MARGIN`.