1function advanced_ads_sticky_check_position_fixed() { 2 var container = document.body; 3 if (document.createElement && container && container.appendChild && container.removeChild) { 4 var el = document.createElement( 'div' ); 5 if ( ! el.getBoundingClientRect) { 6 return null; } 7 el.innerHTML = 'x'; 8 el.style.cssText = 'position:fixed;top:100px;'; 9 container.appendChild( el ); 10 var originalHeight = container.style.height, 11 originalScrollTop = container.scrollTop; 12 // In IE<=7, the window's upper-left is at 2,2 (pixels) with respect to the true client. 13 // surprisely, in IE8, the window's upper-left is at -2, -2 (pixels), but other elements 14 // tested is just right, so we need adjust this. 15 // https://groups.google.com/forum/?fromgroups#!topic/comp.lang.javascript/zWJaFM5gMIQ 16 // https://bugzilla.mozilla.org/show_bug.cgi?id=174397 17 var extraTop = parseInt( document.documentElement.getBoundingClientRect().top, 10 ); 18 extraTop = extraTop > 0 ? extraTop : 0; 19 container.style.height = '3000px'; 20 container.scrollTop = 500; 21 var elementTop = parseInt( el.getBoundingClientRect().top, 10 ); 22 container.style.height = originalHeight; 23 var isSupported = (elementTop - extraTop) === 100; 24 container.removeChild( el ); 25 container.scrollTop = originalScrollTop; 26 return isSupported; 27 } 28 return null; 29}; 30 31// decode sticky ads right after consent is given. 32document.addEventListener('advanced_ads_privacy', function (event) { 33 if (event.detail.state !== 'accepted' && event.detail.state !== 'not_needed') { 34 return; 35 } 36 37 window.advanced_ads_sticky_settings.placements.forEach(function (value) { 38 document.querySelectorAll('script[type="text/plain"][data-tcf="waiting-for-consent"][data-placement="' + value + '"]').forEach(advads.privacy.decode_ad); 39 }); 40}); 41 42jQuery( document ).ready(function($) { 43 var resize_timeout = null, $el, previous_width = $( window ).width(); 44 45 46 // Update position when viewport size changes. 47 function resize_handler() { 48 if ( resize_timeout ) clearTimeout( resize_timeout ); 49 resize_timeout = setTimeout( function() { 50 var new_width = $( window ).width(); 51 if ( previous_width === new_width ) { 52 // Return if the viewport has not actually changed 53 // Scroll event triggered this due to the position of the address bar. 54 return; 55 } 56 previous_width = new_width; 57 58 if ( typeof advanced_ads_sticky_items !== 'undefined' ) { 59 $.each( advanced_ads_sticky_items, function( wrapper_id, data ) { 60 $el = $( '#' + wrapper_id ); 61 // Apply initial 'position: absolute' styles if 'position: absolute' was transformed to 'position: fixed' 62 // using the 'advads.fix_element' function. 63 $el.prop( 'style', data.initial_css ); 64 65 // Fix to windows position and/or center vertically again. 66 data.modifying_func(); 67 } ); 68 } 69 }, 1000 ); 70 } 71 72 if ( 'undefined' === typeof advanced_ads_responsive || ! parseInt( advanced_ads_responsive.reload_on_resize, 10 ) ) { 73 // If the "Reload ads on resize" feature of the Responsive add-on is not used. 74 jQuery( window ).on( 'resize', resize_handler ); 75 } 76 77 //Remove 'position: fixed' if not supported, if the feature enabled in the settings. 78 if ( typeof advanced_ads_sticky_settings === 'undefined' || ! advanced_ads_sticky_settings.check_position_fixed ) { 79 return; 80 } 81 82 // story scroll enable value so it isnât checked multiple times per page view 83 var advanced_ads_sticky_position_fixed_supported = ''; 84 var allowed_offset = $( document.body ).is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0; 85 86 /** 87 * Remove all position related inline styles. 88 * 89 * @param {object=} $stickyads Optional jQuery object. 90 */ 91 function remove_css( $stickyads ) { 92 // if position fixed is unsupported 93 if ( advanced_ads_sticky_position_fixed_supported === false ) { 94 $( window ).off( 'resize', resize_handler ); 95 $stickyads = $stickyads || jQuery( '.' + advanced_ads_sticky_settings.sticky_class ); 96 setTimeout( function() { 97 $stickyads.each( function( key, value ) { 98 var $stickyad = $( value ); 99 if ( window.advanced_ads_sticky_items[ $stickyad.attr( 'id' ) ].can_convert_to_abs ) { 100 $stickyad.css( 'position', 'absolute' ); 101 } else {
102 $stickyad.css( 'position', '' ).css( 'top', '' ).css( 'right', '' ).css( 'bottom', '' ).css( 'left', '' ).css( 'margin-left', '' ) 103 .css( 'transform', 'none' ).css( '-webkit-transform', 'none' ).css( '-moz-transform', 'none' ).css( '-ms-transform', 'none' ); 104 } 105 }); 106 } ); 107 } 108 } 109 110 111 function scroll_handler() { 112 clearTimeout( $.data( this, 'scrollTimer' ) ); 113 // wait 100ms when scrolling before checking 114 $.data(this, 'scrollTimer', setTimeout(function() { 115 // donât do anything if scroll position is 0 == top 116 // or admin bar has not been scrolled. 117 if($( document ).scrollTop() <= allowed_offset ) { return; } 118 // check if position fixed is supported; story result in a variable so test runs only once 119 if(advanced_ads_sticky_position_fixed_supported == ''){ 120 advanced_ads_sticky_position_fixed_supported = advanced_ads_sticky_check_position_fixed(); 121 clearTimeout( $.data( this, 'scrollTimer' ) ); 122 $( window ).off( 'scroll', scroll_handler ); 123 } 124 // rewrite sticky ads 125 remove_css(); 126 }, 100)); 127 } 128 129 if ( navigator.userAgent.indexOf( 'Opera Mini' ) > -1 ) { 130 //Opera mini does not support 'scroll' event. 131 advanced_ads_sticky_position_fixed_supported = false; 132 remove_css(); 133 } else { 134 $( window ).scroll( scroll_handler ); 135 } 136 137 138 // When cache-busting inserts new item. 139 if ( typeof advanced_ads_pro === 'object' && advanced_ads_pro !== null ) { 140 advanced_ads_pro.postscribeObservers.add( function (event) { 141 if ( event.event === 'postscribe_done' && event.ref && event.ad ) { 142 var $stickyad = jQuery( event.ref ).children( '.' + advanced_ads_sticky_settings.sticky_class ); 143 if ( $stickyad.length ) { 144 remove_css( $stickyad ); 145 } 146 } 147 } ); 148 } 149});
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.