/* City University of Hong Kong */ /* JavaScript Base */ /* =========================================== */ /* Utility Tools */ /* =========================================== */ var cityu = {}; var isAcceptCookie; cityu.util = (function () { var includeFile = function (fileName, fileType) { var e; if (fileType === "css" || fileType === "mobilecss") { e = document.createElement("link"); e.setAttribute("rel", "stylesheet"); e.setAttribute("type", "text/css"); e.setAttribute("href", fileName); } else if (fileType === "js") { e = document.createElement("script"); e.setAttribute("type", "text/javascript"); e.setAttribute("src", fileName); } else if (fileType === "printcss") { e = document.createElement("link"); e.setAttribute("rel", "stylesheet"); e.setAttribute("type", "text/css"); e.setAttribute("media", "print"); e.setAttribute("href", fileName); } if (typeof e != "undefined") { document.getElementsByTagName("head")[0].appendChild(e); } }; var getCookie = function (cookieName) { var i, x, y; var cookies = document.cookie.split(";"); for (i = 0; i < cookies.length; i++) { x = cookies[i].substr(0, cookies[i].indexOf("=")); y = cookies[i].substr(cookies[i].indexOf("=") + 1); x = x.replace(/^\s+|\s+$/g, ""); if (x === cookieName) { return unescape(y); } } }; var setCookie = function (cookieName, cookieValue, cookieExpDays) { //if (isAcceptCookie) { var expDate = new Date(); expDate.setDate(expDate.getDate() + cookieExpDays); var temp = window.location.hostname.split('.').reverse(); var curDomain = temp[1] + '.' + temp[0]; var cookieDomain = (curDomain === "scope.edu" ? "scope.edu" : "cityu.edu.hk"); var values = escape(cookieValue) + (cookieExpDays === null ? "" : "; expires=" + expDate.toUTCString()) + "; domain=" + cookieDomain + "; path=/"; document.cookie = cookieName + "=" + values; //} }; isAcceptCookie = getCookie("acceptcookie"); return { includeFile: includeFile, getCookie: getCookie, setCookie: setCookie }; })(); /* =========================================== */ /* Device Info */ /* =========================================== */ cityu.device = (function () { var userAgent = navigator.userAgent.toLowerCase(); var deviceType; if ( userAgent.match(/iphone|ipod|windows phone|blackberry|htc_sen/i) || (userAgent.indexOf("android") !== -1 && userAgent.indexOf("mobile") !== -1) ) { deviceType = "phone"; } else if ( userAgent.indexOf("ipad") !== -1 || userAgent.indexOf("android") !== -1 ) { deviceType = "tablet"; } else { deviceType = "desktop"; } var osType; if (userAgent.match(/iphone|ipod|ipad/i)) { osType = "ios"; } else if (userAgent.indexOf("android") !== -1) { osType = "android"; } else if (userAgent.indexOf("windows phone") !== -1) { osType = "windows phone"; } else { osType = "undefined"; } var browserType; var browserVersion; if (userAgent.indexOf("webkit") !== -1) { browserType = "webkit"; browserVersion = parseFloat( userAgent.slice(userAgent.indexOf("webkit") + 7) ); } else if (userAgent.indexOf("firefox") !== -1) { browserType = "firefox"; browserVersion = parseFloat( userAgent.slice(userAgent.indexOf("firefox") + 8) ); } else if (userAgent.indexOf("msie") !== -1) { browserType = "msie"; browserVersion = parseFloat(userAgent.slice(userAgent.indexOf("msie") + 5)); } else { browserType = "undefined"; browserVersion = -1; } var clientWidth = document.documentElement.clientWidth; var clientHeight = document.documentElement.clientHeight; var orientationMode; if (clientWidth > clientHeight) { orientationMode = "landscape"; } else { orientationMode = "portrait"; } var pixelRatio = window.devicePixelRatio; if (pixelRatio === undefined) { pixelRatio = 1; } return { deviceType: deviceType, osType: osType, browserType: browserType, browserVersion: browserVersion, orientationMode: orientationMode, pixelRatio: pixelRatio, clientWidth: clientWidth, clientHeight: clientHeight }; })(); /* =========================================== */ /* UI Control */ /* (require 'util', 'device', jQuery) */ /* =========================================== */ cityu.ui = (function () { var protocol = window.location.protocol; var templatePath = typeof cityuTemplatePath == "undefined" ? protocol + "//template.cityu.edu.hk/template/" : cityuTemplatePath; var mobileCSSPath = typeof cityuMobileCSSPath == "undefined" ? "" : cityuMobileCSSPath; var mobileWeb = typeof cityuMobileWeb == "undefined" || cityuMobileWeb !== false ? true : false; var mobileTest = typeof cityuMobileTest == "undefined" || cityuMobileTest !== true ? false : true; var autoViewport = typeof cityuAutoViewport == "undefined" || cityuAutoViewport !== false ? true : false; var autoContentHeight = typeof cityuAutoContentHeight == "undefined" || cityuAutoContentHeight !== false ? true : false; var layoutMode = mobileWeb && (cityu.device.deviceType === "phone" || mobileTest) ? "mobile" : "desktop"; var fontSize = "0"; var initViewport = function () { if (autoViewport) { var viewWidth = "device-width"; var initialScale = 1; var viewport = ""; var clientWidth = cityu.device.clientWidth; if (layoutMode !== "mobile") { if (clientWidth <= 560) { viewWidth = 480; } else if (clientWidth <= 640) { viewWidth = 560; } else if (clientWidth <= 720) { viewWidth = 640; } else if (clientWidth <= 760) { viewWidth = 720; } else if (clientWidth <= 800) { viewWidth = 760; } else if (clientWidth <= 880) { viewWidth = 800; } else if (clientWidth <= 960) { viewWidth = 880; } //if ((clientWidth <= 960) && (cityu.device.osType === 'ios')) { if (clientWidth <= 960) { //initialScale = viewWidth / 1000; initialScale = clientWidth / 1000; } } //viewport = 'width=' + viewWidth + ', initial-scale=' + initialScale; viewport = "width=" + clientWidth + ", initial-scale=" + initialScale; $("meta[name=viewport]").attr("content", viewport); //$('body').append('clientwidth=' + clientWidth + ',viewport=' + viewport + 'layout=' + layoutMode); } }; var initScript = function () { if (layoutMode === "mobile") { // Append mobile CSS cityu.util.includeFile( templatePath + "css/cityu.mobile.css", "mobilecss" ); // Append custom mobile CSS if (mobileCSSPath) { cityu.util.includeFile(mobileCSSPath, "mobilecss"); } } else { // Append CSS/JS for IE if ( cityu.device.browserType === "msie" && cityu.device.browserVersion <= 9 ) { cityu.util.includeFile(templatePath + "css/cityu.ie.css", "css"); if (cityu.device.browserVersion <= 7) { cityu.util.includeFile(templatePath + "js/cityu.base.ie7.js", "js"); cityu.util.includeFile( templatePath + "css/font-awesome-ie7.min.css", "css" ); } else if (cityu.device.browserVersion <= 6) { // Append JS for IE 6 (CSS & PNG fix) cityu.util.includeFile(templatePath + "js/plugins/ie7/IE7.js", "js"); } } // Append print css */ if (!$('link[media="print"]').length) { cityu.util.includeFile( templatePath + "css/cityu.print.css", "printcss" ); } } }; var initURLHash = function () { if (window.location.hash && $(".cityu-mobile").length == 0) { var hash = window.location.hash.slice(1); var offsetTop = $("#" + hash).offset().top; $(document).scrollTop(offsetTop - 50); } }; var initContent = function () { // Fill empty nav links $("#cityu-nav-list a:not([href])").attr("href", "#"); $('a[href="#"]').click(function (event) { event.preventDefault(); }); // Fill title for search options $("#cityu-search-type").attr("title", "Search options"); // Fill title for langage links $("#lang-en").attr("title", "English language"); $("#lang-tc").attr("title", "Traditional Chinese language"); $("#lang-sc").attr("title", "Simplified Chinese language"); // Fill title for background icons $(".cityu-link-email").attr("title", "Email"); $(".cityu-link-download").attr("title", "Download"); $(".cityu-link-external").attr("title", "External link"); $(".cityu-link-lock").attr("title", "Login required"); $(".cityu-link-pdf").attr("title", "PDF file"); $(".cityu-link-word").attr("title", "Word file"); $(".cityu-link-excel").attr("title", "Excel file"); $(".cityu-link-powerpoint").attr("title", "PowerPoint file"); $(".cityu-link-text").attr("title", "Text file"); $(".cityu-link-image").attr("title", "Image file"); $(".cityu-link-video").attr("title", "Video file"); $(".cityu-link-audio").attr("title", "Audio file"); // Fill title for main slider $("#cityu-media-slider a").each(function (i) { var imgTitle = $(this) .children() .attr("alt"); $(this).attr("title", imgTitle); $('#cityu-media-slider .nivo-control[rel="' + i + '"]').attr( "title", imgTitle ); }); // Fill title for sub slider (default) $("#cityu-sub-slider a").each(function (i) { var imgTitle = $(this) .children() .attr("alt"); $(this).attr("title", imgTitle); $('#cityu-sub-slider .nivo-control[rel="' + i + '"]').attr( "title", imgTitle ); }); // Fill title for sub slider (2) $("#cityu-sub-slider1 a").each(function (i) { var imgTitle = $(this) .children() .attr("alt"); $(this).attr("title", imgTitle); $('#cityu-sub-slider1 .nivo-control[rel="' + i + '"]').attr( "title", imgTitle ); }); }; var initMobileContent = function () { $("body").addClass("cityu-mobile"); // Main Nav if (!$(".ciytu-m").length) { $('
').insertBefore("#cityu-header-toolbar"); if ($("#cityu-header-quicklinks").length) { $(".cityu-m").addClass("cityu-m-large"); $(".cityu-m").append( $("#cityu-header-quicklinks .cityu-quicklinks-button") ); $("#cityu-header .cityu-inner").append( '' ); $("#cityu-m-quicklinks").append( $("#cityu-header-quicklinks .cityu-quicklinks-menu") ); $("#cityu-header-quicklinks .cityu-quicklinks-menu").remove(); } if ($("#cityu-header-search input").length) { $(".cityu-m").append( '' ); $("#cityu-header .cityu-inner").append($("#cityu-header-search")); } if ( $("#cityu-header-lang a").length && !$("#cityu-header-lang").hasClass("cityu-hidden") ) { $(".cityu-m").append( '' ); $("#cityu-header .cityu-inner").append( '' ); $("#cityu-m-header-lang").append($("#cityu-header-lang>a")); $("#cityu-header-lang").remove(); } if ($("#cityu-nav").length) { $(".cityu-m").append( '' ); } } $(".cityu-search-type-wrapper select").removeAttr("class"); $(".cityu-search-type-wrapper select").removeAttr("id"); $(".cityu-search-text-wrapper input").removeAttr("class"); $(".cityu-search-text-wrapper input").removeAttr("id"); $('.cityu-search-text-wrapper input[type="submit"]').attr("value", "GO"); $(".ddsmoothmenu br").remove(); $("li.cityu-icon-home div").replaceWith("Home"); $(".theme-default #cityu-media-slider.nivoSlider").css( "height", $("#cityu-media-slider").width() / 2 ); $(".theme-default .nivoSlider img").attr( "width", $("#cityu-media-slider").width() ); $(".theme-default .nivoSlider img").attr( "height", $("#cityu-media-slider").height() ); $("#cityu-main:first .cityu-inner:first").append($("#cityu-sidebar-2")); $(".cityu-content img").removeAttr("width"); $(".cityu-content img").removeAttr("height"); // Mobile buttons $(".cityu-m-menu").click(function (e) { e.preventDefault(); if ($("#cityu-nav").css("display") == "none") { $("#cityu-nav").show(); $("#cityu-header-search").hide(); $("#cityu-m-header-lang").hide(); $("#cityu-m-quicklinks").hide(); disableSidebar1(); } else { $("#cityu-nav").hide(); enableSidebar1(); } }); $(".cityu-m-search").click(function (e) { e.preventDefault(); if ($("#cityu-header-search").css("display") == "none") { $("#cityu-header-search").show(); $("#cityu-nav").hide(); $("#cityu-m-header-lang").hide(); $("#cityu-m-quicklinks").hide(); disableSidebar1(); } else { $("#cityu-header-search").hide(); enableSidebar1(); } }); $(".cityu-m-lang").click(function (e) { e.preventDefault(); if ($("#cityu-m-header-lang").css("display") == "none") { $("#cityu-m-header-lang").show(); $("#cityu-nav").hide(); $("#cityu-header-search").hide(); $("#cityu-m-quicklinks").hide(); disableSidebar1(); } else { $("#cityu-m-header-lang").hide(); enableSidebar1(); } }); $(".cityu-quicklinks-button").click(function () { if ($("#cityu-m-quicklinks").css("display") == "none") { $("#cityu-m-quicklinks").show(); $("#cityu-nav").hide(); $("#cityu-header-search").hide(); $("#cityu-m-header-lang").hide(); disableSidebar1(); } else { $("#cityu-m-quicklinks").hide(); enableSidebar1(); } }); // Sidebar Nav if ($("#cityu-sidebar-1").length) { $("#cityu-sidebar-1").hide(); $( ' ' ).insertBefore("#cityu-sidebar-1"); } $(".cityu-m-sidebar1").click(function () { if ($("#cityu-sidebar-1").css("display") == "none") { $("#cityu-sidebar-1").slideDown(); $(".cityu-m-sidebar1 i").attr("class", "icon-caret-up"); } else { $("#cityu-sidebar-1").slideUp(); $(".cityu-m-sidebar1 i").attr("class", "icon-caret-down"); } }); var disableSidebar1 = function () { if ($(".cityu-m-sidebar1").length) { $("#cityu-sidebar-1").hide(); $(".cityu-m-sidebar1 i").attr("class", "icon-caret-down"); $(".cityu-m-sidebar1").hide(); } }; var enableSidebar1 = function () { if ($(".cityu-m-sidebar1").length) { $(".cityu-m-sidebar1").show(); } }; // Expand nav menu for anchors without link //$('.ddsmoothmenu>ul>li:has(ul)').children('a').attr('href','#'); $(".cityu-mobile #cityu-nav .cityu-href-hidden-mobile").attr("href", "#"); $( '.ddsmoothmenu>ul>li>a:not([href]),.ddsmoothmenu>ul>li>a[href="#"]' ).click(function () { if ( $(this) .siblings() .css("display") == "none" ) { $(".ddsmoothmenu>ul>li>ul").hide(); $(this) .siblings() .show(); $(this).focus(); } else { $(this) .siblings() .hide(); } }); }; var adjustContentHeight = function () { if (autoContentHeight) { // Set min height for content page if ($("#cityu-sidebar-1").length) { heightSB1 = $("#cityu-sidebar-1").innerHeight(); } else { heightSB1 = 76; } if ($("#cityu-sidebar-2").length) { heightSB2 = $("#cityu-sidebar-2").innerHeight(); } else { heightSB2 = 76; } if (heightSB1 > heightSB2) { if ($(".cityu-content-page").length) { $(".cityu-content-page").css("min-height", heightSB1 - 76); } else if ($(".cityu-content-columns").length) { $(".cityu-content-columns").css("min-height", heightSB1 - 46); } else { $("#cityu-content").css("min-height", heightSB1); } } else { if ($(".cityu-content-page").length) { $(".cityu-content-page").css("min-height", heightSB2 - 76); } else if ($(".cityu-content-columns").length) { $(".cityu-content-columns").css("min-height", heightSB2 - 46); } else { $("#cityu-content").css("min-height", heightSB2); } } } }; var changeFontSize = function (fontSize) { $(".cityu-wa-fontsize-0").removeClass("disabled"); $(".cityu-wa-fontsize-2").removeClass("disabled"); if (fontSize === "2") { $("#cityu-main").css("font-size", "16px"); } else if (fontSize === "3") { $("#cityu-main").css("font-size", "18px"); } else if (fontSize === "4") { $("#cityu-main").css("font-size", "21px"); $(".cityu-wa-fontsize-2").addClass("disabled"); } else { fontSize = "1"; $("#cityu-main").css("font-size", "14px"); $(".cityu-wa-fontsize-0").addClass("disabled"); } cityu.util.setCookie("fontsize", fontSize, 365); adjustContentHeight(); }; var controlFontSize = function (control) { var curFontSize = parseInt(fontSize); if (control === "0") { // smaller if (curFontSize > 1) { fontSize = (curFontSize - 1).toString(); } } else if (control === "1") { // default fontSize = "1"; } else if (control === "2") { // larger if (curFontSize < 4) { fontSize = (curFontSize + 1).toString(); } } if (parseInt(fontSize) !== curFontSize) { changeFontSize(fontSize); } }; var initFontControl = function () { var html = ""; var lang = $("html").attr("lang"); if (lang === "zh-hk") { html = '