//var window width var viewportGlobal = $(window).width(); //function js cal match height var calMatchHeight = function(){ if($('.js-match-height').length > 0){ $('.js-match-height >ul >li').matchHeight(); } }; //function js scroll header var scrollHeader = function(){ var nav = $('.l-nav.is-home'); var body = $('body'); var menu = $('.c-menu-outer'); var navHeight = nav.height() + 1; console.log(navHeight); if(nav.length > 0){ $(window).scroll(function(){ if($(this).scrollTop() > navHeight - 51){ nav.addClass('has-fixed'); body.addClass('has-padding'); } if($(this).scrollTop() <= navHeight - 51){ nav.removeClass('has-fixed'); body.removeClass('has-padding'); } }); } }; //expand search var expandSearch = function(){ if($('.c-search-wrapper').length > 0){ var boxSearch = $('.c-search-wrapper'); $('.js-search-expand').click(function(e) { e.preventDefault(); boxSearch.addClass('active'); }); $('.js-search-close').click(function(e) { boxSearch.removeClass('active'); }); } }; //function js template slider 3 col var templateSlider3Col = function(){ if($('.js-slider-3-col').length > 0){ $('.js-slider-3-col').owlCarousel({ loop:true, margin:0, responsiveClass:false, nav:true, dots:true, autoplay:true, autoHeight:false, autoplayTimeout:6000, autoplaySpeed:1000, autoplayHoverPause:false, navText:false, responsive:{ 0:{ items:2, margin:12 }, 768:{ items:3, margin:19 } } }); } }; //function js template slider 4 col var templateSlider4Col = function(){ if($('.js-slider-4-col').length > 0){ $('.js-slider-4-col').owlCarousel({ loop:true, margin:0, responsiveClass:false, nav:true, dots:true, autoplay:true, autoHeight:false, autoplayTimeout:6000, autoplaySpeed:1000, autoplayHoverPause:false, navText:false, responsive:{ 0:{ items:2, margin:12 }, 768:{ items:4, margin:18 } } }); } }; //function js template tabs var templateTabs = function(){ if($('.c-tabs').length > 0){ $('.c-tabs .c-tabs__title ul li a').click(function(e) { e.preventDefault(); var id = $(this).attr("href"); var parent = $(this).parent(); var tabs = $(this).parent().parent().parent().parent().parent(); if (!parent.hasClass('active')){ $('.c-tabs__title ul li.active',tabs).removeClass('active'); parent.addClass('active'); $('.c-tabs__pane.active',tabs).removeClass('active').hide(); $(id).addClass('active').show(); } }); } }; //function js expand menu mobile var expandMenu = function(){ if($('.c-menu-expand').length > 0){ $('.js-menu-expand').click(function(e) { e.preventDefault(); var menu = $('.c-menu-smart'); var page = $('body'); var ovelay = $('.js-app-ovelay'); if (page.hasClass('has-page-open')) { page.removeClass('has-page-open'); ovelay.removeClass('has-ovelay-show'); menu.removeClass('has-menu-open'); $(this).removeClass('is-active'); } else { page.addClass('has-page-open'); ovelay.addClass('has-ovelay-show'); menu.addClass('has-menu-open'); $(this).addClass('is-active'); } }); $('.js-app-ovelay').click(function() { var menu = $('.c-menu-smart'); var page = $('body'); var ovelay = $('.js-app-ovelay'); page.removeClass("has-page-open"); ovelay.removeClass("has-ovelay-show"); menu.removeClass("has-menu-open"); $('.js-menu-expand').removeClass('is-active'); return false; }); //close menu in mobile $('.c-mobile-menu a').on('click', function(e) { var menu = $('.c-menu-smart'); var page = $('body'); var ovelay = $('.js-app-ovelay'); if (e.target == this && viewportGlobal < 768){ page.removeClass("has-page-open"); ovelay.removeClass("has-ovelay-show"); menu.removeClass("has-menu-open"); $('.js-menu-expand').removeClass('is-active'); } }); } }; //var function Mobile Sub Menu Expand var submenuMobileExpand = function(){ $('.c-mobile-menu .c-submenu-btn').click(function(e) { e.preventDefault(); var grand = $(this).parent(); var root = $(this).parent().parent(); if (grand.hasClass('active')) { grand.removeClass('active'); $('>.c-dropdown-menu',grand).slideUp(); } else { $('>li.active >.c-dropdown-menu',root).slideUp(); $('>li.active',root).removeClass('active'); grand.addClass('active'); $('>.c-dropdown-menu',grand).slideDown(); } }); }; //sidebar box scroll var sidebarScroll = function(){ if($('.js-sticky-scroll').length > 0){ $('.js-sticky-scroll').each(function () { var contentA = $(this).parent().parent(); $(this).scrollChaser({ wrapper: contentA, offsetTop: 71 }); }); } }; //var function show audio full var showAuioFull = function(){ if($('.c-audio-box').length > 0) { $('.c-audio-box__info').click(function (e) { var audioBox = $('.c-audio-box'); if(audioBox.hasClass('has-full')){ $('.c-audio-box').removeClass('has-full'); }else { $('.c-audio-box').addClass('has-full'); } }); } }; //function js scroll audio var scrollAudio = function(){ var audioBox = $('.c-audio-box'); if (audioBox.length > 0 && viewportGlobal > 1200) { var audioBoxTop = audioBox.offset().top; $(window).scroll(function(){ if($(this).scrollTop() > audioBoxTop){ audioBox.addClass('has-fixed'); } if($(this).scrollTop() <= audioBoxTop){ audioBox.removeClass('has-fixed'); } }); } }; //var function Mega Menu Expand var megaMenuExpand = function(){ if($('.js-menu-more').length > 0){ $('.js-menu-more').click(function(e) { e.preventDefault(); var menu = $('.c-mega-menu'); if (menu.hasClass('active')) { $(this).removeClass('active'); menu.removeClass('active'); } else { $(this).addClass('active'); menu.addClass('active'); } }); } }; var shareScroll = function(){ $(window).scroll(function () { if ($('.js-share-scroll').length > 0) { var nav = $('.js-share-scroll'); var navHeight = nav.height(); var navParent = nav.parent(); var navParentHeight = navParent.height(); var navParentTop = navParent.offset().top; var content = $('.c-news-detail'); var contentHeight = content.height(); var navBottom = navParentTop + navParentHeight + 15 + contentHeight; var keepBottomTop = navBottom - navHeight; var navTopCss = navParentHeight + 15 + contentHeight - navHeight; if ($(this).scrollTop() > keepBottomTop) { nav.addClass('has-ab'); nav.css({ 'top': navTopCss + 'px' }); } else { nav.removeClass('has-ab'); nav.css({ 'top': '68px' }); } if ($(this).scrollTop() > navParentTop) { nav.addClass('has-fixed'); } else { nav.removeClass('has-fixed'); nav.css({ 'top': '8px' }); } } }); }; //function js main slider var mainSlider = function(){ if($('.c-main-slider').length > 0){ $('.js-main-slider').owlCarousel({ items:1, loop:true, margin:0, responsiveClass:false, nav:false, dots:true, autoplay:true, autoHeight:false, autoplayTimeout:7000, autoplaySpeed:1000, autoplayHoverPause:false, navText:false, }); } }; //audio scroll content var jsScrollContent = function(){ if(viewportGlobal > 991 && $('.js-cat-scroll').length > 0) $(".js-cat-scroll").niceScroll({ cursorcolor:"#29c5ff", cursorwidth:"7px", cursorborder: "none" }).resize(); }; //datepicker load var datepickerLoad = function(){ if($('.datepicker').length > 0) $('.datepicker').datepicker({ language: 'vi', todayBtn: "linked", autoclose: true }); }; //var function page copy click var pageCopyClick = function(){ if($('.c-author-page').length > 0){ $('.js-page-copy').click(function(e) { e.preventDefault(); if( viewportGlobal < 992 ){ $('.c-author-page__mobile-pop').addClass('active'); setTimeout( function() { $('.c-author-page__mobile-pop').removeClass('active'); }, 2000); } var $temp = $(""); $("body").append($temp); $temp.val($('#url-copy').text()).select(); document.execCommand("copy"); $temp.remove(); }); } };