Events
Most of our events are modelled after Turbo's events.
General events
-
refreshless:loadTriggered once on initial load and thereafter on every RefreshLess navigation load.event.detail.initialwill betrueif this is the initial load andfalsethereafter.
-
refreshless:clickTriggered on a link when it's clicked and will be handled by RefreshLess.-
event.targetis the link that was clicked. -
event.detail.urlis aURLobject for the location the link points to. -
event.detail.originalEventis the originalclickevent. -
Can be cancelled via
event.preventDefault()to allow the click to fall through to the browser and/or any other click handlers to handle, and will not result in a RefreshLess navigation.
-
Render events
-
refreshless:before-renderTriggered before a page or cached preview is about to be rendered.-
event.detail.delay()can be called and passed a Promise executor function to delay rendering; rendering will only resume once all handlers that have calledevent.detail.delay()have resolved their respective promises. An example use-case for this is to perform a transition out before changes are made to the page content. -
event.detail.isCachedSnapshotis a boolean indicating whether this is a cached snapshot being rendered. A cached snapshot can be both a preview or the final content. See Understanding Caching in the Turbo documentation. -
event.detail.isFreshReplacingPreviewis a boolean indicating whether this is a fresh copy replacing a cached preview; this is primarily useful when doing transitions and the equivalent ofevent.detail.isPreview === false && event.detail.previousPreview === true && event.detail.isCachedSnapshot === false -
event.detail.isPreviewis a boolean indicating whether this is a cached preview being rendered. -
event.detail.newBodyis the newHTMLBodyElementthat will replace the current<body>. -
event.detail.previousPreviewis a boolean indicating whether the previous render was a cached preview being rendered; note that this can still be true if the current render is also a preview. -
event.detail.rendercan be set to a custom function to render the page; see the Turbo custom rendering documentation. -
event.detail.renderMethodis the strategy that will be used to render the page; eitherreplaceormorph.
-
-
refreshless:renderTriggered when a new page has been rendered.-
event.detail.isCachedSnapshotis a boolean indicating whether this is a cached snapshot that has been rendered. A cached snapshot can be both a preview or the final content. See Understanding Caching in the Turbo documentation. -
event.detail.isFreshReplacingPreviewis a boolean indicating whether this is a fresh copy replacing a cached preview; this is primarily useful when doing transitions and the equivalent ofevent.detail.isPreview === false && event.detail.previousPreview === true && event.detail.isCachedSnapshot === false -
event.detail.isPreviewis a boolean indicating whether this is a cached preview being rendered. -
event.detail.previousPreviewis a boolean indicating whether the previous render was a cached preview being rendered; note that this can still be true if the current render is also a preview. -
event.detail.renderMethodis the strategy used to render the page; eitherreplaceormorph.
-
Cache events
-
refreshless:before-cacheTriggered before a page is about to be saved to cache.- This event does not currently have an
event.detail.
- This event does not currently have an
-
refreshless:preloadTriggered after a preload response is received. Note that this requires therefreshless_preloadermodule to be installed. See preloading links for more information.-
event.detail.urlis aURLobject for the location that was preloaded into cache. -
event.detail.fetchResponseis a TurboFetchResponseinstance.
-
See also prefetch events.
Navigation events
-
refreshless:navigation-responseTriggered when a response has been received from the server that will result in a non-redirect RefreshLess navigation.-
event.detail.urlis aURLobject for the location that will be navigated to. -
event.detail.fetchResponseis a TurboFetchResponseinstance.
-
-
refreshless:redirectTriggered when a response has been received from the server that will result in a redirect RefreshLess navigation.-
event.detail.fromis aURLobject for the location that was requested, before redirecting. -
event.detail.tois aURLobject for the location that is being redirected to. -
event.detail.fetchResponseis a TurboFetchResponseinstance.
-
-
refreshless:reloadTriggered when RefreshLess is about to perform a hard (full) reload of the page. This is often in response to a signal from the back-end that something significant has changed that cannot be merged into the existing page.-
event.detail.reasonwill contain the reason for the reload. -
The following currently trigger a reload:
-
Navigating to a page that has a different Drupal theme; for example, going between the default theme and the administration theme or vice versa.
-
If CSS aggregation was not enabled on one page and then was enabled on the subsequent page, or vice versa.
-
If JavaScript aggregation was not enabled on one page and then was enabled on the subsequent page, or vice versa.
-
If the Drupal asset query string changed.
-
If the session's user permissions hash changed; for example, logging in or out, roles added or removed, and so on.
-
-
HTTP events
-
refreshless:before-fetch-requestTriggered before a fetch request is about to be sent.-
event.detail.fetchOptionsis aRequestInitoptions object that will be used to construct the fetch request. -
event.detail.isFormSubmitwill betrueif the request is a form submission, orfalseotherwise. -
event.detail.isPrefetchwill betrueif the request is a prefetch request, orfalseotherwise. -
event.detail.isPreloadwill betrueif the request is a cache preload request, orfalseotherwise. -
event.detail.urlis aURLobject for the location the fetch request will be sent to. -
Can be cancelled via
event.preventDefault(); callevent.detail.resume()to resume sending the fetch request after you've made any changes you need to the fetch options or page changes.
-
-
refreshless:fetch-request-errorTriggered if a fetch request could not be completed.-
event.detail.fetchRequestis the TurboFetchRequestthat could not be completed. -
event.detail.erroris theErrorobject containing the reason for the failure.
-
Note that there is no refreshless:before-fetch-response implemented at this
time. Instead, one of refreshless:navigation-response,
refreshless:prefetch, or refreshless:redirect will be triggered depending
on the type of response received.
Form events
-
refreshless:form-submit-startTriggered when a form submit is about to begin. -
refreshless:form-submit-responseTriggered when a form submit response has been received from the server.
Prefetch events
-
refreshless:before-prefetchTriggered before a prefetch request is about to be sent to the server.-
event.targetis the link that triggered the prefetch. -
event.detail.urlis aURLobject for the location to be prefetched. -
Can be cancelled via
event.preventDefault()to prevent the prefetch from being sent.
-
-
refreshless:prefetchTriggered when a prefetch response has been received.-
event.detail.urlis aURLobject for the location that was prefetched. -
event.detail.fetchResponseis a TurboFetchResponseinstance.
-
-
refreshless:prefetch-usedTriggered if/when a previously sent prefetch is used, meaning the user clicked the link.-
event.targetis the link that triggered the prefetch. -
event.detail.fetchOptionsis aRequestInitoptions object that was used to construct the fetch request. -
event.detail.fetchRequestis the TurboFetchRequestthat was sent to perform the prefetch. -
event.detail.notifyBackend()can be called to resend the fetch request in the background to register a real navigation to the back-end. Returns a Promise that resolves with aResponseobject. This method has optional parameters:-
resend: a boolean indicating whether to resend the notification if it's already been sent; defaults tofalse. -
fetchOptions: aRequestInitoptions object to use to construct the notification fetch request; defaults to the contents ofevent.detail.fetchOptions- if you pass this parameter, it's strongly recommended to re-use the existing options.
-
-
event.detail.backendNotifiedis a boolean indicating whether the back-end has been notified that this prefetch was used. -
event.detail.urlis aURLobject for the location that was prefetched.
-
See also cache events.
Behaviour events
-
refreshless:detachTriggered when behaviours have been detached.-
event.detail.triggeris a string indicating the reason for the detach:-
unloadindicates the page is about to be navigated away from. -
refreshless:before-cacheindicates the page is about to cached. -
refreshless:cached-snapshotindicates that a cached snapshot is about to be rendered.
-
-
-
refreshless:attachTriggered when behaviours have been attached following a RefreshLess load.
drupalSettings events
-
refreshless:drupal-settings-updateTriggered whendrupalSettingshas been updated due to RefreshLess navigation.-
event.detail.newwill contain a copy of the new settings as received in the response. -
event.detail.previouswill contain a copy of the old settings before merging. -
event.detail.mergedwill contain a reference to the current, mergeddrupalSettings.
-
Script events
Note that unlike stylesheets, <script> elements don't currently have remove events because removing has no effect on already-evaluated JavaScript and there's no universal way to remove its effects, unlike removing a stylesheet.
-
refreshless:before-scripts-mergeTriggered before new<script>elements are about to be merged. This is triggered once for scripts in the<head>and a second time for scripts in the<body>.-
event.detail.contextcontains eitherheadorbody. -
event.detail.oldcontains the<script>elements currently attached to the context (i.e.headorbody). -
event.detail.newcontains the new<script>elements about to be merged into the context (i.e.headorbody); this can be modified by event handlers to add or remove elements.
-
-
refreshless:scripts-mergedTriggered after new<script>elements have been merged. This is triggered once for scripts in the<head>and a second time for scripts in the<body>.-
event.detail.contextcontains eitherheadorbody. -
event.detail.oldcontains the<script>elements previously attached to the context (i.e.headorbody) before the merge. -
event.detail.newcontains the new<script>elements that have been merged into the context (i.e.headorbody).
-
-
refreshless:scripts-loadedTriggered when all newly merged<script>elements have loaded. This is triggered only once for the<head>and<body>combined.event.detail.loadedcontains the newly merged and loaded<script>elements.
Stylesheet events
Unlike scripts, stylesheets are always merged into the <head> and as such, these events only trigger once per page load.
-
refreshless:before-stylesheets-mergeTriggered before new stylesheets are about to be merged in.-
event.detail.newStylesheetscontains the new stylesheets to be merged; this can be modified by event handlers to add or remove elements. -
event.detail.oldStylesheetscontains the stylesheets currently attached.
-
-
refreshless:stylesheets-mergedTriggered after new stylesheets have been merged in.-
event.detail.loadingElementsis an array of Promises that resolve when their respective stylesheets have loaded, or reject if they fail to load or hit their time limit. -
event.detail.mergedStylesheetscontains the newly merged in stylesheets.
-
-
refreshless:stylesheets-loadedTriggered when all newly merged stylesheets have finished loading.event.detail.loadingElementsis the array of Promises have resolved when their respective stylesheets have loaded.
-
refreshless:before-stylesheets-removeTriggered before stylesheets are about to be removed.event.detail.stylesheetscontains the stylesheets to be removed; this can be modified by event handlers to add or remove elements.
-
refreshless:stylesheets-removedTriggered after stylesheets have been removed.event.detail.stylesheetscontains the stylesheets that were removed.
Progress bar events
-
refreshless:progress-bar-before-showTriggered when the progress bar is about to be shown and start trickling.- Can be cancelled via
event.preventDefault()to prevent the progress bar being shown.
- Can be cancelled via
-
refreshless:progress-bar-shownTriggered when the progress bar has been shown. -
refreshless:progress-bar-before-hideTriggered when the progress bar is about to start hiding.- Can be cancelled via
event.preventDefault()to keep the progress bar visible and to continue trickling.
- Can be cancelled via
-
refreshless:progress-bar-hiddenTriggered when the progress bar has finished transitioning out and is fully hidden. -
refreshless:progress-bar-value-changedTriggered when the progress bar value has been changed.-
event.detail.valuecontains the new value as a number between or including 0 and 1, where 0 is 0% and 1 is 100%. -
event.detail.oldValuecontains the previous value as a number between or including 0 and 1, where 0 is 0% and 1 is 100%.
-
Page transition events
These events are only available if the refreshless_transitions module is installed. See page transitions for more information.
-
refreshless:page-revealingTriggered when a page has started transitioning into view. -
refreshless:page-revealedTriggered when a page has finished transitioning into view. -
refreshless:page-hidingTriggered when a page has started transitioning out of view. -
refreshless:page-hiddenTriggered when a page has finished transitioning out of view. -
refreshless:page-transition-failsafeTriggered if a page did not begin to transition in after a set amount of time after being hidden; after this event is triggered, we force the page to transition in unconditionally, so this event is primarily intended for debugging and should require no further action. -
refreshless:page-transition-state-errorTriggered if the current transition state does not match an expected state; this is primarily for debugging and no action is required.