PageSourceSearch

https://datilim.co.il/wp-content/plugins/advanced-ads-sticky-ads/public/assets/js/sticky.js?ver=1.7.10

js datilim.co.il collected 2026-09-30 06:07:39 UTC 5,457 bytes, 138 lines download raw bytes

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
31jQuery( document ).ready(function($) {
32	var resize_timeout = null, $el, previous_width = $( window ).width();
33
34
35	// Update position when viewport size changes.
36	function resize_handler() {
37		if ( resize_timeout ) clearTimeout( resize_timeout );
38		resize_timeout = setTimeout( function() {
39			var new_width = $( window ).width();
40			if ( previous_width === new_width ) {
41				// Return if the viewport has not actually changed
42				// Scroll event triggered this due to the position of the address bar.
43				return;
44			}
45			previous_width  = new_width;
46
47			if ( typeof advanced_ads_sticky_items !== 'undefined' ) {
48				$.each( advanced_ads_sticky_items, function( wrapper_id, data ) {
49					$el = $( '#' + wrapper_id );
50					// Apply initial 'position: absolute' styles if 'position: absolute' was transformed to 'position: fixed'
51					// using the 'advads.fix_element' function.
52					$el.prop( 'style', data.initial_css );
53
54					// Fix to windows position and/or center vertically again.
55					data.modifying_func();
56				} );
57			}
58		}, 1000 );
59	}
60
61	if ( 'undefined' === typeof advanced_ads_responsive || ! parseInt( advanced_ads_responsive.reload_on_resize, 10 ) ) {
62		// If the "Reload ads on resize" feature of the Responsive add-on is not used.
63		jQuery( window ).on( 'resize', resize_handler );
64	}
65
66	//Remove 'position: fixed' if not supported, if the feature enabled in the settings.
67	if ( typeof advanced_ads_sticky_settings === 'undefined' || ! advanced_ads_sticky_settings.check_position_fixed ) {
68		return;
69	}
70
71	// story scroll enable value so it isn’t checked multiple times per page view
72	var advanced_ads_sticky_position_fixed_supported = '';
73	var allowed_offset = $( document.body ).is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
74
75	/**
76	 * Remove all position related inline styles.
77	 *
78	 * @param {object=} $stickyads Optional jQuery object.
79	 */
80	function remove_css( $stickyads ) {
81		// if position fixed is unsupported
82		if ( advanced_ads_sticky_position_fixed_supported === false ) {
83			$( window ).off( 'resize', resize_handler );
84			$stickyads = $stickyads || jQuery( '.' + advanced_ads_sticky_settings.sticky_class );
85			setTimeout( function() {
86				$stickyads.each( function( key, value ) {
87					var $stickyad = $( value );
88					if ( window.advanced_ads_sticky_items[ $stickyad.attr( 'id' ) ].can_convert_to_abs ) {
89						$stickyad.css( 'position', 'absolute' );
90					} else {
91						$stickyad.css( 'position', '' ).css( 'top', '' ).css( 'right', '' ).css( 'bottom', '' ).css( 'left', '' ).css( 'margin-left', '' )
92							.css( 'transform', 'none' ).css( '-webkit-transform', 'none' ).css( '-moz-transform', 'none' ).css( '-ms-transform', 'none' );
93					}
94				});
95			} );
96		}
97	}
98
99
100	function scroll_handler() {
101		clearTimeout( $.data( this, 'scrollTimer' ) );
102		// wait 100ms when scrolling before checking
103		$.data(this, 'scrollTimer', setTimeout(function() {
104			// don’t do anything if scroll position is 0 == top
105			// or admin bar has not been scrolled.
106			if($( document ).scrollTop() <= allowed_offset ) { return; }
107			// check if position fixed is supported; story result in a variable so test runs only once
108			if(advanced_ads_sticky_position_fixed_supported == ''){
109				advanced_ads_sticky_position_fixed_supported = advanced_ads_sticky_check_position_fixed();
110				clearTimeout( $.data( this, 'scrollTimer' ) );
111				$( window ).off( 'scroll', scroll_handler );
112			}
113			// rewrite sticky ads
114			remove_css();
115		}, 100));
116	}
117
118	if ( navigator.userAgent.indexOf( 'Opera Mini' ) > -1 ) {
119		//Opera mini does not support 'scroll' event.
120		advanced_ads_sticky_position_fixed_supported = false;
121		remove_css();
122	} else {
123		$( window ).scroll( scroll_handler );
124	}
125
126
127	// When cache-busting inserts new item.
128	if ( typeof advanced_ads_pro === 'object' && advanced_ads_pro !== null ) {
129		advanced_ads_pro.postscribeObservers.add( function (event) {
130			if ( event.event === 'postscribe_done' && event.ref && event.ad ) {
131				var $stickyad = jQuery( event.ref ).children( '.' + advanced_ads_sticky_settings.sticky_class );
132				if ( $stickyad.length ) {
133					remove_css( $stickyad );
134				}
135			}
136		} );
137	}
138});

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.