1/** 2 * scrollbar-init.js â Frontend (public) initialisation. 3 * 4 * Reads settings passed by PHP via wp_localize_script() as 5 * window.PrimeScrollbarSettings, injects a <style> block, and boots 6 * OverlayScrollbars on the chosen target element. 7 * 8 * âââ OverlayScrollbars global resolution ââââââââââââââââââââââââââââââââââââ 9 * Both the ES5 and ES6 browser builds expose the library as: 10 * 11 * var OverlayScrollbarsGlobal = (function(t){ ⦠t.OverlayScrollbars = qn ⦠})({}); 12 * 13 * The constructor is therefore at: 14 * window.OverlayScrollbarsGlobal.OverlayScrollbars â correct 15 * window.OverlayScrollbars â undefined â 16 * 17 * The resolveOS() helper below handles both builds transparently. 18 */ 19( function () { 20 'use strict'; 21 22 /* ââ Resolve OverlayScrollbars constructor âââââââââââââââââââââââââââââââ */ 23 24 function resolveOS() { 25 // ES5 & ES6 browser builds: constructor is a property of the namespace object. 26 var g = window.OverlayScrollbarsGlobal; 27 if ( g && typeof g.OverlayScrollbars === 'function' ) { 28 return g.OverlayScrollbars; 29 } 30 // Fallback for any build that assigns the constructor directly. 31 if ( typeof window.OverlayScrollbars === 'function' ) { 32 return window.OverlayScrollbars; 33 } 34 return null; 35 } 36 37 /* ââ Bail if PHP settings are missing ââââââââââââââââââââââââââââââââââââ */ 38 39 var S = window.PrimeScrollbarSettings; 40 if ( ! S ) return; 41 42 /* ââ Inject dynamic CSS ââââââââââââââââââââââââââââââââââââââââââââââââââ */ 43 44 ( function injectCSS() { 45 var lines = []; 46 47 lines.push( 48 '.prime-scrollbar-theme { --os-size: ' + S.width + '; }', 49 50 '.prime-scrollbar-theme .os-scrollbar-track {', 51 ' background: ' + S.trackColor + ';', 52 ' border-radius: ' + S.trackRadius + ';', 53 '}', 54 '.prime-scrollbar-theme .os-scrollbar-track:hover { background: ' + S.trackHover + '; }', 55 56 '.prime-scrollbar-theme .os-scrollbar-handle {', 57 ' background: ' + S.thumbColor + ';', 58 ' border-radius: ' + S.thumbRadius + ';', 59 '}', 60 '.prime-scrollbar-theme .os-scrollbar-handle:hover { background: ' + S.thumbHover + '; }' 61 ); 62 63 if ( S.position === 'left' ) { 64 lines.push( 65 '.pea-scrollbar-left .os-scrollbar-vertical { left: 0 !important; right: auto !important; }' 66 ); 67 } 68 69 if ( S.hide === 'yes' ) { 70 lines.push( 71 '.prime-scrollbar-theme { display: none !important }', 72 'html, body { scrollbar-width: none !important; -ms-overflow-style: none !important; }', 73 'html::-webkit-scrollbar, body::-webkit-scrollbar { display: none !important; }' 74 ); 75 } 76 77 if ( S.smooth === 'yes' ) { 78 lines.push( 'html { scroll-behavior: smooth; }' ); 79 } 80 81 var style = document.createElement( 'style' ); 82 style.id = 'prime-scrollbar-frontend-css'; 83 style.textContent = lines.join( '\n' ); 84 document.head.appendChild( style ); 85 } )(); 86 87 /* ââ Boot OverlayScrollbars ââââââââââââââââââââââââââââââââââââââââââââââ */ 88 89 if ( S.hide === 'yes' ) return; // hidden = native scrollbars, no OS needed 90 91 var OS = resolveOS(); 92 93 if ( ! OS ) { 94 console.warn( 95 '[PEA Scrollbar] OverlayScrollbars not found.', 96 '\nExpected: window.OverlayScrollbarsGlobal.OverlayScrollbars', 97 '\nGot:', window.OverlayScrollbarsGlobal 98 ); 99 return; 100 } 101 102 // Choose the target element based on "Apply To" control. 103 // var target = ( S.applyTo === 'body' ) 104 // ? document.body 105 // : document.scrollingElement; // 'global' (default) 106 // console.log(S.applyTo); 107 // Apply position class before init so OS picks it up immediately. 108 if ( S.position === 'left' ) { 109 document.documentElement.classList.add( 'pea-scrollbar-left' ); 110 } 111 112 var osInstance = OS( document.body, { 113 scrollbars: { 114 theme : 'os-theme-dark prime-scrollbar-theme', 115 autoHide : S.autoHide || 'scroll', 116 autoHideDelay: S.autoHideDelay || 800, 117 clickScroll : true, 118 dragScroll : true, 119 pointers : [ 'mouse', 'touch', 'pen' ], 120 121 }, 122 overflow: { x: 'hidden', y: 'scroll' }, 123 paddingAbsolute: true, 124 update : { elementEvents: [ [ 'img', 'load' ] ], debounce: [ 0, 33 ] }, 125 } ); 126 127 /* ââ Custom wheel speed ââââââââââââââââââââââââââââââââââââââââââââââââââ */ 128 129 var wheelSpeed = parseFloat( S.wheelSpeed ) || 1; 130 if ( wheelSpeed !== 1 && osInstance ) { 131 var viewport = osInstance.elements && osInstance.elements().viewport; 132 if ( viewport ) { 133 viewport.addEventListener( 'wheel', function ( e ) { 134 e.preventDefault(); 135 viewport.scrollTop += e.deltaY * wheelSpeed; 136 }, { passive: false } ); 137 } 138 } 139 140} )();
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.