1var locale = $('.localeStr').val(); 2if(locale == undefined ){ 3 locale = 'en'; 4} 5var divhtml = ""; 6var dateFormat = $('.dateFormat').val(); 7var hasLocale = $('.hasLocale').val(); 8var hasDateFormat = $('.hasDateFormat').val(); 9var isDisabled = false; 10if(($('.WCMmode').val())!=null){ 11if(($('.WCMmode').val()).indexOf("EDIT")<0){ 12 isDisabled = true; 13} 14} 15 16// Fetch API and Intersection Observer 17$(document).ready(function(){ 18 $('.inline_search_api').each(function(){ 19 var lineId = $(this).prop('id'); 20 var lineUrl = $('#'+lineId).attr('data-url'); 21 var dataId = lineId.replace("inline", "data"); 22 var res = lineId.split("_"); 23 var type = res[0]; 24 IntObs(lineUrl, lineId, dataId, type); 25 }); 26}); 27 28// Calling single intersection method 29function IntObs(urlParam, idParam, uuidParam, type) { 30 var divhtml=""; 31 // Intersection Observer 32 var targetEvents = document.querySelector('#'+idParam); 33 var optionsEvents = {}; 34 function handleIntersection(entries) { 35 entries.map((entry) => { 36 if (entry.isIntersecting && entry.target.id == idParam && document.getElementById(uuidParam).getElementsByTagName('img')[0]!=undefined) { 37 if(type.indexOf("events")>=0) 38 return; 39 GetData(urlParam, idParam, uuidParam, type); 40 } 41 }); 42} 43var observerEvents = new IntersectionObserver(handleIntersection, optionsEvents); 44observerEvents.observe(targetEvents); 45} 46 47// Single Fetch API 48function GetData(url, id, uuidParam, type) { 49 $('#'+id).addClass("loader"); 50 fetch(url).then(function(response) { 51 if (response.ok) { 52 return response.json(); 53 } else { 54 setTimeout(() => { 55 $("#"+id+" img:last-child").remove(); 56 }, 1000); 57 } 58 }).then(function(myJson) { 59 if(myJson.total == 0){ 60 $("#"+id+" img:last-child").remove(); 61 if(isDisabled){ 62 var colsplitEL = $("#"+id).closest(".colsplit"); 63 var colsplitR = $("#"+id).closest(".colsplit")[0]; 64 $("#"+id).removeClass("loader"); 65 66 var hrElm = $("#"+id).parent().next()[0].outerHTML; 67 if(hrElm.indexOf("<hr")>-1){ 68 hrElm.remove(); 69 hrElm = $("#"+id).parent().next()[0].outerHTML; 70 if(hrElm.indexOf("<hr")>-1){ 71 hrElm.remove(); 72 } 73 } 74 75 $("#"+id).parent().remove(); 76 if(colsplitR!=undefined && colsplitR.innerText.length<=0){ 77 colsplitEL.hide(); 78 } 79 80 } 81 }else{ 82 if(type=='blogsinline') { 83 blogData(myJson, url, id, uuidParam, type); 84 } 85 else if(type=='newsinline') { 86 newsData(myJson, url, id, uuidParam, type); 87 } 88 else if(type=='eventsinline') { 89 eventsData(myJson, url, id, uuidParam, type); 90 } 91 else if(type=='prjinline') { 92 projectData(myJson, url, id, uuidParam, type); 93 } 94 else if(type=='researchinline') { 95 researchData(myJson, url, id, uuidParam, type); 96 } 97 else if(type=='whatsnewinline') { 98 whatsnewsData(myJson, url, id, uuidParam, type); 99 } 100 else if(type=='docsnewinline' ) { 101 documentData(myJson, url, id, uuidParam, type); 102 } 103 else if( type=='docsinline') { 104 wdsData(myJson, url, id, uuidParam, type); 105 } 106 else if(type=='wdsResearchinline') { 107 wdsResearchData(myJson, url, id, uuidParam, type); 108 } 109 else if(type=='everythinginline') { 110 everything(myJson, url, id, uuidParam, type); 111 } 112 } 113 }).catch((error) => { 114 setTimeout(() => { 115 var colsplitEL = $("#"+id).closest(".colsplit"); 116 var colsplitR = $("#"+id).closest(".colsplit")[0]; 117 $("#"+id).removeClass("loader"); 118 $("#"+id).parent().remove(); 119 if(colsplitR!=undefined && colsplitR.innerText.length<=0){ 120 colsplitEL.hide(); 121 } 122 123 }, 1000); 124 }); 125 126 } 127 128 function wdsResearchData(myJson, url, id, uuidParam, type) { 129 var dataarr = myJson.documents; 130 if(dataarr != undefined) 131 { 132 var dateArr = []; 133 Object.keys(dataarr).forEach(function(key,index) { 134 var item = dataarr[key]; 135 date = item.hasOwnProperty("docdt") ? getValue(item.docdt) : ""; 136 dateArr.push(date); 137 }); 138 dateFormatAPI(dataarr,dateArr,uuidParam, type); 139} 140} 141 142function blogData(myJson, url, id, uuidParam, type) { 143 var dataarr = myJson.blogs; 144 if(dataarr != undefined) 145 { 146 var dateArr = []; 147 Object.keys(dataarr).forEach(function(key,index) { 148 var item = dataarr[key]; 149 date = item.hasOwnProperty("blog_date") ? getValue(item.blog_date) : ""; 150 dateArr.push(date); 151 }); 152 dateFormatAPI(dataarr,dateArr,uuidParam, type); 153 } 154} 155function everything(myJson, url, id, uuidParam, type) { 156 var dataarr = myJson.everything; 157 console.log(myJson.everything); 158 if(dataarr != undefined) 159 { 160 var dateArr = []; 161 Object.keys(dataarr).forEach(function(key,index) { 162 var item = dataarr[key]; 163 date = item.hasOwnProperty("master_date") ? getValue(item.master_date) : ""; 164 dateArr.push(date); 165 }); 166 dateFormatAPI(dataarr,dateArr,uuidParam, type); 167 } 168} 169 170function newsData(myJson, url, id, uuidParam, type) { 171 var dataarr = myJson.documents; 172 if(dataarr != undefined) 173 { 174 var dateArr = []; 175 Object.keys(dataarr).forEach(function(key,index) { 176 var item = dataarr[key]; 177 date = item.hasOwnProperty("lnchdt") ? getValue(item.lnchdt) : ""; 178 dateArr.push(date); 179 }); 180 dateFormatAPI(dataarr,dateArr,uuidParam,type); 181 } 182} 183 184function eventsData(myJson, url, id, uuidParam, type) { 185 var dataarr = myJson.documents; 186 var array = $.map(dataarr, function(value, index) { 187 return [value]; 188 }); 189 array.sort(custom_sort); 190 if(dataarr != undefined) 191 { 192 var dateArr = []; 193 array.forEach(function(key,index) { 194 var item = key; 195 date = item.hasOwnProperty("eventenddate") ? getValue(item.eventenddate) : ""; 196 dateArr.push(date); 197 198 }); 199 dateFormatAPI(array,dateArr,uuidParam,type); 200 } 201 $("#"+id).removeClass("loader"); 202} 203 204function projectData(myJson, url, id, uuidParam, type) { 205 var dataarr = myJson.projects; 206 if(dataarr != undefined) 207 { 208 var dateArr = []; 209 Object.keys(dataarr).forEach(function(key,index) { 210 var item = dataarr[key]; 211 212 date = item.hasOwnProperty("boardapprovaldate") ? getValue(item.boardapprovaldate) : ""; 213 dateArr.push(date); 214 215 }); 216 dateFormatAPI(dataarr,dateArr,uuidParam,type); 217 } 218} 219 220function researchData(myJson, url, id, uuidParam, type) { 221 var dataarr = myJson.documents; 222 if(dataarr != undefined) 223 { 224 var dateArr = []; 225 Object.keys(dataarr).forEach(function(key,index) { 226 var item = dataarr[key]; 227 date = item.hasOwnProperty("docdt") ? getValue(item.docdt) : ""; 228 dateArr.push(date); 229 }); 230 dateFormatAPI(dataarr,dateArr,uuidParam,type); 231 } 232} 233 234function whatsnewsData(myJson, url, id, uuidParam, type) { 235 var dataarr = myJson.whatsnew; 236 if(dataarr != undefined) 237 { 238 var dateArr = []; 239 Object.keys(dataarr).forEach(function(key,index) { 240 var item = dataarr[key]; 241 date = item.hasOwnProperty("date") ? getValue(item.date) : ""; 242 dateArr.push(date); 243 }); 244 dateFormatAPI(dataarr,dateArr,uuidParam,type); 245 } 246} 247function wdsData(myJson, url, id, uuidParam, type) { 248 var dataarr = myJson.documents; 249 if(dataarr != undefined) 250 { 251 var dateArr = []; 252 Object.keys(dataarr).forEach(function(key,index) { 253 var item = dataarr[key]; 254 date = item.hasOwnProperty("docdt") ? getValue(item.docdt) : ""; 255 dateArr.push(date); 256 }); 257 dateFormatAPI(dataarr,dateArr,uuidParam,type); 258 } 259} 260 261function documentData(myJson, url, id, uuidParam, type) { 262 var dataarr = myJson.whatsnew; 263 if(dataarr != undefined) 264 { 265 var dateArr = []; 266 Object.keys(dataarr).forEach(function(key,index) { 267 var item = dataarr[key]; 268 date = item.hasOwnProperty("docdt") ? getValue(item.docdt) : ""; 269 dateArr.push(date); 270 }); 271 dateFormatAPI(dataarr,dateArr,uuidParam,type); 272 } 273} 274 275function dateFormatAPI(dataarr,dateArr,uuidParam,type) { 276 $.ajax({ 277 method: 'POST', 278 url: '/wbg/aem/service/dateformat', 279 data: JSON.stringify({ "dateFormat":dateFormat ,"locale":locale,"hasLocale":hasLocale,"hasDateFormat":hasDateFormat,"dateArray":dateArr }), 280 dataType: "json", 281 contentType: 'application/json; charset=utf-8', 282 }).done(function(data) { 283 if(data.dateArray != undefined) 284 { 285 dateArr = data.dateArray; 286 } 287 }) .always(function() { 288 if(type=='blogsinline') { 289 generateblogHTML(dataarr,dateArr,uuidParam); 290 } 291 else if(type=='newsinline') { 292 generatenewsHTML(dataarr,dateArr,uuidParam); 293 } 294 else if(type=='eventsinline') { 295 generateeventsHTML(dataarr,dateArr,uuidParam); 296 } 297 else if(type=='prjinline') { 298 299 generateprojectHTML(dataarr,dateArr,uuidParam); 300 } 301 else if(type=='researchinline') { 302 generateresearchHTML(dataarr,dateArr,uuidParam); 303 } 304 else if(type=='whatsnewinline') { 305 generateehatsnewHTML(dataarr,dateArr,uuidParam); 306 } 307 else if(type=='docsnewinline') { 308 generatedocumentsHTML(dataarr,dateArr,uuidParam); 309 } 310 else if(type=='docsinline') { 311 generateresearchHTML(dataarr,dateArr,uuidParam); 312 } 313 else if(type=='wdsResearchinline') { 314 generateWDSResearchHTML(dataarr,dateArr,uuidParam); 315 } 316 else if(type=='everythinginline') { 317 generateEveryThingHTML(dataarr,dateArr,uuidParam); 318 } 319 }); 320} 321 322function generateEveryThingHTML(dataarr,dateArr,uuidParam) 323{ 324 325 if(dataarr != undefined) 326 { 327 328 var title = "", url = "", author = "" , date="" , comments = "", photo = ""; 329 330 331 Object.keys(dataarr).forEach(function(key,index) { 332 divhtml+= "<li class='lp__latest_item_list'>"; 333 var item = dataarr[key]; 334 335 title = item.hasOwnProperty("title") ? getValue(item.title) : ""; 336 author = item.hasOwnProperty("author") ? getValue(item.author) : ""; 337 date = dateArr[index]; 338 photo = item.hasOwnProperty("photo_link") ? getValue(item.photo_link) : ""; 339 url = item.hasOwnProperty("link") ? getValue(item.link) : ""; 340 comments = item.hasOwnProperty("number_of_comments") ? getValue(item.number_of_comments) : ""; 341 342 if(title.length > 0) 343 { 344 divhtml+= "<div class='lp__latest_wrapper'>"; 345 if(date.length > 0) 346 { 347 divhtml+= "<div class='lp__latest_hammer'>"; 348 if(author.length > 0) 349 divhtml+= "<span>
349"+author+"</span>"; 350 divhtml+= "<span>"+date+"</span>"; 351 divhtml+= "</div>"; 352 } 353 divhtml+= "<div class='lp__latest_title'><a href='"+url+"'>"+title+"</a></div>"; 354 355 divhtml+= "</div>"; 356 } 357 358 divhtml+= "</li>" 359 360 }); 361 362 $('#'+uuidParam).html(divhtml); 363 } 364 else 365 { 366 divhtml+= "<li>No Data</li>"; 367 $('#'+uuidParam).html(divhtml); 368 } 369 divhtml = ''; 370} 371 372function generateWDSResearchHTML(dataarr,dateArr,uuidParam) 373{ 374 if(dataarr != undefined) 375 { 376 var title = "", url = "", date="" , contentType = ""; 377 Object.keys(dataarr).forEach(function(key,index) { 378 if(key.indexOf("facets")<0){ 379 var item = dataarr[key]; 380 title = item.hasOwnProperty("display_title") ? getValue(item.display_title) : ""; 381 date = dateArr[index]; 382 url = item.hasOwnProperty("url") ? getValue(item.url) : ""; 383 contType = item.hasOwnProperty("docty") ? getValue(item.docty) : ""; 384 if(title.length > 0) 385 { 386 divhtml+= "<div class='col-lg-3 col-md-3 col-sm-6 col-xs-12'><div class='lp__primary_card'> <div class='lp__card lp__card_sm_text border-1'><div class='lp__card_wrapper'><div class='lp__card_content'>"; 387 if(date.length > 0) 388 { 389 divhtml+= "<div class='lp__hammer'>"; 390 391 if(contType.length > 0) 392 divhtml+= "<span>"+contType+"</span>"; 393 divhtml+= "<span>"+date+"</span>"; 394 divhtml+= "</div>"; 395 } 396 divhtml+= "<div class='lp__card_title'><a href='"+url+"'>"+title+"</a></div>"; 397 divhtml+= "</div></div>"; 398 divhtml+= "<a href='"+url+"' aria-hidden='true' tabindex='-1' class='lp__overlay-link'>"+title+"</a>"; 399 divhtml+= "</div></div></div>"; 400 } 401 } 402 }); 403 $('#'+uuidParam).find('.lp__slide_4').html(divhtml); 404 } 405 else 406 { 407 divhtml+= "<li>No Data</li>"; 408 $('#'+uuidParam).html(divhtml); 409 } 410 divhtml = ''; 411} 412function generateblogHTML(dataarr,dateArr,uuidParam) 413{ 414 415 if(dataarr != undefined) 416 { 417 418 var title = "", url = "", author = "" , date="" , comments = "", photo = ""; 419 420 421 Object.keys(dataarr).forEach(function(key,index) { 422 divhtml+= "<li class='lp__latest_item_list'>"; 423 var item = dataarr[key]; 424 425 title = item.hasOwnProperty("title") ? getValue(item.title) : ""; 426 author = item.hasOwnProperty("author") ? getValue(item.author) : ""; 427 date = dateArr[index]; 428 photo = item.hasOwnProperty("photo_link") ? getValue(item.photo_link) : ""; 429 url = item.hasOwnProperty("link") ? getValue(item.link) : ""; 430 comments = item.hasOwnProperty("number_of_comments") ? getValue(item.number_of_comments) : ""; 431 432 if(title.length > 0) 433 { 434 divhtml+= "<div class='lp__latest_wrapper'>"; 435 if(date.length > 0) 436 { 437 divhtml+= "<div class='lp__latest_hammer'>"; 438 if(author.length > 0) 439 divhtml+= "<span>"+author+"</span>"; 440 divhtml+= "<span>"+date+"</span>"; 441 divhtml+= "</div>"; 442 } 443 divhtml+= "<div class='lp__latest_title'><a href='"+url+"'>"+title+"</a></div>"; 444 445 divhtml+= "</div>"; 446 } 447 448 divhtml+= "</li>" 449 450 }); 451 452 $('#'+uuidParam).html(divhtml); 453 } 454 else 455 { 456 divhtml+= "<li>No Data</li>"; 457 $('#'+uuidParam).html(divhtml); 458 } 459 divhtml = ''; 460} 461 462function generatenewsHTML(dataarr,dateArr,uuidParam) 463{ 464 if(dataarr != undefined) 465 { 466 var title = "", url = "", date="" , contentType = ""; 467 Object.keys(dataarr).forEach(function(key,index) { 468 if(key.indexOf("facets")<0){ 469 divhtml+= "<li class='lp__latest_item_list'>"; 470 var item = dataarr[key]; 471 472 title = item.hasOwnProperty("title") ? getValue(item.title) : ""; 473 date = dateArr[index]; 474 url = item.hasOwnProperty("url") ? getValue(item.url) : ""; 475 contentType = item.hasOwnProperty("displayconttype") ? getValue(item.displayconttype) : ""; 476 if(title.length > 0) 477 { 478 divhtml+= "<div class='lp__latest_wrapper'>"; 479 if(date.length > 0) 480 { 481 divhtml+= "<div class='lp__latest_hammer'>"; 482 483 if(contentType.length > 0){ 484 divhtml+= "<span>"+contentType+"</span>"; 485 }else { 486 for (var x in contentType) { 487 divhtml+= "<span>"+contentType[x]+"</span>"; 488 } 489 } 490 divhtml+= "<span>"+date+"</span>"; 491 divhtml+= "</div>"; 492 } 493 divhtml+= "<div class='lp__latest_title'><a href='"+url+"'>"+title+"</a></div>"; 494 495 divhtml+= "</div>"; 496 } 497 divhtml+= "</li>"; 498 } 499 }); 500 $('#'+uuidParam).html(divhtml); 501 } 502 else 503 { 504 divhtml+= "<li>No Data</li>"; 505 $('#'+uuidParam).html(divhtml); 506 } 507 divhtml = ''; 508} 509 510function custom_sort(a, b) { 511 return new Date(b.master_recent_date).getTime() - new Date(a.master_recent_date).getTime(); 512} 513 514 515function generateeventsHTML(dataarr,dateArr,uuidParam) 516{ 517 if(dataarr != undefined) 518 { 519 var title = "", url = "", date="" , contentType = ""; 520 dataarr.forEach(function(key,index) { 521 if(key.hasOwnProperty("title")){ 522 divhtml+= "<li class='lp__latest_item_list'>"; 523 var item = key; 524 525 title = item.hasOwnProperty("title") ? getValue(item.title) : ""; 526 date = dateArr[index]; 527 url = item.hasOwnProperty("url") ? getValue(item.url) : ""; 528 contentType = item.hasOwnProperty("masterconttype") ? getValue(item.masterconttype) : ""; 529 530 531 if(title.length > 0) 532 { 533 divhtml+= "<div class='lp__latest_wrapper'>"; 534 if(date.length > 0) 535 { 536 divhtml+= "<div class='lp__latest_hammer'>"; 537 if(contentType.length > 0) 538 divhtml+= "<span>"+contentType+"</span>"; 539 divhtml+= "<span>"+date+"</span>"; 540 divhtml+= "</div>"; 541 } 542 divhtml+= "<div class='lp__latest_title'><a href='"+url+"'>"+title+"</a></div>"; 543 544 divhtml+= "</div>"; 545 } 546 547 divhtml+= "</li>"; 548 } 549 550 }); 551 552 553 $('#'+uuidParam).html(divhtml); 554 } 555 else 556 { 557 divhtml+= "<li>No Data</li>"; 558 $('#'+uuidParam).html(divhtml); 559 } 560 divhtml = ''; 561} 562 563function generateprojectHTML(dataarr,dateArr,uuidParam) 564{ 565 if(dataarr != undefined) 566 { 567 568 var title = "", url = "", date="" , contentType = ""; 569 570 571 Object.keys(dataarr).forEach(function(key,index) { 572 if(key.indexOf("facets")<0){ 573 divhtml+= "<li class='lp__latest_item_list'>"; 574 var item = dataarr[key]; 575 576 title = item.hasOwnProperty("project_name") ? getValue(item.project_name) : ""; 577 date = dateArr[index]; 578 579 //date=formatDate(dateArr[index]); 580 date=dateArr[index]; 581 url = item.hasOwnProperty("url") ? getValue(item.url) : ""; 582 if(title.length > 0) 583 { 584 divhtml+= "<div class='lp__latest_wrapper'>"; 585 if(date.length > 0) 586 { 587 divhtml+= "<div class='lp__latest_hammer'>"; 588 589 divhtml+= "<span>"+date+"</span>"; 590 divhtml+= "</div>"; 591 } 592 divhtml+= "<div class='lp__latest_title'><a href='"+url+"'>"+title+"</a></div>"; 593 594 divhtml+= "</div>"; 595 } 596 597 divhtml+= "</li>"; 598 } 599 }); 600 601 $('#'+uuidParam).html(divhtml); 602 } 603 else 604 { 605 divhtml+= "<li>No Data</li>"; 606 $('#'+uuidParam).html(divhtml); 607 } 608 609 divhtml = ''; 610 611} 612 613function generateresearchHTML(dataarr,dateArr,uuidParam) 614{ 615 616 if(dataarr != undefined) 617 { 618 619 var title = "", url = "", date="" , contentType = "", repnb = ""; 620 621 622 Object.keys(dataarr).forEach(function(key,index) { 623 if(key.indexOf("facets")<0){ 624 divhtml+= "<li class='lp__latest_item_list'>"; 625 var item = dataarr[key]; 626 627 title = item.hasOwnProperty("display_title") ? getValue(item.display_title) : ""; 628 629 date = dateArr[index]; 630 url = item.hasOwnProperty("url") ? getValue(item.url) : ""; 631 contentType = item.hasOwnProperty("docty") ? getValue(item.docty) : ""; 632 repnb = item.hasOwnProperty("repnb") ? getValue(item.repnb) : ""; 633 if(title.length > 0) 634 { 635 divhtml+= "<div class='lp__latest_wrapper'>"; 636 if(date.length > 0) 637 { 638 divhtml+= "<div class='lp__latest_hammer'>"; 639 if(repnb.length > 0) 640 divhtml+= "<span>"+repnb+"</span>"; 641 642 if(contentType.length > 0) 643 divhtml+= "<span>"+contentType+"</span>"; 644 divhtml+= "<span>"+date+"</span>"; 645 divhtml+= "</div>"; 646 } 647 divhtml+= "<div class='lp__latest_title'><a href='"+url+"'>"+title+"</a></div>"; 648 649 divhtml+= "</div>"; 650 } 651 divhtml+= "</li>" 652 } 653 }); 654 $('#'+uuidParam).html(divhtml); 655 } 656 else 657 { 658 divhtml+= "<li>No Data</li>"; 659 $('#'+uuidParam).html(divhtml); 660 } 661 divhtml = ''; 662} 663 664function generateehatsnewHTML(dataarr,dateArr,uuidParam) 665{ 666 667 if(dataarr != undefined) 668 { 669 var title = "", url = "", date="" , contentType = ""; 670 Object.keys(dataarr).forEach(function(key,index) { 671 if(key.indexOf("facets")<0){ 672 divhtml+= "<li class='lp__latest_item_list'>"; 673 var item = dataarr[key]; 674 675 title = item.hasOwnProperty("title") ? getValue(item.title) : ""; 676 date = dateArr[index]; 677 url = item.hasOwnProperty("url") ? getValue(item.url) : ""; 678 contentType = item.hasOwnProperty("masterconttype") ? getValue(item.masterconttype) : ""; 679 680 681 if(title.length > 0) 682 { 683 divhtml+= "<div class='lp__latest_wrapper'>"; 684 if(date.length > 0) 685 { 686 divhtml+= "<div class='lp__latest_hammer'>"; 687 if(contentType.length > 0) 688 divhtml+= "<span>"+contentType+"</span>"; 689 divhtml+= "<span>"+date+"</span>"; 690 divhtml+= "</div>"; 691 } 692 divhtml+= "<div class='lp__latest_title'><a href='"+url+"'>"+title+"</a></div>"; 693 694 divhtml+= "</div>"; 695 } 696 697 divhtml+= "</li>"; 698 } 699 }); 700 $('#'+uuidParam).html(divhtml); 701 } 702 else 703 { 704 divhtml+= "<li>No Data</li>"; 705 $('#'+uuidParam).html(divhtml); 706 } 707 divhtml = ''; 708} 709 710function generatedocumentsHTML(dataarr,dateArr,uuidParam) 711{ 712 if(dataarr != undefined && dataarr!=null) 713 { 714 var title = "", url = "", date="" , contentType = ""; 715 Object.keys(dataarr).forEach(function(key,index) { 716 if(key!="facets") 717 console.log("key",key); 718 divhtml+= "<li class='lp__latest_item_list'>"; 719 var item = dataarr[key]; 720 title = item.hasOwnProperty("display_title") ? getValue(item.display_title) : ""; 721 date = dateArr[index]; 722 url = item.hasOwnProperty("url") ? getValue(item.url) : ""; 723 724 console.log("title length",date.length); 725 if(title.length > 0) 726 { 727 divhtml+= "<div class='lp__latest_wrapper'>"; 728 if(date.length > 0) 729 { 730 divhtml+= "<div class='lp__latest_hammer'>"; 731 732 divhtml+= "<span>"+date+"</span>"; 733 divhtml+= "</div>"; 734 } 735 divhtml+= "<div class='lp__latest_title'><a href='"+url+"'>"+title+"</a></div>"; 736 737 divhtml+= "</div>"; 738 } 739 740 divhtml+= "</li>" 741 }); 742 $('#'+uuidParam).html(divhtml); 743 } 744 else 745 { 746 divhtml+= "<li>No Data</li>"; 747 $('#'+uuidParam).html(divhtml); 748 } 749 divhtml = ''; 750} 751 752function getValue(value) { 753 if (typeof value === 'string' || value instanceof String) { 754 return value; 755 } else { 756 if(Array.isArray(value)) { 757 for (var x in value[0]) { 758 return value[0][x]; 759 } 760 } else { 761 for (var x in value) { 762 return value[x]; 763 } 764 } 765 } 766} 767const PAST_EVENTS_TAB = "past-events-tab"; 768const UPCOMING_EVENTS_TAB = "upcoming-events-tab"; 769const LANGUAGES = { 770 en: "English", 771 fr: "French", 772 es: "Spanish", 773 ar: "Arabic", 774 ru: "Russian", 775 zh: "Chinese", 776 ja: "Japanese", 777 pt: "Portuguese", 778 in: "Indonesian", 779 vi: "Vietnamese", 780 ms: "Malay", 781 th: "Thai", 782 hy: "Armenian", 783 mk: "Macedonian", 784 ro: "Romanian", 785 tr: "Turkish", 786 mn: "Mongolian", 787 ka: "Georgian", 788 bs: "Bosnian", 789 sq: "Albanian", 790 az: "Azerbaijani", 791 bg: "Bulgarian", 792 hr: "Croatian", 793 pl: "Polish", 794 sr: "Serbian", 795 uk: "Ukrainian", 796 ko: "Korean", 797 hi: "Hindi", 798 fa: "Dari", 799 ps: "Pashto", 800 ta: "Tamil", 801 si: "Sinhala", 802 ne: "Nepali", 803 km: "Khmer", 804 bn: "Bengali", 805 de: "German", 806 dv: "Divehi", 807 lo: "Lao", 808 so: "Somali", 809 ur: "Urdu", 810}; 811 812const parentDivElement = document.getElementsByClassName( 813 "inline_latest_events" 814)[0]; 815var languageCode = document 816 .getElementsByClassName("localeStr")[0] 817 .getAttribute("value"); 818const eventsULElement = parentDivElement.querySelector( 819 "ul.lp__latest_item_info" 820); 821const page = parentDivElement.getAttribute("data-page"); 822const mode = 823 document.getElementsByName("wcmmode")[0].getAttribute("value") && 824 document 825 .getElementsByName("wcmmode")[0] 826 .getAttribute("value") 827 .toLowerCase() === "disabled" 828 ? "publish" 829 : "author"; 830 831const fetchEvents = async () => { 832 const loader = document.createElement("li"); 833 loader.className = "loader"; 834 loader.innerHTML = `<img src="https://www.worldbank.org/content/dam/wbr-redesign/logos/ajax.gif" alt="loader image">`; 835 eventsULElement.innerHTML = ""; // Clear previous content 836 eventsULElement.appendChild(loader); 837 838 try { 839 const apiURL = parentDivElement.getAttribute("data-eventapiurl"); 840 const rows = parentDivElement.getAttribute("data-rows"); 841 let pageSpecificData = null; 842 let filter = `(contentType: ANY("Event") OR contentType: ANY("Event Series") OR contentType: A
842NY("WBLive Event")) AND language: ANY(\"${LANGUAGES[languageCode]}\")`; 843 const defaultFilter = `(contentType: ANY("Event") OR contentType: ANY("Event Series") OR contentType: ANY("WBLive Event")) AND language: ANY(\"${LANGUAGES[languageCode]}\")`; 844 if (page === "topic") { 845 let topics = parentDivElement.getAttribute("data-topic"); 846 if (topics) { 847 topics = topics.split("|"); 848 if (topics?.length === 1) { 849 filter = `${filter} AND topics: ANY("${topics[0]}")`; 850 } else if (topics?.length > 1) { 851 topics.forEach((value, index) => { 852 if (index === 0) { 853 filter = `${filter} AND (topics: ANY("${value}")`; 854 } else if (index === topics?.length - 1) { 855 filter = `${filter} OR topics: ANY("${value}"))`; 856 } else { 857 filter = `${filter} OR topics: ANY("${value}")`; 858 } 859 }); 860 } 861 } 862 pageSpecificData = topics; 863 } else if (page === "region") { 864 const region = parentDivElement.getAttribute("data-region"); 865 filter += ` AND regions: ANY("${region}")`; 866 pageSpecificData = region; 867 } else if (page === "country") { 868 const country = parentDivElement.getAttribute("data-country"); 869 if (country !== "all") { 870 filter += ` AND countries: ANY("${country}")`; 871 pageSpecificData = country; 872 } 873 } 874 const request = { 875 query: "", 876 pageSize: rows, 877 offset: 0, 878 count: true, 879 siteName: "ibrdevents", 880 filter, 881 orderBy: "eventStartDate desc", 882 }; 883 884 const response = await fetch(apiURL, { 885 method: "POST", 886 headers: { 887 "Content-Type": "application/json", 888 Accept: "application/json", 889 }, 890 body: JSON.stringify(request), 891 }); 892 if (!response.ok) { 893 throw new Error(`HTTP error! status: ${response.status}`); 894 } 895 const data = await response.json(); 896 if (page === "country" && data && data?.ResultsCount < rows) { 897 const remaining = rows - (data.SearchResults?.length || 0); 898 if (remaining > 0) { 899 const globalDataRequest = { 900 ...request, 901 filter: `${defaultFilter} AND distributions: ANY(\"Global\")`, 902 pageSize: remaining, 903 }; 904 const globalDataResponse = await fetch(apiURL, { 905 method: "POST", 906 headers: { 907 "Content-Type": "application/json", 908 Accept: "application/json", 909 }, 910 body: JSON.stringify(globalDataRequest), 911 }); 912 if (globalDataResponse.ok) { 913 const globalData = await globalDataResponse.json(); 914 // Merge new results with the original ones 915 data.SearchResults = [ 916 ...(data.SearchResults || []), 917 ...(globalData.SearchResults || []), 918 ]; 919 } 920 } 921 } 922 updateDOMElements(data, pageSpecificData); 923 } catch (error) { 924 // Remove loader 925 eventsULElement.innerHTML = ""; 926 console.error("Error fetching events:", error); 927 } 928}; 929 930const updateDOMElements = (data, pageSpecificData) => { 931 // Remove loader 932 eventsULElement.innerHTML = ""; 933 data?.SearchResults?.forEach((event) => { 934 const li = document.createElement("li"); 935 li.className = "lp__latest_item_list"; 936 937 const wrapper = document.createElement("div"); 938 wrapper.className = "lp__latest_wrapper"; 939 940 const hammer = document.createElement("div"); 941 hammer.className = "lp__latest_hammer"; 942 const dateSpan = document.createElement("span"); 943 dateSpan.textContent = fetchFormattedDateForCard( 944 event?.document?.structData?.eventStartDate, 945 event?.document?.structData?.eventEndDate, 946 languageCode 947 ); 948 hammer.appendChild(dateSpan); 949 950 const titleDiv = document.createElement("div"); 951 titleDiv.className = "lp__latest_title"; 952 const link = document.createElement("a"); 953 link.href = getRedirectURL(event) || "#"; 954 link.textContent = event?.document?.structData?.title || ""; 955 titleDiv.appendChild(link); 956 957 wrapper.appendChild(hammer); 958 wrapper.appendChild(titleDiv); 959 li.appendChild(wrapper); 960 961 eventsULElement.appendChild(li); 962 }); 963 if(parentDivElement.querySelector("a.lp__btn")!=null){ 964 if (data?.SearchResults?.length > 0) { 965 formViewAllEventsLink( 966 data.SearchResults[0]?.document?.structData?.eventEndDate, 967 page, 968 pageSpecificData 969 ); 970 } else { 971 // Hide the View All Events button if no events are found 972 parentDivElement.querySelector("a.lp__btn").style.display = "none"; 973 } 974} 975}; 976 977const getRedirectURL = (result) => { 978 if (result?.document?.structData?.contentType === "WBLive Event") { 979 if (mode && mode === "author") { 980 return result?.document?.structData?.authorPath; 981 } else { 982 const liveDomains = { 983 en: "https://live.worldbank.org", 984 es: "https://envivo.bancomundial.org", 985 fr: "https://live.banquemondiale.org", 986 ar: "https://live.albankaldawli.org", 987 }; 988 return result?.document?.structData?.publishPath.startsWith( 989 "https://wbliveqa.worldbank.org" 990 ) 991 ? result?.document?.structData?.publishPath.replace( 992 "https://wbliveqa.worldbank.org", 993 liveDomains[result?.document?.structData?.languageCode] 994 ) 995 : result?.document?.structData?.publishPath; 996 } 997 } else { 998 if (mode && mode === "author") { 999 return result?.document?.structData?.authorPath; 1000 } else { 1001 return result?.document?.structData?.publishPath; 1002 } 1003 } 1004}; 1005 1006const formViewAllEventsLink = (latestEventEndDate, page, pageSpecificData) => { 1007 // Check if View All Events should take to Upcoming Events tab or Past Events tab 1008 const currentESTDateTime = formatCurrentESTDateTime(); 1009 let tab = 1010 new Date(latestEventEndDate) > new Date(currentESTDateTime) 1011 ? UPCOMING_EVENTS_TAB 1012 : PAST_EVENTS_TAB; 1013 const languageName = LANGUAGES[languageCode] || "English"; 1014 1015 let eventLandingURL = new URL( 1016 parentDivElement.querySelector("a.lp__btn").href 1017 ); 1018 1019 eventLandingURL.search = ""; 1020 eventLandingURL.searchParams.set("tab", tab); 1021 eventLandingURL.searchParams.set("language", languageName); 1022 if (page === "topic" && pageSpecificData?.length > 0) { 1023 eventLandingURL.searchParams.set("topics", pageSpecificData.join("^")); 1024 } else if (page === "region" && pageSpecificData) { 1025 eventLandingURL.searchParams.set("regions", pageSpecificData); 1026 } else if (page === "country" && pageSpecificData) { 1027 eventLandingURL.searchParams.set("countries", pageSpecificData); 1028 } 1029 1030 parentDivElement.querySelector("a.lp__btn").href = eventLandingURL.href; 1031}; 1032 1033// const formatDate = (date, language = "en") => { 1034// let estEndDate = date.replace("Z", ""); 1035// const options = { 1036// month: "short", 1037// day: "numeric", 1038// year: "numeric", 1039// }; 1040// return new Date(estEndDate).toLocaleDateString(language, options); 1041// }; 1042 1043const fetchFormattedDateForCard = (startDate, endDate, language = "en") => { 1044 let estStartDate = startDate.replace("Z", ""); 1045 let estEndDate = endDate.replace("Z", ""); 1046 const formatDate = (date) => { 1047 const options = { 1048 month: "long", 1049 day: "numeric", 1050 year: "numeric", 1051 }; 1052 return new Date(date).toLocaleDateString(language, options); 1053 }; 1054 1055 const formatEndDateForSameYear = (date) => { 1056 const options = { 1057 month: "long", 1058 day: "numeric", 1059 }; 1060 return new Date(date).toLocaleDateString(language, options); 1061 }; 1062 1063 const formatTime = (date) => { 1064 const options = { 1065 hour: "2-digit", 1066 minute: "2-digit", 1067 hour12: true, 1068 }; 1069 return new Date(date).toLocaleTimeString(language, options); 1070 }; 1071 1072 const start = new Date(estStartDate); 1073 const end = new Date(estEndDate); 1074 1075 if (start.toDateString() === end.toDateString()) { 1076 // Same day: "Month Date, Year StartTime" 1077 return `${formatDate(start)} | ${formatTime(start)} ET`; 1078 } else if (language === "zh" || language === "ja") { 1079 const startYear = start.getFullYear(); 1080 const endYear = end.getFullYear(); 1081 return startYear === endYear 1082 ? `${formatDate(start)} - ${formatEndDateForSameYear(end)} ET` 1083 : `${formatDate(start)} - ${formatDate(end)} ET`; 1084 } 1085 // If manual formatting is needed for Chinese, Japanese, uncomment below 1086 // else if (language === 'zh' || language === 'ja') { 1087 // const startYear = start.getFullYear() 1088 // const startMonth = start.getMonth() + 1 1089 // const startDate = start.getDate() 1090 // const endYear = end.getFullYear() 1091 // const endMonth = end.getMonth() + 1 1092 // const endDate = end.getDate() 1093 // const result = 1094 // startYear === endYear 1095 // ? `${startYear}å¹´${startMonth}æ${startDate}æ¥ - ${endMonth}æ${endDate}æ¥` 1096 // : `${startYear}å¹´${startMonth}æ${startDate}æ¥ - ${endYear}å¹´${endMonth}æ${endDate}æ¥` 1097 // return result 1098 // } 1099 else { 1100 // Different days: "Month StartDate-EndDate, Year"
1101 const startMonth = start.toLocaleString(language, { month: "long" }); 1102 const endMonth = end.toLocaleString(language, { month: "long" }); 1103 const startYear = start.getFullYear(); 1104 const endYear = end.getFullYear(); 1105 const startDay = start.getDate(); 1106 const endDay = end.getDate(); 1107 1108 if (startMonth === endMonth) { 1109 if (startYear === endYear) { 1110 return `${startMonth} ${startDay}-${endDay}, ${startYear} ET`; 1111 } else { 1112 return `${startMonth} ${startDay}, ${startYear}-${endMonth} ${endDay}, ${endYear} ET`; 1113 } 1114 } else { 1115 if (startYear === endYear) { 1116 return `${startMonth} ${startDay} - ${endMonth} ${endDay}, ${startYear} ET`; 1117 } else { 1118 return `${startMonth} ${startDay}, ${startYear} - ${endMonth} ${endDay}, ${endYear} ET`; 1119 } 1120 } 1121 } 1122}; 1123 1124const formatCurrentESTDateTime = () => { 1125 const options = { 1126 timeZone: "America/New_York", // EST time zone 1127 year: "numeric", 1128 month: "2-digit", 1129 day: "2-digit", 1130 hour: "2-digit", 1131 minute: "2-digit", 1132 second: "2-digit", 1133 hour12: false, // 24-hour format 1134 }; 1135 1136 const estTime = new Date().toLocaleString("en-US", options); 1137 const [date, time] = estTime.split(", "); 1138 const dateItems = date.split("/"); 1139 const formattedDate = `${dateItems[2]}-${dateItems[0]}-${dateItems[1]}`; 1140 return `${formattedDate}T${time}Z`; 1141}; 1142 1143fetchEvents(); 1144
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.