1(function() { 2 3 /** 4 * hasClass utility 5 */ 6 function hasClass(el, cls) { 7 if ( el.classList.contains( cls ) ) { 8 return true; 9 } 10 return false; 11 } 12 13 /** 14 * Throttle function 15 * Underscore.js 1.10.2 https://underscorejs.org 16 * (c) 2009-2020 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors 17 * Underscore may be freely distributed under the MIT license. 18 */ 19 function throttle(func, wait, options) { 20 var now = Date.now || function() { 21 return new Date().getTime(); 22 }; 23 var timeout, context, args, result; 24 var previous = 0; 25 if (!options) options = {}; 26 var later = function() { 27 previous = options.leading === false ? 0 : now(); 28 timeout = null; 29 result = func.apply(context, args); 30 if (!timeout) context = args = null; 31 }; 32 var throttled = function() { 33 var _now = now(); 34 if (!previous && options.leading === false) previous = _now; 35 var remaining = wait - (_now - previous); 36 context = this; 37 args = arguments; 38 if (remaining <= 0 || remaining > wait) { 39 if (timeout) { 40 clearTimeout(timeout); 41 timeout = null; 42 } 43 previous = _now; 44 result = func.apply(context, args); 45 if (!timeout) context = args = null; 46 } else if (!timeout && options.trailing !== false) { 47 timeout = setTimeout(later, remaining); 48 } 49 return result; 50 }; 51 return throttled; 52 } 53 54 /** 55 * Runs the burger menu and sticky header functions as soon as the document is `ready` 56 */ 57 document.addEventListener( 'DOMContentLoaded', function() { 58 59 var modals = document.querySelectorAll( '.cover-modal' ); 60 modals.forEach( function( modal ) { 61 modal.addEventListener( 'toggle-target-before-inactive', function( event ) { 62 document.body.classList.add( 'tw-os-modal-fix' ); 63 document.documentElement.style.setProperty('scroll-behavior', 'auto' ); 64 }); 65 modal.addEventListener( 'toggle-target-after-inactive', function( event ) { 66 setTimeout( function() { 67 document.body.classList.remove( 'tw-os-modal-fix' ); 68 document.documentElement.style.removeProperty( 'scroll-behavior' ); 69 }, 550 ); 70 }); 71 } ); 72 73 var header = document.querySelector( '#site-header' ); 74 if ( header != null && hasClass( document.body, 'tw-header-sticky' ) ) { 75 var scrollToElement = document.querySelector( '.to-the-top' ); 76 if ( scrollToElement ) { 77 scrollToElement.addEventListener( 'click', function( event ) { 78 event.preventDefault(); 79 document.documentElement.scrollTop = 0; 80 document.body.scrollTop = 0; 81 }); 82 } 83 84 if ( 'fixed' !== getComputedStyle( header ).position ) { 85 modals.forEach( function( modal ) { 86 modal.addEventListener( 'toggle-target-before-inactive', function( event ) { 87 header.style.setProperty( 'position', 'fixed' ); 88 document.body.style.setProperty( 'padding-top', header.getBoundingClientRect().height + 'px' ); 89 }); 90 modal.addEventListener( 'toggle-target-after-inactive', function( event ) { 91 setTimeout( function() { 92 header.style.removeProperty( 'position' ); 93 document.body.style.removeProperty( 'padding-top' ); 94 }, 550 ); 95 }); 96 } ); 97 } 98 99 if ( hasClass( document.body, 'overlay-header' ) || hasClass( document.body, 'tw-header-transparent' ) ) { 100 var modals = document.querySelectorAll( '.cover-modal' ); 101 modals.forEach( function( modal ) { 102 modal.addEventListener( 'toggle-target-before-inactive', function( event ) { 103 document.body.classList.add( 'tw-modal-active' ); 104 }); 105 modal.addEventListener( 'toggle-target-after-inactive', function( event ) { 106 document.body.classList.remove( 'tw-modal-active' ); 107 }); 108 } ); 109 110 var scrollTop = window.pageYOffset; 111 if ( scrollTop > 30 ) { 112 document.body.classList.add( 'has-header-opaque' ); 113 } 114 115 window.addEventListener( 'scroll', throttle( function() { 116 var scrollTop = window.pageYOffset; 117 if ( scrollTop > 30 ) { 118 document.body.classList.add( 'has-header-opaque' ); 119 } else if ( ! hasClass( document.body, 'tw-modal-active' ) ) { 120 document.body.classList.remove( 'has-header-opaque' ); 121 } 122 }, 100 ) ); 123 } 124 } 125 }); 126})();
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.