1 2function checkPhotoFactory(original, suffix = '') 3{ 4 let original_no_size = original; 5 let position = original.lastIndexOf('.'); 6 let originalType = original.substring(position); 7 let isThumbor = original.includes('/thumbor/'); 8 let size = ''; 9 10 if (!position || !isThumbor) { 11 return { 'original': original }; 12 } 13 14 15 let originalSuffix = original; 16 /** Check if img path alreay has size suffix (_1920x0) **/ 17 if (original.lastIndexOf('x0') > 0 && original.lastIndexOf('_') > 0) { 18 position = original.lastIndexOf('_'); 19 position2 = original.lastIndexOf('.jpg'); 20 suffix = original.substring(position+1, position2); 21 original_no_size = original.substring(0, position) + originalType; 22 } 23 24 let prefix = original_no_size.substring(0, position); 25 let extension = original_no_size.substring(position); 26 27 if (suffix != '') { 28 prefix += '_' + suffix; 29 originalSuffix = prefix + extension; 30 } 31 let webp = prefix + '.webp'; 32 33 return { 'prefix': prefix, 'webp': webp, 'original': original, 'originalSuffix': originalSuffix }; 34} 35function imageComponent(imgObject, options = []) { 36 let webp = (imgObject['webp']) ? `<source srcset="${imgObject['webp']}" type="image/webp">` : ''; 37 let originalSuffix = (imgObject['originalSuffix']) ? `<source srcset="${imgObject['originalSuffix']}" type="image/jpg">` : ''; 38 39 let imgOptions = []; 40 imgOptions['alt'] = (options['alt']) ? options['alt'] : ''; 41 imgOptions['loading'] = (options['loading']) ? options['loading'] : 'low'; 42 imgOptions['fetchpriority'] = (options['fetchpriority']) ? options['fetchpriority'] : 'low'; 43 imgOptions['imgClass'] = (options['imgClass']) ? options['imgClass'] : ''; 44 imgOptions['thumbClass'] = (options['thumbClass']) ? options['thumbClass'] : ''; 45 imgOptions['thumbRatio'] = (options['thumbRatio']) ? 'responsive-img '+ options['thumbRatio'] : ''; 46 47 let imgTemplate = `<picture class="${imgOptions['thumbClass']} ${imgOptions['thumbRatio']}"> 48 ${webp} 49 ${originalSuffix} 50 <img class="${imgOptions['imgClass']}" fetchpriority="${imgOptions['fetchpriority']}" loading="${imgOptions['loading']}" src="${imgObject['original']}" itemprop="thumbnail" alt="${imgOptions['alt']}"> 51 </picture>`; 52 return imgTemplate; 53} 54function tabButton(e) { 55 var el = (e && e.jquery) ? e.get(0) : e; 56 if (!el || !el.getAttribute) return; 57 var target = el.getAttribute('data-tab'); 58 var menu = el.closest('.tabs-menu'); 59 if (!menu) return; 60 menu.querySelectorAll('.js-tabs__buttons > .item, .js-tabs__contents > .item').forEach(function(item) { 61 item.classList.remove('active'); 62 }); 63 el.classList.add('active'); 64 var panel = document.getElementById(target); 65 if (panel) panel.classList.add('active'); 66} 67 68function k_number_format(x) { 69 if(isNaN(x)) { 70 return x 71 } 72 if(x < 999) { 73 return x; 74 } 75 if(x < 1000000) { 76 return (x/1000).toFixed(2) + "K"; 77 } 78 if( x < 10000000) { 79 return (x/1000000).toFixed(2) + "M"; 80 } 81 if(x < 1000000000) { 82 return Math.round((x/1000000)) + "M"; 83 } 84 if(x < 1000000000000) { 85 return Math.round((x/1000000000)) + "B"; 86 } 87 return "1T+"; 88} 89 90 91function outsideClick(event, notelem) { 92 notelem = document.querySelector(notelem); 93 if (event.target === notelem || notelem.contains(event.target)) { 94 let clickOutSide = false;
95 return clickOutSide; 96 } else { 97 let clickOutSide = true; 98 return clickOutSide; 99 } 100} 101 102var modalIsOpened = false; 103function closeModal() { 104 let modal = document.querySelector('.pptv-modal'); 105 let body = document.getElementsByTagName("BODY")[0]; 106 modal.classList.remove('pptv-modal-open'); 107 body.classList.remove('modal-opened'); 108 setTimeout(function() { 109 modal.removeAttribute('style'); 110 }, 300); 111 modalIsOpened = false; 112} 113 114function openModal(selector) { 115 let element = document.querySelector(selector); 116 let body = document.getElementsByTagName("BODY")[0]; 117 if (modalIsOpened === false) { 118 modalIsOpened = true; 119 element.style.display = 'block'; 120 setTimeout(function() { 121 element.classList.add('pptv-modal-open'); 122 body.classList.add('modal-opened'); 123 }, 300); 124 } 125} 126 127function modal() { 128 if(modalIsOpened === true) { 129 let modal = document.querySelector(".pptv-modal"); 130 let modalDialog = ".pptv-modal-dialog"; 131 modal.addEventListener('click', function(e) { 132 if (outsideClick(e, modalDialog)) { 133 closeModal(); 134 } 135 }); 136 } 137} 138 139function docReady(fn) { 140 if (document.readyState === "complete" || document.readyState === "interactive") { 141 setTimeout(fn, 1); 142 } else { 143 document.addEventListener("DOMContentLoaded", fn); 144 } 145} 146 147/*update view count function*/ 148window.updateViewCount = function(section, id) { 149 var apiUrl; 150 if (VIEW_COUNT_ENDPOINT == 'pptv_web') { 151 var baseUrl = window.location.origin; 152 if (baseUrl.search('-live.') > 0 ) { 153 baseUrl = baseUrl.replace('-live.', '.'); 154 } 155 apiUrl = `${baseUrl}${VIEW_COUNT_URL}/${section}/${id}`; 156 } else { 157 apiUrl = `${VIEW_COUNT_URL}/${section}/${id}`; 158 } 159 160 if(getCookie('previous_page_session') != window.location.pathname){ 161 fetch(apiUrl+'?'+(new Date()).getTime(), { method: 'GET', mode: 'cors' }); 162 /*set previous key*/ 163 document.cookie = 'previous_page_session=' + encodeURIComponent(window.location.pathname) + '; path=/'; 164 } 165}; 166 167 168window.updateViewCountImgMethod = function(section, id) { 169 var apiUrl; 170 if (VIEW_COUNT_ENDPOINT == 'pptv_web') { 171 var baseUrl = window.location.origin; 172 if (baseUrl.search('-live.') > 0 ) { 173 baseUrl = baseUrl.replace('-live.', '.'); 174 } 175 apiUrl = `${baseUrl}/api/pixel_view_count?section=${section}&id=${id}`; 176 } else { 177 apiUrl = `${VIEW_COUNT_URL}/${section}/${id}`; 178 } 179 var imgElement = document.createElement("img"); 180 imgElement.setAttribute('src', apiUrl); 181 imgElement.style.width = "1px"; 182 imgElement.style.height = "1px"; 183 imgElement.style.display = "none"; 184 document.body.appendChild(imgElement); 185} 186 187/*share button*/ 188window.addEventListener('load', (event) => { 189 var XHRShareBtn; 190 function open_popup(url, title, width, height){ 191 var width = width || 575, 192 height = height || 400, 193 left = (window.innerWidth - width) / 2, 194 top = (window.innerHeight - height) / 2, 195 url = url, 196 opts = 'status=1' + 197 ',width=' + width + 198 ',height=' + height + 199 ',top=' + top + 200 ',left=' + left; 201 202 window.open(url, title, opts); 203 } 204 205 let sharBtns = document.querySelectorAll('.js-share-btn'); 206 207 for (const button of sharBtns) { 208 button.addEventListener('click', (event) => { 209 event.preventDefault(); 210 211 212 var $share_count_all = document.querySelector('.js-share-popup'); 213 214 if ($share_count_all != null) { 215 var share_count_data_all = $share_count_all.getAttribute('data-share-count-all') || 0; 216 } else { 217 var share_count_data_all = 0; 218 } 219 220 221 var share_url = button.getAttribute('data-share-url'); 222 var share_short_url = button.getAttribute('data-share-short-url'); 223 var share_title = button.getAttribute('data-share-title'); 224 var share_section = button.getAttribute('data-share-section'); 225 var share_social = button.getAttribute('data-share-social'); 226 var share_id = button.getAttribute('data-share-id'); 227 var share_count_data = button.getAttribute('data-share-count'); 228 var is_mobile = button.getAttribute('data-is-mobile'); 229 230 var $share_count = null; 231 232 for (var i = 0; i < button.childNodes.length; i++) { 233 if (button.childNodes[i].className === "social-share__button-share__number share-count js-share-count") { 234 $share_count = button.childNodes[i]; 235 break; 236 } 237 } 238 239 /*if (button.find('.js-share-count').length !== 0) { 240 $share_count = button.find('.js-share-count'); 241 }*/ 242 243 if(XHRShareBtn && XHRShareBtn.readyState == 1){ 244 return; 245 } 246 247 /* update share without updating ui */ 248 var updateShareCount = function () { 249 var apiURL = "/api/share_count/" + share_social + "/"
249+ share_section + "/" + share_id + '?' + (new Date()).getTime(); 250 var xhr = new XMLHttpRequest(); 251 xhr.open('PUT', apiURL); 252 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 253 xhr.onreadystatechange = function () { 254 if (xhr.readyState === 4 && xhr.status >= 200 && xhr.status < 300) { 255 var data = JSON.parse(xhr.responseText); 256 if ($share_count) { 257 $share_count.innerHTML = data.count_format; 258 } 259 button.setAttribute('data-share-count', data.count); 260 } 261 }; 262 xhr.send('count_all=' + encodeURIComponent(share_count_data_all) + '&count=' + encodeURIComponent(share_count_data)); 263 return xhr; 264 }; 265 dataLayer.push({ 266 'event': 'track_event', 267 'event_category': 'social_share', 268 'event_action': `click-${share_social}`, 269 'event_label': `page-${decodeURI(window.location.pathname)}` 270 }); 271 switch(share_social){ 272 case 'facebook': 273 /*if(FB){ 274 FB.ui({method: 'share',href: share_url},function(response) { 275 if ((response && !response.error_code) && ($share_count != null)) { 276 XHRShareBtn = updateShareCount(); 277 } 278 }); 279 }*/ 280 var facebookShareLink = 'https://www.facebook.com/sharer/sharer.php?u=' + share_url; 281 open_popup(facebookShareLink, 'facebook', 575, 400); 282 if ($share_count != null) { 283 XHRShareBtn = updateShareCount(); 284 } 285 break; 286 case 'facebookLink': 287 var facebookShareLink = 'https://www.facebook.com/sharer/sharer.php?u=' + share_url; 288 open_popup(facebookShareLink, 'facebook', 575, 400); 289 if ($share_count != null) { 290 XHRShareBtn = updateShareCount(); 291 } 292 break; 293 case 'twitter': 294 var twitterHref = 'https://twitter.com/share?url='+share_url+'&via=PPTVHD36&text='+share_title; 295 open_popup(twitterHref, 'twitter', 575, 400); 296 if ($share_count != null) { 297 XHRShareBtn = updateShareCount(); 298 } 299 break; 300 case 'google': 301 var googleHref = 'https://plus.google.com/share?url='+share_url; 302 open_popup(googleHref, 'google', 500, 470); 303 if ($share_count != null) { 304 XHRShareBtn = updateShareCount(); 305 } 306 break; 307 case 'line': 308 if(is_mobile){ 309 window.open('http://line.me/R/msg/text/?'+ share_title +'%0D%0A' + share_url, '_blank').focus(); 310 } else { 311 var shareUrl = 'https://lineit.line.me/share/ui?url=' + share_url.split('&').join('%26'); 312 var windowWidth = 503; 313 var windowHeight = 510; 314 var windowLeft = 0; 315 var windowTop = 0; 316 if (typeof window.screenX != "undefined" && (window.screenX >= 0 && window.screenY >= 0)) { 317 /* Chrome */ 318 windowLeft = (window.screen.availWidth - windowWidth) / 2; 319 windowTop = (window.screen.availHeight - windowHeight) / 2; 320 } else if (typeof window.screenLeft != "undefined" && (window.screenLeft >= 0 && window.screenTop >= 0)) { 321 /* IE */
322 windowLeft = (window.screen.availWidth - windowWidth) / 2; 323 windowTop = (window.screen.availHeight - windowHeight) / 2; 324 } 325 window.open(shareUrl, null, 'width=' + windowWidth + ',height=' + windowHeight + ',left=' + windowLeft + ',top=' + windowTop + ',resizable=yes,scrollbars=no,chrome=yes,centerscreen=yes'); 326 } 327 if ($share_count != null) { 328 XHRShareBtn = updateShareCount(); 329 } 330 break; 331 } 332 }); 333 } 334 335 let scrollTopBtn = document.querySelector(".scroll"); 336 if(scrollTopBtn) { 337 scrollTopBtn.addEventListener('click', function(e){ 338 window.scrollTo(0,0); 339 }); 340 } 341 342 let adsBallon = document.querySelector('.ads-balloon'); 343 if (adsBallon) { 344 document.querySelector('#accept_cookie').addEventListener('click', function(e) { 345 document.querySelector('.ads-balloon').classList.remove('active-up'); 346 }); 347 } 348 349 if (!isMobile()) { 350 let memberEle = document.querySelector('.members--success'); 351 if (memberEle !== null) { 352 memberEle.addEventListener('mouseover', function(e) { 353 document.querySelector('.profile__dropdown').style.display = 'block'; 354 }); 355 memberEle.addEventListener('mouseout', function(e) { 356 document.querySelector('.profile__dropdown').style.display = 'none'; 357 }); 358 } 359 } 360 361}); 362 363 364function copyText() { 365 const copyText = document.getElementById('copyURL'); 366 367 const share_url = copyText.value; 368 const el = document.createElement('textarea'); 369 el.value = share_url; 370 document.body.appendChild(el); 371 el.select(); 372 document.execCommand('copy'); 373 document.body.removeChild(el); 374 375 let tooltip = document.querySelector('.js-copy-text-tooltip') 376 tooltip.style.display = 'block'; 377 setTimeout(function() { 378 tooltip.style.display = 'none'; 379 }, 1000); 380} 381 382function setDisplayAvatar(user) { 383 let user_fullname = ''; 384 if (user != 'undefined' && user.image != 'undefined' && user.fullname != 'undefined') { 385 if (user.fullname !== null) { 386 user_fullname = user.fullname; 387 } 388 var templateLoging = 389 '<button class="--mobile mobile-close" type="button" onclick="toggleSidenav()" aria-label="Close"></button>'+ 390 '<div class="members--success">'+ 391 '<ul class="members--success__options">'+ 392 '<li class="profile">'+ 393 '<a class="profile__thumb" href="/profile">'+ 394 '<i class="profile__thumb__icon icon-menu" style="background-image: url('+user.image+') ;"></i>'+ 395 '<span class="profile__thumb__name pptv-hidden@l">'+user_fullname+'</span>'+ 396 '</a>'+ 397 '<ol class="profile__dropdown">'+ 398 '<li class="item">'+ 399 '<a class="item__link --settings" href="/profile">à¹à¸à¹à¹à¸à¸à¹à¸à¸¡à¸¹à¸¥</a>'+ 400 '</li>'+ 401 '<li class="item"><a class="item__link --logoff" href="/logout" onclick="logoutTracking()">à¸à¸à¸à¸à¸²à¸à¸£à¸°à¸à¸</a></li>'+ 402 '</ol>'+ 403 '</li>'+ 404 '</ul>'+ 405 '</div>'; 406 var loginSwitch = document.querySelector('.login_swich'); 407 if (loginSwitch) { 408 loginSwitch.innerHTML = templateLoging; 409 } 410 } 411 window.dispatchEvent(new Event('resize')); 412} 413 414function setCookie(name, data, expiresMinite) { 415 var expires = new Date(Date.now() + (expiresMinite * 60 * 1000)); 416 document.cookie = name + "=" + data + ";expires=" + expires.toUTCString() + ";path=/"; 417} 418 419function deleteCookie(name) { 420 if( getCookie(name) !== '' ) { 421 document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/"; 422 } 423} 424 425function offset(el) { 426 var rect = el.getBoundingClientRect(), 427 scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, 428 scrollTop = window.pageYOffset || document.documentElement.scrollTop; 429 return { top: rect.top + scrollTop, left: rect.left + scrollLeft } 430} 431 432function getCookie(name) { 433 var name = name + '='; 434 var cookieAll = decodeURIComponent(document.cookie).split(';'); 435 for (var i = 0; i < cookieAll.length; i++) { 436 var c = cookieAll[i]; 437 while (c.charAt(0) == ' ') 438 c = c.substring(1); 439 440 if (c.indexOf(name) == 0) 441 return c.substring(name.length, c.length); 442 } 443 return null; 444} 445 446function getJsonCookie(name) { 447 try { 448 var data = getCookie(name); 449 if (data !== '') 450 data = JSON.parse(data); 451 } catch(err) { 452 console.error(err.message, ' !Variable data type ' + typeof data + ' and store value:', data); 453 } 454 return data; 455} 456
457function get_PPTV_USER() { 458 window.PPTV_USER = getJsonCookie('PPTV_USER'); 459 return PPTV_USER; 460} 461 462 463let scrolltopBtn = document.querySelector('.scrolltop'); 464if (scrolltopBtn) { 465 window.addEventListener('scroll', (event) => { 466 if (window.scrollY > 200 ) { 467 scrolltopBtn.classList.add('active'); 468 } else { 469 scrolltopBtn.classList.remove('active'); 470 } 471 }); 472} 473 474function pageMetaData() { 475 let _login_status = 'inactive'; 476 let _user_id = 'none'; 477 let cookie_PPTV_USER = null; 478 479 let metaDataDiv = document.querySelector('#metaData'); 480 481 if (metaDataDiv === null) { 482 console.log('metaDataDiv is null'); 483 return 484 } 485 486 let _ContentCategory = metaDataDiv.getAttribute('data-content-category'); 487 let _ContentSubCategory = metaDataDiv.getAttribute('data-content-subcategory'); 488 let _ContentID = metaDataDiv.getAttribute('data-content-id'); 489 let _ContentAuthorID = metaDataDiv.getAttribute('data-content-author-id'); 490 let _ContentPublicationDate = metaDataDiv.getAttribute('data-content-publication-date'); 491 let _ContentTag = metaDataDiv.getAttribute('data-content-tag'); 492 493 let _userInerestPopup = JSON.parse(localStorage.getItem('userInterestPopup')) || null; 494 let _userInerestPopupChecked = null; 495 if (_userInerestPopup !== null) { 496 _userInerestPopupChecked = JSON.stringify(_userInerestPopup.checked); 497 _userInerestPopupChecked = _userInerestPopupChecked.replace(/"/g, ''); 498 } 499 500 if ((getCookie('PPTV_USER') !== null) && (getCookie('PPTV_USER') !== '')) { 501 cookie_PPTV_USER = JSON.parse(getCookie('PPTV_USER')); 502 _user_id = cookie_PPTV_USER.id; 503 _login_status = 'active'; 504 } 505 506 let _userAllowInConsent = localStorage.getItem('consent_setting'); 507 if (_userAllowInConsent !== null) { 508 try { 509 const consentObj = JSON.parse(_userAllowInConsent); 510 const formattedConsent = Object.entries(consentObj) 511 .map(([key, value]) => `${key}:${value}`) 512 .join(','); 513 _userAllowInConsent = `{${formattedConsent}}`; 514 } catch (err) { 515 console.error(err); 516 } 517 } 518 519 dataLayer.push({ 520 'event': 'page_metadata', 521 'ContentCategory': _ContentCategory, 522 'ContentSubCategory': _ContentSubCategory, 523 'ContentID': _ContentID, 524 'ContentAuthorID': _ContentAuthorID, 525 'ContentPublicationDate': _ContentPublicationDate, 526 'ContentTag': _ContentTag, 527 'login_status': _login_status, 528 'user_id': `user_${_user_id}`, 529 'userInterestPopupChecked': _userInerestPopupChecked, 530 'userallowinconsent': _userAllowInConsent, 531 }); 532} 533 534function loginginTracking() { 535 536 let _login_status = 'inactive'; 537 let _user_id = 'none'; 538 let cookie_PPTV_USER = null; 539 540 if ((getCookie('PPTV_USER') !== null) && (getCookie('PPTV_USER') !== '')) { 541 cookie_PPTV_USER = JSON.parse(getCookie('PPTV_USER')); 542 _user_id = cookie_PPTV_USER.id; 543 _login_status = 'active'; 544 } 545 546 547 const params = new Proxy(new URLSearchParams(window.location.search), { 548 get: (searchParams, prop) => searchParams.get(prop), 549 }); 550 551 552 if ((params.t) && (getCookie('PPTV_USER') !== null)) { 553 let cookie_PPTV_USER = JSON.parse(getCookie('PPTV_USER')); 554 let _user_id = cookie_PPTV_USER.id; 555 let _hash_email = 'none'; 556 let _social_login = getCookie('social_login'); 557 if(cookie_PPTV_USER.hash) { 558 _hash_email = cookie_PPTV_USER.hash; 559 } 560 dataLayer.push({ 561 'event': 'account_event', 562 'event_category': 'user_account', 563 'event_action': 'login_success', 564 'event_label': `account_social-${_social_login}`, 565 'hash_email': _hash_email, 566 'user_id': `user_${_user_id}` 567 }); 568 } 569 570} 571 572function logoutTracking() { 573 if ((getCookie('PPTV_USER') !== null)) { 574 let cookie_PPTV_USER = JSON.parse(getCookie('PPTV_USER')); 575 let _user_id = cookie_PPTV_USER.id; 576 let _hash_email = 'none'; 577 let _social_login = getCookie('social_login'); 578 if(cookie_PPTV_USER.hash) { 579 _hash_email = cookie_PPTV_USER.hash; 580 } 581 dataLayer.push({ 582 'event': 'account_event', 583 'event_category': 'user_account', 584 'event_action': 'logout_success', 585 'event_label': `account_social-${_social_login}`, 586 'hash_email': _hash_email, 587 'user_id': `user_${_user_id}` 588 }); 589 } 590 591} 592 593function removeBlankTag() { 594 let allP = document.querySelectorAll('.article-content blockquote p.selectionShareable'); 595 if (document.querySelectorAll('.article-content blockquote').length > 0) { 596 for (let index = 0; index < allP.length ; index++) { 597 if ((allP[index].innerText).replace(' ', '') === '') { 598 allP[index].remove(); 599 } 600 } 601 602 } 603} 604 605/* Get cookie user profile*/
606get_PPTV_USER(); 607 608/*check auth*/ 609docReady(function(){ 610 removeBlankTag(); 611 deleteCookie('pptv_session'); /*for production*/ 612 deleteCookie('laravel_session'); /* for local and staging */ 613 if (PPTV_USER) { 614 console.log('User Login complete'); 615 setDisplayAvatar(PPTV_USER); 616 617 if (typeof callBackAuthen === 'function') { 618 callBackAuthen(); 619 } 620 /* gtag tracking page_metadata */ 621 loginginTracking(); 622 pageMetaData(); 623 } else if (PPTV_USER === '') { 624 console.log('User Not Login'); 625 626 if (typeof callBackAuthen === 'function') { 627 callBackAuthen(); 628 } 629 /* gtag tracking page_metadata */ 630 loginginTracking(); 631 pageMetaData(); 632 } else { 633 fetch('/api/auth?' + Math.random(), { credentials: 'same-origin' }) 634 .then(function(response) { 635 if (!response.ok) { 636 throw new Error('auth failed'); 637 } 638 return response.json(); 639 }) 640 .then(function(user) { 641 var value = user === false ? '' : JSON.stringify(user); 642 var expiresMinite = 10; 643 setCookie('PPTV_USER', value, expiresMinite); 644 get_PPTV_USER(); 645 646 if (user) { 647 setDisplayAvatar(user); 648 } 649 if (typeof callBackAuthen === 'function') { 650 callBackAuthen(); 651 } 652 loginginTracking(); 653 pageMetaData(); 654 }) 655 .catch(function() { 656 console.log('----fail----'); 657 loginginTracking(); 658 pageMetaData(); 659 }); 660 661 } 662 663 var linkWithGaTracking = document.querySelectorAll('.js-gtag-related'); 664 linkWithGaTracking.forEach(link => { 665 if (link.hasAttribute('data-ga-event')) { 666 var GAdata = link.getAttribute('data-ga-event'); 667 var GAdataObj = JSON.parse(GAdata); 668 var event_action = GAdataObj.action; 669 var event_category = GAdataObj.category; 670 var event_label = GAdataObj.label; 671 link.addEventListener('click', function() { 672 dataLayer.push({ 673 'event': 'track_event', 674 'event_category': event_category, 675 'event_action': event_action, 676 'event_label': event_label 677 }); 678 }); 679 } 680 }); 681}); 682 683 684 685function trackingGtag(event,event_category,event_action,event_label) { 686 dataLayer.push({ 687 'event': event, 688 'event_category': event_category, 689 'event_action': event_action, 690 'event_label': event_label 691 }); 692} 693 694 695function iframeCdn($iframe_url) { 696 var use_on_environment = ['hotfix', 'production']; 697 if (use_on_environment.includes(APP_ENV)) { 698 $iframe_url = $iframe_url.replace('.pptvhd36.com', '-live.pptvhd36.com'); 699 return $iframe_url; 700 } 701 return $iframe_url+ '&cdn=1'; 702} 703 704function assetsCdn(url) { 705 let window_location = window.location; 706 let location_origin = window_location.origin; 707 let image_href = location_origin + '/' + url; 708 if ( 709 location_origin.includes('hotfix.pptvhd36.com') || 710 location_origin.includes('www.pptvhd36.com') 711 ) { 712 const linkCdn = '-live.pptvhd36.com'; 713 url = image_href.replace('.pptvhd36.com', linkCdn); 714 } else { 715 url = image_href; 716 } 717 718 return url; 719} 720 721function dateThai(dateTimeString, format) { 722 const thaiMonthsShort = ['ม.à¸.', 'à¸.à¸.', 'มี.à¸.', 'à¹à¸¡.ย.', 'à¸.à¸.', 'มิ.ย.', 'à¸.à¸.', 'ส.à¸.', 'à¸.ย.', 'à¸.à¸.', 'à¸.ย.', 'à¸.à¸.']; 723 724 const [datePart, timePart] = dateTimeString.split(' '); 725 const [year, month, day] = datePart.split('-').map(Number); 726 const [hours, minutes] = timePart.split(':').map(Number); 727 728 const thaiYear = year + 543; 729 const thaiMonth = thaiMonthsShort[month - 1]; 730 const thaiDate = day; 731 const thaiHours = hours.toString().padStart(2, '0');; 732 const thaiMinutes = minutes.toString().padStart(2, '0'); 733 const period = hours >= 12 ? 'PM' : 'AM'; 734 735 const formattedDate = format 736 .replace('J', thaiDate) 737 .replace('M', thaiMonth) 738 .replace('Y', thaiYear) 739 .replace('HH', thaiHours) 740 .replace('mm', thaiMinutes) 741 .replace('à¸.', 'à¸.') 742 .replace('()', '') 743 .replace(' ', ' '); 744 745 return formattedDate.trim(); 746} 747 748function trackingClick() { 749 const targets = document.querySelectorAll(".js-tracking-click"); 750
751 targets.forEach(target => { 752 let ga_click_category = target.getAttribute('data-ga-click-category'); 753 let ga_click_action = target.getAttribute('data-ga-click-action'); 754 let ga_click_label = target.getAttribute('data-ga-click-label'); 755 target.addEventListener('click', () => { 756 dataLayer.push({ 757 'event': 'track_event', 758 'event_category': ga_click_category, 759 'event_action': ga_click_action, 760 'event_label': ga_click_label 761 }); 762 }) 763 764 }); 765} 766 767 768/* tracking measurability */ 769function trackingMeasurability() { 770 console.log('trackingMeasurability start'); 771 const targets = document.querySelectorAll(".js-tracking-measurability"); 772 if (targets.length === 0) return; 773 774 const timers = new WeakMap(); 775 776 const observer = new IntersectionObserver((entries, observer) => { 777 entries.forEach(entry => { 778 const target = entry.target; 779 780 if (entry.isIntersecting) { 781 782 let ga_measurability_category = target.getAttribute('data-ga-measurability-category'); 783 let ga_measurability_action = target.getAttribute('data-ga-measurability-action'); 784 let ga_measurability_label = target.getAttribute('data-ga-measurability-label'); 785 786 dataLayer.push({ 787 'event': 'track_event', 788 'event_category': ga_measurability_category, 789 'event_action': ga_measurability_action, 790 'event_label': ga_measurability_label 791 }); 792 793 const timer = setTimeout(() => { 794 let ga_viewability_category = target.getAttribute('data-ga-viewability-category'); 795 let ga_viewability_action = target.getAttribute('data-ga-viewability-action'); 796 let ga_viewability_label = target.getAttribute('data-ga-viewability-label'); 797 798 dataLayer.push({ 799 'event': 'track_event', 800 'event_category': ga_viewability_category, 801 'event_action': ga_viewability_action, 802 'event_label': ga_viewability_label 803 }); 804 805 observer.unobserve(target); 806 }, 1000); 807 808 timers.set(target, timer); 809 } else { 810 if (timers.has(target)) { 811 clearTimeout(timers.get(target)); 812 timers.delete(target); 813 } 814 } 815 }); 816 }, { threshold: 0.5 }); 817 818 targets.forEach(target => observer.observe(target)); 819} 820 821 822 823 824 825 826/* à¹à¸à¹à¸à¸à¸µà¹à¸ªà¸³à¸«à¸£à¸±à¸à¹à¸à¹à¹à¸à¸à¸±à¸à¸«à¸²à¸à¸²à¸£à¹à¸«à¸¥à¸à¸«à¸¥à¸²à¸¢à¸à¸±à¸§à¸à¸à¸ embed.js à¸à¸²à¸ Instagram 827 à¸à¸µà¹à¸ªà¹à¸à¸à¸¥à¸à¸³à¹à¸«à¹à¸«à¸à¹à¸²à¹à¸§à¹à¸à¸à¹à¸² à¹à¸¥à¸° embed à¸à¸³à¸à¸²à¸à¹à¸¡à¹à¸ªà¸¡à¸à¸¹à¸£à¸à¹ 828 829 หà¹à¸²à¸¡à¸¥à¸! 830*/ 831document.addEventListener("DOMContentLoaded", function () { 832 /* 1. ลà¸à¸à¸¸à¸ embed.js à¸à¸µà¹à¹à¸«à¸¥à¸à¸¡à¸²à¸à¸²à¸ Instagram */ 833 document.querySelectorAll('script[src*="instagram.com/embed.js"]').forEach(el => el.remove()); 834 835 /* 2. à¹à¸«à¸¥à¸à¹à¸«à¸¡à¹à¹à¸à¹ 1 à¸à¸±à¸§ */ 836 const igScript = document.createElement("script"); 837 igScript.src = "https://www.instagram.com/embed.js"; 838 igScript.async = true; 839 840 /* à¹à¸à¸´à¹à¸¡ error handling */ 841 igScript.onerror = () => { 842 console.error('Failed to load Instagram embed script'); 843 }; 844 845 /* ยà¹à¸²à¸¢ onload มาà¸à¸¢à¸¹à¹à¹à¸à¸à¸µà¹ */ 846 igScript.onload = () => { 847 if (window.instgrm) { 848 window.instgrm.Embeds.process(); 849 } 850 }; 851 852 document.body.appendChild(igScript); 853 854 855 856 /* tracking measurability */ 857 trackingMeasurability(); 858 /* tracking click */ 859 trackingClick(); 860}); 861
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.