1(function (window, $) { 2 "use strict"; 3 4 if (!$) { 5 return; 6 } 7 8 var config = window.SW_ADS_CONFIG || {}; 9 if (!config.cacheUrl || !config.writerUrl) { 10 return; 11 } 12 13 var hasTriedWriter = false; 14 var loggedImpressions = {}; 15 16 function parseCache(text) { 17 if (!text) { 18 return null; 19 } 20 try { 21 return JSON.parse(text); 22 } catch (e) { 23 return null; 24 } 25 } 26 27 function fetchCache() { 28 return $.ajax({ 29 url: config.cacheUrl, 30 cache: false, 31 dataType: "text" 32 }); 33 } 34 35 function callWriter() { 36 return $.ajax({ 37 url: config.writerUrl, 38 cache: false 39 }); 40 } 41 42 function logImpression(ad) { 43 if (!config.logUrl || !ad || !ad.shouldLog) { 44 return; 45 } 46 47 var key = ad.adLocationId + ":" + ad.adId; 48 if (loggedImpressions[key]) { 49 return; 50 } 51 loggedImpressions[key] = true; 52 53 $.ajax({
54 url: config.logUrl, 55 cache: false, 56 data: { 57 aid: ad.adId, 58 lid: ad.adLocationId, 59 atype: ad.adType 60 } 61 }); 62 } 63 64 function renderBanner($container, ad) { 65 if (!ad) { 66 return; 67 } 68 69 if (ad.adType === 1) { 70 $container.html(ad.freeHTML || ""); 71 return; 72 } 73 74 var img = "<img class='ad-image banner-image' src='/AdsUPLImage/" + ad.imageName + "' width='" + ad.imageWidth + "' height='" + ad.imageHeight + "' border='0'"; 75 if (ad.altTag) { 76 img += " alt='" + ad.altTag + "'"; 77 } 78 img += ">"; 79 80 if (ad.clickUrl) { 81 var target = ad.openInNewWindow ? " target='_blank'" : ""; 82 var title = ad.altTag ? " title='" + ad.altTag + "'" : ""; 83 $container.html("<a href='" + ad.clickUrl + "'" + target + title + ">" + img + "</a>"); 84 } else { 85 $container.html(img); 86 } 87 } 88 89 function buildRender(cache) { 90 if (!cache || !cache.locations) { 91 return; 92 } 93 94 $("[data-sw-ad-location]").each(function () { 95 var $el = $(this); 96 var location = ($el.data("sw-ad-location") || "").toString().toLowerCase(); 97 if (!location) { 98 return; 99 } 100 101 var loc = cache.locations[location]; 102 if (!loc || !loc.selected) { 103 return; 104 } 105 106 var ad = loc.selected; 107 ad.imageWidth = ad.imageWidth || loc.imageWidth; 108 ad.imageHeight = ad.imageHeight || loc.imageHeight; 109 renderBanner($el, ad); 110 logImpression(ad); 111 }); 112 } 113 114 function loadAds() { 115 fetchCache().done(function (text) { 116 var cache = parseCache(text); 117 if (!cache) { 118 if (hasTriedWriter) { 119 return; 120 } 121 hasTriedWriter = true; 122 callWriter().always(function () { 123 loadAds(); 124 }); 125 return; 126 } 127 buildRender(cache); 128 }).fail(function () { 129 if (hasTriedWriter) { 130 return; 131 } 132 hasTriedWriter = true; 133 callWriter().always(function () { 134 loadAds(); 135 }); 136 }); 137 } 138 139 $(function () { 140 loadAds(); 141 }); 142})(window, window.jQuery);
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.