1jQuery(document).ready(function($) { 2 const tooltip = $('<div class="mvl-tooltip"></div>'); 3 const tooltipImage = $('<div class="mvl-tooltip-image"></div>'); 4 $('body').append(tooltip, tooltipImage); 5 const tooltipElement = tooltip[0]; 6 const tooltipImageElement = tooltipImage[0]; 7 8 let showTimeout; 9 let hideTimeout; 10 11 function positionTooltip(element, tooltip) { 12 const elementRect = element.getBoundingClientRect(); 13 const tooltipRect = tooltip.getBoundingClientRect(); 14 const position = element.getAttribute('data-mvl-tooltip-position') || element.getAttribute('mvl-tooltip-position') || 'top'; 15 16 tooltip.setAttribute('data-position', position); 17 18 let top, left; 19 const offset = 10; 20 21 switch(position) { 22 case 'top': 23 top = elementRect.top - tooltipRect.height - offset; 24 left = elementRect.left + (elementRect.width / 2); 25 break; 26 case 'bottom': 27 top = elementRect.bottom + offset; 28 left = elementRect.left + (elementRect.width / 2); 29 break; 30 case 'left': 31 top = elementRect.top + (elementRect.height / 2); 32 left = elementRect.left - tooltipRect.width - offset; 33 break; 34 case 'right': 35 top = elementRect.top + (elementRect.height / 2); 36 left = elementRect.right + offset; 37 break; 38 } 39 40 const viewportWidth = window.innerWidth; 41 const viewportHeight = window.innerHeight; 42 43 if (left < 0) left = 0; 44 if (left + tooltipRect.width > viewportWidth) left = viewportWidth - tooltipRect.width; 45 if (top < 0) top = 0; 46 if (top + tooltipRect.height > viewportHeight) top = viewportHeight - tooltipRect.height; 47 48 tooltip.style.top = (top + window.scrollY) + 'px'; 49 tooltip.style.left = (left + window.scrollX) + 'px'; 50 } 51 52 function showTooltip(element, tooltip, content) { 53 clearTimeout(hideTimeout); 54 clearTimeout(showTimeout); 55 56 showTimeout = setTimeout(() => { 57 tooltip.textContent = content || ''; 58 tooltip.style.display = 'block'; 59 positionTooltip(element, tooltip); 60 }, 100); 61 } 62 63 function showImageTooltip(element, tooltip, imageUrl) { 64 clearTimeout(hideTimeout); 65 clearTimeout(showTimeout); 66 67 showTimeout = setTimeout(() => { 68 const image = document.createElement('img'); 69 image.src = imageUrl || ''; 70 image.alt = 'Preview'; 71 72 tooltip.textContent = ''; 73 tooltip.appendChild(image); 74 tooltip.style.display = 'block'; 75 positionTooltip(element, tooltip); 76 }, 100); 77 } 78 79 function hideTooltip(tooltip) { 80 clearTimeout(showTimeout); 81 hideTimeout = setTimeout(() => { 82 tooltip.style.display = 'none'; 83 }, 100); 84 } 85 86 $(document).on('mouseenter', '[mvl-tooltip-text], [data-mvl-tooltip-text]', function() { 87 const text = this.getAttribute('data-mvl-tooltip-text') || this.getAttribute('mvl-tooltip-text'); 88 tooltipImageElement.style.display = 'none'; 89 showTooltip(this, tooltipElement, text); 90 }); 91 92 $(document).on('mouseleave', '[mvl-tooltip-text], [data-mvl-tooltip-text]', function() { 93 hideTooltip(tooltipElement); 94 }); 95 96 $(document).on('mouseenter', '[mvl-tooltip-image]', function() { 97 const imageUrl = this.getAttribute('mvl-tooltip-image'); 98 tooltipElement.style.display = 'none'; 99 showImageTooltip(this, tooltipImageElement, imageUrl); 100 }); 101 102 $(document).on('mouseleave', '[mvl-tooltip-image]', function() { 103 hideTooltip(tooltipImageElement); 104 }); 105 106 $(window).on('scroll resize', function() { 107 if (tooltipElement.style.display === 'block') { 108 const activeElement = document.querySelector('[mvl-tooltip-text]:hover, [data-mvl-tooltip-text]:hover'); 109 if (activeElement) { 110 positionTooltip(activeElement, tooltipElement); 111 } 112 } 113 if (tooltipImageElement.style.display === 'block') { 114 const activeElement = document.querySelector('[mvl-tooltip-image]:hover'); 115 if (activeElement) { 116 positionTooltip(activeElement, tooltipImageElement); 117 } 118 } 119 }); 120});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.