1/* 2 * Support for a progress bar showing scroll position below header 3 * 4 * 5 * @since 5.6 6 * @by Günter 7 */ 8 9"use strict"; 10 11// global namespace 12var avia_js_shortcodes = avia_js_shortcodes || {}; 13var aviaJS = aviaJS || {}; 14 15(function() 16{ 17 if( ! avia_js_shortcodes.aviaHeaderReadingProgress ) 18 { 19 class aviaHeaderReadingProgress 20 { 21 container = null; // container element 22 id = ''; 23 settings = { 24 color: '' 25 }; 26 header = []; 27 currentPos = 0; 28 29 constructor( container ) 30 { 31 this.container = container; 32 this.container.aviaHeaderReadingProgress = this; 33 this.id = container.getAttribute('id'); 34 this.header = container.closest( '#header' ); 35 36 if( ! this.header || this.header.classList.contains( 'av_header_sticky_disabled' ) ) 37 { 38 this.container.style.display = 'none'; 39 return; 40 } 41 42 let passed = JSON.parse( this.container.dataset.settings ); 43 this.settings = Object.assign( this.settings, passed ); 44 45 if( this.settings.color ) 46 { 47 this.container.style['background-color'] = this.settings.color; 48 } 49 50 this.bindEvents(); 51 this.scrollPosChanged(); 52 } 53 54 bindEvents() 55 { 56 window.addEventListener( 'scroll', this.onScroll.bind( this ) ); 57 window.addEventListener( 'resize', aviaJS.aviaJSHelpers.debounce( this.onResize.bind( this ), 200 ) ); 58 59 window.addEventListener( 'avia_height_change', this.onAviaHeightChange.bind( this ) ); 60 document.body.addEventListener( 'avia_resize_finished', this.onAviaHeightChange.bind( this ) ); 61 } 62 63 onScroll( e ) 64 { 65 this.scrollPosChanged(); 66 } 67 68 onResize( e ) 69 { 70 this.scrollPosChanged(); 71 } 72 73 onAviaHeightChange( e ) 74 { 75 this.scrollPosChanged(); 76 } 77 78 scrollPosChanged() 79 { 80 this.currentPos = this.currentScrollPercentage(); 81 82 this.container.style.width = this.currentPos + '%'; 83 } 84 85 currentScrollPercentage() 86 { 87 let elScrollTop = document.documentElement.scrollTop, 88 bodyScrollTop = document.body.scrollTop, 89 elScrollHeight = document.documentElement.scrollHeight, 90 elClientHeight = document.documentElement.clientHeight; 91 92 let pos = ( elScrollTop + bodyScrollTop ) / ( elScrollHeight - elClientHeight ) * 100.0; 93 94 return pos; 95 } 96 } 97 98 // class factory 99 avia_js_shortcodes.aviaHeaderReadingProgress = function( container ) 100 { 101 return new aviaHeaderReadingProgress( container ); 102 }; 103 104 aviaJS.aviaPlugins.register( avia_js_shortcodes.aviaHeaderReadingProgress, '.header-reading-progress' ); 105 } 106 107})(); 108
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.