VistaView Class
The VistaView class is the core controller that manages the entire lifecycle of the lightbox viewer. Each instance represents a lightbox that can be opened, navigated, and controlled programmatically.
Overview
Section titled “Overview”VistaView orchestrates all aspects of the lightbox experience:
- Instance Management: Ensures only one lightbox is active at a time via
GlobalVistaState - Image Navigation: Handles next/prev navigation with smooth transitions and rapid-swap optimization
- UI Controls: Manages zoom, close, and navigation buttons
- Event Coordination: Integrates pointer events, keyboard shortcuts, and extension hooks
- State Management: Tracks current index, zoom level, and UI activation state
- Extension Integration: Calls extension lifecycle hooks at key moments
Constructor
Section titled “Constructor”Creates a new VistaView instance.
Parameters:
elements: Either a CSS selector string or an array of image configurationsoptions: Optional configuration object (see VistaOpt)
Example:
Public Properties
Section titled “Public Properties”options
Section titled “options”The merged configuration options for this instance. Combines user-provided options with DefaultOptions.
See VistaOpt for complete type definition.
The current state manager containing:
currentIndex: Current image indexelmLength: Total number of imageszoomedIn: Whether the current image is zoomedextensions: Set of registered extensionschildren: Current DOM elements and VistaBox instancesabortController: For canceling transitions
See VistaState for complete documentation.
imageContainer
Section titled “imageContainer”Reference to the DOM element containing the image elements. null when the lightbox is closed.
externalPointerListener
Section titled “externalPointerListener”Array of external pointer event listeners registered via registerPointerListener(). Used by extensions to hook into pointer events.
See VistaExternalPointerListenerArgs for the event argument type.
Public Methods
Section titled “Public Methods”open()
Section titled “open()”Opens the lightbox at the specified image index.
Parameters:
startIndex: The index of the image to display first (default:0)
Behavior:
- Prevents opening if another VistaView instance is already open
- Prevents body scrolling
- Creates and injects the lightbox DOM structure
- Sets up event handlers and keyboard listeners
- Calls
onOpenevent callback and extension hooks - Supports negative indices and values beyond the array length (wraps around)
Example:
close()
Section titled “close()”Closes the lightbox and cleans up resources.
Parameters:
animate: Whether to animate the close transition (default:true)
Behavior:
- Waits for close animation to complete (if
animateistrue) - Removes DOM elements and event handlers
- Destroys all VistaBox instances
- Restores body scrolling
- Calls
onCloseevent callback and extension hooks - Resets
GlobalVistaState
Example:
destroy()
Section titled “destroy()”Completely destroys the VistaView instance and removes all event listeners.
Behavior:
- Closes the lightbox without animation
- Removes click listeners from trigger elements
- Clears external pointer listeners
- Cannot be reopened after destruction
Example:
next()
Section titled “next()”Navigates to the next image in the sequence.
Behavior:
- Wraps around to the first image after the last one
- Triggers transition animation
- Calls
onImageViewevent callback
Example:
prev()
Section titled “prev()”Navigates to the previous image in the sequence.
Behavior:
- Wraps around to the last image when at the first one
- Triggers transition animation
- Calls
onImageViewevent callback
Example:
view()
Section titled “view()”Jumps to a specific image by index.
Parameters:
index: The target image indexvia: Optional object indicating navigation direction (used internally)
Behavior:
- Supports negative indices and values beyond array length (wraps around)
- Aborts any in-progress transition
- Calls
onImageViewevent callback - Handles rapid navigation with optimized transitions
Example:
zoomIn()
Section titled “zoomIn()”Zooms in on the current image by a factor of 1.68x.
Behavior:
- Respects
maxZoomLeveloption - Throttled to prevent excessive calls (222ms)
- Disables zoom-in button when at maximum zoom
- Can be disabled via
deactivateUi(['zoomIn'])
Example:
zoomOut()
Section titled “zoomOut()”Zooms out of the current image by a factor of 0.68x.
Behavior:
- Returns to minimum zoom (fit to viewport)
- Throttled to prevent excessive calls (222ms)
- Disables zoom-out button when at minimum zoom
- Can be disabled via
deactivateUi(['zoomOut'])
Example:
getCurrentIndex()
Section titled “getCurrentIndex()”Returns the current image index.
Returns: The zero-based index of the currently displayed image, or -1 if closed.
Example:
reset()
Section titled “reset()”Recalculates the image list and reattaches click listeners.
Behavior:
- Queries the DOM for elements matching the selector (if using string selector)
- Updates
state.elmLength - Removes and re-adds click event listeners
Use Case: Call this if the DOM has changed (elements added/removed) and you need to update the gallery.
Example:
Queries for an element within the lightbox root element.
Parameters:
selector: CSS selector string
Returns: The first matching element or null
Example:
qsOrigin()
Section titled “qsOrigin()”Queries for elements in the document (not limited to lightbox root).
Parameters:
selector: CSS selector string
Returns: NodeList of matching elements
Example:
registerPointerListener()
Section titled “registerPointerListener()”Registers an external pointer event listener.
Parameters:
listener: Function that receives VistaExternalPointerListenerArgs pointer event data
Use Case: Extensions can use this to respond to pointer events without directly managing event handlers.
Example:
deactivateUi()
Section titled “deactivateUi()”Temporarily disables UI controls.
Parameters:
names: Array of control names to disable (e.g.,['zoomIn', 'zoomOut'])requestBy: Optional VistaBox instance making the request
Behavior:
- Sets
disabledattribute on specified buttons - Notifies extensions via
onDeactivateUihook - Automatically reactivated before navigation or transitions
Example:
Related
Section titled “Related”- Main Function - The
vistaView()function that creates VistaView instances - VistaOpt - Configuration options type
- Event Callbacks - Events fired during lifecycle
- Lifecycle Functions - Customizable lifecycle hooks