var adsense_ad_names = []; var ai_preview_window = typeof ai_preview !== 'undefined'; function ai_process_adsense_ad (element) { var ai_debug = typeof ai_debugging !== 'undefined'; var adsense_iframe = jQuery(element); var adsense_width = adsense_iframe.attr ('width'); var adsense_height = adsense_iframe.attr ('height'); var adsense_iframe2 = adsense_iframe.contents().find ('iframe[allowtransparency]'); var url_parameters = getAllUrlParams (adsense_iframe2.attr ('src')) if (typeof url_parameters ['client'] !== 'undefined') { var adsense_ad_client = url_parameters ['client']; var adsense_publisher_id = adsense_ad_client.replace ('ca-', ''); var adsense_ad_slot = url_parameters ['slotname']; var adsense_index = url_parameters ['ifi']; if (ai_debug) console.log ('AI ADSENSE', adsense_index, adsense_ad_client, adsense_ad_slot, url_parameters ['format'], url_parameters ['w'], url_parameters ['h']); var adsense_overlay = jQuery('
'); var adsense_ad_info = ''; if (typeof adsense_ad_slot !== 'undefined') { var adsense_ad_name = ''; if (typeof adsense_ad_names ['publisher_id'] !== 'undefined' && adsense_ad_names ['publisher_id'] == adsense_publisher_id && typeof adsense_ad_names [adsense_ad_slot] !== 'undefined') { adsense_ad_name = '
' + adsense_ad_names [adsense_ad_slot] + '
'; } adsense_ad_info = '
' + adsense_ad_slot + '
' + adsense_ad_name; } else { var adsense_auto_ads = adsense_iframe.closest ('div.google-auto-placed').length != 0; if (adsense_auto_ads) { adsense_overlay.addClass ('ai-auto-ads'); adsense_ad_info = '
Auto ads
'; } else adsense_overlay.addClass ('ai-no-slot'); } var adsense_info = jQuery('
AdSense #' + adsense_index + '
' + adsense_width + 'x' + adsense_height + '
' + adsense_ad_info + '
'); adsense_iframe.after (adsense_info); if (!ai_preview_window) { adsense_iframe.after (adsense_overlay); } } } function ai_process_adsense_ads () { jQuery('ins ins iframe').each (function () { ai_process_adsense_ad (this); }); } jQuery(document).ready(function($) { var ai_debug = typeof ai_debugging !== 'undefined'; var ajaxurl = 'AI_AJAXURL'; var nonce = 'AI_NONCE'; var adsense_data = {'ai': 1}; // dummy $.post (ajaxurl, {'action': 'ai_ajax', 'ai_check': nonce, 'adsense-ad-units': adsense_data} ).done (function (data) { if (data != '') { try { adsense_ad_names = JSON.parse (data); if (ai_debug) console.log (''); if (ai_debug) console.log ("AI ADSENSE DATA:", Object.keys (adsense_ad_names).length - 1, 'ad units'); } catch (error) { if (ai_debug) console.log ("AI ADSENSE DATA ERROR:", data); } } }).fail (function (xhr, status, error) { if (ai_debug) console.log ("AI ADSENSE DATA ERROR:", xhr.status, xhr.statusText); }).always (function (data) { if (ai_debug) console.log ('AI ADSENSE DATA', 'END'); }); if (!ai_preview_window) setTimeout (function() {ai_process_adsense_ads (jQuery);}, 2000); }); function getAllUrlParams (url) { // get query string from url (optional) or window var queryString = url ? url.split('?')[1] : window.location.search.slice(1); // we'll store the parameters here var obj = {}; // if query string exists if (queryString) { // stuff after # is not part of query string, so get rid of it queryString = queryString.split('#')[0]; // split our query string into its component parts var arr = queryString.split('&'); for (var i=0; i