atom-fm / client
Standalone Atom browser runtime for server-rendered HTML
Requires
None
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-28 20:40:14 UTC
README
atom-fm/client enhances server-rendered HTML with navigation, form submission, and small UI interactions. It works with plain PHP templates, Slim, and other hosts that return HTML. The browser scripts run directly without a JavaScript build step.
Install and load the client
For new applications, start with Atom Pages. In existing PHP applications, the client can enhance one server-rendered form at a time.
Install the tagged release directly from GitHub in your Composer project:
composer config repositories.atom-client vcs https://github.com/atom-fm/client
composer require "atom-fm/client:^0.1"
Copy resources/atom.js into your public assets on deployment, or serve it from an application route using Atom\Client\Assets::DIRECTORY . "/atom.js". Load it once in your shared layout.
<script defer src="/assets/atom.js"></script>
Navigate and submit forms
Return a full HTML document with a title for each page. Give each layout the same update boundary. For example, a notes page can render this markup inside its body.
<main atom:update-root> <a href="/archive" atom:navigate>View saved notes</a> <form method="post" action="/notes" atom:submit> <label for="note">Note</label> <textarea id="note" name="note" required></textarea> <button type="submit">Save note</button> </form> </main>
An enhanced link sends a GET with X-Requested-With: Atom. Atom updates the page title, content, and browser history. Both URLs should also work on a direct visit or reload.
For the POST route, validate the submitted fields on the server. Return the form as HTML with status 422 to display errors and the submitted values. After a successful save, return 303 See Other with a Location header pointing to a GET route. Use your host application's CSRF protection. Atom includes hidden form fields and can read a CSRF token from a csrf-token meta element or an input named _token.
Show and dismiss a dropdown
<button type="button" atom:toggle aria-controls="note-actions" aria-expanded="false"> Note actions </button> <div id="note-actions" hidden atom:click-outside="hide"> <a href="/archive" atom:navigate>View saved notes</a> </div>
atom:toggle opens the target on the first click and closes it on the second. Use atom:show on a button to open the target on every activation. Both resolve a single element ID from aria-controls and synchronize aria-expanded when provided. Set its initial value to match the target's visibility.
atom:click-outside="hide" sets the panel's hidden property when the user clicks outside. A click on a descendant link can still activate that link.
Dismiss a save notice
<div class="save-notice" role="status" atom:remove-after="5000" atom:click-outside="remove" atom:transition>Note saved.</div> <style> @media (prefers-reduced-motion: no-preference) { .save-notice { transition: opacity 160ms ease; } .save-notice[data-atom-leaving] { opacity: 0; } } </style>
The notice leaves after five seconds or an outside click. Hovering or focusing inside pauses the countdown until both pointer and focus leave. Set the duration in whole milliseconds from 1 through 2147483647. With atom:transition, Atom marks the element with data-atom-leaving so its CSS exit can run before removal. For a one-time save confirmation, consume the flash message on the server when rendering the page.
Optional MorphDOM updates
The default updater replaces the update root's contents. To enable DOM reconciliation, serve the bundled scripts from resources and load atom.js, morphdom.js, and atom-morphdom.js in that order. Give each new timed notice a distinct HTML ID so it gets a fresh timer when MorphDOM reuses surrounding elements.
Atom Client uses the MIT license. Include the MorphDOM license when redistributing the bundled MorphDOM script.