Expand all

mw.editcheck.EditCheckGutterSectionIconWidget

Extends

Constructor

new mw.editcheck.EditCheckGutterSectionIconWidget(config) #

EditCheckGutterSectionIconWidget

The icon shown in the edit check gutter for one section of the document.

A section can be much taller than the viewport, so the icon doesn't just sit at its top: it's kept in view as the section scrolls past, in three states.

  • top: the section's top hasn't reached the sticky line, so the icon rests at the top of the section.
  • stuck: the section straddles the line, so the icon is pinned to the line.
  • bottom: the section's bottom has caught up with the pinned icon, so the icon rides the bottom out of view.

That's what position: sticky does, and this is shaped for handing over to it: $element is the element that would be sticky, and the observer and sentinel are emulation to be deleted with it. Sticky is blocked for now by ancestors of the gutter which are themselves scroll containers, trapping it short of the scroller.

Parameters:

Name Type Description
config Object

Configuration options

Properties:
Name Type Description
$section jQuery

Element covering the whole section this icon belongs to, observed to work out where the icon should be

Source:

EditCheckGutterSectionIconWidget

The icon shown in the edit check gutter for one section of the document.

Methods

disconnectObserver()private #

Disconnect the observer, clearing the cached margin so it can be rebuilt

Source:
Disconnect the observer, clearing the cached margin so it can be rebuilt

onIntersection(entries)private #

Handle the section or the sentinel crossing the line

Parameters:

Name Type Description
entries Array.<IntersectionObserverEntry>
Source:
Handle the section or the sentinel crossing the line

setActing(acting) #

Set whether the quick action is currently being performed

Parameters:

Name Type Description
acting boolean
Source:
Set whether the quick action is currently being performed

setAction(action, count) #

Update the icon to represent an action

Parameters:

Name Type Description
action mw.editcheck.EditCheckAction

Primary action of the section

count number

Number of actions in the section

Source:
Update the icon to represent an action

setState(state)private #

Position the icon for a sticky state

Parameters:

Name Type Description
state string

One of 'top', 'stuck' or 'bottom'

Source:
Position the icon for a sticky state

setStickyMetrics(metrics) #

Keep the icon in view as its section scrolls past.

One observer watches the region of the scroll root above the line, asking two elements the same question. The section overlaps that region once its top passes the line, i.e. once the icon's resting place is out of view; the sentinel does so once the section's bottom reaches where a pinned icon sits, which is when the icon must be released. A region rather than a line, so a fast scroll can't skip it.

Parameters:

Name Type Description
metrics Object | null

Metrics from .static.getStickyMetrics, or null to leave the icon resting at the top of its section

Properties:
Name Type Description
root Element | null

Scroll root to observe against, null for the viewport

rootTop number

Root top, in viewport coordinates

rootHeight number

Root height

line number

Line to pin the icon at, in viewport coordinates

Source:
Keep the icon in view as its section scrolls past.

teardown() #

Teardown the widget

updateState()private #

Move the icon to whichever state the observed flags imply

Source:
Move the icon to whichever state the observed flags imply

getStickyMetrics(target) → {Object|null}static #

Collect the metrics the sticky emulation needs. They're the same for every section, so they're gathered once per update and shared between the icons.

Parameters:

Name Type Description
target ve.init.mw.Target

Returns:

{ root, rootTop, rootHeight, line } in viewport coordinates, or null if IntersectionObserver is unsupported

Type
Object | null
Source:
Collect the metrics the sticky emulation needs.