window.Site = function(){ var init = function(opts) { if (opts == null || opts.constructor != Object) return; opts.pageId && ui.setPageId(opts.pageId); opts.menuClass && ui.setActiveMenu(opts.menuClass); opts.submenuClass && ui.setActiveSubmenu(opts.submenuClass); opts.sidemenuClass && ui.setActiveSidemenu(opts.sidemenuClass); opts.filterClass && ui.setActiveFilter(opts.filterClass); opts.transparentHeader && ui.setTransparentHeader(); component.backToTop.init(); component.readMore.init(); $('body').on('click', '[data-locale-change]', function(e) { e.preventDefault(); var locale = $(this).data('locale-change'); if (!locale) return; changeLocale(locale); }); $('[data-moment-date]').each(function() { var date = $(this).data('moment-date'); if (!date) return; var format = $(this).data('moment-format') ? $(this).data('moment-format') : moment.defaultFormat; $(this).text(moment(date).utcOffset(480).format(format)); }); $('[data-moment-time]').each(function() { var time = $(this).data('moment-time'); if (!time) return; var format = $(this).data('moment-format') ? $(this).data('moment-format') : moment.defaultTimeFormat; $(this).text(moment('1970-01-01T' + time).utcOffset(480).format(format)); }); //back-to-top $(".button-back-to-top").on("click",function(){ $(".page-header").find("a").first().focus(); }).on("keypress",function(e){ if (e.keycode===13){ $(".page-header").find("a").first().focus();} }); //popup loop var exiting = $("#popup-exiting-site"); var hamberger = $("#hamberger-toggle"); var pupupMenu = $("#mobile-main-menu"); var collection = $(".collection-popup-container") function pupupLoop(location){ location.find(".start").on("keydown",function(e){ if (e.shiftKey && e.keyCode === 9) { setTimeout(function(){ location.find(".end").focus(); }) } }) location.find(".end").on("keydown",function(e){ if (!e.shiftKey && e.keyCode === 9) { location.focus(); } }) } function pupupLoop2(button,pupup){ button.on("keydown",function(e){ if( button.attr("aria-expanded") ){ if (e.shiftKey && e.keyCode === 9) { setTimeout(function(){ pupup.find(".end").focus(); }) } } }) pupup.find(".end").on("keydown",function(e){ if (!e.shiftKey && e.keyCode === 9) { setTimeout(function(){ button.focus(); }) } }) } pupupLoop(exiting); pupupLoop2(hamberger,pupupMenu); // active aria-current function activeCurrent(){ // $(".category-list").find("a").attr("aria-current","false"); // $("#main-menu").find("a").attr("aria-current","false"); setTimeout(function(){ $(".category-list").find(".active").find("a").attr("aria-current","true"); $("#main-menu").find(".active").find("a").attr("aria-current","true"); $(".category-list").find("a.active").attr("aria-current","true"); }); } activeCurrent(); $(".category-list").find("a").on("click",function(){ activeCurrent(); }).on("keypress",function(e){ if(e.keycode===13) activeCurrent(); }); //table role setTimeout(function () { tableRole(); }); window.onresize = function () { tableRole(); }; function tableRole() { var table = $(".section-table"); if (window.innerWidth <= 768) { table.removeAttr("role"); table.find("ul").removeAttr("role"); table.find("li").removeAttr("role"); table .find("li") .find("div") .attr("role", "generic"); } else { table.attr("role", "table"); table.find("li").find("div").attr("role", "cell"); table .find("ul") .first() .find("div") .attr("role", "columnheader"); if(table.find("ul").find("ul").length > 0){ table.find("ul").find("ul").attr("role", "rowgroup"); table.find("li").find("li").attr("role", "row"); } else{ table.find("ul").attr("role", "rowgroup"); table.find("li").attr("role", "row"); } } } // $(window).on('scroll', function() { var docViewTop = $(window).scrollTop(); var _wh = $(window).height(); if (docViewTop > _wh / 3 ) { $('.page-header').addClass('fade-out'); $('.sub-menu').addClass('snap-top-top'); } else { $('.page-header').removeClass('fade-out'); $('.sub-menu').removeClass('snap-top-top'); } if (docViewTop > _wh / 10) { $('.filter-language').attr('aria-expanded', false).find('.show').removeClass('show'); } if ($(window).width() >= 1024 && !$('.sidebar-menu').hasClass('.not-fixed') && docViewTop > _wh / 3) { $('.sidebar-menu').addClass('adjust-margin-top'); } else { $('.sidebar-menu').removeClass('adjust-margin-top'); } }); setTimeout(function() { $('body').removeClass('no-animation'); }); }; var ui = { setPageId: function(id) { $('#main-content').addClass(id); }, setActiveMenu: function(menuClass) { $('#main-menu .page-' + menuClass).addClass('active'); }, setActiveSubmenu: function(menuClass) { $('.sub-menu .' + menuClass).addClass('active'); }, setActiveSidemenu: function(menuClass) { $('.sidebar-menu .' + menuClass).addClass('active').parents('li.parent').addClass('active'); }, setActiveFilter: function(filterClass) { /* accept array of classes for different filters */ if (filterClass.constructor != Array) { filterClass = filterClass.split(' '); } jQuery.each(filterClass, function(idx, value) { var $item = $('.filter-list .' + value); $item.addClass('active'); $item.parents('.filter-menu').find('.filter-menu-wrapper-mobile > .dropdown-toggle').text($item.text()); }); }, setTransparentHeader: function() { $('.page-header').addClass('transparent'); }, }; var component = { backToTop: { init: function() { $('body').on('click', 'a[href^="#"]', function(e) { var selector = $(this).attr('href'); if (selector == '#') { var top = 0; } else if ($(selector).length) { var top = $(selector).offset().top - $('.sub-menu').outerHeight() - 30; } else { return; } e.preventDefault(); $('html, body').animate({ scrollTop: top, }, 400, 'linear'); }); } }, readMore: { init: function() { $('.readmore-wrapper').each(function() { var _container = $(this); var _mask = _container.children('.readmore-mask'); var _toggle = _mask.find('.readmore-toggle'); var height = _container.outerHeight(); if (height > 360) { _container.data('height', height).height(360); _toggle.on('click', function() { _container.animate({ height: _container.data('height') }, 'fast', function() { _container.height('auto'); }); _mask.animate({ height: 0 }, 'fast', function() { _mask.remove(); }); }); } else { _mask.remove(); } }); } } }; var changeLocale = function(locale) { if (window.location.href.match(/\/(en|tc|sc)\//i)) { var href = window.location.href.replace(/\/(en|tc|sc)\//i, '/' + locale + '/'); } else if (window.location.href.match(/\/(en_us|zh_tw|zh_cn)\//i)) { var href = window.location.href.replace(/\/(en_us|zh_tw|zh_cn)\//i, '/' + locale + '/'); } else { var href = window.location.origin + '/' + locale + window.location.pathname + window.location.search + window.location.hash; } if (href != window.location.href) { window.location.assign(href); } }; var redirect = function(url) { if (window.location.pathname.match(/\.html$/)) { url += '.html'; } window.location.assign(url); }; return({ init: init, changeLocale: changeLocale, redirect: redirect }); }(); function setCookie(cname,cvalue,exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); let expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getCookie(name) { function escape(s) { return s.replace(/([.*+?\^$(){}|\[\]\/\\])/g, '\\$1'); } var match = document.cookie.match(RegExp('(?:^|;\\s*)' + escape(name) + '=([^;]*)')); return match ? match[1] : null; } function checkCookie() { if(window.location.href.indexOf("/en/")>-1 || window.location.href.indexOf("/en_US/")>-1 ){ setCookie("lang", 'en', 1); } else if(window.location.href.indexOf("/tc/")>-1 || window.location.href.indexOf("/zh_TW/")>-1){ setCookie("lang", 'tc', 1); } else if(window.location.href.indexOf("/sc/")>-1 || window.location.href.indexOf("/zh_CN/")>-1){ setCookie("lang", 'sc', 1); } } $('a').click(function(){       checkCookie(); var links = document.getElementsByTagName("a"); for ( var i = 0; i < links.length; i++) {   links[i].href = links[i].href.replace('https://www.lcsd.gov.hk/CE/Museum/Arts/','https://hk.art.museum/');   links[i].href =links[i].href.replace('http://www.lcsd.gov.hk/CE/Museum/Arts/','https://hk.art.museum/'); } }); $(document).ready(function(){ checkCookie(); //swiper for keyboard, add swiperID to Increase funcction var swiperID= ["#exhibition-highlights","#explore"]; var b = function (id) { var e = new Swiper(id + " .swiper-container", { slidesPerView: "auto", touchRatio: 1, navigation: { nextEl: ".swiper-button-next", prevEl: ".swiper-button-prev", }, breakpoints: { 768: { touchRatio: 0 } }, }); $(".swiper-button-next").keypress(function (el) { if (el.keyCode === 13) e.slideNext(); }); $(".swiper-button-prev").keypress(function (el) { if (el.keyCode === 13) e.slidePrev(); }); var f = function () {}; return { init: f }; }; swiperID.forEach(data=>{ var c = new b(data); c.init(); }) // page title sronly function srOnly() { if ($(window).width() < 752) { $(".page-title").removeClass("sr-only"); } else { $(".page-title").addClass("sr-only"); } } $(window).resize(function () { srOnly(); }); srOnly(); //// setTimeout(function(){ $(".filter-menu-wrapper-mobile").find("button").removeAttr("aria-haspupup") $(".filter-list").find("button").removeAttr("aria-haspupup") if(window.location.href.includes("zh_TW")||window.location.href.includes("tc")){ $(".btnPrev").find("img").attr("alt","上一個圖片") $(".btnNext").find("img").attr("alt","下一個圖片") } else if(window.location.href.includes("zh_CN")||window.location.href.includes("sc")){ $(".btnPrev").find("img").attr("alt","上一个图片") $(".btnNext").find("img").attr("alt","下一个图片") } else{ $(".btnPrev").find("img").attr("alt","Previous image") $(".btnNext").find("img").attr("alt","Next image") } }) }); let hambergerMenuText_closeMenu = "Close Menu"; let hambergerMenuText_menuToggle = "Menu Toggle"; if(window.location.href.toLowerCase().indexOf('/tc/') > 0){ hambergerMenuText_closeMenu = "關閉菜單"; hambergerMenuText_menuToggle = "菜單開關"; } if(window.location.href.toLowerCase().indexOf('/sc/') > 0){ hambergerMenuText_closeMenu = "关闭菜单"; hambergerMenuText_menuToggle = "菜单开关"; } //Old template $(document).on("click", "#hamberger-toggle", function(){ var getDate = document.getElementById("lastRevDates").innerHTML; var getDateConvert = new Date(getDate); if( new Date("2023-07-21").getTime() > getDateConvert.getTime() ){ if( $("#hamberger-toggle").attr("aria-expanded") == "false") { document.getElementById("hamberger-toggle").setAttribute("aria-expanded", "true"); document.getElementById("hamberger-toggle").setAttribute("aria-label", hambergerMenuText_closeMenu); document.getElementById("mobile-main-menu").setAttribute("aria-hidden", "false"); document.getElementById("mobile-main-menu").setAttribute("data-expanded", "true"); document.getElementById("mobile-main-menu").setAttribute("aria-expanded", "true"); $("body").addClass("freeze"); $("#main-content").attr("aria-hidden","true"); } else{ document.getElementById("hamberger-toggle").setAttribute("aria-expanded", "false"); document.getElementById("hamberger-toggle").setAttribute("aria-label", hambergerMenuText_menuToggle); document.getElementById("mobile-main-menu").setAttribute("aria-hidden", "true"); document.getElementById("mobile-main-menu").setAttribute("data-expanded", "false"); document.getElementById("mobile-main-menu").setAttribute("aria-expanded", "false"); $("body").removeClass("freeze") $("#main-content").attr("aria-hidden","false"); } } }); //New template window.addEventListener("load", function () { var links = document.getElementsByTagName('a'); for (var i=0; i', { 'html': this.title }).text(); }); var d = function () { var f = $(".page-header"); var e = $(".sub-menu"); var i = function () { if (e.is(":visible")) { f.addClass("fill-full-backgorund") } }; var h = function () { $(window).scroll(function (k) { var l = $(window).scrollTop(); var j = $(window).height(); if (l > j / 3) { f.addClass("fade-out"); e.addClass("snap-top-top") } else { f.removeClass("fade-out"); e.removeClass("snap-top-top") } }) }; var g = function () { h(); i() }; return { init: g } }; var c = new d(); c.init(); var a = function () { var e = $("#hamberger-toggle"); var h = $("#mobile-main-menu"); var f = function () { if (e.attr("aria-expanded") == "false") { e.attr("aria-expanded", "true"); e.attr("aria-label",hambergerMenuText_closeMenu); h.attr("aria-hidden", "false"); h.attr("data-expanded", "true"); h.attr("aria-expanded", "true"); $("body").addClass("freeze"); $("#main-content").attr("aria-hidden","true"); } else { e.attr("aria-expanded", "false"); e.attr("aria-label",hambergerMenuText_menuToggle); h.attr("aria-hidden","true"); h.attr("data-expanded", "false"); h.attr("aria-expanded", "false"); $("body").removeClass("freeze") $("#main-content").attr("aria-hidden","false"); } }; var g = function () { e.on("keypress",function(x){ if(x.keyCode==13) { f(); }; }); //if(!window.location.href.includes("test_1")){ e.on("click", function () { f(); }) //} }; return { init: g } }; var b = new a(); b.init() });