Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 2x 2x 14x 14x 14x 14x 14x 14x 14x 14x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 5x 5x 14x 14x 14x 14x 14x 14x 14x 2x 2x 14x 14x 14x 14x 14x 14x 14x 15x 15x 15x 15x 15x 15x 14x 14x 14x 14x 14x 2x 2x 2x 2x 2x 14x 14x 14x 14x 14x 14x 14x 17x 2x 2x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 2x 15x 17x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 1x | /*!
* WikiLambda Vue scroll composable for hash-based navigation
*
* @module ext.wikilambda.app.composables.useScroll
* @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
* @license MIT
*/
'use strict';
const { ref, onMounted, onBeforeUnmount } = require( 'vue' );
const scrollUtils = require( '../utils/scrollUtils.js' );
/**
* Scroll composable that provides scroll functionality for components
* Includes methods for scrolling to elements and handling hash navigation
*
* @return {Object} Scroll composable API
*/
module.exports = function useScroll() {
const hasScrolledToHash = ref( false );
const debouncedHashScroll = ref( null );
/**
* Scrolls to an element by ID
*
* @param {string} elementId - The ID of the element to scroll to (without #)
* @param {Object} options - Scroll options
* @return {Promise<boolean>} - Promise that resolves to true if element was found and scrolled to
*/
function scrollToElement( elementId, options = {} ) {
return scrollUtils.scrollToElement( elementId, options );
}
/**
* Scrolls to the current URL hash
*
* @param {Object} options - Scroll options
* @return {Promise<boolean>} - Promise that resolves to true if hash element was found and scrolled to
*/
function scrollToCurrentHash( options = {} ) {
return scrollUtils.scrollToCurrentHash( options );
}
/**
* Scrolls to an element with retry logic for dynamic content
*
* @param {string} elementId - The ID of the element to scroll to (without #)
* @param {Object} options - Scroll options
* @return {Promise<boolean>} - Promise that resolves to true if element was eventually found and scrolled to
*/
function scrollToElementWithRetry( elementId, options = {} ) {
return scrollUtils.scrollToElementWithRetry( elementId, options );
}
/**
* Scrolls to the current hash with retry logic
*
* @param {Object} options - Scroll options
* @return {Promise<boolean>} - Promise that resolves to true
* if hash element was eventually found and scrolled to
*/
function scrollToCurrentHashWithRetry( options = {} ) {
return scrollUtils.scrollToCurrentHashWithRetry( options );
}
/**
* Handles hash change events and scrolls to the new hash
*
* @param {Object} options - Scroll options
*/
function handleHashChange( options = {} ) {
scrollToCurrentHashWithRetry( options );
}
/**
* Sets up hash change listener
*
* @param {Object} options - Scroll options for hash navigation
*/
function setupHashNavigation( options = {} ) {
// Create a debounced version of handleHashChange for this component
debouncedHashScroll.value = scrollUtils.createDebouncedHashScroll( options );
// Listen for hash changes
window.addEventListener( 'hashchange', debouncedHashScroll.value );
}
/**
* Cleans up hash change listener
*/
function cleanupHashNavigation() {
if ( debouncedHashScroll.value ) {
window.removeEventListener( 'hashchange', debouncedHashScroll.value );
debouncedHashScroll.value = null;
}
}
/**
* Attempts to scroll to hash on component mount with appropriate timing
*
* @param {Object} options - Scroll options
*/
function scrollToHashOnMount( options = {} ) {
if ( hasScrolledToHash.value ) {
return;
}
hasScrolledToHash.value = true;
const defaultOptions = {
maxRetries: 15,
retryDelay: 200,
behavior: 'smooth',
block: 'center',
offset: 0 // Account for potential fixed headers
};
const finalOptions = Object.assign( {}, defaultOptions, options );
// Use a small timeout to ensure DOM is ready
setTimeout( () => {
scrollToCurrentHashWithRetry( finalOptions );
}, 50 );
}
// Setup and cleanup lifecycle hooks
onMounted( () => {
// Set up hash navigation by default
setupHashNavigation();
// Attempt to scroll to hash on mount
scrollToHashOnMount();
} );
onBeforeUnmount( () => {
cleanupHashNavigation();
} );
return {
hasScrolledToHash,
scrollToElement,
scrollToCurrentHash,
scrollToElementWithRetry,
scrollToCurrentHashWithRetry,
handleHashChange,
setupHashNavigation,
cleanupHashNavigation,
scrollToHashOnMount
};
};
|