Members
-
dispatcher :NexusHoratio.base.Dispatcher
-
Details
-
item :external:Element
-
Details
-
itemUid :string
-
Details
-
logger :NexusHoratio.base.Logger
-
Details
-
name :string
-
Details
-
<private, static> eventTypes :Array.<NexusHoratio.base.Dispatcher~EventType>
-
Description
Scroller events.
Details
Methods
-
defaultUid( element ) → {string}
-
Description
Return normalized text for an element.
Like
HTMLElement.innerText, but cleaner and mostly deduped.Parameters
Name Type Description elementexternal:Element Element to examine.
Returns
Details
-
next()
-
Description
Move to the next item in the collection.
Details
-
prev()
-
Description
Move to the previous item in the collection.
Details
-
first()
-
Description
Move to the first item in the collection.
Details
-
last()
-
Description
Move to last item in the collection.
Details
-
goto( item )
-
Description
Move to a specific item if possible.
Parameters
Name Type Description itemexternal:Element Item to go to.
Details
-
gotoUid( uid ) → {boolean}
-
Description
Move to a specific item if possible, by uid.
Parameters
Name Type Description uidstring The uid of a specific item.
Returns
Details
-
shine()
-
Description
Adds the registered CSS classes to the current element.
Details
-
dull()
-
Description
Removes the registered CSS classes from the current element.
Details
-
show()
-
Description
Bring current item into view.
Details
-
focus()
-
Description
Move browser focus to current item.
Fires
Details
-
<async> activate()
-
Description
Activate the scroller.
Fires
Details
-
deactivate()
-
Description
Deactivate the scroller (but do not destroy it).
Fires
Details
-
destroy()
-
Description
Mark instance as inactive and do any internal cleanup.
Details
-
<private> attributesHandler( type, records )
-
Description
Currently removes
scrollerIdat the drop of a hat.XXX: This was originally intended to clear scrollerId before duplications were detected. But such detection happens inside
getItems, so this does not help with that. Still, might be useful in cases where the uid depends on attributes, even if duplicates are not involved.Parameters
Name Type Description typestring Event type.
recordsArray.<MutationRecords> Standard MutationRecords.
Details
-
<private> isItemViewable( item ) → {boolean}
-
Description
Determine if the item can be viewed.
Often this used to see if the content is being loaded lazily and is not ready yet.
Parameters
Name Type Description itemexternal:Element The item to inspect.
Returns
Details
-
<private> onClick( evt )
-
Description
If an item is clicked, switch to it.
Parameters
Name Type Description evtEvent Standard
clickevent.Fires
Details
-
<private> realHeight( element ) → {number}
-
Description
Return the computed height of an element.
The usual
element.clientHeightis too unpredictable.Parameters
Name Type Description elementexternal:Element Element to examine.
Returns
Details
-
<private> containersMutationHandler( records )
-
Parameters
Name Type Description recordsArray.<MutationRecord> Standard mutation records.
Details
-
<private> bottomHalf( val )
-
Description
Since the
itemgetter will try to validate the current item (since it could have changed out from under us), it too can update information.Parameters
Name Type Description valexternal:Element Element to make current.
Fires
Details
-
<private> getItems() → {Array.<external:Element>}
-
Description
Builds the list of elements using the registered CSS selectors.
Returns
Details
-
<private> postProcessItems( items ) → {Array.<external:Element>}
-
Description
Log items and do any fixups on them.
Parameters
Name Type Description itemsArray.<external:Element> Elements in the Scroller.
Returns
Details
-
<private> uid( element ) → {string}
-
Description
Returns the uid for the current element. Will use the registered
How.uidCallbackfunction for this.Parameters
Name Type Description elementexternal:Element Element to identify.
Returns
Details
-
<private> matchItem( element ) → {boolean}
-
Description
Checks if the element is the current one. Useful as a callback to
Array.find.Parameters
Name Type Description elementexternal:Element Element to check.
Returns
Details
-
<private> gentlyScrollIntoView( item )
-
Description
If necessary, scroll the bottom into view, then same for top.
Parameters
Name Type Description itemexternal:Element The item to scroll into view.
Details
-
<private> scrollToCurrentItem()
-
Description
Scroll the current item into the view port. Depending on the instance configuration, this could snap to the top, snap to the bottom, or be a no-op.
Details
-
<private> jumpToEndItem( first )
-
Description
Jump to an item at one end of the collection.
Parameters
Name Type Description firstboolean If true, the first item in the collection, else, the last.
Details
-
<private> scrollBy( delta )
-
Description
Move forward or backwards in the collection by at least n.
Parameters
Name Type Description deltanumber How many items to move and the intended direction.
Fires
Details
-
<private> validateInstance()
-
Throws
Details
-
<private> validateWhat()
-
Throws
Details
-
<private> validateHow()
-
Throws
Details
-
<private> waitForContainers() → {Promise.<Array.<external:Element>>}
-
Description
The page may still be loading, so wait for things to settle.
Returns
Details
-
<private> currentItemWatcher() → {Promise.<string>}
-
Description
Watches for the current item, if there was one, to return.
Used during activation to deal with items still being loaded.
Returns
Details
Type Definitions
-
EventData
-
Description
Data sent along with events fired.
Different events will populate different properties.
Properties
Name Type Attributes Description scrollerNexusHoratio.nav.Scroller Instance firing the event.
itemexternal:Element <optional> Current item.
deltanumber <optional> Number of attempted steps that triggered an
out-of-rangeevent.Details
-
uidCallback( scroller, element ) → {string}
-
Description
Function that generates a, preferably, reproducible unique identifier for an Element.
The method
defaultUidexists to both provide an example and fallback implementation. However, it may not always be reproducible (consider items that consist of counts for reads and likes). It may also not be unique within a particular instance.It is a good practice to verify the stability and uniqueness of callbacks across page reloads. Built in logging will identify duplicates.
Parameters
Name Type Description scrollerNexusHoratio.nav.Scroller The calling
Scrollerinstance.elementexternal:Element Element to examine.
Returns
Details
-
ContainerItemsSelector
-
Description
Contains CSS selectors to first find a base element, then items that it contains.
Properties
Name Type Description containerstring CSS selector to find the container element.
itemsstring CSS selector to find the items inside the container.
Details
-
ElementFinder( element ) → {external:Element}
-
Description
Function that finds a DOM element based upon another one.
Useful for cases where CSS selectors are not sufficient.
Parameters
Name Type Description elementexternal:Element Starting point.
Returns
Details
-
What
-
Description
There are two ways to describe what elements go into a
Scroller:- An explicit container (via
base) element and selectors stemming from it. - An array of
ContainerItemsSelectors that can allow for multiple containers with items. This approach will also allow theScrollerto automatically wait for all container elements to exist during activation.
Properties
Name Type Description namestring Name for this
Scroller, used for logging.baseexternal:Element The container to use as a base for selecting elements.
selectorsArray.<string> Array of CSS selectors to find elements to collect, calling
base.querySelectorAll().containerItemsArray.<NexusHoratio.nav.Scroller~ContainerItemsSelector> Array of
ContainerItemsSelectors.Details
- An explicit container (via
-
How
-
Properties
Name Type Attributes Default Description uidCallbackNexusHoratio.nav.Scroller~uidCallback Callback to generate a uid.
maxUidLengthnumber <optional> 20 Max length for default uid text.
classesArray.<string> <optional> [] Array of CSS classes to add/remove from an element as it becomes current.
watchForClicksboolean <optional> true Whether the Scroller should watch for clicks and if one is inside an item, select it.
autoActivateboolean <optional> false Whether to call the activate method at the end of construction.
observeAttributesboolean <optional> false Whether the built in
MutationObservershould also observer node attributes (useful if the uid depends on attributes).snapToTopboolean <optional> false Whether items should snap to the top of the window when coming into view. should happen when
snapToTopis false.waitForItemTimeoutnumber <optional> 3000 Time to wait, in milliseconds, for existing item to reappear upon reactivation.
containerTimeoutnumber <optional> 0 Time to wait, in milliseconds, for a
ContainerItemsSelector.containerto show up. Some pages may not always provide all identified containers. The default of0disables timing out. NB: Any containers that timeout will not handle further activate() processing, such aswatchForClicks.Details
Events
-
activate
-
Description
This instance is being activated.
Details
-
activated
-
Description
This instance has been activated.
Details
-
change
-
Description
The value of item is changing.
Details
-
changed
-
Description
The value of item has changed.
Details
-
changed
-
Description
A clicked item is about to be processed.
Details
-
changed
-
Description
A clicked item has been processed.
Details
-
deactivate
-
Description
This instance is being deactivated.
Details
-
deactivated
-
Description
This instance has been deactivated.
Details
-
focus
-
Description
Focus is changing to a different item.
Details
-
focused
-
Description
Focus has changed to a different item.
Details
-
out-of-range
-
Description
Scrolling went past one end of the collection. This is NOT an error condition, but rather a design feature.
Details