new SPA( details )

Description

A userscript driver for working with a Single-Page Application.

In many cases, as a user navigates through a SPA, the website will change the URL. This allows for easy bookmarking by users. By monitoring the changes to the URL, this class facilitates making userscripts that adapt to different views.

Generally, a single instance of this class is created, and all Page subclasses are registered with it. As the user navigates through the SPA, this class will react to the changes and enable and disable view specific Pages as appropriate.

Each Page can be customized to augment the individual site page.

Parameters
Name Type Description
details NexusHoratio.spa.Details

Implementation specific details.

Details

Members


details :NexusHoratio.spa.Details

Methods


Symbol.dispose()

Description

Dispose of the instance.

Details

register( Klass ) → {NexusHoratio.spa.SPA}

Description

Add a new page to those supported by this instance.

Parameters
Name Type Description
Klass NexusHoratio.spa.Page

A NexusHoratio.spa.Page class to instantiate.

Returns

This instance, for chaining.

Details

<private> activate( pathname )

Description

Handle switching from the old page (if any) to the new one.

Parameters
Name Type Description
pathname string

A {URL.pathname}.

Details

<private> findPages( pathname ) → {Set.<Page>}

Description

Determine which pages can handle this portion of the URL.

Parameters
Name Type Description
pathname string

A {URL.pathname}.

Returns

The pages to use.

Details

<private> startUserscriptManagerUrlMonitor()

Description

Start userscript manager based URL monitoring.

This explicitly listens on window.

Tampermonkey was the first(?) userscript manager to provide events about URLs changing. Hence the need for @grant window.onurlchange in the UserScript header.

Details

<private> urlChangeAdapter( info )

Description

The info that TM gives is not really an event. So we turn it into one and throw it again, this time onto document where something is listening for it.

Parameters
Name Type Description
info object

Generic object from the userscript manager.

Fires
Details

<private> startMutationObserverUrlMonitor()

Description

Install a long lived MutationObserver that watches {Details.urlChangeMonitorSelector}.

Whenever it is triggered, it will check to see if the current URL has changed, and if so, send an appropriate event.

Fires
Details

<private> startUrlMonitor()

Description

Start URL monitoring.

If the userscript manager supports monitoring, that will be used.

This explicitly uses document for the event.

Details

<private> stopUrlMonitor()

Description

Stop URL monitoring.

Details

<private> onUrlChange( evt )

Description

Handle urlchange events that indicate a switch to a new page.

Parameters
Name Type Description
evt CustomEvent

Custom 'urlchange' event.

Details

Type Definitions


Pages

Properties
Name Type Description
active Set.<NexusHoratio.spa.Page>

Currently active pages.

old Set.<NexusHoratio.spa.Page>

Pages being deactivated.

new Set.<NexusHoratio.spa.Page>

Pages being activated.

Details
object

Events


activate

Details

activated

Details

initialize

Details

initialized

Details