Overview
ThePokemonTour class provides an interactive, step-by-step tour of the Pokémon Explorer application. It highlights UI elements, displays instructional popups, and ensures Pokémon data is loaded before showing relevant steps.
Constructor
- Step definitions
- Current step tracking (starts at 0)
- Overlay and popup references (initially null)
Properties
Index of the currently displayed tour step
Array of tour step objects, each containing:
Reference to the dark overlay element (created when tour starts)
Reference to the popup element containing tour content
Tour Steps
The default tour includes 5 steps:- Search Section (
#search-section) - Smart search capabilities - Filters Section (
#filters-section) - Advanced filtering options - Pokémon Grid (
#pokemonGrid) - Card display and interactions - Pagination (
#pagination) - Navigation controls - Completion (
body) - Final encouragement message
Core Methods
Tour Control
start()
start()
- Checks if tour is already active (prevents duplicate tours)
- Resets to step 0
- Creates overlay and popup elements
- Adds
tour-in-progressclass to body - Checks for Pokémon data availability
- Loads 25 Pokémon if needed (shows loading step)
- Displays first tour step
Promise<void>Example:showStep()
showStep()
- Title and description update
- Element highlighting
- Popup positioning
- Smooth scrolling to element
- Navigation button updates
- Hides popup and overlay (300ms transition)
- Removes previous highlights
- Updates popup content
- Highlights target element
- Positions popup relative to element
- Scrolls element into view
- Shows popup and overlay
voidnextStep()
nextStep()
voidpreviousStep()
previousStep()
voidclose()
close()
- Hides popup and overlay (with transition)
- Removes highlight from elements
- Removes
tour-in-progressclass from body - Removes overlay and popup from DOM (after 300ms)
- Resets references to null
- Scrolls page to top
voidUI Management
createElements()
createElements()
- Dark overlay backdrop
- Popup container with header, content, and footer
- Close button
- Navigation buttons (previous, next, finish)
- Progress indicator
- Directional arrow
- Overlay click → close tour
- Close button → close tour
- Previous button → previous step
- Next button → next step
- Finish button → close tour
voidshowLoadingStep()
showLoadingStep()
- Title: ”⏳ Preparando la Guía Interactiva”
- Description: “Cargando Pokémon para mostrarte todas las funciones…”
- Progress: “Preparando…”
- All navigation buttons hidden
- Popup centered on screen
voidPositioning
positionPopup(element)
positionPopup(element)
element(HTMLElement): The element to position relative to
- Calculates available space in all directions
- Prioritizes: bottom → top → right → left
- Adjusts if popup would overflow viewport
- Positions arrow to point at element
- Maintains 15px margin from viewport edges
.tour-arrow.bottom- Arrow points up (popup below element).tour-arrow.top- Arrow points down (popup above element).tour-arrow.right- Arrow points left (popup to the right).tour-arrow.left- Arrow points right (popup to the left)
voidcenterPopup()
centerPopup()
top: 50%left: 50%transform: translate(-50%, -50%)- Arrow hidden
voidHighlighting
highlightElement(element)
highlightElement(element)
tour-highlighted CSS class to an element to make it stand out during the tour.Parameters:element(HTMLElement): Element to highlight
voidremoveHighlight()
removeHighlight()
tour-highlighted class from any currently highlighted element.Returns: voidButton Management
updateButtons()
updateButtons()
Usage Example
Integration with PokemonExplorer
The tour integrates with the mainPokemonExplorer class:
Initialization
The tour is automatically initialized when the DOM loads:CSS Classes
The tour relies on these CSS classes (defined in your stylesheet):.tour-overlay- Dark backdrop.tour-popup- Main popup container.tour-popup.visible- Visible state with animation.tour-highlighted- Highlighted element style.tour-arrow- Directional arrow.tour-arrow.top/bottom/left/right- Arrow positioning.tour-in-progress- Applied to body during tour
Accessibility Features
- Smooth scrolling: Elements scroll into view smoothly
- Keyboard support: Close on overlay click
- Visual feedback: Clear highlighting and transitions
- Progress indicator: Shows “X of Y” step counter
- Responsive positioning: Adapts to viewport constraints
Performance Considerations
- Lazy data loading: Only loads Pokémon when needed
- Transition delays: 300ms transitions prevent jarring changes
- Element checks: Verifies element visibility before positioning
- Cleanup: Properly removes DOM elements and event listeners
- Debouncing: Prevents duplicate tour instances
See Also
- PokemonExplorer - Main application class
- Getting Started - Application overview
- User Guide - Complete feature guide