1(function ($) { 2 'use strict'; 3 4 const origin = (new URL(document.currentScript.src)).origin; 5 6 function buildLocoHtml(items) { 7 if (items.length === 0) { 8 return ''; 9 } 10 11 let html = '<div class="loco-prescroll">' + 12 '<div class="loco-scroll">' + 13 '<div class="widget-loco">'; 14 15 const chunks = [ 16 {count: 3, class: 'widget-loco--grid_triple'}, 17 {count: 2, class: 'widget-loco--grid_double'}, 18 {count: 1, class: 'widget-loco--grid_single'} 19 ]; 20 21 $.each(chunks, function(k, chunkInfo) { 22 let subItems = [...items]; 23 24 while (subItems.length) { 25 let banners = [subItems.shift()]; 26 let textLength = banners[0].title.length; 27 while (banners.length < chunkInfo.count && subItems.length && (textLength + subItems[0].title.length < 20 * chunkInfo.count)) { 28 textLength += subItems[0].title.length; 29 banners.push(subItems.shift()); 30 } 31 32 html += '<!--loco ' + chunkInfo.count + '--><div class="widget-loco--grid ' + chunkInfo.class + '">'; 33 34 $.each(banners, function (k, banner) { 35 html += '<!--banner--><div class="loco-item loco-tooltip" data-id="' + banner.id + '" data-tooltip-content="#tooltip' + banner.id + '" data-tooltipster=\'{"theme":"tooltipster-borderless", "gradientStartColor":"' + banner.gradient.f + '", "gradientEndColor":"' + banner.gradient.t + '", "buttonColor":"' + banner.popup.btn.color + '"}\' style="--gradient-start-color: ' + banner.gradient.f + '; --gradient-end-color: ' + banner.gradient.t + ';">' + 36 '<div class="loco-item--inner">' + 37 '<div class="loco-item--icon">' + banner.image + '</div>' + 38 '<div class="loco-item--name">' + banner.title + '</div>' + 39 '</div>' + 40 '</div><!--!banner-->'; 41 }); 42 43 html += '</div><!--!loco ' + chunkInfo.count + '-->'; 44 } 45 }); 46 47 html += '</div>' + 48 '</div>' + 49 '<a class="widget-loco--arrow widget-loco--arrow_prev" href="javascript:void(0);">' + 50 '<svg><use href="/nimg/loco-arrow-right.svg#icon"></use></svg>' + 51 '</a>' + 52 '<a class="widget-loco--arrow widget-loco--arrow_next" href="javascript:void(0);">' + 53 '<svg><use href="/nimg/loco-arrow-right.svg#icon"></use></svg>' + 54 '</a>' + 55 '</div>'; 56 57 return html; 58 } 59 60 function buildTooltipHtml(items) { 61 if (items.length === 0) { 62 return ''; 63 } 64 65 let html = '<div class="unitip-wrap">'; 66 67 $.each(items, function(key, item) { 68 html += '<div class="unitip-info" id="tooltip' + item.id + '">' + 69 '<div class="unitip-popup">'; 70 if (item.image) { 71 html += '<div class="unitip-popup--image">' + item.image + '</div>'; 72 } 73 html += '<div class="unitip-popup--inner">' + 74 '<div class="unitip-popup--head">' + 75 '<div class="unitip-popup--heading">' + item.popup.title + '</div>' + 76 '<div class="unitip-popup--subheading">' + item.popup.text + '</div>' + 77 '</div>' + 78 '<a class="unitip-popup--button" data-id="' + item.id + '" href="' + item.popup.btn.url + '" target="_blank">' + 79 item.popup.btn.text + 80 '<svg><use href="/nimg/ext-arrow-loco.svg#arrow"></use></svg>' + 81 '</a>' + 82 '</div>' + 83 '</div>' + 84 '</div>'; 85 }); 86 87 html += '</div>'; 88 89 return html; 90 } 91 92 function initLoco() { 93 const sendClick = (id, type) => { 94 $.ajax({ 95 url: origin + '/misc/header-banner-click', 96 dataType: 'jsonp', 97 data: {id, type} 98 }); 99 }; 100 101 $('.locoDesktop .unitip-popup--button').on('click', function() { 102 sendClick($(this).data('id'), 2); // 2 - TYPE_POPUP 103 }); 104 105 $('.loco-tooltip:not(.tooltipstered)').tooltipster({ 106 functionInit: function(instance, helper) { 107 let $origin = $(helper.origin), 108 dataOptions = $origin.attr('data-tooltipster'); 109 if (dataOptions) { 110 dataOptions = JSON.parse(dataOptions); 111 $.each(dataOptions, function(name, option) { 112 instance.option(name, option); 113 }); 114 } 115 }, 116 functionBefore: function(instance, helper) { 117 sendClick($(helper.origin).data('id'), 1); // 1 - TYPE_BANNER 118 }, 119 animation: 'fade', 120 animationDuration: 0, 121 interactive: true, 122 side: 'bottom', 123 trigger: 'custom', 124 triggerOpen: { 125 click: true, 126 tap: true 127 }, 128 triggerClose: { 129 click: true, 130 tap: true 131 } 132 }); 133 134 $(window).resize(function() { 135 $('.loco-tooltip.tooltipstered').tooltipster('close'); 136 }); 137 138 new Swiper('.loco-scroll', { 139 wrapperClass: 'widget-loco', 140 slideClass: 'widget-loco--grid', 141 slidesPerView: 1, 142 navigation: { 143 nextEl: '.widget-loco--arrow_next', 144 prevEl: '.widget-loco--arrow_prev', 145 disabledClass: 'widget-loco--arrow_disabled' 146 } 147 }); 148 } 149 150 function buildPiHtml(banner, className) { 151 return '<a class="' + className + ' pr-tooltip" href="javascript:void(0);" data-tooltip-content="#tooltipPr" data-tooltipster=\'{"theme":"tooltipster-borderless", "gradientStartColor":"' + banner.gradient.f + '", "gradientEndColor":"' + banner.gradient.t + '", "buttonColor":"' + banner.popup.btn.color + '"}\' style="--gradient-start-color: ' + banner.gradient.f + '; --gradient-end-color: ' + banner.gradient.t + ';">' + 152 '<svg width="33" height="32"><use href="' + banner.icon + '"></use></svg>
152' + 153 '</a>'; 154 } 155 156 function initPi() { 157 $('.pr-tooltip').tooltipster({ 158 functionInit: function (instance, helper) { 159 let $origin = $(helper.origin), 160 dataOptions = $origin.attr('data-tooltipster'); 161 if (dataOptions) { 162 dataOptions = JSON.parse(dataOptions); 163 $.each(dataOptions, function (name, option) { 164 instance.option(name, option); 165 }); 166 } 167 }, 168 animation: 'fade', 169 animationDuration: 0, 170 side: 'bottom', 171 interactive: true, 172 trigger: 'custom', 173 triggerOpen: { 174 click: true, 175 tap: true 176 }, 177 triggerClose: { 178 click: true, 179 tap: true 180 } 181 }); 182 } 183 184 function shuffle(array) { 185 for (let i = array.length - 1; i > 0; i--) { 186 let j = Math.floor(Math.random() * (i + 1)); 187 [array[i], array[j]] = [array[j], array[i]]; 188 } 189 } 190 191 $(function () { 192 $.ajax({ 193 url: origin + '/ssi/loco.php', 194 dataType: 'jsonp', 195 cache: true, 196 jsonpCallback: 'loco' 197 }).done(function (json) { 198 if (json) { 199 if (json.loco && json.loco.length > 0) { 200 shuffle(json.loco); 201 202 for (let pos = 3; pos > 0; pos--) { 203 let totalProb = 0; 204 $.each(json.loco, function (k, v) { 205 if (v.pos === pos) { 206 totalProb += v.prob; 207 } 208 }); 209 210 let rand = Math.random() * totalProb; 211 212 let selectedKey; 213 $.each(json.loco, function (k, v) { 214 if (v.pos === pos) { 215 rand -= v.prob; 216 if (rand < 0) { 217 selectedKey = k; 218 return false; 219 } 220 } 221 }); 222 223 if (!selectedKey) { 224 $.each(json.loco, function (k, v) { 225 if (v.pos === 0) { 226 selectedKey = k; 227 return false; 228 } 229 }); 230 } 231 232 let v = json.loco.splice(selectedKey, 1); 233 v.pos = selectedKey; 234 json.loco.unshift(v[0]); 235 } 236 237 json.loco[0].image = json.loco[0].image.replace('loading="lazy"', ''); 238 239 const locoHtml = buildLocoHtml(json.loco); 240 const tooltipHtml = buildTooltipHtml(json.loco); 241 242 $('.locoDesktop').html(locoHtml + tooltipHtml); 243 $('.loco-placeholder_mobile').html(locoHtml); 244 245 initLoco(); 246 } 247 248 if (json.pi && json.pi.length > 0) { 249 shuffle(json.pi); 250 251 let totalProb = 0; 252 $.each(json.pi, function (k, v) { 253 totalProb += v.prob; 254 }); 255 256 let rand = Math.random() * totalProb; 257 let selected; 258 259 $.each(json.pi, function (k, v) { 260 rand -= v.prob; 261 if (rand < 0) { 262 selected = v; 263 return false; 264 } 265 }); 266 267 if (!selected) { 268 selected = json.pi.shift(); 269 } 270 271 selected.id = 'Pr'; 272 273 const piHtml = buildPiHtml(selected, 'menu-top--promo'); 274 const piMobileHtml = buildPiHtml(selected, 'mobile-top--promo'); 275 const tooltipHtml = buildTooltipHtml([selected]); 276 277 $('.mobile-top--inner').prepend(piMobileHtml); 278 $('span.menu-top--promo').replaceWith(piHtml + tooltipHtml); 279 280 initPi(); 281 } 282 } 283 }); 284 }); 285})(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.