1/** 2 * Creates the player search result. 3 * @param object The search result. 4 * @returns JQueryElement. 5 */ 6function createPlayerSearchResult(result) { 7 const URL = SEARCH_PLAYER_URL + result.slug; 8 9 const img = !!result.image 10 ? `<img src="${result.image}" alt="${result.title}" 11 onerror="this.onerror=null;this.src='${SEARCH_DEFAULT_PLAYER_IMAGE}';" 12 />` 13 : ''; 14 const flag = !!result.flag ? `<i><img src="${result.flag}" /></i>` : ''; 15 let image = img || flag ? '<div class="player-img">%image% %flag%</div>' : ''; 16 17 image = image.replaceAll('%image%', img); 18 image = image.replaceAll('%flag%', flag); 19 20 const playerValue = !!result.transfer_value ? `<div class="player-price"><span class="player-tag">${result.transfer_value}</span></div>` : ''; 21 22 let template = `<a href="%slug%" title="%title%" class="playerList-box type2"> 23 %image% 24 <div class="player-desc"> 25 <div class="ttl"> 26 <strong>%title%</strong> 27 <span>%title_sub%</span> 28 </div> 29 </div> 30 %value% 31 </a>`; 32 33 const variables = { 34 '%slug%': URL, 35 '%title%': result.title, 36 '%title_sub%': result.title_sub, 37 '%image%': image, 38 '%value%': playerValue 39 }; 40 41 return $(replaceInTemplate(template, variables)); 42} 43 44/** 45 * Creates the player compact search result. 46 * @param object The search result. 47 * @returns JQueryElement. 48 */ 49function createPlayerCompactSearchResult(result) { 50 const URL = SEARCH_PLAYER_URL + result.slug; 51 52 const img = !!result.image 53 ? `<i class="plyr-prfl-img"> 54 <img src="${result.image}" alt="${result.title}" 55 onerror="this.onerror=null;this.src='${SEARCH_DEFAULT_PLAYER_IMAGE}';" 56 /> 57 </i>` 58 : ''; 59 const flag = !!result.flag ? `<figure class="small-icon-image"><img src="${result.flag}" /></figure>` : ''; 60 let image = img || flag ? '<div class="player-image-holder">%image% %flag%</div>' : ''; 61 62 image = image.replaceAll('%image%', img); 63 image = image.replaceAll('%flag%', flag); 64 65 const playerValue = !!result.transfer_value ? `<div class="pl_value">${result.transfer_value}</div>` : ''; 66 67 let template = `<a href="%slug%" title="%title%" class="newItem player"> 68 %image% 69 <div class="text"> 70 <b>%title%</b> 71 <span class="sub-text d-md-block">%title_sub%</span></div> 72 </div> 73 %value% 74 </a>`; 75 76 const variables = { 77 '%slug%': URL, 78 '%title%': result.title, 79 '%title_sub%': result.title_sub, 80 '%image%': image, 81 '%value%': playerValue 82 }; 83 84 return $(replaceInTemplate(template, variables)); 85} 86 87/** 88 * Creates the team search result. 89 * @param object The search result. 90 * @returns JQueryElement. 91 */ 92function createTeamSearchResult(result) { 93 const URL = SEARCH_TEAM_URL + result.slug; 94 95 const img = !!result.image 96 ? `<img src="${result.image}" alt="${result.title}" 97 onerror="this.onerror=null;this.src='${SEARCH_DEFAULT_TEAM_IMAGE}';" 98 />` 99 : ''; 100 const flag = !!result.flag ? `<i><img src="${result.flag}" /></i>` : ''; 101 let image = img || flag ? '<div class="player-img">%image% %flag%</div>' : ''; 102 103 image = image.replaceAll('%image%', img); 104 image = image.replaceAll('%flag%', flag); 105 106 const playerValue = !!result.transfer_value ? `<div class="player-price"><span class="player-tag">${result.transfer_value}</span></div>` : ''; 107 108 let template = `<a href="%slug%" title="%title%" class="playerList-box type2 team"> 109 %image% 110 <div class="player-desc"> 111 <div class="ttl"> 112 <strong>%title%</strong> 113 <span>%title_sub%</span> 114 </div> 115 </div> 116 %value% 117 </a>`; 118 119 const variables = { 120 '%slug%': URL, 121 '%title%': result.title, 122 '%title_sub%': result.title_sub,
123 '%image%': image, 124 '%value%': playerValue 125 }; 126 127 return $(replaceInTemplate(template, variables)); 128} 129 130/** 131 * Creates the team compact search result. 132 * @param object The search result. 133 * @returns JQueryElement. 134 */ 135function createTeamCompactSearchResult(result) { 136 const URL = SEARCH_TEAM_URL + result.slug; 137 138 const img = !!result.image 139 ? `<i class="plyr-prfl-img"> 140 <img src="${result.image}" alt="${result.title}" 141 onerror="this.onerror=null;this.src='${SEARCH_DEFAULT_TEAM_IMAGE}';" 142 /> 143 </i>` 144 : ''; 145 const flag = !!result.flag ? `<figure class="small-icon-image"><img src="${result.flag}" /></figure>` : ''; 146 let image = img || flag ? '<div class="player-image-holder">%image% %flag%</div>' : ''; 147 148 image = image.replaceAll('%image%', img); 149 image = image.replaceAll('%flag%', flag); 150 151 let template = `<a href="%slug%" title="%title%" class="newItem team"> 152 %image% 153 <div class="text"> 154 <b>%title%</b> 155 <span class="sub-text d-md-block">%title_sub%</span></div> 156 </div> 157 </a>`; 158 159 const variables = { 160 '%slug%': URL, 161 '%title%': result.title, 162 '%title_sub%': result.title_sub, 163 '%image%': image 164 }; 165 166 return $(replaceInTemplate(template, variables)); 167} 168 169/** 170 * Creates the article search result. 171 * @param object The search result. 172 * @returns JQueryElement. 173 */ 174function createArticleSearchResult(result) { 175 const URL = SEARCH_ARTICLE_URL + result.slug; 176 177 const img = !!result.image ? `<img src="${result.image}" alt="${result.title}" />` : ''; 178 const flag = !!result.flag ? `<i><img src="${result.flag}" /></i>` : ''; 179 let image = img || flag ? '<div class="player-img">%image% %flag%</div>' : ''; 180 181 image = image.replaceAll('%image%', img); 182 image = image.replaceAll('%flag%', flag); 183 184 const playerValue = !!result.transfer_value ? `<div class="player-price"><span class="player-tag">${result.transfer_value}</span></div>` : ''; 185 186 let template = `<a href="%slug%" title="%title%" class="playerList-box type2 news"> 187 %image% 188 <div class="player-desc"> 189 <div class="ttl"> 190 <strong>%title%</strong> 191 <span>%title_sub%</span> 192 </div> 193 </div> 194 %value% 195 </a>`; 196 197 const variables = { 198 '%slug%': URL, 199 '%title%': result.title, 200 '%title_sub%': timeAgo(result.title_sub), 201 '%image%': image, 202 '%value%': playerValue 203 }; 204 205 return $(replaceInTemplate(template, variables)); 206} 207 208/** 209 * Creates the article compact search result. 210 * @param object The search result. 211 * @returns JQueryElement. 212 */ 213function createArticleCompactSearchResult(result) { 214 const URL = SEARCH_ARTICLE_URL + result.slug; 215 216 const img = !!result.image ? `<i class="plyr-prfl-img article-search"><img src="${result.image}" alt="${result.title}" /></i>` : ''; 217 const flag = !!result.flag ? `<figure class="small-icon-image"><img src="${result.flag}" /></figure>` : ''; 218 let image = img || flag ? '<div class="player-image-holder d-flex align-items-center">%image% %flag%</div>' : ''; 219 220 image = image.replaceAll('%image%', img); 221 image = image.replaceAll('%flag%', flag); 222 223 let template = `<a href="%slug%" title="%title%" class="newItem news"> 224 %image% 225 <div class="text"> 226 <b>%title%</b> 227 <span class="sub-text d-md-block">%title_sub%</span></div> 228 </div> 229 </a>`; 230 231 const variables = { 232 '%slug%': URL, 233 '%title%': result.title, 234 '%title_sub%': timeAgo(result.title_sub), 235 '%image%': image 236 }; 237 238 return $(replaceInTemplate(template, variables)); 239} 240 241lastVal = ""; 242 243function delay(callback, ms) { 244 var timer = 0; 245 246 return function () { 247 var context = this, args = arguments; 248 249 clearTimeout(timer); 250 251 timer = setTimeout(function () { 252 callback.apply(context, args); 253 }, ms || 0); 254 }; 255} 256 257/** 258 * Displays the date according to the rules. 259 */ 260function timeAgo(dateParam) { 261 if (!dateParam) { 262 return null; 263 } 264 265 const date = moment(dateParam); 266 const today = moment(); 267 const yesterday = moment().add(-1, 'days'); 268 269 const seconds = today.diff(date, 'seconds'); 270 const minutes = today.diff(date, 'minutes'); 271 const isToday = today.isSame(date, 'day'); 272 const isYesterday = yesterday.isSame(date, 'day'); 273 const isThisYear = today.isSame(date, 'year'); 274 275 if (seconds < 5) { 276 return SEARCH_TRANSLATIONS.time_now; 277 } else if (seconds < 60) { 278 return SEARCH_TRANSLATIONS.time_seconds_ago.replace('%s', seconds); 279 } else if (seconds < 90) { 280 return SEARCH_TRANSLATIONS.time_minute_ago; 281 } else if (minutes < 60) { 282 return SEARCH_TRANSLATIONS.time_minutes_ago.replace('%s', minutes); 283 } else if (isToday) { 284 return date.format(`[${SEARCH_TRANSLATIONS.time_today}] [${SEARCH_TRANSLATIONS.time_at}] H:mm`); // Yesterday at 10:20 285 } else if (isYesterday) { 286 return date.format(`[${SEARCH_TRANSLATIONS.time_yesterday}] [${SEARCH_TRANSLATIONS.time_at}] H:mm`); // Yesterday at 10:20 287 } else if (isThisYear) { 288 return date.format(`DD MMMM [${SEARCH_TRANSLATIONS.time_at}] H:mm`); // 10. January 2017. at 10:20 289 } 290 291 return date.format(`DD MMMM Y [${SEARCH_TRANSLATIONS.time_at}] H:mm`); // 10. January 2017. at 10:20 292} 293 294function activateSearch(val) { 295 $("#header-part.new .search-panel").addClass("active"); 296 297 val = val.trim(); 298 299 // Create virtual text element to sanitize string 300 let searchQuery = $('<input>').text(val.replace('highlight', '')).text(); 301
302 if (searchQuery == "" && lastVal != "highlight") { 303 searchQuery = "highlight" 304 } 305 306 if (searchQuery.length == 0 || searchQuery == lastVal) { 307 return; 308 } 309 310 $.ajax({ 311 url: SEARCH_AJAX_URL, 312 type: 'POST', 313 data: { 314 'search_value': searchQuery 315 }, 316 success: function (response) { 317 const totalResults = response.hits.length; 318 const found = response.found; 319 320 let containerExists = $("#header-part.new .search-panel").find('.searchResults'); 321 322 if (!!containerExists) { 323 containerExists.remove(); 324 } 325 326 const searchResults = $('<div class="searchResults"></div>'); 327 const results = $('<div class="fndItems"></div>'); 328 329 if (response.hits) { 330 $.each(response.hits, function (index, hit) { 331 switch (hit.document.type) { 332 case "player": 333 results.append(createPlayerCompactSearchResult(hit.document)); 334 break; 335 case "team": 336 results.append(createTeamCompactSearchResult(hit.document)); 337 break; 338 case "news": 339 results.append(createArticleCompactSearchResult(hit.document)); 340 break; 341 } 342 }); 343 } 344 345 const resultsText = replaceInTemplate('<a href="%search_url%?search_value=%search_value%">%results_total%</a>', { 346 '%search_value%': searchQuery, 347 '%search_url%': SEARCH_URL, 348 '%results_total%': replaceInTemplate(SEARCH_TRANSLATIONS.results_total, { 349 '%results%': found == 1 ? SEARCH_TRANSLATIONS.result : SEARCH_TRANSLATIONS.results, 350 '%found%': found, 351 '%total_results%': totalResults, 352 }), 353 }); 354 355 const allResultsText = replaceInTemplate('<a href="%search_url%?search_value=%search_value%">%results_all%</a>', { 356 '%search_value%': searchQuery, 357 '%search_url%': SEARCH_URL, 358 '%results_all%': replaceInTemplate(SEARCH_TRANSLATIONS.results_all, { '%found%': found }) 359 }); 360 361 const note = replaceInTemplate('<div class="note">%results% | %advanced_search%</div>', { 362 '%results%': found > response.hits.length ? allResultsText : resultsText, 363 '%advanced_search%': '<a href="' + SEARCH_URL + '" title="' + SEARCH_TRANSLATIONS.advanced_search + '">' + SEARCH_TRANSLATIONS.advanced_search + '</a>', 364 }); 365 366 if (results.length > 0) { 367 searchResults.append(results); 368 searchResults.append(note); 369 370 $("#header-part.new .search-panel").append(searchResults); 371 } 372 373 lastVal = searchQuery; 374 } 375 }); 376} 377 378 379function clearSearch() { 380 $("#header-part.new .search-panel").removeClass("active"); 381 $("#header-part.new .search-panel").find(".searchResults").remove(); 382 $("#header-part.new .search-panel input").val(""); 383} 384 385$(document).ready(function () { 386 let lastSearchValue = ""; 387 388 const searchPanel = $("#header-part.new .search-panel"); 389 const searchInput = searchPanel.find('input'); 390 391 searchInput.on("keyup", delay(function (e) { 392 const searchValue = $(this).val(); 393 394 if (searchValue != lastSearchValue) { 395 activateSearch(searchValue); 396 lastSearchValue = searchValue; 397 } 398 399 if (e.keyCode == 13) { 400 window.location.href = SEARCH_URL + (!!searchValue ? "?search_value=" + searchValue : ''); 401 } 402 403 }, 400)); 404 405 firstFocus = false; 406 407 searchInput.on("focus", function () { 408 const searchValue = $(this).val(); 409 410 if (searchValue != lastSearchValue || !firstFocus) { 411 activateSearch(searchValue); 412 lastSearchValue = searchValue; 413 firstFocus = true; 414 } 415 }); 416 417 // Search when the button has been clicked 418 searchPanel.find(".fa-search").click(function () { 419 searchValue = searchInput.val(); 420 if (searchValue == '') { 421 activateSearch(searchValue); 422 searchInput.focus(); 423 } else { 424 window.location.href = SEARCH_URL + (!!searchValue ? "?search_value=" + searchValue : ''); 425 } 426 }); 427 428 // Hide the search container when the target of the click isn't the container nor a descendant of the container 429 $(document).mouseup(function (e) { 430 if (!searchPanel.is(e.target) && searchPanel.has(e.target).length === 0) { 431 clearSearch(); 432 } 433 }); 434 435 searchPanel.find(".fa-arrow-left").click(function () { 436 clearSearch(); 437 }); 438 439 searchPanel.find(".fa-times").click(function () { 440 if (searchInput.val().length > 0) { 441 searchPanel.find(".searchResults").remove(); 442 searchInput.val("").focus(); 443 } else { 444 clearSearch(); 445 } 446 }); 447 448});
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.