var lang; $(document).ready(function () { lang = $("html").attr("lang"); setMainPadding(); initFocusableEl(); initAnimation(); headerFooterFixed(); initA11ySkip(); initCustomSelect(); initCustomDate(); initSwitchLang(); initLogin(); girdRowHeight(); initPopup(); initTabCheck(); initBackTop(); initHeaderSearch(); initMobileMenu(); initToggleTextarea(); removeStyle(); initShare(); initNewsFilter(); initNewsPageControl(); initInnerFilter() newsFilterItem(); initGallery(); initSearchPaging() }); $(window).scroll(function () { headerFooterFixed(); }); $(window).resize(function () { setMainPadding(); girdRowHeight(); removeStyle(); }); var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); } } return false; }; function setMainPadding() { if ($("body").is(".add-main-padding")) { var headerHeight = "133px"; if ($(window).width() <= 1280) { headerHeight = "125px"; } if ($(window).width() <= 1024) { headerHeight = "115px"; } if ($(window).width() <= 991) { headerHeight = "91px"; } if ($(window).width() <= 560) { headerHeight = "77px"; } //$("main").css("padding-top", headerHeight); var fixHeaderHTML = '
'; if ($(".fix-header").length == 0) { $("main").before(fixHeaderHTML); } else { $(".fix-header").css("height", headerHeight); } } } function initFocusableEl() { jQuery.extend(jQuery.expr[":"], { focusable: function (el, index, selector) { return $(el).is("a, button, :input, [tabindex]"); }, }); } function initA11ySkip() { $(".a11y-to-content").click(function (e) { e.preventDefault(); $("main :focusable").first().focus(); }); $(".a11y-to-footer").click(function (e) { e.preventDefault(); $(".footer__main-logo-container").focus(); }); } function initAnimation() { inView(".header").on("enter", function () { $(".header").addClass("animated"); }); inView(".has-animate").on("enter", function (e) { e.classList.remove("has-animate"); e.classList.add("animated"); }); inView(".index-circle-banner__bg").on("enter", function (e) { e.classList.remove("hide"); }); } function headerFooterFixed() { if ($(window).scrollTop() > 100) { $(".header").addClass("fixed"); $(".back-to-top").addClass("fixed"); if ( $(window).scrollTop() + $(window).height() > $(".footer").offset().top ) { $(".back-to-top").removeClass("fixed"); } } else { $(".header").removeClass("fixed"); $(".back-to-top").removeClass("fixed"); } } function initCustomSelect() { $(".custom-select").change(function () { var text = $(this).find("option:checked").text(); $(this).find(".custom-select__mask").text(text); }); $(".custom-select").change(); } function initCustomDate() { if ($(".custom-date").length < 1) { return false; } $(".custom-date input").datepicker({ dateFormat: "yy-mm-dd", altFormat: "yy-mm-dd", showAnim: "fadeIn", }); $(".custom-date input").change(function () { var val = $(this).val(), thisMask = $(this) .parents(".custom-date") .find(".custom-date__mask"); if (val == "") { val = $(thisMask).attr("data-basic"); } $(thisMask).text(val); }); } function girdRowHeight() { if ($(".grid-box").length > 0) { if ($(".grid-box").is(".news-grid")) { if ($(window).width() > 991) { var colMinHeightInt = ($(".news-grid__container").eq(0).width() / 2) * 1.1, colMinHeight = colMinHeightInt / 2 - 12 + "px"; } else { var colMinHeightInt = $(".news-grid__container").eq(0).width() * 1.1, colMinHeight = colMinHeightInt / 2 + "px"; } $(".news-grid .grid-box__col").css("min-height", colMinHeight); } else { if ($(window).width() > 991) { var colMinHeightInt = ($(".grid-box__row").eq(0).width() / 2) * 1.1, colMinHeight = colMinHeightInt + "px", halfcolMinHeight = colMinHeightInt / 2 - 12 + "px"; } else { var colMinHeightInt = $(".grid-box__row").eq(0).width() * 1.1, colMinHeight = colMinHeightInt + "px", halfcolMinHeight = colMinHeightInt / 2 + "px"; } $(".grid-box__row > .grid-box__col:not(.has-half-row)").css( "min-height", colMinHeight ); $(".grid-box__half-row > .grid-box__col").css( "min-height", halfcolMinHeight ); /* index & covid grid */ if ($(window).width() > 991) { var colMinHeightInt = ($(".grid-box.need-to-sort .wrapper").eq(0).width() / 2) * 1.1, colMinHeight = colMinHeightInt + "px", halfcolMinHeight = colMinHeightInt / 2 - 12 + "px"; } else { var colMinHeightInt = $(".grid-box.need-to-sort .wrapper").eq(0).width() * 1.1, colMinHeight = colMinHeightInt + "px", halfcolMinHeight = colMinHeightInt / 2 + "px"; } $(".grid-box.need-to-sort .grid-box__col").css( "min-height", halfcolMinHeight ); $(".grid-box.need-to-sort .grid-box__col--large").css( "min-height", colMinHeight ); var myColumns = new Columns(".columns", { count: 4, gap: 24, itemClass: "grid-box__col", imageLoad: true, }); } } } var elBeforePopup; function initPopup() { // video popup $(".popup-video__btn").click(function (e) { e.preventDefault(); elBeforePopup = $(this); var videoLink = $(this).attr("href"), video = $(".popup-video iframe").get(0); //video = $(".popup-video video").get(0); $("body").addClass("overflow-hidden"); //$(".popup-video video source").attr("src", videoLink); $(".popup-video iframe").attr("src", videoLink); //video.load(); $(".popup-video").fadeIn(300); $(".popup-video__close-btn").focus(); //video.play(); }); $(".popup-video__close").click(function (e) { e.preventDefault(); $("body").removeClass("overflow-hidden"); //$(".popup-video video").get(0).pause(); $(".popup-video iframe").attr("src", ""); $(".popup-video").fadeOut(300); if (lastKey == 13) { $(elBeforePopup).focus(); } }); $(".popup-video__close").blur(function () { if ($(".popup-video").is(":visible") && lastKey == 9 && isShift) { $(".popup-video iframe").focus(); } }); $(".popup-video__tab-return").focus(function () { $(".popup-video__close").focus(); }); } var lastKey, isShift; function initTabCheck() { $("body").keydown(function (e) { lastKey = e.keyCode; isShift = e.shiftKey; }); } function initBackTop() { $(".back-to-top") .click(function (e) { e.preventDefault(); $("html, body").animate( { scrollTop: 0, }, 500 ); }) .keydown(function (e) { if (e.keyCode == 13 || e.keyCode == 32) { $(this).click(); $(".header-logo").focus(); } }); } function initHeaderSearch() { $(".header-menu__search-toggle-btn") .click(function (e) { e.preventDefault(); $(this).toggleClass("active"); $(".header").toggleClass("search-open"); $(".header-menu__search").fadeToggle(300); }) .blur(function () { if ($(this).is(".active") && lastKey == 9) { if (isShift) { $(".header-menu__search-submit").focus(); } else { $(".header-menu__search-input").focus(); } } }); $(".header-menu__search-input").blur(function () { if (lastKey == 9 && isShift) { $(".header-menu__search-toggle-btn").focus(); } }); $(".header-menu__search-submit").blur(function () { if (lastKey == 9 && !isShift) { $(".header-menu__search-toggle-btn").focus(); } }); } function initMobileMenu() { $(".header-menu__mobile-btn").click(function (e) { $(this).toggleClass("active"); $(".header-menu") .toggleClass("header-menu--mobile-active") .fadeToggle(500); $(".header").toggleClass("mobile-menu-open"); $("body").toggleClass("overflow-hidden"); }); $(".header-menu__subitem-toggle-btn").click(function (e) { $(this).toggleClass("active"); $(this).next(".header-menu__subitem").slideToggle(500); }); } function removeStyle() { if ($(window).width() > 991) { // Remove mobile Style if (!$(".popup-video").is(":visible")) { $("body").removeClass("overflow-hidden"); } $(".header-menu__mobile-btn").removeClass("active"); $(".header-menu").removeAttr("style"); $(".header-menu__subitem").removeAttr("style"); $(".header-menu__subitem-toggle-btn").removeClass("active"); } else { // Remove desktop Style $(".header-menu__search").removeAttr("style"); $(".header-menu__search-toggle-btn").removeClass("active"); } } function initToggleTextarea() { $(".section-fold__toggle-btn").click(function (e) { if (!$(this).is(".section-fold__toggle-btn--link") && !$(this).is(".section-fold__toggle-btn--download")) { e.preventDefault(); var holder = $(this).parents(".section-fold__item"), content = $(holder).find(".section-fold__content"); $(this).toggleClass("active"); $(holder).toggleClass("active"); $(content).slideToggle(500); } }); } var $windowCount = 0; function initShare() { $(".inner-header__social-item").click(function (e) { e.preventDefault(); var pageShareTitle = $("title").text().replace("|", "-"); var pageShareContent = window.location.href; var href = ""; var type = "default"; var pageUrl = window.location.href; if ($(this).is(".facebook")) { type = "facebook"; href = "https://www.facebook.com/sharer/sharer.php?u=" + pageUrl; } else if ($(this).is(".email")) { type = "email"; href = "mailto:?subject=" + pageShareTitle + "&body=" + pageShareTitle + "%0A" + pageUrl; } else if ($(this).is(".twitter")) { type = "twitter"; href = "http://twitter.com/share?text=" + pageShareTitle + "&url=" + pageUrl; } PopupCenter(href, "shareWindow_" + $windowCount, 600, 500, type); $windowCount++; }); } function PopupCenter(url, title, w, h, type) { if (type == "email") { window.location.href = url; } else { // Fixes dual-screen position Most browsers Firefox var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left; var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top; var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; var left = width / 2 - w / 2 + dualScreenLeft; var top = height / 2 - h / 2 + dualScreenTop; var newWindow = window.open( url, title, "scrollbars=yes, width=" + w + ", height=" + h + ", top=" + top + ", left=" + left ); // Puts focus on the newWindow if (window.focus) { newWindow.focus(); } } } var newsFilterList = {}; var showPageTimeout, showItemTimeout = []; function initNewsFilter() { if($(".news-grid.has-filter").length < 1) {return false} $(".news-filter__left select, .news-filter__left input").change( function () { $(".news-filter__left select, .news-filter__left input").each( function () { var thisID = "data-" + $(this).attr("id"), thisVal = $(this).val(); newsFilterList[thisID] = thisVal; } ); newsFilterItem(); } ); $(".news-filter__left #type").change(function () { if ($(this).val() == "1") { $(".news-filter__left #status").val("").change(); $(".news-filter__left #status") .parents(".news-filter__select-item") .hide(); } else { $(".news-filter__left #status") .parents(".news-filter__select-item") .show(); } }); $(".news-filter__search").submit(function (e) { e.preventDefault(); var thisVal = $("#newsSearch").val(); newsFilterList["text"] = thisVal.toLowerCase(); newsFilterItem(); }); var urlYear = getUrlParameter("year") if( urlYear && $("#year option").filter(`[value=${urlYear}]`).length) { $("#year").val(urlYear).change() } } function initNewsPageControl() { if($(".news-grid.has-filter").length < 1) {return false} $(".news-grid__control-detail").submit(function (e) { e.preventDefault(); var newPage = 1; if ($(".news-grid__page-input").val() != "") { newPage = parseInt($(".news-grid__page-input").val()); } newsPageTo(newPage, true); }); $(".news-grid__page-input").blur(function () { var newPage = 1; if ($(this).val() != "") { newPage = parseInt($(this).val()); } newsPageTo(newPage, true); }); $(".news-grid__prev-btn, .news-grid__next-btn").click(function (e) { e.preventDefault(); if (!$(this).is(".disabled")) { var currentPage = parseInt($(".news-grid__page-input").val()), newPage = currentPage - 1; if ($(this).is(".news-grid__next-btn")) { newPage = currentPage + 1; } newsPageTo(newPage, true); } }); } function newsFilterItem() { if ($(".news-filter").length < 1) { return false; } $(".grid-box__col").removeClass( "news-grid__col--show news-grid__col--half-temporary" ); $(".grid-box__col").each(function () { var thisCol = $(this), isShow = true; $.each(newsFilterList, function (key, value) { if (value != "" && typeof value != "undefined") { if (key == "text") { var thisText = thisCol.text().toLowerCase(); if (thisText.indexOf(value) == -1) { isShow = false; } } else { var thisKey = thisCol .attr(key) .replaceAll(" ", "") .split(","), i = 0, canShow = false; for (i; i < thisKey.length; i++) { thisKey[i] == value ? (canShow = true) : ""; } !canShow ? (isShow = false) : ""; /* if (thisCol.attr(key) != value) { isShow = false; } */ } } }); if (isShow) { thisCol.addClass("news-grid__col--show"); } }); updateNewsPage(); } function updateNewsPage() { var itemPerPage = parseInt($(".news-grid__item-per-page").val()), rowPerPage = itemPerPage / 4, totalPage, totalSize = 0, pageCount = 1, rowCount = 1, colCount = 0; $(".news-grid__col--show").each(function () { var thisItem = $(this), thisSize = 1; thisItem.removeAttr("data-page"); if (colCount == 4) { colCount = 0; rowCount++; } if (thisItem.is(".news-grid__col--half")) { thisSize = 2; } if (colCount + thisSize > 4) { thisItem .prevAll(".news-grid__col--show.news-grid__col--quarter:first") .addClass("news-grid__col--half-temporary"); totalSize++; colCount = 0; rowCount++; } if (rowCount > rowPerPage) { rowCount = 1; pageCount++; } totalSize += thisSize; colCount += thisSize; thisItem.attr("data-page", pageCount); }); if (totalSize % itemPerPage != 0) { totalPage = parseInt(totalSize / itemPerPage) + 1; } else { totalPage = totalSize / itemPerPage; } $(".news-grid__total-page").text(totalPage); newsPageTo(1); } function newsPageTo(page, scroll) { clearTimeout(showPageTimeout); $.each(showItemTimeout, function (i) { clearTimeout(showItemTimeout[i]); }); $(".news-grid__col").stop(); var delay = 0, newPage = page, totalPage = parseInt($(".news-grid__total-page").text()), basicHeight = $(".news-grid__container").outerHeight(); $(".news-grid__container").css("height", basicHeight); $(".has-filter .grid-box__col").fadeOut(300); $(".news-grid__no-result").hide(); $(".news-grid__prev-btn").removeClass("disabled"); $(".news-grid__next-btn").removeClass("disabled"); if (scroll == true) { $("html, body").animate( { scrollTop: $(".news-filter").offset().top - $(".header").outerHeight(), }, 500 ); } if (newPage < 1) { newPage = 1; } if (newPage > totalPage) { newPage = totalPage; } if (newPage == 1 || totalPage == 0) { $(".news-grid__prev-btn").addClass("disabled"); } if (newPage == totalPage) { $(".news-grid__next-btn").addClass("disabled"); } $(".news-grid__page-input").val(newPage); showPageTimeout = setTimeout(function () { $(".news-grid__col--show[data-page=" + newPage + "]").each(function ( index ) { var thisItem = $(this); var thisTiemout = setTimeout(function () { thisItem.fadeIn(500); if ( index == $(".news-grid__col--show[data-page=" + newPage + "]") .length - 1 ) { $(".news-grid__container").css("height", ""); $( ".news-grid__col--show:not([data-page=" + newPage + "])" ).fadeOut(300); } }, delay); showItemTimeout.push(thisTiemout); delay += 200; }); }, 310); if ($(".news-grid__col--show").length < 1) { $(".news-grid__no-result").fadeIn(300); } } var innerFilterVal = {} function initInnerFilter() { $(".inner-filter__container select").change(function(){ var targetHolder = $(this).parents(".inner-filter").find(".inner-filter__target") innerFilterChange($(this), $(targetHolder)) }) /* $(".inner-filter__container input").keydown(function(){ var targetHolder = $(this).parents(".inner-filter").find(".inner-filter__target") innerFilterChange($(this), $(targetHolder)) }) */ $(".inner-filter__search").submit(function(e){ e.preventDefault() var targetHolder = $(this).parents(".inner-filter").find(".inner-filter__target") innerFilterChange($(this).find("input"), $(targetHolder)) }) } function innerFilterChange(el, holder){ var thisID = "data-" + el.attr("id"), thisVal = el.val(); innerFilterVal[thisID] = thisVal; var filterItem = holder.find(".inner-filter__target-item") $(filterItem).fadeOut(300) $(filterItem).each(function () { var thisItem = $(this), isShow = true; $.each(innerFilterVal, function (key, value) { if (value != "" && typeof value != "undefined") { if (key == "data-text") { var thisText = thisItem.text().toLowerCase(); if (thisText.indexOf(value) == -1) { isShow = false; } } else { var thisKey = thisItem.attr(key).replaceAll(" ", "").split(","), i = 0, canShow = false; for (i; i < thisKey.length; i++) { thisKey[i] == value ? (canShow = true) : ""; } !canShow ? (isShow = false) : ""; } } }); if (isShow) { thisItem.fadeIn(300) } }); } function initLogin() { // login popup $(".login-popup__btn, .header-menu__login:not(.header-menu__logout)").click( function (e) { e.preventDefault(); elBeforePopup = $(this); $("body").addClass("overflow-hidden"); $(".popup-login").fadeIn(300); if (typeof $(this).attr("data-redirect") != "undefined") { $(".popup-login__redirect").val($(this).attr("data-redirect")); } else { $(".popup-login__redirect").val(""); } } ); $(".popup-login__close").click(function (e) { e.preventDefault(); $("body").removeClass("overflow-hidden"); $(".popup-login").fadeOut(300); if (lastKey == 13) { $(elBeforePopup).focus(); } }); $(".popup-login__close").blur(function () { if ($(".popup-login").is(":visible") && lastKey == 9 && isShift) { $(".popup-login__form-submit").focus(); } }); $(".popup-login__tab-return").focus(function () { if (lastKey == 9 && isShift) { $(".popup-login__form-submit").focus(); } else { $(".popup-login__close").focus(); } }); // login form submit $(".popup-login__form").submit(function (e) { e.preventDefault(); $(".popup-login__error").hide(); $.ajax({ url: "/login", data: $(this).serialize(), dataType: "json", success: function (result) { if (result["status"] == 1) { // success if ($(".popup-login__redirect").val().length > 0) { window.location.href = $( ".popup-login__redirect" ).val(); } else { location.reload(); } } else { $(".popup-login__error").show(); } }, }); }); } var gallerySwiper = [], galleryThumbsSwiper = []; function initGallery() { if ($(".gallery-main").length < 1 || $(".gallery-main__item").length == 1) { return false; } $(".gallery-main").each(function(index){ if($(this).find(".swiper-slide").length < 2) {return} var $thumbsEl = $(this).next(".gallery-thumbs") galleryThumbsSwiper[index] = new Swiper($thumbsEl, { slidesPerView: "auto", spaceBetween: 10, freeMode: true, watchSlidesProgress: true, }); gallerySwiper[index] = new Swiper(this, { autoHeight: true, spaceBetween: 10, navigation: { nextEl: ".gallery-main__next", prevEl: ".gallery-main__prev", }, thumbs: { swiper: galleryThumbsSwiper[index], }, }); }) } function initSwitchLang() { $(".switch-lang select").change(function(){ if($(this).val() != lang) { var newHref = window.location.href.replace("/"+lang, "/"+$(this).val()) window.location.href = newHref } }) } function initSearchPaging() { if($(".search-result").length < 1) {return false} var newPage = 1; $(".search-result__control-detail").submit(function (e) { e.preventDefault(); if ($(".search-result__page-input").val() != "") { newPage = parseInt($(".search-result__page-input").val()); } showSearchCurrentPage(newPage) }); $(".search-result__page-input").blur(function () { if ($(this).val() != "") { newPage = parseInt($(this).val()); } showSearchCurrentPage(newPage) }); $(".search-result__prev-btn").click(function(e){ e.preventDefault() if($(this).is("disabled")){return false} newPage-- showSearchCurrentPage(newPage) }) $(".search-result__next-btn").click(function(e){ e.preventDefault() if($(this).is("disabled")){return false} newPage++ showSearchCurrentPage(newPage) }) showSearchCurrentPage(newPage) } var searchPageTimeout, searchItemTimeout = [], searchHeightTimeout; function showSearchCurrentPage(page) { clearTimeout(searchPageTimeout); $.each(searchItemTimeout, function (i) { clearTimeout(searchItemTimeout[i]); }); clearTimeout(searchHeightTimeout) $(".search-result__item").stop(); var delay = 0, basicHeight = $(".search-result__item-container").outerHeight(); $(".search-result__item-container").css("min-height", basicHeight); $(".search-result__item").fadeOut(300); $(".search-result__prev-btn").removeClass("disabled"); $(".search-result__next-btn").removeClass("disabled"); var maxPage = parseInt($(".search-result__total-page").text()), itemPerPage = parseInt($(".search-result__item-per-page").val()); if(page > maxPage) { page = maxPage } else if(page < 1) { page = 1 } if (page == 1) { $(".search-result__prev-btn").addClass("disabled"); } if (page == maxPage) { $(".search-result__next-btn").addClass("disabled"); } $(".search-result__page-input").val(page) var firstEl = itemPerPage * (page - 1) if(page == 1) { firstEl = 0 } var lastEl = firstEl + itemPerPage; if(lastEl >= $(".search-result__item").length) { lastEl = $(".search-result__item").length } searchPageTimeout = setTimeout(function () { for(let i = firstEl; i < lastEl; i++) { let thisItem = $(".search-result__item").eq(i) var thisTiemout = setTimeout(function () { thisItem.fadeIn(500); if (i == lastEl - 1) { searchHeightTimeout = setTimeout(function() { $(".search-result__item-container").css("min-height", ""); }, 510) } }, delay); searchItemTimeout.push(thisTiemout); delay += 200; } }, 310); }