Skip to main content

AnchorSpyController

Purpose

A utility controller to detect and write anchors in the URL. i.e. "https://example.com#foo", the anchor is foo

When actions happen (i.e. an accordion opening) - write an anchor the URL that when revisited, would mean the accordion is reopened in the same place.

When the page loads with a matching anchor, fire events that can wire up other controllers. i.e. To reopen accordions/tabs when the page opens with the correct anchor.

Actions

ActionPurpose
writeWrite the value of keyValue to the current URL's anchor.

Targets

TargetPurposeDefault
---

Classes

ClassPurposeDefault
activeThe class to apply to the controller root element when the URL's anchor matches keyValueactive
inactiveThe class to apply to the controller root element when the URL's anchor does not match keyValueinactive

Values

ValueTypeDescriptionDefault
keyStringThe anchor to associate with the behaviour you want to drive.-

Events

EventWhenDispatched onevent.detail
anchor-spy:activeWhen the page loads or the url changes and the anchor matches keyValueThe controller root element-
anchor-spy:inactiveWhen the page loads or the url changes and the anchor does not match keyValueThe controller root element-

Side Effects

The controller will install event listeners for:

Window:

  • hashchange

How to Use