1/** 2 * plain js functions for displaying ads by size 3 * 4 **/ 5 6// basic variables 7var advanced_ads_resizetimeout = 1000; // time to wait until resized window width is saved, in millisec 8var advanced_ads_cookieexpires = 30; // days until the cookie expires 9var advanced_ads_browser_width = advanced_ads_get_browser_width(); 10 11// save browserWidth in a cookie if not set or not equal to current saved width 12if ( window.advads !== undefined && ! advads.get_cookie( 'advanced_ads_browser_width' ) || 13 advads.get_cookie('advanced_ads_browser_width') !== advanced_ads_browser_width ) { 14 15 advanced_ads_save_width( advanced_ads_browser_width ); 16 17} 18 19// save new browser width, when window resizes 20if (window.addEventListener) { // most non-IE browsers and IE9 21 window.addEventListener("resize", advanced_ads_resize_window, false); 22} else if (window.attachEvent) { // Internet Explorer 5 or above 23 window.attachEvent("onresize", advanced_ads_resize_window); 24} 25 26function advanced_ads_resize_window () { 27 advads_resize_delay(function(){ 28 var previous_width = advanced_ads_browser_width; 29 advanced_ads_browser_width = advanced_ads_get_browser_width(); 30 if ( previous_width === advanced_ads_browser_width ) { 31 // Return if the viewport has not actually changed 32 // Scroll events were triggering this on iOS due to the position of the address bar. 33 return; 34 } 35 36 advanced_ads_save_width( advanced_ads_browser_width ); 37 38 var advanced_ads_responsive = window.advanced_ads_responsive || {} 39 if ( window.jQuery && parseInt( advanced_ads_responsive.reload_on_resize, 10 ) ) { 40 jQuery( document ).triggerHandler( 'advanced-ads-resize-window' ); 41 } 42 }, advanced_ads_resizetimeout); 43} 44 45// save width in cookie 46function advanced_ads_save_width ( width ) { 47 if( window.advads !== undefined ){ 48 advads.set_cookie( 'advanced_ads_browser_width', width, advanced_ads_cookieexpires ); 49 } 50} 51 52// create a listener calling only once after resize 53// http://stackoverflow.com/questions/2854407/javascript-jquery-window-resize-how-to-fire-after-the-resize-is-completed 54var advads_resize_delay = (function(){ 55 var timer = 0; 56 return function (callback, ms) { 57 clearTimeout(timer); 58 timer = setTimeout(callback, ms); 59 }; 60})(); 61 62/** 63 * get the width of the browser 64 */ 65function advanced_ads_get_browser_width() { 66 if ( window.jQuery ){ 67 return jQuery(window).width(); 68 } else { 69 var browserWidth = 0; 70 if( typeof( window.innerWidth ) == 'number' ) { 71 //Non-IE 72 browserWidth = window.innerWidth; 73 } else if( document.documentElement && document.documentElement.clientWidth ) { 74 //IE 6+ in 'standards compliant mode' 75 browserWidth = document.documentElement.clientWidth; 76 } else if( document.body && document.body.clientWidth ) { 77 //IE 4 compatible 78 browserWidth = document.body.clientWidth; 79 } 80 return browserWidth; 81 } 82}
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.