popovers.js
Mobile/touch pop-frame provider for inline link previews, replacing the old popins.js module.
Read this when Use this page when tracing browser-side behavior, runtime state, event handling, popups, or UI code around popovers.
Overview
popovers.js implements the mobile/touch pop-frame provider used by extracts.js. Desktop clients use Popups; mobile clients, or clients with extracts-force-popovers set in local storage, use Popovers.
The provider exposes the same broad pop-frame interface that extracts.js expects: register targets, create a frame for a target, set content, track loading states, scroll content into view, and remove frames during cleanup.
Unlike the removed popins.js naming, the current source uses Popovers, .popover, spawns-popover, preparePopover, and spawnedPopovers.
Key Behavior
Node.prototype.getPopover()andsetPopover()store the associated popover under_gw_popover, avoiding collision with the native HTMLpopoverattribute.Popovers.setup()runs cleanup, attaches Escape andpopstatehandlers, and firesPopovers.setupDidComplete.Popovers.addTarget()binds click activation, storestarget.preparePopover, and marks the target withspawns-popover.Popovers.injectPopoverForTarget()creates the frame, calls the target's prepare function, attaches it near the target, updates the spawned stack, and firesPopovers.popoverDidInject.Popovers.updateLocationForSpawnedPopovers()records the current stack in URL/hash history state.Popovers.cleanPopoversFromContainer()removes stale popovers from content that is about to be replaced.
Public API
setup() / cleanup()
Initialize or tear down the popover provider. Cleanup removes all spawned popovers and unregisters the global handlers.
addTarget(target, prepareFunction)
Registers a target element. The prepare function receives the new popover and is expected to populate its body/title/footer data or return null to cancel.
removeTarget(target)
Unregisters a target and removes its currently spawned popover, if any.
containingPopFrame(element)
Finds the containing .popover, including the Shadow DOM body path through .shadow-body.
allSpawnedPopovers()
Returns the current spawnedPopovers stack.
scrollElementIntoViewInPopFrame(element, alwaysRevealTopEdge)
Scrolls the popover body so a target element becomes visible.
removePopover(popover, remove = false)
With the default remove = false, delegates removal to browser history by calling history.back(). With remove = true (used from the popstate handler), fires Popovers.popoverWillDespawn, detaches the popover from its target, removes it from the stack, and restores scroll state without another history navigation.
Related Files
- extracts.js chooses between
PopupsandPopovers. - extracts-content.js provides content handlers consumed by pop-frame providers.
- popups.js is the desktop hover/window provider.