1/* ================================================================================================= 2file: feedin.js wcms 3-------------------------- 414:49 2021-01-12 add "ymdhms" variable and function 512:02 2021-01-26 change doyouknow js location 615:37 2021-01-26 avoid CSP error on location.host check by use "!==" comparison 717:25 2021-01-28 fix dropmenu on housing public (that have 3 lines) 811:45 2021-01-29 try fix flash on dropmenu 909:27 2021-02-02 fix feedin_lang 1010:05 2021-02-03 for dev 1112:34 2021-02-04 doyouknow 1214:56 2021-02-04 test for webcast end 1315:03 2021-02-16 change DoYouKnow source to NEWS.gov, seems CSP do NOT allow JSONP on local domain 1414:28 2021-02-17 doyouknow try use a2.php 1515:31 2021-02-17 update double slash handling 1613:59 2021-02-25 formcatid handling 1709:27 2021-02-26 mark obsolete functions 1811:02 2021-03-02 formcatid add cluster=1, hide non-active items 1911:26 2021-03-03 update a-span title for multilang issue 2015:18 2021-03-03 remove osof_fix 2115:39 2021-03-10 remove "cluster=1" to align old method 2214:33 2021-03-11 new webcast URL as request AND clear cache 2314:59 2021-03-17 eFormJSON (formcatid) 2410:43 2021-03-19 change "eformsearch" to "R4-Keyword-GovFormCatalogue" 2514:01 2021-03-24 to fix Taxes FAQ table 2615:13 2021-05-07 fix gih 2714:51 2021-06-07 set cookie lang for all pages 2815:43 2021-06-08 matomo on doyouknow, quicklinks, cluster 2911:08 2021-06-18 fix language 3014:38 2021-06-29 matomo on checkitout, etc 3110:00 2022-12-10 fix lang - cookie problem 3210:00 2023-12-07 moved chatbot stat to chatbot.js 3317:36 2024-11-21 XSS prevention 3411:52 2024-11-22 remove some obsolete code 3515:18 2024-11-26 fix IE problem 3617:05 2025-09-22 IE detection 37================================================================================================= */ 38 39// production 40var search_domain_top = "search.gov.hk"; 41var search_domain_deep = "www.search.gov.hk"; 42 43// 10:31 2021-03-02 44var feedin_eform_total = 0; 45var feedin_eform_processed = 0; 46 47// 16:28 2018-04-17 added, for the right hand side DESKTOP search panel only 48let autocomplete_step_in = 0; 49let autocomplete_src_id = ""; 50 51// 14:41 2018-06-21 freeze_for_search_autocomplete 52let freeze_for_search_autocomplete = 0; 53 54// 15:00 2018-07-18, 15:13 2018-09-11 55let feedin_app_win_obj = []; 56let feedin_app_win_title = []; 57let feedin_app_win_index = 0; 58// let feedin_first_app_closed = false; 59 60// 10:56 2016-12-22 61// pagetype for other page to override, such as override as "mobileapps" 62var page_type = "default"; 63 64/* === remove duplicate slash if have === */ 65// 8:36 2020-04-08 change to pathname for win 66//var org_url = location.href; 67// 15:24 2021-02-17 search is empty if empty 68var org_search = location.search; 69var org_url = location.pathname; 70//var new_url = org_url.replace(/([^:]\/)\/+/g, "$1"); 71var new_url = org_url.replace(/\/\/+/g, '/'); 72console.log('path:org_search='+org_search); 73console.log('path:org_url = '+org_url); 74console.log('path:new_url = '+new_url); 75 76// 15:27 2021-02-17 compare pathname only 77if (org_url!=new_url) { 78 // 15:27 2021-02-17 add param (if empty, will be empty string) 79 //location.href = new_url+org_search; 80 //XSS protection 81 var filtered_url = new_url.replace(/[^A-Za-z0-9 /._-]/g, ''); 82 location.href = filtered_url; 83} 84 85 86// === 14:12 2016-11-15 fix homepage with common useful link hash === 87// remove the hash value if like "#block_" 88if (new_url.indexOf('#block_')>=0 ) { 89 location.href = location.pathname; 90} 91 92 93var wcms_num = 0; 94// 15:37 2021-01-26 cannot use ">=0" here, will case CSP error 95// 09:16 2021-02-02 restore to host>=0 as "I Want To" show English 96console.log("location.host = "+location.host); 97console.log("location.href = "+location.href); 98//if (location.host.indexOf("wcms")!==false) { 99if (location.host.indexOf("wcms")>=0) { 100 wcms_num = 5; 101 // further check 16:51 2020-03-09 102 if (location.href.indexOf("injection/")>=0) { 103 wcms_num = 10; 104 } 105} 106 107console.log('wcms_num = ' + wcms_num); 108 109// use first, same as govhk.js 110var feedin_ui_lang = $('html').attr('lang'); 111 112 113// 10:47 2019-11-21 refactoring feedin_ and lang_ variables 114var folders; 115 116// 14:11 2020-03-06 change from "href" to "pathname", 3-7 to 1-5 117// as pathname will NOT have "?" and "#" suffix. 118//folders = location.href.split('/'); 119//folders = location.pathname.split('/'); 120 121//17:36 2024-11-21 XSS prevention 122var oriPathName = filterUntrustedChar(location.pathname); 123folders = oriPathName.split('/'); 124 125// 9:36 2016-11-28: in case there is not 5 folders, set the folders[i] to empty 126// 16:30 2017-04-21 bug fix for folder is param or bookmark 127//for (var i=3+wcms_num;i<=7+wcms_num;i++) { 128for (var i=1+wcms_num;i<=5+wcms_num;i++) { 129 // use f9 to store the folder name 130 // use f1 to store first char of folder (default is empty string) 131 var f9 = folders[i]; 132 var f1 = ''; 133 134 // if folder is undefined or empty 135 if (f9==undefined || f9=='' || f9=='index.htm') { 136 f9=''; 137 } else { 138 // set first char to f1 139 f1 = f9.substring(0,1); 140 } 141 142 // if folder is undefined or first char is param or bookmark, mark folder empty to avoid js error 143 if (f9=='' || f1=='?' || f1=='#') { 144 folders[i]=''; 145 } 146} 147 148// 14:10 2020-03-06 change from 3-7 to 1-5 149// global variable for feedin.js 150var feedin_lang = folders[wcms_num+1]; 151var feedin_usergroup = folders[wcms_num+2]; 152var feedin_cluster = folders[wcms_num+3]; 153var feedin_subcat = folders[wcms_num+4]; 154var feedin_folder_5 = folders[wcms_num+5]; 155 156// Note: "lang_" may have double slashs 157// 08:55 2021-02-26 show in console
158// 08:55 2021-02-26 hide here, show below 159//console.log( "feedin_lang = " + feedin_lang); 160//console.log( "feedin_usergroup = " + feedin_usergroup); 161//console.log( "feedin_cluster = " + feedin_cluster); 162//console.log( "feedin_subcat = " + feedin_subcat); 163//console.log( "feedin_folder_5 = " + feedin_folder_5); 164 165// 11:49 2019-11-22 ER fix first 166/* 167if (feedin_cluster.length == 0 ) { 168 feedin_cluster = 'index2.htm'; 169} 170*/ 171 172// conditions: 173// lang 174if (feedin_lang=='en' || feedin_lang=='tc' || feedin_lang=='sc') { 175 // do nothing 176} else { 177 console.log('no feedin_lang'); 178 feedin_lang='en' 179 // get lang from user agent 180 // var b1 = navigator.language || navigator.userLanguage; 181 // var b2 = b1.toLowerCase(); 182 // if (b2.indexOf('en')>=0 ) feedin_lang = 'en'; 183 // if (b2.indexOf('cn')>=0 ) feedin_lang = 'sc'; 184 // if (b2.indexOf('hk')>=0 || b2.indexOf('tw')>=0) feedin_lang = 'tc'; 185} 186 187// usergroup 188if (feedin_usergroup=='residents' || feedin_usergroup=='nonresidents' || feedin_usergroup=='business' || feedin_usergroup=='about' || feedin_usergroup=='theme') { 189 // do nothing 190} else { 191 feedin_usergroup = 'residents'; 192} 193 194// long path 195// var lang_folder = feedin_lang // 10:44 2019-11-21 keep this first 196var lang_folder = '/' + feedin_lang // e.g. change from "en" to "/en" 197 198var lang_usergroup = lang_folder; 199if (feedin_usergroup.length > 0) { lang_usergroup = lang_folder + '/' + feedin_usergroup; } 200 201var lang_cluster = lang_usergroup; 202if (feedin_cluster.length > 0) { lang_cluster = lang_usergroup + '/' + feedin_cluster; } 203 204var lang_subcat = lang_cluster; 205if (feedin_subcat.length > 0) { lang_subcat = lang_cluster + '/' + feedin_subcat; } 206 207var lang_folder_5 = lang_subcat; 208if (feedin_folder_5.length > 0) { lang_folder_5 = lang_subcat + '/' + feedin_folder_5; } 209 210// 10:46 2019-11-21 remark first 211// var lang_subcat_n = lang_subcat; // just in case still have this variable 212// var lang_folder_5n = lang_folder_5; // just in case still have this variable 213 214// 13:57 2016-08-29 handle subcat as fa, e.g: "/en/nonresidents/living/pets.htm" 215var subcat_fa = 0; 216 217 218// 14:35 2021-01-12 add date for json 219Object.defineProperty(Date.prototype, 'YYYYMMDDHHMMSS', { 220 value: function() { 221 function pad2(n) { // always returns a string 222 return (n < 10 ? '0' : '') + n; 223 } 224 225 return this.getFullYear() + 226 pad2(this.getMonth() + 1) + 227 pad2(this.getDate()) + 228 pad2(this.getHours()) + 229 pad2(this.getMinutes()) + 230 pad2(this.getSeconds()); 231 } 232}); 233 234var ymdhms = new Date().YYYYMMDDHHMMSS(); 235 236/* 237 14:43 2016-09-09 from "R3" 238*/ 239$.extend({ 240 getUrlVars: function(){ 241 url = window.location.href; 242 var vars = parseUrlVars(url); 243 return vars; 244 }, 245 getUrlVar: function(name){ 246 return $.getUrlVars()[name]; 247 } 248}); 249 250// Get object of URL parameters - global variable to use 251var QueryString = $.getUrlVars(); 252 253// Demo for Getting URL var by its name 254/* 255var q1 = QueryString['subcat']; 256alert('q1 = '+q1); 257*/ 258 259 260// 12:11 2016-08-29: case for "/en/nonresidents/living/pets.htm" (no subcat, subcat become filename) 261// 17:15 2016-08-29 fix do you know disappear 262// 11:57 2016-09-27 fix for "/en/residents/onlineservices/index.htm", have to check subcat is not "index.htm" 263// 15:08 2017-04-03 264if (lang_subcat.indexOf('.htm') > 0 && lang_subcat.indexOf('index.htm') < 0) { 265 // use cluster as subcat name, all ending with "/" 266 subcat_fa = 1; 267 // 15:07 2017-04-03 268 lang_subcat = lang_cluster ; 269} 270 271// 08:55 2021-02-26 show here 272// 10:30 2019-11-21 feedin 273console.log( "feedin_lang=" + feedin_lang ); 274console.log( "feedin_usergroup=" + feedin_usergroup ); 275console.log( "feedin_cluster=" + feedin_cluster ); 276console.log( "feedin_subcat=" + feedin_subcat ); 277console.log( "feedin_folder_5=" + feedin_folder_5 ); 278// 10:30 2019-11-21 lang 279console.log( "lang_usergroup=" + lang_usergroup ); 280console.log( "lang_cluster=" + lang_cluster ); 281console.log( "lang_subcat=" + lang_subcat ); 282console.log( "lang_folder_5=" + lang_folder_5 ); 283 284 285// 11:48 2019-11-15 lang_subcat is up to subcat (e.g. /en/residents/taxes/etax/ or /en/resident/taxes/abc.htm) 286// consideration URLs 287// http://www.gov.hk/en/theme/bf/communication/blg/index.htm go to 5 folder. so just change to subcat 288// http://www.gov.hk/tc/about/helpdesk/faq/infosec/index.htm 289// http://www.gov.hk/tc/residents/onlineservices/ 290 291// 12:02 2019-11-15 default esp for http://www.gov.hk/tc/about/helpdesk/faq/infosec/index.htm 292// ==== menu_url_pattern to match: 10:03 2016-10-13: general case is up to last folder (without last slash) === 293//var menu_url_pattern = location.pathname.substring(0,location.pathname.lastIndexOf('/')); 294 295//17:36 2024-11-21 XSS prevention 296var oriPathName = filterUntrustedChar(location.pathname); 297var menu_url_pattern = oriPathName.substring(0,oriPathName.lastIndexOf('/')); 298 299// === SPECIAL handling for "theme" sites (esp for "bf") === 300if ( oriPathName.indexOf('/theme/')>0 && feedin_subcat.length > 0 ) { 301 menu_url_pattern = lang_subcat; 302} 303
304/* 305if ( location.pathname.indexOf('/theme/')>0 && feedin_folder_5.length > 0 ) { 306 menu_url_pattern = lang_folder_5; 307} 308*/ 309 310 311 312// 12:19 2019-11-15 For 3 main usergroups 313// for 3 usergroup, menu_url_pattern is up to subcat (without last slash) 314// 15:19 2017-04-03 check feedin_cluster 315if ((feedin_usergroup=='residents' || feedin_usergroup=='nonresidents' || feedin_usergroup=='business') && (feedin_cluster.length > 0) ){ 316 // 16:04 2016-08-09 change to "lang_subcat_n" 317 // 15:07 2017-04-03 318 menu_url_pattern = lang_subcat; 319} 320 321// 12:19 2019-11-15 For 3 main usergroups - forms and online services 322// if it is "forms" or "onlineservices" full list, menu_url_pattern is up to cluster only 323if (feedin_cluster=='forms' || feedin_cluster=='onlineservices') { 324 menu_url_pattern = lang_cluster; 325} 326 327 328 329// === SPECIAL handling for "about" and "theme" sites === 330// 15:22 2019-11-15 SPECIAL handling for "about" and "theme" sites 331// 12:19 2019-11-15 menu_url_pattern is FULL PATH (no matter long or short) 332// 11:44 2019-11-25 add faq 333// 11:05 2016-08-17 add software req. 334// 15:58 2016-09-02 add linkpolicy 335// 15:23 2019-11-15 add "theme/forms" 336if ( location.pathname.indexOf('/about/linkpolicy/')>0 || 337 location.pathname.indexOf('/about/helpdesk/softwarerequirement/')>0 || 338 location.pathname.indexOf('/about/helpdesk/faq/')>0 || 339 location.pathname.indexOf('/theme/multilanguage/')>0 || 340 location.pathname.indexOf('/theme/forms/')>0 ) { 341 // alert('tagBlock'); 342 // temp fix 15:09 2016-08-11 for hardcode philippines active 343 // $('#mainHolder .tagBlock .blockTagHolder a').removeClass('active'); 344 // use the full path to match for multilanguage theme site 345 // 10:12 2016-10-13 remove query string on URL (add "split") 346 menu_url_pattern = oriPathName.split('?')[0]; 347 348 // 17:31 2016-09-02: for those cases, if missing ".htm" (means "/"), add it for matching criteria 349 if (location.pathname.indexOf('.htm')<0) { 350 // 15:27 2017-04-03 if the path ends with a folder, web server add slash at the end automatically, so just add "index.htm" 351 menu_url_pattern += 'index.htm'; 352 } 353 354} 355 356 357 358/* 359if ( location.pathname.indexOf('/about/govdirectory/govwebsite/')>0 ) { 360 // alert('tagBlock'); 361 // temp fix 15:09 2016-08-11 for hardcode philippines active 362 // $('#mainHolder .tagBlock .blockTagHolder a').removeClass('active'); 363 // use the full path to match for multilanguage theme site 364 menu_url_pattern = location.pathname + "#p1"; 365} 366*/ 367 368//console.log("menu_url_pattern:"+menu_url_pattern); 369 370 371var doyouknow_items = 0; 372// 16:52 2018-02-14 for homepage 373var isHomePage_f = false;
374 375// news tc and sc need document ready 376$(document).ready(function() { 377 378 379 380 381 // doc.load is bad also 382 // 15:33 2016-10-31 add size() 383 if ($('#doYouKnow').length) { 384 ajaxDoYouKnow(); 385 // 15:25 2019-09-10 added for webcast 386 387 // 9:25 2020-01-06 enable 388 ajaxWebCast(); 389 } 390 391 // 15:19 2021-03-03 move osof_fix() to bg 392 // 08:53 2020-12-31 add osof class first 393 //osof_fix(); 394 395 // 09:28 2021-02-26 eform full list, try remark 396 // 16:02 2018-12-12 397 //fix_related_os_bar(); 398 399 // 16:52 2018-02-14 for homepage 400 isHomePage_f = $('body').hasClass('homePage'); 401 402 store_lang_preference(); 403 404 // 17:14 2021-02-25 still keep 405 top_level_page_dom_fix(); // 10:20 2016-12-07 406 407 // 17:06 2021-02-25 move to bg 408 //tab_menu_page_dom_fix(); // 11:43 2017-01-11 409 410 // 15:56 2020-07-06 change HTML to not run rotating_banner_dom_fix gradually 411 rotating_banner_dom_fix(); // 9:40 2016-12-07 412 413 // 16:12 2021-02-25 obsolete after homepage revamp 414 // 14:30 2019-04-24 move next to rotating banner 415 //checkitout_fix(); 416 417 // 11:39 2019-11-25 handle only "THEME" menus only 418 // have to remove before menu handling 419 theme_leftrightmenu(); // 10:43 2017-01-24, 10:37 2019-11-25 refactor 420 421 // 11:39 2019-11-25 generate leftmenu (include theme leftmenu) hightlight and dropdown menu title 422 // 9:40 2016-10-13 move after jsons 423 leftmenu_highlight(); // 9:03 2016-08-19 424 425 // 15:59 2021-01-28 add for housing 3 lines issue 426 // must do after leftmenu_highlight() 427 dropmenu_fix(); 428 429 // add the body class for govhk.js to process the ham menu showing, do the highlight of ham menu if fine. 430 body_add_class(); // 9:03 2016-08-19 431 432 // 08:58 2021-02-26 obsolete after homepage revamp 433 //seasonal_graphics(); // 9:12 2016-12-08 434 435 // 17:14 2021-02-25 still keep first 436 about_page_fix(); // 10:09 2016-10-31 437 438 // 17:37 2021-02-18 move to bg 439 //mobileapps_page_fix(); // 17:42 2016-10-31 440 441 // 15:42 2019-11-25 doyouknow org here 442 443 /* 16:11 2021-02-17 obsolete after homepage revamp 444 // 15:10 2016-06-06 : change to if have todayWeather 445 if ($('#todayWeather').length) { 446 weatherJson(); 447 } 448 */ 449 450 /* 451 // 16:08 2021-02-17 obsolete after homepage revamp 452 // 15:10 2016-06-06 : change to if have top Stories 453 if ($('#homepageBannerAndNews').length) { 454 // alert('calling newsJson'); 455 //newsJson(); 456 } 457 */ 458 459 breadcrumb_fix(); 460 461 // 15:30 2021-02-19 move to bg 462 // 10:07 2016-09-07 js fix 463 //i_want_to_fix(); 464 465 // 10:49 2016-09-12, 14:30 2019-04-24 move up 466 //checkitout_fix(); 467 468 // 14:42 2018-01-15 esp for epayment phone number, remove tel hyperlink in desktop 469 format_tel(); 470 471 // 15:56 2017-01-16 472 hyperlink_fix(); 473 474 // 14:42 2016-05-27 475 searchKeyword(); 476 477 // 15:37 2021-02-19 seems use for print, keep 478 external_link_icon(); 479 480 // 14:49 2016-08-01 add inlineLink 481 feature_article_fix(); 482 483 // 16:16 2021-02-17 obsolete after homepage revamp 484 // 15:16 2016-08-03 485 //govhk_qna_fix(); 486 487 // 15:52 2021-02-22 move to bg 488 // 11:42 2016-08-16 489 //common_useful_link_fix(); 490 491 // 17:15 2021-02-25 still keep first 492 // 15:20 2016-09-15 493 special_page_fix(); 494 495 // 16:35 2016-09-09 496 // 9:39 2016-10-13 move to special_page_fix 497 // copyright_fix(); 498 499 // 11:49 2016-09-30 500 gih_buttons(); 501 502 // 14:33 2017-12-20 hide it 503 //search_autocomplete(); 504 505 // 16:22 2021-02-17 obsolete after homepage revamp 506 // 10:24 2017-05-12 507 //hp_mobile_apps_fix(); 508 509 // 16:17 2021-02-25 still keep first 510 // 16:04 2017-11-17 make "lastRevision" under "giveFeedback", within "bottomBar" 511 bottom_bar_dom_fix(); 512 513 // === 9:35 2017-12-29 KEEP at BOTTOM === 514 popGenericWindow(); 515 516 // 16:17 2021-02-25 add 517 eformJson(); 518 519 // 14:01 2021-03-24 to fix Taxes FAQ table 520 faq_table_fix(); 521 522 // 14:26 2021-06-07 set cookie 523 feedin_lang_cookie(); 524 525 if (isHomePage_f && location.search.indexOf('rmchat')<0) { 526 initIdsPopupBanner(); 527 } 528 529 // 2025-09-22 check ie 530 checkOldBrowser(); 531 532 533}); 534 535// 16:01 2021-01-28 add resize on feedin.js 536// 16:02 2021-01-28 dropmenu need to fix on resize 537$(window).resize(function () { 538 dropmenu_fix(); 539}); 540 541// 16:22 2021-02-17 obsolete after homepage revamp 542// 10:24 2017-05-12 limit mobile apps to 10 items 543function hp_mobile_apps_fix() { 544 545 // zero based - old method 12:22 2017-05-11
546 //$('div.blockContent.swiper-container.mobile-app-slider .swiper-slide:gt(9)').remove(); 547 548 var br = "<br>\n"; 549 var ca = ","; 550 //////console.log('hello'+br); 551 552 var app_show = 10; 553 var app_total = $('div.blockContent.swiper-container.mobile-app-slider .swiper-slide').length; 554 var app_mandate = 3; 555 var app_random = app_total - app_mandate; // e.g. 15-3=12 556 var pick_total = app_show - app_mandate; // e.g. 10-3=7 557 var app_pick = []; 558 var pick_count = 0; 559 560 561 // if slides to show more than limit 562 if (app_random > app_show ) { 563 // initialize the array 564 for (var i=0;i<app_random;i++) { 565 app_pick[i] = 0; 566 } 567 568 // initialize value 569 var cnt=-1; 570 var app_needle = Math.floor(Math.random() * app_random); 571 572 // debug 573 /* ////console.log('app_random=' + app_random + br); 574 ////console.log('pick_count=' + pick_count + br); 575 ////console.log('pick_total=' + pick_total + br); 576 ////console.log('app_needle=' + app_needle + br); */ 577 578 // random select some slides 579 while (pick_count < pick_total) { 580 581 // cnt is process count 582 cnt++; 583 // app index 584 var app_index = (app_needle + cnt) % app_random; 585 var chance = Math.random(); // 0 to 1 (exclusive 1) 586 587 // if in 2nd loop, always 1 588 if (cnt>app_random) { 589 chance = 1; 590 } 591 592 // 50 percent to show slide 593 if (chance > 0.5) { 594 app_pick[app_index] = 1; 595 pick_count++; 596 } 597 598 // debug 599 /* ////console.log(br+ ',cnt='+cnt + ',app_index='+app_index + ',pick_count='+pick_count + ',app_pick='+app_pick[app_index]); */ 600 } 601 602 // set the slide 603 for (var i=app_random-1;i>=0;i--) { 604 var app_index=i+app_mandate; 605 /* ////console.log(br+',i='+i + ',app_index='+app_index + ',app_pick='+app_pick[i]); */ 606 607 if (app_pick[i]==0) { 608 $('div.blockContent.swiper-container.mobile-app-slider .swiper-slide:eq('+app_index+')').remove(); 609 /* ////console.log(':slide remove'); */ 610 } 611 } 612 } 613 614 615 // CAUTION: 9:29 2017-12-29 Dont know why the Homepage Mobile App cannot be click (as at 9:31 2017-12-29) , just force to open href in same window 616 $('div.blockContent.swiper-container.mobile-app-slider a').on('click', function(e){ 617 618 if (e.button != 0) return; 619 e.preventDefault(); 620 621 var href = $(this).attr('href'); 622 location.href = href; 623 624 }); 625 626 627} 628 629// 09:09 2021-02-26 will be obsolete after all formref removed 630function hyperlink_fix() { 631 632 // 15:33 2021-02-19 still may use in cluster pages 633 // 12:07 2017-01-16 634 // fix formref with double "?" 635 $('a[href*="?formref="]').each(function(){ 636 637 var url_formref = $(this).attr('href'); // full url 638 var index1 = url_formref.indexOf('?formref='); 639 640 var url_bd = url_formref.substr(0,index1); // before "?formref=" 641 var index2 = url_bd.indexOf('?'); 642 643 if (index2>0) { 644 var url_suffix = url_formref.substr(index1+1); // start at "formref=" to end 645 var url_fix = url_bd + "&"+ url_suffix; 646 //alert('url_bd='+url_bd+',index2='+index2+',url_suffix='+url_suffix+',url_fix='+url_fix); 647 $(this).attr('href',url_fix); 648 } 649 650 }); 651 652 // 15:58 2017-01-16 653 // theme site hyperlink h4 heading anchor 654 /* 655 $('.themeParksInfo h4 a[id]:not([href])').each(function(){ 656 var id1 = $(this).attr('id'); 657 var html = $(this).html(); 658 $(this).replaceWith("<span id='"+id1+"'>"+html+"</span>") 659 }); 660 */ 661 662} 663 664// 14:30 2017-03-30 added 665function fixEmpty(val, initialValue){ 666 if (typeof(val)===undefined || val == null ) { val = initialValue; } 667 return val; 668} 669 670// 16:24 2021-02-17 obsolete after homepage revamp 671// 8:56 2016-12-08 672function seasonal_graphics() { 673 // 2024-11-22 - removed 674} 675 676// 17:14 2021-02-25 still keep 677function top_level_page_dom_fix() { 678 679 // === top level page index === 680 // 17:13 2021-02-25 still need 681 // 15:09 2017-01-06 682 if ( location.pathname.indexOf('/about/copyright')>0 ) { 683 684 $('body').addClass('top_level_page_index'); 685 686 /* 16:26 2021-02-17 it is now <h2>, no need 687 $('article .disclaimerWrap .disclaimerTitle:contains("Copyright Notice")').replaceWith( '<h2 class="disclaimerTitle">Copyright Notice</h2>' ); 688 $('article .disclaimerWrap .disclaimerTitle:contains("çæ¬å示")').replaceWith( '<h2 class="disclaimerTitle">çæ¬å示</h2>' ); 689 $('article .disclaimerWrap .disclaimerTitle:contains("çæå示")').replaceWith( '<h2 class="disclaimerTitle">çæå示</h2>' ); 690 */ 691 692 return; // do not do "content" fix 693 } 694 695 // === top level page content : below === 696 697 // 17:12 2021-02-25 seems below not found, but keep first 698 // (1) remove "boldLink" class on section link 17:37 2016-12-07 699 $('section.blockItem.helpDesksContents div.blockContentWrap a.contentLink.boldLink').removeClass('boldLink'); 700 701 // (2) replace inner content 702 $('section.blockItem.helpDesksContents div.blockContentWrap').replaceWith( 703 function(_,content){ 704 return '<section class="blockItem">' + content + '</section>'; 705 } 706 ); 707 708 // (3) replace outer content 709 $('section.blockItem.helpDesksContents').replaceWith( 710 function(_,content){ 711 return '<div class="helpDesksContents">' + content + '</div>'; 712 } 713 ); 714 715 716} 717 718// 17:06 2021-02-25 move to bg 719function tab_menu_page_dom_fix() { 720 $('.innerPageHolder section.blockItem span.sectionTitle').replaceWith( 721 function(_,content){ 722 return '<h3 class="sectionTitle">' + content + '</h3>'; 723 } 724 ); 725} 726 727// 15:56 2020-07-06 change HTML to not run rotating_banner_dom_fix gradually 728function rotating_banner_dom_fix() { 729 730 // page may use "promotionTablet" or "communicationTablet", assume "promotion" prefix first 731 // 09:23 2020-06-26 as latest is "slider", use "slider" 732 var sliderTabletId = "#sliderTablet"; 733 var sliderDesktopId = "#sliderDesktop"; 734 var commTabletId = "#communicationTablet"; 735 var commDesktopId = "#communicationDesktop"; 736 var promTabletId = "#promotionTablet"; 737 var promDesktopId = "#promotionDesktop"; 738 739 // original may have "slider", "commmunication" or "promotion" prefix, map to ID exist in the page 740 var chg_flag = 0; 741 if ($(commTabletId).length) { chg_flag = 1; sliderTabletId = commTabletId; } 742 if ($(commDesktopId).length) { chg_flag = 1; sliderDesktopId = commDesktopId; } 743 if ($(promTabletId).length) { chg_flag = 1; sliderTabletId = promTabletId; } 744 if ($(promDesktopId).length) { chg_flag = 1; sliderDesktopId = promDesktopId; } 745 746 // 16:26 2020-06-26 if already use "slider", then no need to do DOM fix 747 if (chg_flag==0) return; 748 749 // ======= add by govhk: start 11:33 2016-12-06 ============== 750 //var lang = location.href.split('/')[3]; 751 752 var prop = { 753 'en' : {'pause':'Pause','previous':'Previous', 'next':'Next'}, 754 'tc' : {'pause':'æ«å', 'previous':'ä¸ä¸å¼µ', 'next':'ä¸ä¸å¼µ'}, 755 'sc' : {'pause':'æå', 'previous':'ä¸ä¸å¼ ', 'next':'ä¸ä¸å¼ '} 756 }; 757 758 var sw_con = '<div class="swiper-control">'; 759 sw_con += '<div class="swiper-control-holder">'; 760 sw_con += '<div class="swiper-button-pause" title="'+prop[feedin_lang].pause+'"></div>'; 761 sw_con += '<div class="swiper-button-prev-custom" title="'+prop[feedin_lang].previous+'"></div>'; 762 sw_con += '<div class="swiper-pagination"></div>'; 763 sw_con += '<div class="swiper-button-next-custom" title="'+prop[feedin_lang].next+'"></div>'; 764 sw_con += '</div>'; 765 sw_con += '</div>'; 766 767 // 14:24 2017-01-12 add "communicationTablet" and desktop 768 769 // 09:18 2020-06-26: should be no need for next 2 lines 770 // replace to "sliderTablet" 771 /* 772 var sliderTabletHtml = '<div class="outer moveToTarget" id="sliderTablet" data-target-desktop="#sliderDesktop" data-target-tablet="#sliderTablet" data-target-mobile="#sliderTablet">'; 773 $(sliderTabletId).replaceWith(sliderTabletHtml); 774 */ 775 776 // replace to "sliderDesktop" 777 778 // 1) Remove the slider control to avoid duplicate (will add back below) 779 // 09:21 2020-06-26: seems no such control, in case only 780 $(sliderDesktopId +' aside div.swiper-control').remove(); 781 782 // 2) Replace class "slide" to "swiper-slide" if have 783 $(sliderDesktopId +' aside .slide').addClass('swiper-slide'); 784 $(sliderDesktopId +' aside .slide').removeClass('slide'); 785 786 // 3) Get "swiper-slide" divS 787 var slidesHtml = $(sliderDesktopId +' aside').html(); 788 789 // 4) if already have "swiper-wrapper", got its html (do not duplicate "swiper-wrapper" below 790 if ($(sliderDesktopId +' div.swiper-wrapper').length) { 791 slidesHtml = $(sliderDesktopId +' div.swiper-wrapper').html(); 792 } 793 794 var sliderDesktopHtml = '<div class="outer moveToTarget" id="sliderDesktop" data-target-desktop="#sliderDesktop" data-target-tablet="#sliderTablet" data-target-mobile="#sliderTablet"><aside class="swiper-container promote-slider"><div class="swiper-wrapper">'+slidesHtml+'</div>'+sw_con+'</div></div>' 795 796 // 5) Replace whole promotionDesktop to sliderDesktop 797 $(sliderDesktopId).replaceWith(sliderDesktopHtml); 798 799 // 6) image size enlarge 9:24 2016-12-14 not work 800 //$('#sliderDesktop img').width(273).height(152); 801 802 803 // 11:48 2018-12-05 for app title 804 $('.swiper-slide a').each(function() { 805 let title = $(this).find('img').attr('title'); 806 $(this).attr('title',title); 807 }) 808 809 810 // 14:25 2018-05-28 fix for rotating banner internal link click 2 times to display 811 // 17:02 2018-09-18 restrict to rotating banner only i.e #sliderDesktop 812 // 15:54 2019-11-15 for homepage_banner again (remove #sliderDesktop) 813 $('.swiper-slide a').on('click', function(e){ 814 //$('#sliderDesktop .swiper-slide a').on('click', function(e){ 815 if (e.button != 0) return; 816 e.preventDefault(); 817 818 // 14:34 2018-05-29 if URL is external link and not apps, set location 819 let uri = $(this).attr('href'); 820 if (uri.indexOf('://')<0 && uri.indexOf('/apps/')<0) { 821 location.href = uri; 822 } 823 }); 824 825 // ======= add by govhk: end ============== 826} 827 828 829// 09:11 2021-02-26 not call by this file (feedin.js) 830function search_autocomplete() { 831 832 // 15:36 2017-01-13 833 //var akurl = 'http://www.search.gov.hk/autokeyword'; 834 var akurl = '//'+ search_domain_deep+'/autokeyword'; 835 836 $( "#searchMainBar" ).autocomplete({ 837 delay: 300, 838 minLength: '2', 839 position: { my : "left top", at: "left bottom" }, 840 source: akurl, 841 // 11:14 2016-12-08 add select 842 select:function(event, ui){ 843 if(ui.item){ 844 this.value = ui.item.value; //assign value back to the form element 845 } 846 $(event.target.form).submit(); // submit the form 847 } 848 849 }); 850 851 $( "#searchMenuBar" ).autocomplete({ 852 delay: 300, 853 minLength: '2', 854 position: { my : "left top", at: "left bottom" }, 855 source: akurl, 856 // 11:14 2016-12-08 add select 857 select:function(event, ui){ 858 if(ui.item){ 859 this.value = ui.item.value; //assign value back to the form element 860 } 861 $(event.target.form).submit(); // submit the form 862 } 863 }); 864 865 /* 9:05 2016-11-14 set after ui-autocomplete */ 866 /* 867 $( "#subSearchBar" ).autocomplete({ 868 delay: 300, 869 minLength: '2', 870 position: { my : "left top", at: "left bottom" }, 871 source: akurl 872 }); 873 */ 874 875} 876 877// 11:49 2016-09-30 878function gih_buttons() { 879 880 881 var prop = { 882 'en' : {'locationMap':'Location Map:ID=', 'geoInfoMap':'Link to GeoInfo Map:ID='}, 883 'tc' : {'locationMap':'ä½ç½®å:ID=', 'geoInfoMap':'é£çµå°çè³è¨å°å:ID='}, 884 'sc' : {'locationMap':'ä½ç½®å¾:ID=', 'geoInfoMap':'è¿ç»å°çèµè®¯å°å¾:ID='} 885 }; 886 887 // array to txt 888 var locationMap = prop[feedin_lang].locationMap; 889 var geoInfoMap = prop[feedin_lang].geoInfoMap; 890 891 892 $('img[src*="/images/gih/gih_button1.gif"]').each( function () { 893 894 var gih_id = $(this).attr('alt'); 895 //console.log('hello'+gih_id); 896 897 // 14:50 2021-05-07 update to CSP suitable below 898 899 var typeMap = ""; 900 901 // 15:11 2021-05-07 NOTE: use class "btn" to make display "inline"; 902 // staticMap 903 typeMap = "staticMap";
904 var typeMapId1 = typeMap + gih_id; 905 var str1 = '<a href="#" class="btn '+typeMap+'" id="'+typeMapId1+'" title="'+locationMap+gih_id+'"><img alt="Location Map:ID='+gih_id+'" src="/'+feedin_lang+'/images/gih/gih_button1.gif"></a>'; 906 907 // advanceMap 908 typeMap = "advanceMap"; 909 var typeMapId2 = typeMap + gih_id; 910 var str2 = '<a href="#" class="btn '+typeMap+'" id="'+typeMapId2+'" title="'+geoInfoMap+gih_id+'"><img alt="Link to GeoInfo Map:ID='+gih_id+'" src="/'+feedin_lang+'/images/gih/gih_button2.gif"></a>'; 911 912 $(this).replaceWith(str1+str2); 913 914 // 15:40 2021-05-07 attach event to show gih map 915 $( "#"+typeMapId1 ).click(function(e) { 916 e.preventDefault(); 917 showPopupStaticMap(gih_id, feedin_lang); 918 }); 919 920 $( "#"+typeMapId2 ).click(function(e) { 921 e.preventDefault(); 922 showPopupAdvancedMap(gih_id, feedin_lang); 923 }); 924 925 /* 14:51 2021-05-07 remark old code below: 926 var str1 = '<a class="staticMap" href="javascript:showPopupStaticMap(\''+gih_id+'\', \''+feedin_lang+'\')" title="'+locationMap+gih_id+'"><img alt="Location Map:ID='+gih_id+'" src="/'+feedin_lang+'/images/gih/gih_button1.gif"></a>'; 927 928 var str2 = '<a class="advancedMap" href="javascript:showPopupAdvancedMap(\''+gih_id+'\', \''+feedin_lang+'\')" title="'+geoInfoMap+gih_id+'"><img alt="Link to GeoInfo Map:ID='+gih_id+'" src="/'+feedin_lang+'/images/gih/gih_button2.gif"></a>'; 929 930 //$(this).append(str1+str2); 931 932 $(this).replaceWith(str1+str2); 933 */ 934 935 }); 936 937} 938 939 940// 16:48 2016-10-26 if visit tc or sc multilanguage page, redirect to en 941function redirection_fix() { 942 if ( location.pathname.indexOf('/tc/theme/multilanguage/mlp/')>=0 ) { 943 var url = location.pathname.replace(/\/tc\//g,'/en/'); 944 var filtered_url =sanitize(url); 945 location.href = filtered_url; 946 } 947 if ( location.pathname.indexOf('/sc/theme/multilanguage/mlp/')>=0 ) { 948 var url = location.pathname.replace(/\/sc\//g,'/en/'); 949 var filtered_url =sanitize(url); 950 location.href = filtered_url; 951 } 952} 953 954// 09:12 2021-02-26 still keep 955// 15:19 2016-09-15 for rss page hide left menu 956function special_page_fix(){ 957 958 959 // 10:44 2021-02-25 continue to use js first - as bg have issue 960 if ( location.pathname.indexOf('/theme/mygovhk/')>0 ) { 961 962 $("body.innerPage .innerPageWrapper").addClass('yourService'); 963 964 // change innerPageHolder to recommendHolder 965 $("body.innerPage .innerPageHolder").addClass('recommendHolder'); 966 $("body.innerPage .innerPageHolder").removeClass('innerPageHolder'); // 17:53 2016-10-26 for align FS 967 968 969 970 // 17:59 2016-10-26 remove common useful links. 971 $("aside.innerPageWrapper").remove(); 972 973 // 17:42 2016-10-24 make title big 974 $("h1.title").removeClass('articleTitle'); 975 976 $("section.blockItem").addClass('item'); 977 $("section.blockItem").removeClass('blockItem'); 978 979 }; 980 981 982 983 // 14:45 2016-09-19 for pakistan right to left 984 if ( location.pathname.indexOf('/theme/multilanguage/mlp/pakistan.htm')>0 ) { 985 $("body #mainHolder").addClass('RightToLeft'); 986 } 987 988 // 15:24 2018-02-14 for feedback to scroll (feedback.js) 989 if ( location.pathname.indexOf('/theme/multilanguage/mlp/')>0 ) { 990 $('#innerPageSideNav').addClass('nonSyncHeight'); 991 } 992 993 // 16:09 2021-02-25 retain first 994 // 11:58 2016-10-12 for Resident, if URL have "?tab=life", tab to "life Events" 995 if ( location.pathname.indexOf('/residents/forms/')>0 ) { 996 // 14:35 2016-10-07 active both tab and panel 997 998 var tab = QueryString['tab']; 999 if (tab=='life') { 1000 $('#servicesTab').removeClass('active'); 1001 $('#lifeTab').addClass('active'); 1002 $('#servicesAccord').removeClass('active'); 1003 $('#lifeAccord').addClass('active'); 1004 } 1005 } 1006 1007} 1008 1009// 16:12 2021-02-25 obsolete after homepage revamp 1010function checkitout_fix() { 1011 1012 // 11:52 2024-11-22 removed 1013} 1014 1015 1016// 15:30 2021-02-19 move to bg 1017// 10:59 2016-09-07 js fix 1018function i_want_to_fix() { 1019 1020 var prop = { 1021 'en' : {'wantTo':'I Want To', 'expandAll':'Expand All+', 'collapseAll':'Collapse All-'}, 1022 'tc' : {'wantTo':'ææ³', 'expandAll':'é¡¯ç¤ºå ¨é¨+', 'collapseAll':'ééå ¨é¨-'}, 1023 'sc' : {'wantTo':'ææ³', 'expandAll':'æ¾ç¤ºå ¨é¨+', 'collapseAll':'å ³éå ¨é¨-'} 1024 }; 1025 1026 // I want To 1027 var wantTo = prop[feedin_lang].wantTo; 1028 $('#wantToDesktop .cell.wantToText h3').html( wantTo ); 1029 1030 // FAQ 10:59 2016-09-07 1031 var expandAll = prop[feedin_lang].expandAll; 1032 var collapseAll = prop[feedin_lang].collapseAll;
1033 $('.faqSection.accordions .extendAll .textExtend strong').html( expandAll ); 1034 $('.faqSection.accordions .extendAll .textCollapse strong').html( collapseAll ); 1035 1036} 1037 1038// 13:57 2021-03-24 faq table fix for Taxes 1039function faq_table_fix() { 1040 $('.innerPageWrapper .faqSection.accordions .qaHolder .qaContent table').wrap('<div class="innerPageHolder"><div class="blockTable"></div></div>'); 1041 1042} 1043 1044// 10:55 2019-11-21 refactoring body_add_class 1045function body_add_class() { 1046 1047 //console.log("body_add_class 1"); 1048 1049 // class gen by FS, remove 15:47 2016-08-09 1050 $('.title.titleCommunication').removeClass('titleCommunication'); 1051 1052 // reset those class generate by presentation 1053 $('body').removeClass('pageResidents'); 1054 $('body').data("menu-target", ''); 1055 $('body').data("menu-subtarget", ''); 1056 1057 // init variable 1058 var shortUG = []; 1059 shortUG["residents"] = "RS"; 1060 shortUG["business"] = "BT"; 1061 shortUG["nonresidents"] = "NR"; 1062 shortUG["theme"] = "TH"; 1063 //shortUG["about"] = "AB"; 1064 1065 var shortUGCurrent = shortUG[feedin_usergroup]; 1066 // if not in 5 folders, 14:52 2016-09-05 1067 if (shortUGCurrent==undefined || shortUGCurrent=='') { 1068 shortUGCurrent = 'AB'; 1069 } 1070 1071 // 10:09 2019-11-21 init variable, default /en/residents 1072 var feedMenuTarget_css = "subMenuResidents" ; 1073 var feedMenuTarget = "#" + feedMenuTarget_css ; 1074 var highlight_path = lang_usergroup; 1075 1076 // 10:12 2019-11-21 assume it is homepage first 1077 if (feedin_usergroup=='business') { 1078 1079 $('body').addClass('pageBusiness'); 1080 feedMenuTarget_css = "subMenuBusiness" ; 1081 feedMenuTarget = "#" + feedMenuTarget_css ; 1082 1083 } else if (feedin_usergroup=='nonresidents') { 1084 1085 $('body').addClass('pageNonResidents'); 1086 feedMenuTarget_css = "subMenuNonResidents" ; 1087 feedMenuTarget = "#" + feedMenuTarget_css ; 1088 1089 } else if (feedin_usergroup=='theme') { 1090 1091 $('body').addClass('pageThematic'); 1092 feedMenuTarget_css = "subMenuThematic" ; 1093 feedMenuTarget = "#" + feedMenuTarget_css ; 1094 1095 // 17:15 2019-04-11 esp add "theme-bf" to body 1096 $('body').addClass('theme-'+feedin_cluster); 1097 1098 } else { 1099 1100 // 15:59 2019-11-22 for "resident" and "about" 1101 // 15:59 2019-11-22 fallback to residents 1102 $('body').addClass('pageResidents'); 1103 feedMenuTarget_css = "subMenuResidents" ; 1104 feedMenuTarget = "#" + feedMenuTarget_css ; 1105 1106 } 1107 1108 //console.log("body_add_class 2"); 1109 1110 // 11:48 2019-11-22 CAUTION: remove "var" for feedMenu variable below 1111 // 10:15 2019-11-21 assume feedin_cluster is real cluster (not "index.htm", not "?abc") here 1112 1113 1114 // 10:01 2019-11-21 show 1 Cluster N subcat menu 1115 if (feedin_cluster.length>0) { 1116 1117 // test if expect menuTarget exist first 1118 feedMenuTarget2_css = feedin_cluster + "Menu" + shortUGCurrent ; 1119 feedMenuTarget2 = "#" + feedMenuTarget2_css ; 1120 1121 // 11:18 2019-11-25 move out 1122 highlight_path = lang_subcat; 1123 1124 console.log( "feedMenuTarget2="+ feedMenuTarget2 ); 1125 1126 if ( $(feedMenuTarget2).length > 0 ) { 1127 // 1128 feedMenuTarget_css = feedMenuTarget2_css ; 1129 feedMenuTarget = feedMenuTarget2 ; 1130 } 1131 } 1132 1133 // 10:01 2019-11-21 show 1 Subcat N subsubcat menu (normally for theme site only) 1134 if (feedin_subcat.length>0 && (feedin_usergroup=='theme'|| feedin_usergroup=='about') ) { 1135 1136 // test if expect menuTarget exist first 1137 feedMenuTarget2_css = feedin_subcat + "Menu" + shortUGCurrent ; 1138 feedMenuTarget2 = "#" + feedMenuTarget2_css ; 1139 1140 // 11:18 2019-11-25 move out 1141 highlight_path = lang_folder_5; 1142 1143 if ( $(feedMenuTarget2).length > 0 ) { 1144 // 1145 feedMenuTarget_css = feedMenuTarget2_css ; 1146 feedMenuTarget = feedMenuTarget2 ; 1147 } 1148 1149 } 1150 1151 /* 9:46 2019-11-21 debug */ 1152 //console.log("shortUGCurrent = " + shortUGCurrent); 1153 //console.log("feedMenuTarget = " + feedMenuTarget); 1154 //console.log("feedMenuTarget_css = " + feedMenuTarget_css); 1155 //console.log("highlight_path = " + highlight_path); 1156 1157 // 9:30 2016-09-12 if the feedMenuTarget id exist, add Class, 1158 // 9:45 2016-09-12 and handle menu-subtarget 1159 1160 // 14:48 2019-11-22 if have menuTarget, set Class and reuse FS code to open right menu 1161 if ( $(feedMenuTarget).length > 0 ) { 1162 1163 // alert('body_add_class'); 1164 $('body').data("menu-target", feedMenuTarget); 1165 1166 // 16:24 2019-11-22 old 1167 //$('body').data("menu-thematic", "thematic"); 1168 1169 // for css (h1) title 1170 console.log("body feedMenuTarget_css: "+ feedMenuTarget_css); 1171 $('body').addClass( feedMenuTarget_css); 1172 1173 1174 1175 // 16:24 2019-11-22 old 1176 // $(".infoItem", feedMenuTarget).eq(feedMenuSubTarget * 1 - 1).addClass('active'); 1177 1178 // var rightMenuItems = feedMenuTarget + " .infoItem"; 1179 // 16:21 2019-11-22 both culture and theme have "subMenuCol" 1180 var rightMenuItems = feedMenuTarget + " .subMenuCol .infoItem a"; 1181 //console.log("rightMenuItems:" + rightMenuItems); 1182 1183 1184 1185 // 14:49 2019-11-22 NOTE: usergroup have NOT submenu 1186 // 14:48 2019-11-22 at least on Cluster or subcat 1187 // 17:03 2020-01-20 if os,of,govdir, not do submenu highlight (active)
1188 // 8:55 2020-01-22 as discuss, still do highlight 1189 // if ( feedin_cluster=='forms' || feedin_cluster=='onlineservices' || feedin_cluster=='govdirectory' ) { 1190 // do nothing (Not do highlight) 1191 // } else 1192 if ( feedin_cluster.length > 0 ) { 1193 1194 //console.log("feedin_cluster.length=" + feedin_cluster.length); 1195 1196 var feedMenuSubTarget = 0; 1197 1198 // 14:50 2019-11-22 loop thru rightmenu and find relevant match submeu 1199 // 14:50 2019-11-22 and set submenu number for FS code to open the submenu 1200 $( rightMenuItems).each(function () { 1201 1202 // count++ 1203 feedMenuSubTarget++; 1204 1205 // 15:17 2019-11-22 if item path eq or longer than current path, active it 1206 var hf1 = $(this).attr('href'); 1207 1208 // 9:14 2020-01-22 not use OR condition 1209 //if (hf1.indexOf(highlight_path) >= 0 || highlight_path.indexOf(hf1) >= 0) { 1210 if (hf1.indexOf(highlight_path) >= 0 ) { 1211 1212 console.log("hf: hf1="+hf1); 1213 console.log("hf: highlight_path " + highlight_path); 1214 1215 // active (highlight) the item 1216 $(this).addClass("active"); 1217 1218 // if the item have SUBmenu, set menu-subtarget and let FS code to open the submenu 1219 var hf2 = $(this).hasClass('innerPageLink'); 1220 if (hf2) { 1221 //console.log("body add menu-subtarget: "+ feedMenuSubTarget); 1222 $('body').data("menu-subtarget", feedMenuSubTarget); 1223 } 1224 1225 return false; // break jquery loop 1226 } 1227 1228 1229 }); 1230 } 1231 1232 } 1233 1234} 1235 1236// 09:13 2021-02-26 in use 1237function leftmenu_highlight() { 1238 1239 //console.log("menu_url_pattern:"+menu_url_pattern); 1240 1241 // 9:37 2017-03-10 1242 // do nothing when 'theme' and pattern up to 3rd folder only (just up to theme site only) 1243 if ( feedin_usergroup == 'theme' && menu_url_pattern == lang_cluster ) { 1244 return 0; 1245 } 1246 1247 1248 1249 /* 10:01 2019-11-07 REMARK this, test if still fine on softwarerequirement and faq pages. 1250 // 17:11 2016-11-09 for those path, the "h4" is fine, quit the function 1251 if ( location.pathname.indexOf('/about/helpdesk/softwarerequirement/')>0 || 1252 location.pathname.indexOf('/about/helpdesk/faq/')>0 1253 ) { 1254 return; 1255 } 1256 */ 1257 1258 // 16:29 2019-11-21 try change href^= to href= (starts-with to exact match) 1259 // 9:35 2019-11-07 add "nav" to be more specific to leftmenu 1260 // highlight 1261 //$('.blockTagHolder a[href^="'+menu_url_pattern+'"]').addClass('active'); 1262 1263 // 17:36 2024-11-21 XSS prevention 1264 menu_url_pattern = filterUntrustedChar(menu_url_pattern); 1265 if (location.pathname.includes('/cc/preview/') && !menu_url_pattern.includes('/cc/preview/')) menu_url_pattern = location.pathname.split('/').slice(0, 6).join('/') + menu_url_pattern 1266 // 12:10 2019-11-25 "> a" 1267 $('nav .blockTagHolder > a[href^="'+menu_url_pattern+'"]').addClass('active'); 1268 // 9:58 2019-11-07 for full list of online services (NOTE: nav and class in same element) 1269 $('nav.blockTagHolder > a[href^="'+menu_url_pattern+'"]').addClass('active'); 1270 1271 // 12:10 2019-11-25 "> a" 1272 var dropmenu_title = $('nav .blockTagHolder > a[href^="'+menu_url_pattern+'"]').text(); 1273 var dropmenu_title2 = $('nav.blockTagHolder > a[href^="'+menu_url_pattern+'"]').text(); 1274 1275 //console.log ('dropmenu_title:'+dropmenu_title+"---"); 1276 //console.log ('dropmenu_title2:'+dropmenu_title2+"---"); 1277 1278 // 14:34 2019-11-15 there are 2 possible of menu, type TWO use less and as supplementary 1279 if (dropmenu_title.length==0) { 1280 dropmenu_title = dropmenu_title2; 1281 } 1282 1283 // 11:31 2020-11-27 if dropmenu_title(2) still empty, use default text 1284 if (dropmenu_title.length==0) { 1285 var prop = { 1286 'en' : {'dropmenu_default':'Please select a sub-category'}, 1287 'tc' : {'dropmenu_default':'è«é¸æåé¡'}, 1288 'sc' : {'dropmenu_default':'è¯·éæ©åç±»'} 1289 }; 1290 1291 // assign to default value 1292 dropmenu_title = prop[feedin_lang].dropmenu_default; 1293 } 1294 1295 1296 // 15:49 2016-08-03 1297 // For Smart Menu (have I Want To), move breadcrumb 3 level to big title 1298 // item.length !! 1299 if ( $('.item.wantTo').length ) { 1300 // alert('have wantTo'); 1301 var third_title = $('.contentWrapper .navigator li:nth-child(3)').text(); 1302 // $('.blockDetailHolder h1').html(third_title); 1303 1304 // All H1 replace to third title - 12:01 2016-07-29 1305 $('h1').html(third_title); 1306 // 12:00 2016-07-29 temp fix first. have to handle layout.css line 9293 icons after title on tablet 1307 } 1308 1309 // set h2 title 1310 $('.contentWrapper .sideNav h2').html(dropmenu_title); 1311 1312 // 14:44 2016-07-20 grey bar on Feature Article 1313 $('.contentWrapper .sideNav h4').html(dropmenu_title); 1314 1315 // 12:05 2017-11-17 now hide "Business Sector Cover" (default text) by CSS, and show correct value by JS 1316 // 16:59 2017-12-01 have bug on studyhk, hide first 1317 // 9:40 2017-12-04 now hide h4 and restore to "inline-block" 1318 $('.blockHead.showOnTablet h4').css("display","inline-block"); 1319 1320 /* 9:18 2019-11-07 remark, seems not use 1321 // 16:15 2019-04-30 1322 let drop_h2 = $('.blockHead.showOnTablet h2').height(); 1323 ... 1324 */ 1325 1326 1327 1328 1329} 1330 1331 1332// 09:13 2021-02-26 in use 1333// 15:16 2019-11-21 dropmenu_fix() move to leftmenu_highlight 1334// 15:58 2021-01-28 recreate dropmenu_fix() for housing public 3 lines issue 1335function dropmenu_fix() { 1336 1337 if ( $('.contentWrapper .sideNav h2').length || $('.contentWrapper .sideNav h4').length ) { 1338 // continue 1339 } else { 1340 return 0; 1341 } 1342 1343 // 11:36 2021-01-29 reset the height to 2 lines text first 1344 $('.contentWrapper .blockHead.showOnTablet').height('48px'); 1345
1346 // 17:10 2021-01-28 housing public use h2, software requirement use h4 1347 // 11:44 2021-01-29 reset change attribute, if already resized 1348 $('.contentWrapper .sideNav h2, .contentWrapper .sideNav h4').height('auto'); 1349 $('.contentWrapper .sideNav h2, .contentWrapper .sideNav h4').css('float','none'); 1350 $('.contentWrapper .sideNav h2, .contentWrapper .sideNav h4').css('clear','none'); 1351 1352 // 15:05 2021-01-28 do after assign height 1353 var drop_h1 = $('.contentWrapper .blockHead.showOnTablet').height(); 1354 1355 // 17:16 2021-01-28 1356 var drop_h2 = 0; 1357 1358 // check if h2 exist, else check h4 exist 1359 if ( $('.contentWrapper .sideNav h2').length ) { 1360 drop_h2 = $('.contentWrapper .sideNav h2').height(); 1361 } else if ( $('.contentWrapper .sideNav h4').length ) { 1362 drop_h2 = $('.contentWrapper .sideNav h4').height(); 1363 } else { 1364 // do nothing 1365 } 1366 1367 console.log("drop_h1 " + drop_h1); 1368 console.log("drop_h2 " + drop_h2); 1369 1370 // 15:05 2021-01-28 normally drop_h1=46 and drop_h2=48 1371 // drop_h2=72 when more text, then assign the height back to container 1372 if ( drop_h2 - drop_h1 > 2 ) { 1373 1374 // 11:38 2021-01-29 set height of container (first) 1375 $('.contentWrapper .blockHead.showOnTablet').height(drop_h2); 1376 1377 // 11:38 2021-01-29 show it then 1378 $('.contentWrapper .sideNav h2, .contentWrapper .sideNav h4').css('float','left'); 1379 1380 // 11:01 2021-01-29 try fix flash on actual mobile device 1381 $('.contentWrapper .sideNav h2, .contentWrapper .sideNav h4').css('clear','both'); 1382 1383 // 17:11 2021-01-28 no need but keep first 1384 //$('.contentWrapper .sideNav').height(drop_h2) 1385 } 1386} 1387 1388 1389// 15:52 2021-02-22 move to bg 1390function common_useful_link_fix() { 1391 1392 // 17:55 2016-12-14: not do at "theme" site, because it may have special content without bullet point 1393 if ( location.pathname.indexOf('/en/theme/')>=0 || 1394 location.pathname.indexOf('/tc/theme/')>=0 || 1395 location.pathname.indexOf('/sc/theme/')>=0 ) { 1396 1397 // For Theme Site 1398 // 11:48 2017-04-11 remove empty link 1399 $('.tagContentHolder a[href=""]').remove(); 1400 1401 // 12:22 2017-04-11 assume EACH Theme Site block will have at least one link, if not, remove the link and shrink the height (from "81px") 1402 // if the block exist 1403 if ( !$('.tagContentHolder a').length ) { 1404 $('#shortCutDesktop div.hrLine').remove(); 1405 $('#serviceLinkDesktop div.hrLine').remove(); 1406 $('#shortCutDesktop').height('40px'); 1407 $('#serviceLinkDesktop').height('40px'); 1408 } 1409 1410 // theme site handling ended 1411 return ; 1412 } 1413 1414 // === Non-theme (Residents, Business, NonRes, About) ==== 1415 1416 // remove empty list first 1417 $('ul.tagContentHolder li:empty').remove(); 1418 1419 // check header and li, 1420 // add ".tagBlock" for "common useful link" only 17:06 2016-08-16 1421 $('.tagBlock .blockHead.block-1-3.blockMb-1-1').each( function () { 1422 1423 var h3 = $(this).find('h3').text(); 1424 1425 // if have not h3, find h4 16:41 2016-09-01 1426 // Top OS and OF is H3 1427 // Related Links is H4 1428 if (h3=='') { 1429 h3 = $(this).find('h4').text(); 1430 } 1431 1432 //alert('h3 '+ h3); 1433 1434 var li_empty_flag = 0; // init variable 1435 1436 // if header is empty, remove whole block 1437 if (h3=='') { 1438 // mark empty flag and remove block below 1439 li_empty_flag==1 1440 } else { 1441 1442 1443 // 9:24 2018-02-15 change for HP mobile apps move to RL/TGF/TOS block 1444 // NOTE: ul is in next block 1445 //var ul = $(this).next('ul.tagContentHolder'); 1446 var ul = $(this).next('.tagContentHolder'); 1447 if (ul.is('ul') ) { 1448 1449 var li = ul.find('li:first'); 1450 1451 //if (li=='') { 1452 1453 var li_text = li.text(); 1454 1455 1456 //alert('h3 '+ h3+ ' li xxx'+ li_text + 'xxx'); 1457 1458 if ( li_text=='') { li_empty_flag = 1; } 1459 if ( li_text.indexOf('Top Online Service')>=0) { li_empty_flag = 1; } 1460 if ( li_text.indexOf('Top Government Forms')>=0) { li_empty_flag = 1; } 1461 if ( li_text.indexOf('常ç¨ç¶²ä¸æå')>=0 ) { li_empty_flag = 1; } 1462 if ( li_text.indexOf('常ç¨ç½ä¸æå¡')>=0 ) { li_empty_flag = 1; } 1463 if ( li_text.indexOf('å¸¸ç¨æ¿åºè¡¨æ ¼')>=0 ) { li_empty_flag = 1; } // note: tc and sc is same text 1464 1465 } 1466 1467 } 1468 1469 // if li empty, remove 1470 if (li_empty_flag==1 ) { 1471 1472 // 11:05 2017-04-11 remove the whole block (for "about" folder only
1472), if the block exist 1473 if (feedin_usergroup=='about') { 1474 $('#shortCutDesktop').remove(); 1475 $('#serviceLinkDesktop').remove(); 1476 } 1477 1478 // alert('bingo ' + li_text); 1479 // NOTE: ul is in next block 1480 //$(this).next('ul.tagContentHolder').remove(); 1481 ul.remove(); 1482 $(this).remove(); 1483 } 1484 1485 }); 1486 1487 /* remark, use presentation 12:27 2016/10/1 1488 $('ul#block__top_online_services li:last a[href$="/onlineservices/index.htm"]').each(function(){ 1489 var title = $(this).text().replace(/\s\s+/g, ' '); 1490 $(this).attr('title',title); 1491 }); 1492 1493 $('ul#block__top_online_forms li:last a[href$="/forms/index.htm"]').each(function(){ 1494 var title = $(this).text().replace(/\s\s+/g, ' '); 1495 $(this).attr('title',title); 1496 }); 1497 */ 1498 1499 1500 1501 1502} 1503 1504// 16:16 2021-02-17 obsolete after homepage revamp 1505// 10:49 2017-01-05 merge govhk_qna_fix() and qna_fix() 1506function govhk_qna_fix() { 1507 // 15:16 2016-08-03 add "active" to single "article" 1508 // note: system display one type at a time only 1509 $('.blockContent.qaHolder').addClass('active'); 1510 1511 // in case QnA hide 9:41 2016-11-30 1512 if ( !$('#blockQnA').length && $('#blockMobileApp').length ) { 1513 $('#blockMobileApp').addClass('block-3-3'); 1514 } 1515} 1516 1517// 15:37 2021-02-19 seems use for print, keep 1518function external_link_icon() { 1519 1520 /* 17:06 2016-09-22 remark 1521 // remove all icons generate by HTML 1522 // at "I Want To" 1523 $('.wantToList a.externalLink').removeClass('externalLink'); 1524 // at "Cards" 1525 $('.outer .text h3.externalLink').removeClass('externalLink'); 1526 */ 1527 1528 // 17:06 2016-09-22 for all externalLink (in a big Holder) 1529 $('#mainHolder a.externalLink').removeClass('externalLink'); 1530 1531 // if URL start with http://www.gov.hk/, remove it 1532 // 12:02 2017-06-01 add https 1533 if (location.pathname.includes('/cc/preview/')){ 1534 $('a[href^="http://www.gov.hk/"],a[href^="https://www.gov.hk/"]').each(function(){ 1535 var url = $(this).attr('href'); 1536 // 14:56 2020-12-22 if this item is fundraising audit report, NOT remove www.gov.hk (return) 1537 if ( url.indexOf('gov.hk/fundraisinginfo')>0 ) { return 0; } 1538 var parts = location.pathname.split("/"); 1539 var suffix = url.replace(/^.*\/\/[^\/]+/, ''); 1540 var url2 = "/cc/preview/"+parts[3]+"/"+parts[4]+"/"+parts[5] + suffix; 1541 $(this).attr('href',url2); 1542 }); 1543 }else{ 1544 $('a[href^="http://www.gov.hk/"],a[href^="https://www.gov.hk/"]').each(function(){ 1545 var url = $(this).attr('href'); 1546 1547 // 14:56 2020-12-22 if this item is fundraising audit report, NOT remove www.gov.hk (return) 1548 if ( url.indexOf('gov.hk/fundraisinginfo')>0 ) { return 0; } 1549 1550 var url2 = url.replace(/^.*\/\/[^\/]+/, ''); 1551 $(this).attr('href',url2); 1552 }); 1553 } 1554 // === /en/residents/government/legal/advice/advice.htm 1555 // === duplicate on 2 block above, change to "mailto:" === 1556 // handle "mailto:" 16:09 2016-09-08 1557 // handle <a> self have externalLink 1558 $('.wantToList a[href^="http"]').addClass('externalLink'); 1559 $('.wantToList a[href^="mailto:"]').addClass('externalLink'); 1560 $('.tagContentHolder a[href^="http"]').addClass('externalLink'); 1561 $('.tagContentHolder a[href^="mailto:"]').addClass('externalLink'); 1562 $('.blockItem a[href^="http"]').addClass('externalLink'); 1563 $('.blockItem a[href^="mailto:"]').addClass('externalLink'); 1564 1565 // 17:12 2019-07-09 added externalLink for guidebook 1566 $('.guidebookContentExpand a[href^="http"]').addClass('externalLink'); 1567 $('.guidebookContentExpand a[href^="mailto:"]').addClass('externalLink'); 1568 1569 // 10:53 2019-07-30 added externalLink for finder 1570 $('.findertagItemList a[href^="http"]').addClass('externalLink'); 1571 $('.findertagItemList a[href^="mailto:"]').addClass('externalLink'); 1572 1573 1574 1575 1576 // 10:24 2016-10-28 accordionContent in /tc/residents/forms/, remove 1577 //$('.accordionContent a[href^="http"]').addClass('externalLink'); 1578 //$('.accordionContent a[href^="mailto:"]').addClass('externalLink'); 1579 1580 // 11:11 2016-09-15: add imgLink for remove external icons 1581 $('.blockItem a[href^="http"] img').each(function(){ 1582 $(this).parents('a').addClass('imgLink'); 1583 }); 1584 1585 1586 // handle writesup - h3 or h4 have externalLink : 15:29 2016-07-22 1587 $('.outer .text a.itemTitle[href^="http"]').each(function(){ 1588 $(this).find('h3').addClass('externalLink'); 1589 $(this).find('h4').addClass('externalLink'); 1590 }); 1591 // handle "mailto:" 16:09 2016-09-08 1592 $('.outer .text a.itemTitle[href^="mailto:"]').each(function(){ 1593 $(this).find('h3').addClass('externalLink'); 1594 $(this).find('h4').addClass('externalLink'); 1595 }); 1596 1597 // === below consider as internal page (no external link icon) === 1598 // 10:48 2017-11-10 mygovhk 1599 $('a[href*="www.personalised.gov.hk/"]').removeClass('externalLink'); 1600 1601 /* 1602 // 16:27 2016-07-21: if www.gov.hk/a/b/c.pdf, mark as internal-pdf 1603 $('a[href^="http://www.gov.hk/"][href$=".pdf"]').attr('data-govhk-type','internal-pdf'); 1604 $('a:not([href^="http"])[href$=".pdf"]').attr('data-govhk-type','internal-pdf'); 1605 */ 1606} 1607 1608// 09:14 2021-02-26 in use 1609function feature_article_fix() { 1610 1611 // add class for feature article inline link 12:09 2016-08-19 1612 $('.blockItem p a').addClass('inlineLink'); 1613 1614 // 16:48 2016-11-22: feature article "a" with "id" only will make the rotating banner not function (plain) 1615 // quick fix: replace "a" to "span" to avoid it 1616 $('.blockItem p a[id]:not([href])').each(function(){ 1617 var id1 = $(this).attr('id'); 1618 var html = $(this).html(); 1619 $(this).replaceWith("<span id='"+id1+"'>"+html+"</span>") 1620 }); 1621 1622 1623 // 11:18 2016-09-09 for /en/residents/government/legal/advice/advice.htm 1624 // when a is inside ul li, no p contains it! 1625 $('.blockItem ul li a').addClass('inlineLink'); 1626 1627 1628 // 16:56 2016-08-22 make left right is nothing - move to css 1629 // $('.blockItem :not(p) a').css('clear','both'); 1630 1631 // ============= .innerPageHolder .blockItem =============== 1632 // unwrap double p tag to single p tag, in case 12:21 2016-08-19 1633 $('body.innerPage .innerPageHolder .blockItem p p').unwrap(); 1634 1635 // remove empty p tag 12:10 2016-08-19 1636 $('body.innerPage .innerPageHolder .blockItem p:empty').remove(); 1637 1638 /* if section last item is <p>, remove the margin-bottom */ 1639 /* note: The :last-child selector matches every element that is the last child of its parent (section in this case) */ 1640 // 8:59 2016-08-26 Org: /en/residents/housing/maintenance/fireprevention/tips/firesafetyathome.htm 1641 // 16:07 2017-01-06 affect top_level_page, remark 1642 // $('body.innerPage .innerPageHolder .blockItem p:last-child').css('margin-bottom',0); 1643 // it is also at layout.css 8666 1644 1645 1646 // unset "ul p" 1647 // 10:34 2016-09-07 for /en/residents/employment/jobsearch/employyoung.htm 1648 $('body.innerPage .innerPageHolder .blockItem ul p').css('margin-bottom',''); 1649 1650 1651 // 18:05 2016-08-26 FA table 1652 $('body.innerPage .innerPageHolder .blockItem table').wrap('<div class="blockTable"></div>'); 1653 1654 // 9:14 2016-09-02 FA li have p tag 1655 1656 // 10:59 2016-09-13 remark for /tc/residents/culture/recreation/leisurelink/leisurelink.htm 1657 // when added, bullet point will remove "li" 1658 //$('body.innerPage .innerPageHolder .blockItem ul li p').unwrap(); 1659 1660 1661 /* 1662 9:16 2016-09-05: special handling for "/po/" 1663 Target is /en/about/govdirectory/po/cce.htm (those profile) 1664 but also set /en/about/govdirectory/po/index.htm (no harm) 1665 /en/about/govdirectory/po/fs.htm 1666 */ 1667 1668 //alert('loc path = '+location.pathname); 1669 if ( location.pathname.indexOf('/about/govdirectory/po/')>0 || 1670 location.pathname.indexOf('/about/form_types.htm')>0 ) { 1671 $("body.innerPage .innerPageHolder .blockItem p img").attr('style','float:left;'); 1672 } 1673 1674 // 17:38 2016-09-14 if "p" have "margin-left", add "js-margin-left" 1675 $("body.innerPage .innerPageHolder .blockItem p ").each(function () { 1676 var style1 = $(this).attr('style'); 1677 if (style1!==undefined) { 1678 var style2 = style1.replace(/ /g,''); 1679 if (style2.indexOf("margin-left")>=0) { 1680 $(this).addClass("js-margin-left"); 1681 } 1682 } 1683 }); 1684 1685 /* 1686 14:35 2016-09-02 1687 move <img style="float: left;"> to css "js-left" 1688 e.g: /en/residents/environment/air/airquality.htm 1689 */ 1690 $("body.innerPage .innerPageHolder .blockItem p img").each(function () { 1691 1692 1693 var style1 = $(this).attr('style'); 1694 1695 // it can be undefined : 9:22 2016-09-07 1696 if (style1!==undefined) { 1697 var style2 = style1.replace(/ /g,''); 1698 1699 //alert('style = '+style2); 1700 if (style2.indexOf("float:left;")>=0) { 1701 //alert('style2 = '+style2); 1702 $(this).addClass("js-left"); 1703 $(this).css('float',''); 1704 1705 $(this).parents('p').siblings('ul').addClass("js-left"); 1706 $(this).parents('p').siblings('ol').addClass("js-left"); 1707 $(this).parents('p').siblings('p').addClass("js-left"); 1708 1709 $(this).parents('p').addClass("js-left"); 1710 1711 /* 1712 // ul and ol wrap div first 1713 $(this).parents('p').siblings('ul').wrap('<div class="js-left-sibling"></div>'); 1714 $(this).parents('p').siblings('ol').wrap('<div class="js-left-sibling"></div>'); 1715 1716 // replace p-s sibling's p to div first 1717 $(this).parents('p').siblings('p').each(function () { 1718 var div_html = '<div class="js-left-sibling">'+$(this).html()+'</div>'; 1719 $(this).replaceWith(div_html); 1720 }); 1721 1722 // then replace current p to div 1723 var div_html = '<div class="js-left">'+$(this).parents('p').html()+'</div>'; 1724 $(this).parents('p').replaceWith(div_html); 1725 */ 1726 1727 } 1728 if (style2.indexOf("float:right;")>=0) { 1729 //alert('style3 = '+style2); 1730 // img: 1731 $(this).addClass("js-right"); 1732 $(this).css('float',''); 1733 1734 /* 1735 17:06 2016-10-14 1736 for /tc/residents/environment/waste/constructionwaste.htm 1737 method: 1738 1) change "p" to "span.js-right" 1739 add "js-right" to ul and ol 1740 span is inline 1741 create 2 line break for span 1742 */ 1743 1744 $(this).parents('p').siblings('ul').addClass("js-right"); 1745 $(this).parents('p').siblings('ol').addClass("js-right"); 1746 1747 $(this).parents('p').siblings('p').addClass("js-right"); 1748 $(this).parents('p').addClass("js-right"); 1749 1750 /* test 1751 // replace p-s sibling's p to span first 1752 $(this).parents('p').siblings('p').each(function () { 1753 var span_html = '<span class="js-right">'+$(this).html()+'</span>'; 1754 $(this).replaceWith(span_html); 1755 }); 1756 1757 // then replace current p to span 1758 var span_html = '<span class="js-right">'+$(this).parents('p').html()+'</span>'; 1759 $(this).parents('p').replaceWith(span_html); 1760 */ 1761 1762 } 1763 } 1764 }); 1765 1766 // override table height: 14:52 2016-09-07 1767 // for /tc/residents/taxes/taxfiling/taxrates/salariesrates.htm 1768 $("body.innerPage .innerPageHolder .blockItem table").css('height',''); 1769 1770 /* 16:14 2016-12-23 remark by consider table pages: 1771 /en/residents/housing/moving/coa_form.htm 1772 /en/residents/taxes/taxfiling/taxrates/salariesrates.htm 1773 /en/residents/taxes/property/propertycompute.htm 1774 */ 1775 //$("body.innerPage .innerPageHolder .blockItem table").css('width',''); 1776 1777 1778 /* 1779 16:57 2016-09-14: for /tc/about/helpdesk/softwarerequirement/onlineservice.htm 1780 for old style <table height="185"> 1781 */ 1782 $("body.innerPage .innerPageHolder .blockItem table").height('auto'); 1783 1784 // move to special page fix 1785 1786 // ============= .innerPageHolder .blockContentWrap =============== 1787 // 8:58 2016-08-26 KC: temp fix for /en/about/helpdesk/ (margin become 20px + 30px)... 1788 /* 18:00 2016-10-24 move to layout_append.css 1789 $('body.innerPage .innerPageHolder .blockContentWrap').css('margin-bottom','50px'); 1790 $('body.innerPage .innerPageHolder .blockContentWrap').css('display','block'); 1791 $('body.innerPage .innerPageHolder .blockContentWrap').css('clear','both'); 1792 $('body.innerPage .innerPageHolder .blockContentWrap').css('float','left'); 1793 */ 1794 1795 // ============= .innerPageListGrid =============== 1796 // temp fix for writesup (card) 14:24 2016-08-19 1797 // remove empty p tag 1798 $('body.innerPage .innerPageListGrid .item p:empty').remove(); 1799 // add "itemDesc" to p tag 1800 $('body.innerPage .innerPageListGrid .item p').addClass('itemDesc'); 1801 1802 // 16:56 2016-08-22 blockItem immediate a 1803 //$('.blockItem > a').css('clear','both'); 1804 //$('.blockItem > a').css('padding-top','10px'); 1805 1806 // 14:51 2016-08-25 Temp fix for card, a-title=null 1807 $('body.innerPage .innerPageListGrid .item .outer .text a.itemTitle').each(function () { 1808 var txt = $(this).text().trim(); 1809 $(this).attr('title',txt); 1810 }); 1811 1812 // 16:41 2016-08-30 For oohk.htm 1813 $('body.innerPage .innerPageHolder section.blockItem p a:not([href]) br').each(function(){ 1814 1815 //$(this).parent('a').removeClass('inlineLink'); 1816 //var temp = $(this).parents('a').attr('id') + ' ' + $(this).parents('a').attr('class') + ' '+ $(this).parents('a').text(); 1817 //alert('temp = '+temp); 1818 $(this).parents('a').removeClass('inlineLink'); 1819 }); 1820 1821 // 9:53 2017-11-29 fix font small www.gov.hk/tc/residents/government/publication/consultation/2006.htm 1822 if ( location.pathname.indexOf('/residents/government/publication/consultation/')>0 ) { 1823 $('body.innerPage .innerPageHolder section.blockItem span').removeAttr('style'); 1824 } 1825 1826} 1827 1828 1829// 16:31 2016-07-06 1830function breadcrumb_fix() { 1831 // alert('b c fix'); 1832 1833 // remove empty breadcrumb item(s) 1834 $('.contentWrapper ul.navigator li').each(function(){ 1835 // 12:20 2019-10-25 add href empty will remove. 1836 //if($(this).html() == "" || typeof($(this).html())=="undefined") 1837 if($(this).html() == "" || typeof($(this).html())=="undefined" || $(this).find("a").attr('href') == "") 1838 { 1839 $(this).remove(); 1840 } 1841 }); 1842 1843 // get last 2 item and compare if it is same 1844 // last 2 item length 1845 var bc_len9 = $('.contentWrapper ul.navigator li').length; 1846 var bc_len8 = bc_len9 - 1; 1847 //alert('bc_len8,9 = '+bc_len8 + ','+bc_len9); 1848 1849 // last 2 item text 1850 var a = $('.contentWrapper .navigator li:nth-child('+bc_len8+')').text().trim(); 1851 var b = $('.contentWrapper .navigator li:nth-child('+bc_len9+')').text().trim(); 1852 //alert('a,b = '+a+ ','+b); 1853 1854 // if last 2 item text same, remove last one 1855 if (a==b) { 1856 //alert('a==b'); 1857 $('.contentWrapper .navigator li:nth-child('+bc_len9+')').remove(); 1858 } 1859 1860 // remove last item - hyperlink 1861 $('.contentWrapper .navigator li:last-child a').contents().unwrap(); 1862 1863 var selector_2nd = ''; 1864 selector_2nd += ' body.innerPage .navigator li a[href="/en/about"]'; // 1st do not have comma 1865 selector_2nd += ', body.innerPage .navigator li a[href="/tc/about"]'; 1866 selector_2nd += ', body.innerPage .navigator li a[href="/sc/about"]'; 1867 selector_2nd += ', body.innerPage .navigator li a[href="/en/theme"]'; 1868 selector_2nd += ', body.innerPage .navigator li a[href="/tc/theme"]'; 1869 selector_2nd += ', body.innerPage .navigator li a[href="/sc/theme"]'; 1870 1871 1872 // 16:54 2016-09-02 special handling for "about" and "theme" 2nd folder 1873 $(selector_2nd).each(function(){ 1874 $(this).parents('li').addClass('breadCrumbAbout'); 1875 }); 1876 1877 // 10:59 2016-11-10 remove "mlp" (Introduction) by user request 1878 // Note: now language page not affect because pages do not have "a" wrap the text 1879 $('body.innerPage .navigator li a[href*="/theme/multilanguage/mlp"]').each(function(){ 1880 $(this).parents('li').addClass('breadCrumbAbout'); 1881 }); 1882 1883} 1884 1885 1886function getTxtByLang2(arrayTxt) { 1887 var currentLang = 0; 1888 switch (feedin_ui_lang) { 1889 case 'zh-hk': 1890 currentLang = 1; 1891 break; 1892 case 'zh-cn': 1893 currentLang = 2; 1894 break; 1895 default: 1896 currentLang = 0; 1897 } 1898 return (arrayTxt[currentLang]); 1899} 1900 1901 1902// 15:07 2019-09-10 1903function ajaxWebCast() { 1904 1905 //console.log("ajaxWebCast"); 1906 //var webcast_json_en = 'https://www.isd.gov.hk/webcast/en/a1.js'; 1907 //var webcast_json_tc = 'https://www.isd.gov.hk/webcast/tc/a1.js'; 1908 //var webcast_json_sc = 'https://www.isd.gov.hk/webcast/sc/a1.js'; 1909 1910 // 12:08 2021-03-11 new webcast URL as request 1911 var webcast_json_en = 'https://webcast.info.gov.hk/govhk/en/a1.js'; 1912 var webcast_json_tc = 'https://webcast.info.gov.hk/govhk/tc/a1.js'; 1913 var webcast_json_sc = 'https://webcast.info.gov.hk/govhk/sc/a1.js'; 1914 1915 console.log("location.host = "+location.host); 1916 1917 console.log("location.host.index = "+location.host.indexOf("www.gov.hk") ); 1918 1919 // 16:42 2020-11-25 after apply CSP. only IE11 will see the webcast 1920 // 14:35 2021-02-04 NOTE: path cannot use "/webcast/en/a1.js" because CSP will have error) 1921 1922 // 11:38 2021-02-17 NOTE: JSONP cannot use in same domain under current CSP setting 1923 // 12:55 2021-02-04 testing path 1924 /* 14:55 2021-02-04 remark 1925 webcast_json_en = 'https://www.gov.hk/applications/webcast/en/a1.js'; 1926 webcast_json_tc = 'https://www.gov.hk/applications/webcast/tc/a1.js'; 1927 webcast_json_sc = 'https://www.gov.hk/applica
1927tions/webcast/sc/a1.js'; 1928 */ 1929 1930 // 14:26 2021-03-11 add ymdhms to clear cache 1931 // var webcast_json_curr = getTxtByLang2([webcast_json_en,webcast_json_tc,webcast_json_sc]); 1932 var webcast_json_curr = getTxtByLang2([webcast_json_en,webcast_json_tc,webcast_json_sc]) + "?" + ymdhms; 1933 1934 console.log('webcast_json_curr = ' + webcast_json_curr); 1935 1936 $.ajax({ 1937 async: true, 1938 type: 'GET', 1939 dataType: 'jsonp', 1940 url: webcast_json_curr 1941 }); 1942 1943} 1944 1945 1946// callback from ISD 1947// 15:21 2019-09-10 added 1948function WebCast(r) { 1949 1950 // alert('DoYouKnowr function called'); 1951 1952 //alert('DoYouKnow(r):start'); 1953 1954 var html = ''; 1955 var data = r.webcast; 1956 1957 1958 //console.log("WebCast:WebCastText: "+data.WebCastText); 1959 //console.log("WebCast:WebCastDisplay"+data.WebCastDisplay); 1960 //console.log("WebCast:WebCastTitle"+data.WebCastTitle); 1961 //console.log("WebCast:WebCastUrl"+data.WebCastUrl); 1962 //console.log("WebCast:WebCastTime"+data.WebCastTime); 1963 1964 1965 try { 1966 if (data.WebCastDisplay==1) { 1967 $("#WebCast").css('display', 'inline'); // 9:21 2020-01-06 R42 change back from block to inline 1968 $("#WebCast").attr('href', data.WebCastUrl); 1969 $("#WebCastText").html(data.WebCastText); 1970 $("#WebCastTitle").html(data.WebCastTitle); 1971 $("#WebCastTime").html(data.WebCastTime); 1972 } else { 1973 // 9:31 2019-10-24 CAUTION: remove the WebCast element (like NOT exist in HTML) 1974 $("#WebCast").remove(); 1975 //$("body").addClass("noWebCast"); // 9:24 2020-01-06 R42 removed 1976 } 1977 } catch(e) { 1978 // 9:31 2019-10-24 CAUTION: remove the WebCast element (like NOT exist in HTML) 1979 $("#WebCast").remove(); 1980 // $("body").addClass("noWebCast"); // 9:24 2020-01-06 R42 removed 1981 } 1982 1983 // 14:54 2019-12-04 try remove dynamicHomeTopPaddingTop as init.js function also removed 1984 //dynamicHomeTopPaddingTop(); 1985} 1986 1987 1988// ajax call to Do You Know JSONP 1989function ajaxDoYouKnow() { 1990 1991 // 14:31 2021-02-17 NOTE: CSP do NOT allow JSONP on local domain 1992 // 16:11 2019-11-25 use production directly 1993 // 12:00 2021-01-26 try use local, consider www.gov.hk will display slow in other site 1994 // 15:37 2021-01-26 cannot use ">=0" here, will case CSP error 1995 // 09:27 2021-02-02 seem not related, restore to ">=0" 1996 //if (location.host.indexOf("r4ts")!==false) 1997 1998 // 11:53 2021-02-17 condition for padding 1999 // 12:17 2021-02-17 use local as SC cannot display (fix by CSP add sc.news) 2000 // 14:29 2021-02-17 padding true use news.gov, false use local 2001 var padding = false; 2002 // 11:55 2021-02-17 init URL 2003 var do_you_know_json_en = ''; 2004 var do_you_know_json_tc = ''; 2005 var do_you_know_json_sc = ''; 2006 2007 if (padding==true) { 2008 2009 // 15:03 2021-02-16 change DoYouKnow source to NEWS.gov, CSP do NOT allow JSONP on local domain (either specify the domain or not) 2010 do_you_know_json_en = 'https://www.news.gov.hk/en/common/html/a1.js'; 2011 do_you_know_json_tc = 'https://www.news.gov.hk/tc/common/html/a1.js'; 2012 do_you_know_json_sc = 'https://sc.news.gov.hk/TuniS/www.news.gov.hk/tc/common/html/a1.js'; 2013 2014 } else { 2015 2016 // 11:08 2021-02-17 convert JSONP back to JSON via a2.php (then can use in local) 2017 do_you_know_json_en = '/en/json/doyouknow/a2.php'; 2018 do_you_know_json_tc = '/tc/json/doyouknow/a2.php'; 2019 do_you_know_json_sc = '/sc/json/doyouknow/a2.php'; 2020 } 2021 2022 2023 // do_you_know_json_(3 langs) from inline javascript variable 2024 var do_you_know_json_curr = getTxtByLang2([do_you_know_json_en,do_you_know_json_tc,do_you_know_json_sc]); 2025 console.log('do_you_know_json_curr = ' + do_you_know_json_curr); 2026 //console.log('call doyouknow 2'); 2027 2028 2029 if (padding==true) { 2030 // 11:07 2021-02-17 method via JSONP (MUST in different domain) 2031 $.ajax({ 2032 async: true, 2033 type: 'GET', 2034 dataType: 'jsonp', 2035 url: do_you_know_json_curr 2036 }); 2037 2038 } else { 2039 2040 // 11:07 2021-02-17 via JSON (SAME domain) 2041 $.ajax({ 2042 async: true, 2043 type: 'GET', 2044 dataType: 'json', 2045 url: do_you_know_json_curr, 2046 success: DoYouKnow 2047 }); 2048 } 2049 2050} 2051 2052 2053// 16:32 2019-11-25 function DoYouKnow(r) move to "/js/top-enhancement.js" 2054 2055function popDoYouKnowWindow() { 2056 2057 2058 // new pop up window for do you know - full (generic pop win cannot handle) 2059 //$('a[data-govhk-window="popup"]').on('click', function(e){ 2060 $('a[data-govhk-window^="doyouknow"]').each(function(e){ 2061 2062 var popW = 680; 2063 //var popH = 430; 10:28 2016-11-17 2064 var popH = 480; 2065 2066 // screen WH 2067 var scrW = screen.width; 2068 var scrH = screen.height; 2069 2070 // window XY,WH 2071 var winX = (document.all)?window.screenLeft:window.screenX; 2072 var winY = (document.all)?window.screenTop:window.screenY; 2073 var winW = $(window).width(); 2074 var winH = $(window).height(); 2075 2076 // popXY, calc it 2077 var popX = winX + (winW-popW)/2 - 10; 2078 var popY = winY + (winH-popH)/2 - 5; 2079 2080 // lower bound 2081 popX = (popX<0) ? 0 : popX; 2082 popY = (popY<0) ? 0 : popY; 2083 2084 // upper bound 2085 if (popX+popW>scrW) { popX = scrW-popW; } 2086 if (popY+popH>scrH) { popY = scrH-popH; } 2087 2088 var href = $(this).attr('href'); 2089 var win_name = $(this).attr('data-govhk-window'); 2090 2091 2092 $(this).on('click',function(e){ 2093 2094 if (e.button != 0) return; 2095 e.preventDefault(); 2096 2097 2098 if (win_name=='doyouknow-popup') { 2099 // popup 2100 var win = window.open(href, "_blank", "width="+popW+",height="+popH +",top="+popY+",left="+popX+",directories=no,menubar=no,scrollbars=no,status=yes,toolbar=no,resizable=no"); 2101 win.focus(); 2102 showEServiceSurvey($(this), win); 2103 } else { 2104 var win = window.open(href); 2105 showEServiceSurvey($(this), win); 2106 } 2107 2108 }); 2109 2110 2111 }); 2112} 2113 2114// 09:17 2021-02-26 obsolete after homepage revamp 2115function newsJson() { 2116 2117 //alert('newsJson'); 2118 2119 var newsfile = []; 2120 //newsfile['residents'] = 'highlight.json'; 2121 // 10:06 2018-01-09 rename for better understanding 2122 newsfile['residents'] = 'topstories.json'; 2123 newsfile['business'] = 'finance.json'; 2124 newsfile['nonresidents'] = 'city_life.json'; // 10:35 2016-07-21 fix word 2125 2126 //var feedin_lang = location.href.split('/')[3]; 2127 //var feedin_usergroup = location.href.split('/')[4]; 2128 2129 var news_json_curr = '/' +feedin_lang+ '/json/news/' + newsfile[feedin_usergroup]; 2130 2131 //////console.log("newsJson"); 2132 //alert('news_json_curr = ' + news_json_curr); 2133 2134 $.ajax({ 2135 async: true, 2136 type: 'GET', 2137 dataType: 'json', 2138 url: news_json_curr, 2139 success: newsJsonDisplay , 2140 error: newsJsonError 2141 }); 2142 2143} 2144 2145 2146// 09:17 2021-02-26 obsolete after homepage revamp 2147function newsJsonDisplay(json) { 2148 //alert("newsJsonDisplay"); 2149 2150 var js_channel = json.rss.channel; 2151 //var feedin_lang = location.href.split('/')[3]; 2152 var prop = { 2153 'en' : {'topstories':'Top Stories'}, 2154 'tc' : {'topstories':'é黿°è'}, 2155 'sc' : {'topstories':'éç¹æ°é»'} 2156 }; 2157 2158 var items_html = ""; 2159 2160 // html string for first 3 items 2161 for (var i=0;i<=2;i++) { 2162 var item_link = js_channel.item[i].link; 2163 var item_title = js_channel.item[i].title; 2164 var item_desc = js_channel.item[i].description; 2165 2166 //var j = i+1; 2167 var url_id = "#topStoriesUrl" + i; // it is "a" tag 2168 var title_id = "#topStoriesTitle" + i; 2169 2170 //alert('url_id = '+url_id); 2171 2172 // 10:27 2017-03-29 for https integration, remove protocol for news.gov.hk images 2173 // Note: have to remove the procotol before create DIV 2174 item_desc = item_desc.replace('http://sc.news.gov.hk/TuniS/www.news.gov.hk/','//www.news.gov.hk/'); 2175 item_desc = item_desc.replace('http://www.news.gov.hk/','//www.news.gov.hk/'); 2176 2177 // item link also 2017-03-31 2178 item_link = item_link.replace('http://www.news.gov.hk/','//www.news.gov.hk/'); 2179 //item_link = item_link.replace('http://sc.news.gov.hk/','//sc.news.gov.hk/'); 2180 2181 // create a div from rss, get the "img src"
2182 var div_img = $('<div>'+item_desc+'</div>'); 2183 var img_src = div_img.find('img').attr('src'); 2184 2185 2186 $(url_id+" h5").html(item_title); 2187 $(url_id+" ").attr('title',item_title); 2188 $(url_id+" ").attr('href',item_link); 2189 //alert('item link' + item_link); 2190 $(url_id+" img").attr('src',img_src); 2191 $(url_id+" img").attr('title',item_title); 2192 $(url_id+" img").attr('alt',item_title); 2193 } 2194} 2195 2196 2197// 09:17 2021-02-26 obsolete after homepage revamp 2198function newsJsonError(xhr,status) { 2199 ////console.log(status); 2200} 2201 2202// 16:15 2021-02-17 obsolete after homepage revamp 2203function weatherJson() { 2204 2205 // 11:52 2024-11-22 removed : obsolete code 2206} 2207 2208// 16:15 2021-02-17 obsolete after homepage revamp 2209// test 2210//getWarningString('tc1'); 2211function getWarningString(signal) { 2212 // 11:52 2024-11-22 removed : obsolete code 2213} 2214 2215 2216// 16:15 2021-02-17 obsolete after homepage revamp 2217// var a = getCurrentString(82); 2218function getCurrentString(weather_number) { 2219 2220 // 11:52 2024-11-22 removed : obsolete code 2221 2222} 2223 2224 2225 2226// 16:15 2021-02-17 obsolete after homepage revamp 2227function weatherJsonDisplay(json) { 2228 // 11:52 2024-11-22 removed : obsolete code 2229} 2230 2231// 16:15 2021-02-17 obsolete after homepage revamp 2232function weatherJsonError(xhr,status) { 2233 ////console.log(status); 2234} 2235 2236// 09:19 2021-02-26 not call in this file(?) 2237function convert_to_12h(time_str) { 2238 2239 var time = time_str.match(/(\d+):(\d+)/); 2240 var hours = Number(time[1]); 2241 var minutes = Number(time[2]); 2242 var meridian = 'AM'; // assume 2243 2244 if (hours == 0 ) { 2245 hours = hours + 12; 2246 } else if (hours > 12) { 2247 hours = hours - 12; 2248 meridian = 'PM' 2249 } else {} 2250 2251 var str = hours + ':'+ minutes + ' ' + meridian; 2252 2253 return str; 2254}; 2255 2256/* 2257 15:44 2020-06-11 showEServiceSurvey already redefine in uss_govhk.js 2258*/ 2259 2260/* 16:48 2016-05-26 KC: New window for application link */ 2261function popGenericWindow(container1) { 2262 2263 // 17:01 2018-12-07 get title from text 2264 // 11:14 2021-03-03 for web acc. - add tooltips to a-span if have (instead of a-only) 2265 $('a:not([title])').each(function(){ 2266 2267 // 09:25 2021-03-15 keep it simple first 2268 // 11:49 2021-05-21 remove extra spaces 2269 //let title = $(this).text(); 2270 let title = $(this).text().replace(/\s+/g,' ').trim(); 2271 $(this).attr('title',title); 2272 2273 /* 09:25 2021-03-15 just in case need to separate span 2274 // if a have span 2275 if ( $(this).find('span').length > 0 ) { 2276 // add title to each span 2277 $(this).find('span:not([title]').each(function(){ 2278 let title = $(this).text(); 2279 $(this).attr('title',title); 2280 }); 2281 } else { 2282 // if a NO span, add title (tooltips) 2283 let title = $(this).text(); 2284 $(this).attr('title',title); 2285 } 2286 */ 2287 }); 2288 2289 2290 2291 // first, if user input domain with www.gov.hk, remove it 2292 // 12:09 2017-06-01 remove https also 2293 if (location.pathname.includes('/cc/preview/')){ 2294 $('a[href^="http://www.gov.hk/"],a[href^="https://www.gov.hk/"]').each(function(){ 2295 var url = $(this).attr('href'); 2296 // 14:56 2020-12-22 if this item is fundraising audit report, NOT remove www.gov.hk (return) 2297 if ( url.indexOf('gov.hk/fundraisinginfo')>0 ) { return 0; } 2298 var parts = location.pathname.split("/"); 2299 var suffix = url.replace(/^.*\/\/[^\/]+/, ''); 2300 var url2 = "/cc/preview/"+parts[3]+"/"+parts[4]+"/"+parts[5] + suffix; 2301 $(this).attr('href',url2); 2302 }); 2303 }else{ 2304 $('a[href^="http://www.gov.hk/"],a[href^="https://www.gov.hk/"]').each(function(){ 2305 var url = $(this).attr('href'); 2306 2307 // 14:56 2020-12-22 if this item is fundraising audit report, NOT remove www.gov.hk (return) 2308 if ( url.indexOf('gov.hk/fundraisinginfo')>0 ) { return 0; } 2309 2310 var url2 = url.replace(/^.*\/\/[^\/]+/, ''); 2311 $(this).attr('href',url2); 2312 }); 2313 } 2314 // handle full popup window 2315 2316 2317 2318 // mark all pdf will open window (no matter internal or external) 2319 $('a[href$=".pdf"]').attr('data-govhk-window','new-full-win'); 2320 // 14:25 2017-09-05 update 2321 $('a[href$=".docx"]').attr('data-govhk-window','new-full-win'); 2322 2323 // 11:23 2017-03-10 2324 // mark all xml will open window (no matter internal or external) 2325 $('a[href$=".xml"]').attr('data-govhk-window','new-full-win'); 2326 2327 // 15:28 2016-10-31 theme site, will exist in content page only. 2328 // 10:00 2016-11-01ãadd business/bf 2329 // 15:07 2016-11-23 for production, open new win 2330 // 17:12 2017-09-15 change www to www.gov.hk 2331 // 9:18 2017-12-15 change to "www.gov.hk/" 2332 if (location.href.indexOf('www.gov.hk/')>0 ) { 2333 // 9:42 2017-03-24 2334 // $('a:not([href^="http"])[href*="/theme/bf"]').attr('data-govhk-window','new-full-win'); 2335 // 16:09 2017-03-31 remark it also 2336 // $('a:not([href^="http"])[href*="/business/bf"]').attr('data-govhk-window','new-full-win'); 2337 // 8:56 2017-05-31 remark 2338 // $('a:not([href^="http"])[href*="/theme/eprocurement"]').attr('data-govhk-window','new-full-win'); 2339 // 11:51 2017-10-31 remark 2340 //$('a:not([href^="http"])[href*="/theme/fundraising"]').attr('data-govhk-window','new-full-win'); 2341 // 8:48 2017-12-29 remark 2342 // $('a:not([href^="http"])[href*="/theme/govhknotifications"]').attr('data-govhk-window','new-full-win'); 2343 // 12:16 2018-02-07 remark 2344 //$('a:not([href^="http"])[href*="/theme/ilearnathome"]').attr('data-govhk-window','new-full-win'); 2345 $('a:not([href^="http"])[href*="/theme/wifi"]').attr('data-govhk-window','new-full-win'); 2346 } 2347 2348 2349 // 16:52 2016-09-23 : Yearbook 2350 $('a[href*="/about/abouthk/Yearbook.htm"]').attr('data-govhk-window','new-full-win'); 2351 2352 // if still start with http(s), it is external 2353 $('a[href^="http"]').attr('data-govhk-window','new-full-win'); 2354 2355 var allNoPopGenericWindowEles = document.querySelectorAll(".no_pop_generic_window"); 2356 var allNoPopGenericWindowList = Array.prototype.slice.call(allNoPopGenericWindowEles); 2357 2358 allNoPopGenericWindowList.forEach(function(noPopGenericWindowEle) { 2359 noPopGenericWindowEle.removeAttribute("data-govhk-window"); 2360 }); 2361 2362 2363 // 9:17 2016-08-19 share bar links 2364 //$('.shareBar a').attr('data-govhk-window','new-share-win'); 2365 2366 // moreover:
2367 // mark all apps link with apps window 2368 2369 // normal application 2370 // 11:25 2016-12-08 add "/docs/apps" (note: star match) 2371 $('a[href*="/en/apps/"], a[href*="/tc/apps/"], a[href*="/sc/apps/"], a[href*="/docs/apps/"]').each(function(){ 2372 if (location.pathname.includes('/cc/preview/') && !$(this).attr('href').includes('/cc/preview/')) $(this).attr('href', location.pathname.split('/').slice(0, 6).join('/') + $(this).attr('href')) 2373 var url = $(this).attr('href'); 2374 var pos = url.lastIndexOf("."); 2375 var wname = 'application-' + url.substring(9,pos); 2376 $(this).attr('data-govhk-window',wname); 2377 2378 // 10:42 2018-06-27 add "appslink" for styling 2379 $(this).addClass('appslink'); 2380 2381 // 16:05 2020-06-11 blindly add needEServiceSurvey class here for default USS case 2382 // 16:43 2020-09-08 remark: apps pop USS by JSON only 2383 // $(this).addClass('needEServiceSurvey'); 2384 2385 }); 2386 2387 // override: for etax 2388 $('a[href^="/en/apps/ird"], a[href^="/tc/apps/ird"], a[href^="/sc/apps/ird"]').each(function(){ 2389 var url = $(this).attr('href'); 2390 var pos = url.lastIndexOf("."); 2391 var wname = 'application-irdetaxhtm'; 2392 $(this).attr('data-govhk-window',wname); 2393 }); 2394 2395 // override: for eform.one.gov.hk 2396 $('a[href*="eform.one.gov.hk/"]').attr('data-govhk-window','application-eform-one-gov-hk'); 2397 2398 // 10:19 2018-03-22 for IMMD apps 2399 $('a[href*="govhkappswin"]').attr('data-govhk-window','application-govhkappswin'); 2400 2401 2402 2403 // 15:20 2018-05-29 container for govforms and online services 2404 let container2 = fixEmpty(container1,"") + " " ; 2405 ////console.log ( " container2 " + container2); 2406 2407 // new window - full 2408 // 12:17 2018-05-28 for not winattached 2409 //$('a[data-govhk-window="new-full-win"]').on('click', function(e){ 2410 $(container2+' a[data-govhk-window="new-full-win"]').on('click', function(e){ 2411 2412 if (e.button != 0) return; 2413 e.preventDefault(); 2414 2415 var href = $(this).attr('href'); 2416 2417 // 11:16 2019-07-30 2418 // //console.log("new-full-win "+href); 2419 2420 // 16:13 2017-12-07 check if it is ajax new dom element, if yes, add piwik outlink 2421 var ajax = fixEmpty($(this).attr('data-govhk-ajax'),0); 2422 if (ajax==1) { 2423 $(this).attr('data-govhk-ajax',2); 2424 try { 2425 pTracker1.setUserId(ws_userid); // added 11:50 2018-02-05 2426 pTracker1.trackLink( href, 'link'); 2427 } catch (e) {} 2428 } 2429 2430 2431 var win = window.open(href); 2432 2433 showEServiceSurvey($(this), win); 2434 2435 2436 }); 2437 2438 // new window - application 2439 // 12:17 2018-05-28 for not winattached 2440 //$('a[data-govhk-window^="application"]').on('click', function(e){ 2441 $(container2+' a[data-govhk-window^="application"]').on('click', function(e){ 2442 2443 //11:03 2018-12-05 remark 2444 //let feedin_app_win_index = 0; 2445 if (e.button != 0) return; 2446 e.preventDefault(); 2447 2448 var rel = $(this).attr('data-govhk-window'); 2449 //var wname = $(this).attr('data-govhk-window'); 14:35 2016-11-16 update for TD apps 2450 var wname = rel.substring(rel.lastIndexOf('-')+1); 2451 2452 var href = $(this).attr('href'); 2453 2454 // 16:13 2017-12-07 check if it is ajax new dom element, if yes, add piwik outlink 2455 var ajax = fixEmpty($(this).attr('data-govhk-ajax'),0); 2456 if (ajax==1) { 2457 $(this).attr('data-govhk-ajax',2); 2458 try { 2459 pTracker1.setUserId(ws_userid); // added 11:50 2018-02-05 2460 pTracker1.trackLink( href, 'link'); 2461 } catch (e) {} 2462 } 2463 2464 // 12:07 2018-12-05 use showEServiceSurvey 2465 var win = window.open(href, wname, "width="+screen.width+",height="+(screen.height-70) +",top=0,left=0,directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes"); 2466 win.focus(); 2467 2468 showEServiceSurvey($(this), win); 2469 2470 2471 }) 2472 2473 2474/* // new window - share bar 2475 $('a[data-govhk-window="new-share-win"]').on('click', function(e){ 2476 if (e.button != 0) return; 2477 e.preventDefault(); 2478 2479 var rel = $(this).attr('data-govhk-window'); 2480 var wname = $(this).attr('data-govhk-window'); 2481 var href = $(this).attr('href'); 2482 var win = window.open(href, wname, "width=300,height=200"+",top=300,left
2482=200,directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes"); 2483 win.focus(); 2484 }) */ 2485 2486} 2487 2488 2489// 14:57 2018-07-18 add for check app close 2490function check_app_close(win_index){ 2491 2492 if (feedin_app_win_obj[win_index] == null || feedin_app_win_obj[win_index].closed ) { 2493 //console.log('window '+win_index+' is closed <br>'); 2494 2495 // 15:13 2018-09-11 add condition, if this is first app close, balleon up 2496 // 2497 /*if (feedin_first_app_closed==false) {*/ 2498 2499 // Capture timestamp when the new window is closed 2500 var timeStampCloseExternalWindow = +new Date(); 2501 sessionStorage.setItem("timeStampCloseExternalWindow", timeStampCloseExternalWindow); 2502 2503 2504 if($.cookie("OeSSurvey") !== undefined) { 2505 //console.log("OeSSurvey is NOT undefined, so no survey"); 2506 sessionStorage.clear(); 2507 } else { 2508 //console.log("OeSSurvey is undefined, now open survey banner, this is an app link!"); 2509 2510 2511 2512 // 15:15 2018-07-18 show banner 2513 // 10:06 2018-10-10 with title 2514 surveyBannerAppear(feedin_app_win_title[win_index]); 2515 2516 } 2517 /*}*/ 2518 2519 // 15:14 2018-09-11 set flag for first app is closed 2520 /*feedin_first_app_closed = true;*/ 2521 2522 return; 2523 } else { 2524 //console.log('window '+win_index+' is still alive <br>'); 2525 } 2526 2527 setTimeout( check_app_close , 2000, win_index); 2528} 2529 2530 2531// 09:20 2021-02-26 in use 2532function searchKeyword() { 2533 2534 2535 $('.hotSearchHolder a').each(function(e){ 2536 2537 var keyword = $(this).text(); 2538 // 15:36 2017-01-13 2539 //var queryURL = 'http://www.search.gov.hk/search.html?ui_lang='+feedin_ui_lang+'&ui_charset=utf-8&query='+encodeURIComponent($.trim(keyword)); 2540 //var queryURL = '//' +search_domain_top+'/search.html?ui_lang='+feedin_ui_lang+'&ui_charset=utf-8&query='+encodeURIComponent($.trim(keyword)); 2541 // 10:43 2017-03-31 use deep domain 2542 var queryURL = '//' +search_domain_deep+'/search.html?ui_lang='+feedin_ui_lang+'&ui_charset=utf-8&query='+encodeURIComponent($.trim(keyword)); 2543 //alert('keyword = '+queryURL ); 2544 2545 $(this).attr('title',keyword); 2546 $(this).attr('href',queryURL); 2547 // change current window, no need to popup 2548 2549 }); 2550 2551} 2552 2553/* 255415:05 2016-09-09 function from "R3", use at top of js 2555*/ 2556function parseUrlVars(url) { 2557 var vars = [], hash; 2558 var hashes = url.slice(url.indexOf('?') + 1).split('&'); 2559 for(var i = 0; i < hashes.length; i++) 2560 { 2561 hash = hashes[i].split('='); 2562 vars.push(hash[0]); 2563 vars[hash[0]] = hash[1]; 2564 } 2565 return vars; 2566} 2567 2568/* ======= webstat start ======= */ 2569// for webstat: 20141120 add to 5 variable 2570var govhk_cluster = feedin_cluster 2571var w = Math.round($(window).width()/100)*100; 2572var h = Math.round($(window).height()/100)*100; 2573var ws_windowsize = w+'x'+h; 2574 2575// 9:24 2018-01-22 move ws variable here 2576// 9:44 2018-01-19 f_url now like "/en/residents/communication/mobilecomm" 2577// use to make "qq_url" only 2578 2579var rdpx = '?'; 2580//var f_url = self.location.pathname; 2581//17:36 2024-11-21 XSS prevention 2582var f_url = filterUntrustedChar(self.location.pathname); 2583 2584// 12:07 2018-01-16 replace "/index.htm" to "/" 2585// (NOTE: needed because "/en/residents/index.htm" need to replace "/index.htm" to blank 2586var f_url = f_url.replace(/\/index.htm/g,''); 2587 2588//////console.log('f_url = ' + f_url); 2589var qq_url = f_url.replace(/\//g,'::'); 2590var tpat = '::/target-'; 2591var tp2 = '/target/'; 2592var qq = '::'; 2593 2594// put current url to array "f" 2595// 9:05 2018-01-19 add else condition, add "qq" if not empty 2596var f = f_url.split('/'); 2597for (i=0;i<=4;i++) { 2598 var tempCheck = fixEmpty(f[i],""); 2599 if (tempCheck=="") { 2600 f[i] = ""; 2601 } else { 2602 f[i]=qq+f[i]; 2603 } 2604 //////console.log('fi'+i+' = yyy'+f[i]+'xxx'); 2605} 2606 2607// for different source 2608// 9:06 2018-01-19 remove "qq" since added in else condition 2609var qq_lang = f[1]; 2610var qq_usergroup = qq_lang + f[2]; 2611var qq_cluster = qq_usergroup + f[3]; 2612var qq_subcat = qq_cluster + f[4]; 2613 2614function ws_recordvisit(url, level) { 2615 2616 /* 2016-12-05 remark 2617 // 10:31 2016-11-23 store the visit path in cookie, 2618 // call stat only when path is different 2619 // check if visit same path 2620 var visit_path_level = "visit_path_" + level; 2621 visit_path_value = $.cookie(visit_path_level); 2622 //alert('ws_recordvisit, level=' + level + ' visit_path_value='+visit_path_value + ' url=' + url); 2623 2624 if (visit_path_value == url ) { 2625 return 0; 2626 } 2627 //alert('so do piwik'); 2628 2629 // record the path in cookie 2630 $.cookie(visit_path_level,url, {path:'/'}); 2631 */ 2632 2633 try { 2634 var i=level; 2635 var ws_string = '/visit_' + i + url; 2636 2637 // switch to new id 2638 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 2639 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 2640 pTracker2.setDocumentTitle('?visitlevel=::'+i); 2641 pTracker2.setCustomUrl(ws_string); 2642 pTracker2.trackPageView(); 2643 // back to org id 2644 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 2645 2646 /* 2647 // v by c 2648 _paq.push(['setSiteId', ws_siterdid]); 2649 _paq.push(['setDocumentTitle', '?visitlevel=::'+i]); 2650 _paq.push(['setCustomUrl', ws_string]); 2651 _paq.push(['trackPageView']); 2652 // change back to site1 2653 _paq.push(['setSiteId', ws_siteid]); 2654 _paq.push(['enableLinkTracking']); 2655 */ 2656 2657 } catch( err ) {} 2658} 2659function ws_visitbycluster(url) { 2660 var s = '/'; 2661 var path = s; 2662 var ws_string = ""; 2663 var level=6; 2664 var arr1 = new Array(0,0,0,0,0); 2665 var arr2 = new Array(); 2666 for (i=3;i<=level;i++) { 2667 utemp = url.split('/')[i]; 2668 if (typeof(utemp) !== 'undefined' && utemp != null && utemp!='') { 2669 path += utemp + s; 2670 arr1[i-2]=1; 2671 arr2[i-2]=path; 2672 } else { 2673 // quit early 2674 i=level+1; 2675 } 2676 } 2677 // CAUTION: cannot loop this 2678 // 9:53 2016-11-09: separate to different time 2679 // 10:04 2019-11-04 remove visit_1 and visit_2 2680 //i=1;if (arr1[i]==1) { ws_recordvisit(arr2[i], i); } 2681 //i=2;if (arr1[i]==1) { ws_recordvisit(arr2[i], i); } 2682 i=3;if (arr1[i]==1) { ws_recordvisit(arr2[i], i); } 2683 i=4;if (arr1[i]==1) { ws_recordvisit(arr2[i], i); } 2684 2685 /* 2686 i=1;if (arr1[i]==1) { setTimeout(function(){ ws_recordvisit(arr2[i], i); }, 100); } 2687 i=2;if (arr1[i]==1) { setTimeout(function(){ ws_recordvisit(arr2[i], i); }, 300); } 2688 i=3;if (arr1[i]==1) { setTimeout(function(){ ws_recordvisit(arr2[i], i); }, 600); } 2689 i=4;if (arr1[i]==1) { setTimeout(function(){ ws_recordvisit(arr2[i], i); }, 1000); } 2690 */ 2691 2692} 2693 2694function ws_formatpagetitle(url, pagetitle) { 2695 2696 // 20130510: remove path from pagetitle 2697 var title1 = pagetitle; 2698 /* remove GovHK prefix */ 2699 var title2 = title1.replace("GovHK 馿¸¯æ¿åºä¸ç«éï¼", ""); 2700 var title3 = title2.replace("GovHK:", ""); 2701 2702 return title3; 2703 2704} 2705 2706function ws_getpagetitle() { 2707 var pagetitle = document.title; 2708 var url = location.href; 2709 var fpt = ws_formatpagetitle(url, pagetitle); 2710 return fpt; 2711} 2712 2713/* ======= webstat end ======= */ 2714 2715// 09:21 2021-02-26 in use 2716// 10:10 2016-10-31 2717function about_page_fix() { 2718 2719 2720 // 16:20 2021-02-25 dont know which page still fulfill condition, but keep first 2721 if (!$('.innerPageHolder').length && $('.helpDesksContents')) { 2722 // 10:21 2016-10-31 for top level page content, add back "innerPageHolder" 2723 // except "mobileapps.htm" page 2724 if ( location.pathname.indexOf('/about/govdirectory/mobileapps.')>0 || location.pathname.indexOf('/about/govdirectory/mobileapps_')>0 ) { 2725 // do nothing 2726 } else { 2727 $('.helpDesksContents').wrap("<div class='innerPageHolder'></div>"); 2728 } 2729 } 2730 2731 /* 16:18 2021-02-25 obsoleted, page removed 2732 // 10:19 2016-10-31 fix for mobilewebsites table 2733 if ( location.pathname.indexOf('/about/govdirectory/mobilewebsites')>0 ) { 2734 $('.innerPageHolder').wrap("<div class='notifcationPage'></div>"); 2735 } 2736 */ 2737 2738} 2739 2740// 16:22 2021-02-25 move to bg , but seem obsolete 2741function mobileapps_page_fix() { 2742 2743 if ( location.pathname.indexOf('/about/govdirectory/mobileapps.')>0 || location.pathname.indexOf('/about/govdirectory/mobileapps_')>0 ) { 2744 // ======= do first ============ 2745 // 15:13 2016-11-01 if have "innerPageHolder", remove the class 2746 $('.innerPageHolder').removeClass('innerPageHolder'); 2747 // 14:32 2016-11-01: add hrefUI to ul 2748 $('section.blockItem ul').addClass('hrefUl'); 2749 2750 // if content have "h3", change to "blockItemAppIntro" class 2751 $('h3.blockContentTitle').parents('section').addClass('blockItemAppIntro').removeClass('blockItem'); 2752 $('.blockItemAppIntro a[href^="http"]').addClass('externalLink'); 2753 2754 // ======= container level ============ 2755 // 16:30 2016-10-25 mock FS design 2756 $('#innerPageSideNav').addClass('govDirMobileApp'); 2757 2758 // div.helpDesksContents 2759 $('.helpDesksContents').removeClass('helpDesksContents'); 2760 2761 // remove "article" container 2762 $('.shareBar').unwrap('article'); 2763 2764 // ======= big title level ============ 2765 // 14:31 2016-11-01: h3 change to h2 2766 $('h3.blockContentTitle').wrapInner('<h2 class="subMainTitle"></h2>'); 2767 $('h2.subMainTitle').unwrap('h3.blockContentTitle'); 2768 2769 // ======= apps level ============ 2770 // 16:55 2021-02-17 move to bg
2771 //$('.mobileAppTitle').wrapInner('<h4></h4>'); 2772 2773 2774 /* 12:08 2016-10-26 change DIMA link to brown - remove span add by FS */ 2775 /* 2776 var bpa = $('.blockContentWrap p a'); 2777 bpa.addClass('contentLink'); 2778 bpa.html(bpa.text()); 2779 */ 2780 2781 // ========= old version for reference ============== 2782 // remove left menu: done in css 2783 // $('aside.sideNav').remove(); 2784 2785 // expand content to 100% 2786 /* 16:24 2016-10-25 remark since change from theme to top level page content 2787 $('#innerPageSideNav').removeClass('block-3-4'); 2788 $('#innerPageSideNav').addClass('block-1-1'); 2789 */ 2790 2791 /* 2792 // 16:30 2016-10-25 mock FS design 2793 $('#innerPageSideNav').addClass('govDirMobileApp'); 2794 2795 // 17:04 2016-10-25 remove "article.blockDetailHolder.articleHolder" 2796 // $('.shareBar').unwrap('article'); 2797 2798 // 17:04 2016-10-25 remove 'div.innerPageHolder' 2799 //$('section.blockItem.helpDesksContents').unwrap('.innerPageHolder'); 2800 2801 // 17:10 2016-10-25 remove 2802 //$('.blockContentWrap').unwrap('section.blockItem.helpDesksContents'); 2803 2804 //$('.mobileAppTitle').wrapInner('<h4></h4>'); 2805 2806 //$('.blockContentWrap ul').addClass('hrefUl'); 2807 2808 $('h3.blockContentTitle').wrapInner('<h2 class="subMainTitle"></h2>'); 2809 $('h2.subMainTitle').unwrap('h3.blockContentTitle'); 2810 2811 // 12:08 2016-10-26 change DIMA link to brown - remove span add by FS 2812 var bpa = $('.blockContentWrap p a'); 2813 bpa.addClass('contentLink'); 2814 bpa.html(bpa.text()); 2815 */ 2816 } 2817 2818} 2819 2820 2821/* 14:12 2016-12-19: add for web stat */ 2822function wsaddhttp(url) { 2823 2824 // capture undefined url, avoid javascript error 2825 if (url==undefined) { return 'wsaddhttp-dummy'; } 2826 2827 //17:36 2024-11-21 XSS prevention 2828 urlc1 = filterUntrustedChar(location.href); 2829 rnum = urlc1.lastIndexOf('/'); 2830 urlc2 = urlc1.substr(0,rnum); 2831 urlc3 = location.host; 2832 2833 // external link 2834 // 17:10 2018-01-10 add starts-with "//" 2835 if (url.indexOf('//')==0 || url.indexOf('http:')==0 || url.indexOf('https:')==0 || url.indexOf('mailto:')==0) { 2836 return url; 2837 } else if (url.indexOf('/')==0) { 2838 // start with slash, add http and domain 2839 fullpath = 'http://'+urlc3+url; 2840 return fullpath; 2841 } else { 2842 // start with filename add http, domain and path 2843 fullpath = urlc2+'/'+url; 2844 return fullpath; 2845 } 2846} 2847 2848// 10:15 2016-12-22 webstat for mobileapps 2849function ws_other_capture() { 2850 2851 // mobile apps 2852 if (page_type=="mobileapps") { 2853 // redirect and webstat capture 2854 mobileapps_redirect(); 2855 } 2856} 2857 2858// 14:57 2017-02-06 added 2859function ws_ajaxsearch(q) { 2860 try { 2861 //17:36 2024-11-21 XSS prevention 2862 var oriPathName = filterUntrustedChar(location.href); 2863 2864 var f = oriPathName.split('/'); 2865 var s = '-'; 2866 2867 /* 2868 // "default" and "about" in case 9:53 2018-01-18 2869 var dt = "?R4-Keyword-Default=::"+q; 2870 if (f[4]=='about') dt = "?R4-Keyword-About=::"+q; 2871 // should be those only 9:53 2018-01-18 2872 if (f[5]=='govdirectory') dt = "?R4-Keyword-GovDir=::"+q; 2873 if (f[5]=='forms') dt = "?R4-Keyword-GovForm=::"+q; 2874 // 20140911: add for onlineservices tag cloud 2875 if (f[5]=='onlineservices') dt = "?R4-Keyword-OnlineServices=::"+q; 2876 2877 dt += ' ('+f[3]+s+f[4].substr(0,3)+s+f[5].substr(0,4)+s+f[6].substr(0,4)+')'; 2878 // switch to new id 2879 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 2880 pTracker2.setCustomUrl('/target/ajax'); 2881 pTracker2.setDocumentTitle(dt); 2882 pTracker2.trackPageView(); 2883 // back to org id 2884 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 2885 */ 2886 2887 // 10:42 2021-03-19 for know have ajax search 2888 console.log('ws_ajaxsearch: q is '+q); 2889 2890 // 10:26 2021-03-19 change "eformsearch" to "R4-Keyword-GovFormCatalogue" 2891 // rollback eform - start (16:22 2018-03-07) 2892 if (f[5]=='forms') { 2893 //var dt = "?eformsearch=::"+q; 2894 var dt = "?R4-Keyword-GovFormCatalogue::"+q; 2895 dt += ' ('+f[3]+s+f[4].substr(0,3)+s+f[5].substr(0,4)+s+f[6].substr(0,4)+')'; 2896 // switch to new id 2897 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 2898 pTracker2.setCustomUrl('/target/ajax'); 2899 pTracker2.setDocumentTitle(dt); 2900 pTracker2.trackPageView(); 2901 // back to org id 2902 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 2903 return; 2904 2905 } 2906 // rollback eform - end 2907 2908 /* === New 9:16 2018-01-22 === */ 2909 var rdtype = "R4-Keyword-Default="; 2910 if (f[4]=='about') rdtype = "R4-Keyword-About="; 2911 // govdirectory do not separate to "organ" and "alpha" 2912 if (f[5]=='govdirectory') rdtype = "R4-Keyword-GovDirectory="; 2913 if (f[5]=='forms') rdtype = "R4-Keyword-GovForm="; 2914 if (f[5]=='onlineservices') rdtype = "R4-Keyword-OnlineServices="; 2915 2916 // Note: "q" is query keyword 2917 var rdtitle = rdpx + rdtype + qq_subcat + qq + q; 2918 // switch to new id 2919 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 2920 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 2921 pTracker2.setCustomUrl(tp2+rdtype); 2922 pTracker2.setDocumentTitle(rdtitle); 2923 pTracker2.trackPageView(); 2924 // back to org id 2925 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 2926 2927 } catch( err ) {} 2928} 2929 2930function ws_folder_desc(level) { 2931 var desc = "Language"; 2932 if (level==1) desc="Language"; 2933 else if (level==2) desc="Homepage"; 2934 else if (level==3) desc="ClusterPage"; 2935 else if (level==4) desc="Sub-catPage"; 2936 else desc="FeatureArticlePage"; 2937 return desc; 2938} 2939 2940function ws_target_desc(tmp_href,tmp_hrefflag,tmp_id,tmp_linktext,tmp_linktitle) { 2941 var out = ""; 2942 2943 // if hrefflag=1, use full url 2944 var tmp_finalhref = tmp_href; 2945 if (tmp_hrefflag==1) { tmp_finalhref = wsaddhttp(tmp_href); } 2946 2947 // generate output string 2948 if (tmp_href.length > 1 && tmp_href.indexOf("javascript:")<0 ) { out=tmp_finalhref; } 2949 else if (tmp_id.length > 1) { out=tmp_id; } 2950 else if (tmp_linktext.length > 1) { out="link-text=" + tmp_linktext; } 2951 else if (tmp_linktitle.length > 1) { out="link-title=" + tmp_linktitle; } 2952 else { out="href="+tmp_href+",id="+tmp_id+",link-text="+tmp_linktext+",link-title="+tmp_linktitle; } 2953 2954 //alert('ws_target_desc: out is = '+out); 2955 //////console.log('ws_target_desc: out is = '+out); 2956 return out; 2957} 2958 2959// 11:51 2024-10-25 webstat domain 2960function ws_domain_capture() { 2961 2962 let hostname = location.hostname; 2963 if(hostname !== "www.gov.hk"){ 2964 2965 //2024-10-23 2966 var rdtype = 'GovHK-Domain='; 2967 var rdtitle = "?" + rdtype + "::" + hostname; 2968 2969 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 2970 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 2971 pTracker2.setCustomUrl(tp2+rdtype); 2972 pTracker2.setDocumentTitle(rdtitle); 2973 pTracker2.trackPageView(); 2974 2975 } 2976} 2977 2978// 11:51 2025-10-09 webstat blue 2979function ws_blue_capture() { 2980 2981 let para = location.search + location.hash; 2982 const urlRegex = /[^A-Za-z0-9 ?#|=,/._-]/g; 2983 if (urlRegex.test(para)) { 2984 2985 //2024-10-23 2986 var rdtype = 'GovHK-Blue='; 2987 var rdtitle = "?" + rdtype + "::" + encodeURI(location.pathname + para); 2988 2989 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 2990 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 2991 pTracker2.setCustomUrl(tp2+rdtype); 2992 pTracker2.setDocumentTitle(rdtitle); 2993 pTracker2.trackPageView(); 2994 2995 } 2996} 2997 2998// 17:13 2016-12-19 webstat new 2999function ws_area_capture() { 3000 3001 // do only when ws_health=2 3002 if (ws_health==2) { 3003 3004 try { 3005 3006 // 14:18 2018-01-16 all add "R4-" prefix 3007 // 15:37 2021-06-08 update as revamped 3008 //$('header #doYouKnow a').on('click', function(e){ 3009 $('#doYouKnowBtn a').on('click', function(e){ 3010 var rdtype = 'R4-header-DoYouKnow='; 3011 3012 // 15:30 2018-01-23 changed 3013 var tmp_href = fixEmpty($(this).attr('href'),""); 3014 var tmp_id = fixEmpty($(this).attr('id'),""); 3015 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3016 var tmp_linktext = fixEmpty($(this).text(),""); 3017 var tmp_target = ws_target_desc(tmp_href,0,tmp_id,tmp_linktext,tmp_linktitle); 3018 3019 var rdtitle = rdpx + rdtype + qq + tmp_target ; 3020 3021 // switch to new id 3022 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3023 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3024 pTracker2.setCustomUrl(tp2+rdtype); 3025 pTracker2.setDocumentTitle(rdtitle); 3026 pTracker2.trackPageView(); 3027 // back to org id 3028 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3029 }) 3030 3031 // header #topBar a - 10:57 2018-01-16 3032 $('header #topBar a').on('click', function(e){ 3033 var rdtype = 'R4-header-TopBar'; 3034 var tmp_id = fixEmpty($(this).attr('id'),"no-id"); 3035 var tmp_href = fixEmpty($(this).attr('href'),"no-href"); 3036 3037 // For 3 language switching, remove capture specific URL, thats not useful 3038 // like "ws-desktop-lang-en", "ws-earth-lang-tc" 3039 if ( tmp_id.indexOf('-lang-en')>0 || tmp_id.indexOf('-lang-tc')>0 || tmp_id.indexOf('-lang-sc')>0) { 3040 tmp_href=""; 3041 } 3042 3043 var rdtitle = rdpx + rdtype + qq + tmp_id + '-' + tmp_href ; 3044 // switch to new id 3045 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3046 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3047 pTracker2.setCustomUrl(tp2+rdtype); 3048 pTracker2.setDocumentTitle(rdtitle); 3049 pTracker2.trackPageView(); 3050 // back to org id 3051 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3052 }) 3053 3054 // header .logoBlock a - 10:57 2018-01-16 3055 $('header .logoBlock a').on('click', function(e){ 3056 var rdtype = 'R4-header-GovHKLogo'; 3057 3058 // 15:30 2018-01-23 changed 3059 var tmp_href = fixEmpty($(this).attr('href'),""); 3060 var tmp_id = fixEmpty($(this).attr('id'),""); 3061 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3062 var tmp_linktext = fixEmpty($(this).text(),""); 3063 var tmp_target = ws_target_desc(tmp_href,0,tmp_id,tmp_linktext,tmp_linktitle); 3064 3065 3066 var rdtitle = rdpx + rdtype + qq + tmp_target ; 3067 3068 // switch to new id 3069 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3070 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3071 pTracker2.setCustomUrl(tp2+rdtype); 3072 pTracker2.setDocumentTitle(rdtitle); 3073 pTracker2.trackPageView(); 3074 // back to org id 3075 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3076 }) 3077 3078 // 3 Usergroups (16:44 2018-11-19) 3079 $('.homeNav .tagArea a').on('click', function(e){ 3080 // 16:48 2018-11-19 change rdtype 3081 var rdtype = 'R4-HP-Usergroup'; 3082 3083 // 15:30 2018-01-23 changed 3084 var tmp_href = fixEmpty($(this).attr('href'),""); 3085 var tmp_id = fixEmpty($(this).attr('id'),""); 3086 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3087 var tmp_linktext = fixEmpty($(this).text(),""); 3088 var tmp_target = ws_target_desc(tmp_href,0,tmp_id,tmp_linktext,tmp_linktitle); 3089 3090 3091 var rdtitle = rdpx + rdtype + qq + tmp_target ; 3092 3093 // switch to new id 3094 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3095 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3096 pTracker2.setCustomUrl(tp2+rdtype); 3097 pTracker2.setDocumentTitle(rdtitle); 3098 pTracker2.trackPageView(); 3099 // back to org id 3100 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3101 }) 3102 3103 3104 // header nav a - 10:57 2018-01-16 3105 $('header nav a').on('click', function(e){ 3106 var rdtype = 'R4-header-FloatMenu'; 3107 3108 // 15:30 2018-01-23 changed 3109 var tmp_href = fixEmpty($(this).attr('href'),""); 3110 var tmp_id = fixEmpty($(this).attr('id'),""); 3111 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3112 var tmp_linktext = fixEmpty($(this).text(),""); 3113 var tmp_target = ws_target_desc(tmp_href,0,tmp_id,tmp_linktext,tmp_linktitle); 3114 3115 3116 var rdtitle = rdpx + rdtype + qq + tmp_target ; 3117 // switch to new id 3118 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3119 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3120 pTracker2.setCustomUrl(tp2+rdtype); 3121 pTracker2.setDocumentTitle(rdtitle); 3122 pTracker2.trackPageView(); 3123 // back to org id 3124 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3125 }) 3126 3127 3128 // footer 3129 $('footer a').on('click', function(e){ 3130 var rdtype = 'R4-CommonFooter='; 3131 /* 15:39 2018-01-18 same as header 3132 var href = $(this).attr('href'); 3133 var hturl = wsaddhttp(href); 3134 var rdtitle = rdpx + rdtype + qq_lang + tpat + hturl ; 3135 */ 3136 3137 var tmp_id = fixEmpty($(this).attr('id'),"no-id"); 3138 var tmp_href = fixEmpty($(this).attr('href'),"no-href"); 3139 var rdtitle = rdpx + rdtype + qq + tmp_id + '-' + tmp_href ; 3140 3141 // switch to new id 3142 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3143 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3144 pTracker2.setCustomUrl(tp2+rdtype); 3145 pTracker2.setDocumentTitle(rdtitle); 3146 pTracker2.trackPageView(); 3147 // back to org id 3148 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3149 }) 3150 3151 // 13:34 2020-12-14 should have "#chatbot_tc" only, but add for reserve 3152 $('#chatbot_tc, #chatbot_en, #chatbot_sc, #chatbo_btn').on('click', function(e){ 3153 var rdtype = 'R4-Chatbot='; 3154 var tmp_id = fixEmpty($(this).attr('id'),"no-id"); 3155 3156 3157 // 14:16 2020-12-14 capture browser url for this kind 3158 //17:36 2024-11-21 XSS prevention 3159 var tmp_href1 = filterUntrustedChar(location.pathname); 3160 var tmp_href2 = tmp_href1; 3161 // 09:24 2020-12-15 add "index.htm" if endswith slash 3162 var tmp2 = tmp_href1.slice(-1); 3163 if (tmp2=='/') { 3164 tmp_href2 += 'index.htm'; 3165 } 3166 var tmp_href9 = tmp_href2.replace(/\//g,"::"); 3167 3168 var rdtitle = rdpx + rdtype + qq + tmp_id + '-' + tmp_href9 ; 3169 3170 console.log("#chatbot_check href=" + tmp_href9); 3171 3172 // switch to new id 3173 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3174 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3175 pTracker2.setCustomUrl(tp2+rdtype); 3176 pTracker2.setDocumentTitle(rdtitle); 3177 pTracker2.trackPageView(); 3178 // back to org id 3179 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3180 }) 3181 3182 // 14:30 2021-06-29 add webcast (<a id="WebCast") 3183 $('#WebCast').on('click', function(e){ 3184 var rdtype = 'R4-HP-WebCast='; 3185 var href = $(this).attr('href'); 3186 var hturl = wsaddhttp(href); 3187 var rdtitle = rdpx + rdtype + qq_usergroup + tpat + hturl; 3188 // switch to new id 3189 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3190 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3191 pTracker2.setCustomUrl(tp2+rdtype); 3192 pTracker2.setDocumentTitle(rdtitle); 3193 pTracker2.trackPageView(); 3194 // back to org id 3195 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3196 }) 3197 3198 // 14:08 2021-06-29 already revamp 3199 // homepage banner, qq_usergroup (14:10 2018-01-16 keep same name) 3200 //$('#blockAnnounce a').on('click', function(e){ 3201 $('.hmNewAnnoucement a').on('click', function(e){ 3202 var rdtype = 'R4-HP-Banner='; 3203 var href = $(this).attr('href'); 3204 var hturl = wsaddhttp(href); 3205 var rdtitle = rdpx + rdtype + qq_usergroup + tpat + hturl; 3206 // switch to new id 3207 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3208 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3209 pTracker2.setCustomUrl(tp2+rdtype); 3210 pTracker2.setDocumentTitle(rdtitle); 3211 pTracker2.trackPageView(); 3212 // back to org id 3213 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3214 }) 3215 3216 // 14:35 2021-06-29 add HP-Guidebook 3217 $('.hmNewGuidebooks a').on('click', function(e){ 3218 var rdtype = 'R4-HP-Guidebook='; 3219 var href = $(this).attr('href'); 3220 var hturl = wsaddhttp(href); 3221 var rdtitle = rdpx + rdtype + qq_usergroup + tpat + hturl; 3222 // switch to new id 3223 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3224 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3225 pTracker2.setCustomUrl(tp2+rdtype); 3226 pTracker2.setDocumentTitle(rdtitle); 3227 pTracker2.trackPageView(); 3228 // back to o
3228rg id 3229 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3230 }) 3231 3232 // 15:34 2024-01-15 add HP-NewFeatures 3233 $('.hmNewLifeEvent a').on('click', function(e){ 3234 var rdtype = 'R4-HP-NewFeatures='; 3235 var href = $(this).attr('href'); 3236 var hturl = wsaddhttp(href); 3237 var rdtitle = rdpx + rdtype + qq_usergroup + tpat + hturl; 3238 3239 // switch to new id 3240 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3241 pTracker2.setUserId(ws_userid); 3242 pTracker2.setCustomUrl(tp2+rdtype); 3243 pTracker2.setDocumentTitle(rdtitle); 3244 pTracker2.trackPageView(); 3245 // back to org id 3246 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3247 }) 3248 3249 // 14:35 2021-06-29 add HP-SocialGroups 3250 $('.hmNewSocialGrps a').on('click', function(e){ 3251 var rdtype = 'R4-HP-SocialGroups='; 3252 var href = $(this).attr('href'); 3253 var hturl = wsaddhttp(href); 3254 var rdtitle = rdpx + rdtype + qq_usergroup + tpat + hturl; 3255 // switch to new id 3256 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3257 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3258 pTracker2.setCustomUrl(tp2+rdtype); 3259 pTracker2.setDocumentTitle(rdtitle); 3260 pTracker2.trackPageView(); 3261 // back to org id 3262 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3263 }) 3264 3265 /* 3266 // 14:05 2021-06-29 should obsolete 3267 // Top Stories (homepage) 3268 $('#blockTopStory a').on('click', function(e){ 3269 var rdtype = 'R4-HP-TopStories='; 3270 var href = $(this).attr('href'); 3271 var hturl = wsaddhttp(href); 3272 var rdtitle = rdpx + rdtype + qq_usergroup + tpat + hturl; 3273 // switch to new id 3274 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3275 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3276 pTracker2.setCustomUrl(tp2+rdtype); 3277 pTracker2.setDocumentTitle(rdtitle); 3278 pTracker2.trackPageView(); 3279 // back to org id 3280 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3281 }) 3282 */ 3283 3284 // Related Links - 11:35 2018-01-16, (hp, cluster) are different ID 3285 $('#block__related_links a, #related_links a, #tagRelatedLinks a').on('click', function(e){ 3286 var rdtype = 'R4-RelatedLinks='; 3287 var href = $(this).attr('href'); 3288 /* 8:59 2018-01-18 source change to SUBCAT (RelatedLinks) */ 3289 var count = (qq_subcat.match(/::/g)||[]).length; // count source url 3290 var f_desc = "-" + ws_folder_desc(count); 3291 var hturl = wsaddhttp(href); 3292 var rdtitle = rdpx + rdtype + qq + count + f_desc + qq_subcat + tpat + hturl; 3293 // switch to new id 3294 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3295 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3296 pTracker2.setCustomUrl(tp2+rdtype); 3297 pTracker2.setDocumentTitle(rdtitle); 3298 pTracker2.trackPageView(); 3299 // back to org id 3300 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3301 }) 3302 3303 /* BreadCrumb 11:56 2018-01-19 */ 3304 $('nav.contentWrapper ul.navigator a').on('click', function(e){ 3305 var rdtype = 'R4-BreadCrumb='; 3306 var href = $(this).attr('href'); 3307 var hturl = wsaddhttp(href); 3308 var rdtitle = rdpx + rdtype + qq_url + tpat + hturl; 3309 // switch to new id 3310 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3311 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3312 pTracker2.setCustomUrl(tp2+rdtype); 3313 pTracker2.setDocumentTitle(rdtitle); 3314 pTracker2.trackPageView(); 3315 // back to org id 3316 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3317 }) 3318 3319 /* LeftMenu 12:05 2018-01-19 */ 3320 $('aside.sideNav nav div.blockTagHolder a').on('click', function(e){ 3321 var rdtype = 'R4-LeftMenu='; 3322 3323 // 14:56 2018-01-31 3324 var tmp_href = fixEmpty($(this).attr('href'),""); 3325 var tmp_id = fixEmpty($(this).attr('id'),""); 3326 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3327 var tmp_linktext = fixEmpty($(this).text(),""); 3328 var tmp_target = ws_target_desc(tmp_href,1,tmp_id,tmp_linktext,tmp_linktitle); 3329 var rdtitle = rdpx + rdtype + qq_cluster + tpat + tmp_target ; 3330 3331 // switch to new id 3332 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3333 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3334 pTracker2.setCustomUrl(tp2+rdtype); 3335 pTracker2.setDocumentTitle(rdtitle); 3336 pTracker2.trackPageView(); 3337 // back to org id 3338 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3339 }) 3340 3341 // Top Online Services - 11:35 2018-01-16 (hp and cluster) 3342 $('#block__top_online_services a').on('click', function(e){ 3343 var rdtype = 'R4-TopOnlineServices='; 3344 var href = $(this).attr('href'); 3345 /* 8:59 2018-01-18 source change to cluster */ 3346 var count = (qq_cluster.match(/::/g)||[]).length; // count source url 3347 var f_desc = "-" + ws_folder_desc(count); 3348 var hturl = wsaddhttp(href); 3349 var rdtitle = rdpx + rdtype + qq + count + f_desc + qq_cluster + tpat + hturl; 3350 3351 // switch to new id 3352 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3353 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3354 pTracker2.setCustomUrl(tp2+rdtype); 3355 pTracker2.setDocumentTitle(rdtitle); 3356 pTracker2.trackPageView(); 3357 // back to org id 3358 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3359 }) 3360 3361 // Top Online Forms - 11:35 2018-01-16 (hp and cluster) 3362 $('#block__top_online_forms a').on('click', function(e){ 3363 var rdtype = 'R4-TopGovForms='; 3364 var href = $(this).attr('href'); 3365 /* 8:59 2018-01-18 source change to cluster only */ 3366 var count = (qq_cluster.match(/::/g)||[]).length; // count source url 3367 var f_desc = "-" + ws_folder_desc(count); 3368 var hturl = wsaddhttp(href); 3369 var rdtitle = rdpx + rdtype + qq + count + f_desc + qq_cluster + tpat + hturl; 3370 3371 // switch to new id 3372 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3373 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3374 pTracker2.setCustomUrl(tp2+rdtype); 3375 pTracker2.setDocumentTitle(rdtitle); 3376 pTracker2.trackPageView(); 3377 // back to org id 3378 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3379 }) 3380 3381 // 14:02 2021-06-29 update as already revamped 3382 // Check It Out (HomePage) 3383 // $('.checkItOutSlider a').on('click', function(e){ 3384 $('.hmNewCheckItOut a').on('click', function(e){ 3385 var rdtype = 'R4-HP-CheckItOut'; 3386 3387 // 14:34 2018-01-31 3388 var tmp_href = fixEmpty($(this).attr('href'),""); 3389 var tmp_id = fixEmpty($(this).attr('id'),""); 3390 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3391 var tmp_linktext = fixEmpty($(this).text(),""); 3392 var tmp_target = ws_target_desc(tmp_href,1,tmp_id,tmp_linktext,tmp_linktitle); 3393 var rdtitle = rdpx + rdtype + qq_usergroup + tpat + tmp_target ; 3394 3395 // switch to new id 3396 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3397 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3398 pTracker2.setCustomUrl(tp2+rdtype); 3399 pTracker2.setDocumentTitle(rdtitle); 3400 pTracker2.trackPageView(); 3401 // back to org id 3402 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3403 }) 3404 3405 3406 // 11 Cluster (on HomePage) 3407 // 15:42 2021-06-08 update as revamped 3408 //$('#blockInfoServices a').on('click', function(e){ 3409 $('.hmNewInfoService__items a').on('click', function(e){ 3410 var rdtype = 'R4-HP-ClusterTitle'; 3411 3412 // 14:34 2018-01-31 3413 var tmp_href = fixEmpty($(this).attr('href'),""); 3414 var tmp_id = fixEmpty($(this).attr('id'),""); 3415 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3416 var tmp_linktext = fixEmpty($(this).text(),""); 3417 var tmp_target = ws_target_desc(tmp_href,1,tmp_id,tmp_linktext,tmp_linktitle); 3418 var rdtitle = rdpx + rdtype + qq_usergroup + tpat + tmp_target ; 3419 3420 // switch to new id 3421 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3422 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3423 pTracker2.setCustomUrl(tp2+rdtype); 3424 pTracker2.setDocumentTitle(rdtitle); 3425 pTracker2.trackPageView(); 3426 // back to org id 3427 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3428 }) 3429 3430 // QuickLinks (on HomePage) 15:41 2021-06-08 update as revamped 3431 //$('#blockQuickLinks a').on('click', function(e){ 3432 $('.hmNewQuickLinks a').on('click', function(e){ 3433 var rdtype = 'R4-HP-QuickLink'; 3434 3435 3436 // 14:34 2018-01-31 3437 var tmp_href = fixEmpty($(this).attr('href'),""); 3438 var tmp_id = fixEmpty($(this).attr('id'),""); 3439 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3440 var tmp_linktext = fixEmpty($(this).text(),""); 3441 var tmp_target = ws_target_desc(tmp_href,1,tmp_id,tmp_linktext,tmp_linktitle); 3442 var rdtitle = rdpx + rdtype + qq_usergroup + tpat + tmp_target ; 3443 3444 // switch to new id 3445 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3446 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3447 pTracker2.setCustomUrl(tp2+rdtype); 3448 pTracker2.setDocumentTitle(rdtitle); 3449 pTracker2.trackPageView(); 3450 // back to org id 3451 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3452 }) 3453 3454 /* 3455 // 14:10 2021-06-29 should obsolete 3456 // Enquiries (on HomePage) 14:12 2018-01-16 3457 $('#blockEnquiries a').on('click', function(e){ 3458 var rdtype = 'R4-HP-Enquiry'; 3459 3460 // 14:34 2018-01-31 3461 var tmp_href = fixEmpty($(this).attr('href'),""); 3462 var tmp_id = fixEmpty($(this).attr('id'),""); 3463 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3464 var tmp_linktext = fixEmpty($(this).text(),""); 3465 var tmp_target = ws_target_desc(tmp_href,1,tmp_id,tmp_linktext,tmp_linktitle); 3466 var rdtitle = rdpx + rdtype + qq_usergroup + tpat + tmp_target ; 3467 3468 // switch to new id 3469 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3470 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3471 pTracker2.setCustomUrl(tp2+rdtype); 3472 pTracker2.setDocumentTitle(rdtitle); 3473 pTracker2.trackPageView(); 3474 // back to org id 3475 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3476 }) 3477 */ 3478 3479 // I Want To (Cluster) 3480 $('.wantToList a').on('click', function(e){ 3481 var rdtype = 'R4-IWantTo='; 3482 var href = $(this).attr('href'); 3483 var hturl = wsaddhttp(href); 3484 var rdtitle = rdpx + rdtype + qq_cluster + tpat + hturl; 3485 // switch to new id 3486 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3487 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3488 pTracker2.setCustomUrl(tp2+rdtype); 3489 pTracker2.setDocumentTitle(rdtitle); 3490 pTracker2.trackPageView(); 3491 // back to org id 3492 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3493 }) 3494 3495 // Cluster Banner (Cluster) 3496 $('#sliderDesktop a, #sliderTablet a').on('click', function(e){ 3497 var rdtype = 'R4-ClusterBanner='; 3498 var href = $(this).attr('href'); 3499 var hturl = wsaddhttp(href); 3500 var rdtitle = rdpx + rdtype + qq_cluster + tpat + hturl; 3501 // switch to new id 3502 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3503 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3504 pTracker2.setCustomUrl(tp2+rdtype); 3505 pTracker2.setDocumentTitle(rdtitle); 3506 pTracker2.trackPageView(); 3507 // back to org id 3508 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3509 }) 3510 3511 // 15:19 2021-03-03 move osof_fix() to bg 3512 // 08:45 2020-12-31 move to function and put higher 3513 // add Class: GovFormsFullList 3514 // add Class: OnlineServicesFullList 3515 // osof_fix(); 3516 3517 // Gov Forms Full List 3518 $('.GovFormsFullList .commonlyUsed a').on('click', function(e){ 3519 var rdtype = 'R4-GovFromFullList='; 3520 3521 // 15:29 2018-01-23 3522 var tmp_href = fixEmpty($(this).attr('href'),""); 3523 var tmp_id = fixEmpty($(this).attr('id'),""); 3524 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3525 var tmp_linktext = fixEmpty($(this).text(),""); 3526 var tmp_target = ws_target_desc(tmp_href,1,tmp_id,tmp_linktext,tmp_linktitle); 3527 3528 var rdtitle = rdpx + rdtype + qq_url + tpat + tmp_target; 3529 3530 // switch to new id 3531 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3532 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3533 pTracker2.setCustomUrl(tp2+rdtype); 3534 pTracker2.setDocumentTitle(rdtitle); 3535 pTracker2.trackPageView(); 3536 // back to org id 3537 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3538 }) 3539 3540 // Online Services Full List 3541 $('.OnlineServicesFullList .commonlyUsed a').on('click', function(e){ 3542 var rdtype = 'R4-OnlineServFullList='; 3543 3544 // 15:29 2018-01-23 3545 var tmp_href = fixEmpty($(this).attr('href'),""); 3546 var tmp_id = fixEmpty($(this).attr('id'),""); 3547 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 3548 var tmp_linktext = fixEmpty($(this).text(),""); 3549 var tmp_target = ws_target_desc(tmp_href,1,tmp_id,tmp_linktext,tmp_linktitle); 3550 3551 var rdtitle = rdpx + rdtype + qq_url + tpat + tmp_target; 3552 3553 // switch to new id 3554 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 3555 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 3556 pTracker2.setCustomUrl(tp2+rdtype); 3557 pTracker2.setDocumentTitle(rdtitle); 3558 pTracker2.trackPageView(); 3559 // back to org id 3560 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3561 }) 3562 3563 // Log Search as external link, added: 14:38 2018-02-22 3564 $('#searchFormMobMenu, #searchFormHome, #searchFormMenu').on('submit', function(e){ 3565 3566 var tmp_location = location.href; 3567 var tmp_domain = "//www.search.gov.hk/result?"; 3568 var tmp_all_q = $( this ).serialize(); 3569 var tmp_outlink = tmp_domain + tmp_all_q + "&location=" + tmp_location; 3570 3571 // 16:23 2019-11-14 fix for search autocomplete cannot click 3572 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 3573 3574 pTracker1.setUserId(ws_userid);
3575 pTracker1.trackLink( tmp_outlink, 'link'); 3576 3577 ////console.log( tmp_outlink); 3578 //alert(tmp_outlink); 3579 }) 3580 3581 3582 } catch( err ) {} 3583 3584 } // ws_health==2 3585 3586} 3587 3588// 15:19 2021-03-03 move osof_fix() to bg 3589// 08:50 2020-12-31 move from ws_area_capture for call 2 time (1 is matomo, 1 is doc.ready) to make sure have the class 3590function osof_fix() { 3591 3592 console.log("location.pathname = "+location.pathname); 3593 3594 // add Class: GovFormsFullList 3595 if ( location.pathname.indexOf('/residents/forms/')>0 || 3596 location.pathname.indexOf('/nonresidents/forms/')>0 || 3597 location.pathname.indexOf('/business/forms/')>0 3598 ) { 3599 $('body').addClass('GovFormsFullList'); 3600 } 3601 3602 // add Class: OnlineServicesFullList 3603 if ( location.pathname.indexOf('/residents/onlineservices/')>0 || 3604 location.pathname.indexOf('/nonresidents/onlineservices/')>0 || 3605 location.pathname.indexOf('/business/onlineservices/')>0 3606 ) { 3607 $('body').addClass('OnlineServicesFullList'); 3608 } 3609} 3610 3611// 10:02 2017-02-10 15:52 2017-01-18 3612// add random number 3613// for apps Piwik 3614function redirect_to(url, ran) { 3615 $(document).ready(function() { 3616 3617 // if have not 2nd parameter, set to zero 3618 if (ran === undefined) { 3619 ran = 0; 3620 } 3621 3622 var url2 = url.replace(/&/g, '&'); 3623 3624 // initialize target_url 3625 var target_url = url2; 3626 3627 // if apps need random number (mygovhk), add it. 3628 if (ran==1) { 3629 var sym = "?"; 3630 if (url2.indexOf('?')>0) sym = "&"; 3631 target_url = url2 + sym + 'GovHKCacheRandomNumber=' +Math.random(); 3632 } 3633 3634 location.href=target_url; 3635 }); 3636} 3637 3638// 10:37 2019-11-25 refactor 3639function theme_leftrightmenu() { 3640 3641 // ====== menu one and two ========== 3642 //console.log('theme_leftrightmenu0: '); 3643 3644 // 9:32 2019-11-22 if path up to 3rd folder only, do nothing and return 3645 if (menu_url_pattern == lang_cluster ) { 3646 return; 3647 } 3648 if (location.pathname.includes('/cc/preview/')) lang_subcat = location.pathname.split('/').slice(0, 6).join('/') + lang_subcat 3649 // menuone highlight (17:28 2019-11-21 may duplicate with feedin.js now) 3650 var menuone_hook = $('nav .blockTagHolder a[href^="'+lang_subcat+'"]'); 3651 //menuone_hook.addClass('active'); 3652 3653 // 9:33 2019-11-22 even URL have 4th folder only, should show sub-menu with 5th folders 3654 // menutwo add to menuone 3655 var menutwo = $('.blockTagHolderSub').detach(); 3656 menuone_hook.after(menutwo); 3657 3658 // init 3659 var lang_compare = location.pathname.includes('/cc/preview/') ? (location.pathname.split('/').slice(0, 6).join('/') + lang_folder_5) : lang_folder_5; 3660 3661 //console.log("feedin_folder_5 " + feedin_folder_5); 3662 //console.log("feedin_folder_5.length " + feedin_folder_5.length); 3663 3664 // 9:19 2019-11-22 add condition 3665 // Assumption (and keep) 3666 // MAIN menu item is 4th folder or files 3667 // SUB menu item is 5th folder or files (or with more folder or files) 3668 if (feedin_folder_5.length > 0) { 3669 // 9:52 2019-11-22 3670 // means have 5th file or folder, add "/" except BF theme site 3671 // as BF have some exception like: 3672 // 1. /en/theme/bf/communication/blg 3673 // 2. /en/theme/bf/advisory/intro 3674 3675 // 14:18 2020-01-02 for etax faq ie11 expand support 3676 // BUT lucky BF SUB menu item all have 5th folder or files. 3677 // if (feedin_cluster!=='bf' && !feedin_folder_5.includes('.htm') ) { 3678 if (feedin_cluster!=='bf' && feedin_folder_5.indexOf('.htm')<0 ) { 3679 lang_compare += "/"; 3680 } 3681 } else { 3682 // 10:51 2020-09-17 add else condition 3683 // for case "/en/theme/bf/smart" 3684 // if folder_5 is empty, either like: 3685 // "/en/theme/bf/smart" or "/en/theme/bf/smart/index.htm" ("index.htm" cropped) 3686 // only way to match the sub item "/en/theme/bf/smart/index.htm" is having "index.htm" (request user to add it) 3687 // compare with other sub item like "/en/theme/bf/smart/report/", it has 5th item "report/" 3688 lang_compare += '/index.htm'; 3689 } 3690 3691 // 10:32 2020-09-17 check 3692 // console.log('theme_leftrightmenu1: lang_compare=' + lang_compare); 3693 $('.blockTagHolderSub a[href^="'+lang_compare+'"]').addClass('active'); 3694 3695 // 16:28 2019-11-22 must in feedin.js? 3696 // function theme_rightmenu_init() { 3697 3698 // 10:46 2017-01-24 3699 // remove obsolete menutwo 3700 //alert('hello rightmenu'); 3701 $('#subMenuThematic .infoItem a').each(function () { 3702 var menutwo_id = $(this).data('target'); 3703
3704 //alert('menutwo_id=' + menutwo_id); 3705 3706 // NOTE: if have not menutwo id, go to page directly, do: 3707 // change: innerPageLink infoLink innerRow linkBlock 3708 // to: infoLink topicLink 3709 //if (!$(menutwo_id).length) { 3710 if ($(menutwo_id).length > 0 ) { 3711 // do nothing 3712 } else { 3713 $(this).removeData('target'); 3714 $(this).removeClass('innerPageLink infoLink innerRow linkBlock'); 3715 $(this).addClass('innerRow linkBlock'); 3716 } 3717 3718 }); 3719 3720 //console.log('theme_leftrightmenu2: lang_compare=' + lang_compare); 3721 // 10:29 2019-11-25 rightmenu active 3722 $('#subMenuThematic .infoItem a[href^="'+lang_compare+'"]').addClass('active'); 3723 3724} 3725 3726 3727 3728/* 12:13 2017-12-20 move to search.js 3729 17:24 2017-12-29 NOTE: still in use by AJAX 3730*/ 3731function validateForm(frontForm, lang) { 3732 var alertMsg = ['Please enter search keyword(s).', 'è«è¼¸å ¥æ¥è©¢å串ã', '请è¾å ¥æ¥è¯¢å串ã']; 3733 var currentLang = 0; 3734 switch (lang) { 3735 case 'zh-hk': 3736 currentLang = 1; 3737 break; 3738 case 'zh-cn': 3739 currentLang = 2; 3740 break; 3741 default: 3742 currentLang = 0; 3743 } 3744 3745 var flag = true; 3746 /* avoid null query */ 3747 var searchInput = $.trim(frontForm.find('.searchBar').val()); 3748 if (searchInput === '') { 3749 alert(alertMsg[currentLang]); 3750 flag = false; 3751 } 3752 return flag; 3753} 3754 3755 3756function store_lang_preference() { 3757 3758 $.govhk = { 3759 domain : '.' + location.host.split('.')[location.host.split('.').length-3] + '.' 3760 + location.host.split('.')[location.host.split('.').length-2] + '.' 3761 + location.host.split('.')[location.host.split('.').length-1] 3762 }; 3763 3764 $('a[data-govhk-lang]').click(function(e){ 3765 $.cookie('language', $(this).data('govhk-lang'), {expires:1, path:'/', domain:$.govhk.domain}); 3766 //2022-12-14 - fixing duplicated language record in cookie 3767 $.cookie('language', $(this).data('govhk-lang'), {expires:60, path:'/'}); 3768 }); 3769} 3770 3771/* 377209:23 2021-02-26 in use 377316:04 2017-11-17 ThemePage "lastRevision" is not inside "bottomBar" by HTML code 3774make "lastRevision" under "giveFeedback", within "bottomBar" 3775*/ 3776function bottom_bar_dom_fix() { 3777 3778 // 17:25 2020-02-26 giveFeedback is old element, remove if exist 3779 if ($('.bottomBar .giveFeedback').length) { 3780 $('.bottomBar .giveFeedback').remove(); 3781 } 3782 3783 // 16:45 2020-02-25 move feedbackFormWrapper by js (for preview site) 3784 if ($('.bottomBar #feedbackFormWrapper').length) { 3785 // do nothing, should moved by server program 3786 } else if ($('#feedbackFormWrapper').length) { 3787 // move to bottomBar 3788 var bottomBar = $('.bottomBar'); 3789 var fbForm = $('#feedbackFormWrapper').detach(); 3790 bottomBar.append(fbForm); 3791 } 3792 3793 // 9:20 2017-11-30 Note: bottomBar contains both giveFeedback and then lastRevision 3794 if ($('.lastRevision').length) { 3795 var bottomBar = $('.bottomBar'); 3796 var lastRevision = $('.lastRevision').detach(); 3797 bottomBar.append(lastRevision); 3798 } 3799 3800 3801} 3802 3803/* 14:40 2018-01-15 add function to handle tel in desktop */ 3804function page_is_phone() { 3805 3806 if( navigator.userAgent.match(/Android/i) 3807 || navigator.userAgent.match(/iPhone/i) 3808 || navigator.userAgent.match(/Windows Phone/i) 3809 ){ 3810 return true; 3811 } 3812 else { 3813 return false; 3814 } 3815} 3816 3817function format_tel() { 3818 3819 var is_phone = page_is_phone(); 3820 3821 if (is_phone==false) { 3822 $('a[href^="tel:"]').each(function() { 3823 // replace "a" with its content (phone number) 3824 $(this).replaceWith(this.childNodes); 3825 }); 3826 } 3827} 3828 3829/* ================================================================================================= 3830webstat 3831================================================================================================= */ 3832 3833function ws_fix_empty(val, initialValue){ 3834 if (typeof(val)===undefined || val == null ) { val = initialValue; } 3835 return val; 3836} 3837 3838// ======= 9:36 2018-02-02 ========== 3839// ======= ws_userid ================ 3840 3841var ws_userid = ws_fix_empty($.cookie("userid"),""); 3842var ws_user_logged = ws_fix_empty($.cookie("user_logged"),0); 3843 3844// call by footer 3845function ws_userid_init() { 3846 3847 ////console.log("init userid yyy" + ws_userid + "xxx"); 3848 3849 // if no userid, create iframe immediately (not after doc.ready) and get from webstat server 3850 if (ws_userid=='') { 3851 3852 ////console.log("empty userid here"); 3853 3854 // iframe location, 16:20 2018-12-05 add https 3855 var ws_get_userid_url = 'https://'+ws_sec_server+'/applications/webstat/get_userid.php?callback=?'; 3856 3857 $.ajax({ 3858 type:'GET', 3859 dataType:'jsonp', 3860 url:ws_get_userid_url 3861 }) 3862 3863 // callback is "ws_process_userid(userid)"; 3864 3865 } else { 3866 3867 // have userid in cookie 3868 // but have to log userid at first page of visit 3869 ////console.log("have userid, call ws_call_footer_async"); 3870 3871 3872 ws_call_footer_async(); 3873 } 3874 3875 // if it is first page of the visit 3876 //} else if (ws_user_logged==0) { 3877} 3878 3879// store userid on govhk and mark log-ged 3880function ws_process_userid(userid) { 3881 3882 ////console.log("ws_process_userid: init "); 3883 ////console.log("userid return is " + userid); 3884 3885 // set ws_userid (global variable) 3886 ws_userid = userid; 3887 3888 // set userid to cookie 3889 ws_set_cookie_long("userid", ws_userid); 3890 3891 3892 ////console.log("ws_process_userid: ended"); 3893 3894 ws_call_footer_async(); 3895 3896} 3897 3898function ws_call_footer_async() { 3899 3900 ////console.log("ws_call_footer_async: init"); 3901 3902 // check value to 1, not log on second page and more page 3903 // 9:51 2018-02-07 add path 3904 $.cookie("user_logged",1,{ path: '/'} ); 3905 3906 // call to footer function
3907 ws_footer_async_init(); 3908} 3909 3910 3911 3912function ws_set_cookie_long(cook_id, cook_value) { 3913 3914 var currentDate = new Date(); 3915 3916 // 30 days 3917 var dayExtend = 30; 3918 3919 // it is okay to add days, it will calculate to correct date 3920 var expirationDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+dayExtend, 0, 0, 0); 3921 3922 // store to cookie 3923 $.cookie(cook_id, cook_value,{ path: '/' ,expires:expirationDate}); 3924 3925} 3926 3927function ws_portal_capture_all() { 3928 3929 // v by c 3930 var url = location.href; 3931 ws_visitbycluster(url); 3932 3933 // area capture 3934 ws_area_capture(); 3935 3936 // other capture 3937 ws_other_capture(); 3938 3939 // for blue2025 3940 //ws_blue_capture(); 3941 3942 ws_domain_capture(); 3943} 3944 3945 3946// 09:25 2021-02-26 eform full list, try remove 3947// 16:02 2018-12-12 3948function fix_related_os_bar() { 3949 3950 // remove all bar first 3951 $("span.eformsNotes").replaceWith( 3952 function(_,content){ 3953 let html1 = content; 3954 ////console.log("content:"+content); 3955 let html2 = '<span class="eformsNotes">' + html1.replace(/\ \|\ /g,'') + '</span>'; 3956 return html2; 3957 } 3958 ); 3959 3960 // add all bar (n+2) is tested. 3961 $("span.eformsNotes a:nth-child(n+2)").before('<span class="eformsBar"> | </span>'); 3962 3963} 3964 3965 3966 3967// 11:01 2021-02-25 add 3968function eformJson() { 3969 3970 // 10:32 2021-03-02: this is global variable, not count "more" 3971 feedin_eform_total = $('a[data-formcatid]').length ; 3972 console.log("feedin_eform_total " + feedin_eform_total); 3973 3974 $('a[data-formcatid]').each(function(){ 3975 3976 var formcatid = $(this).attr('data-formcatid'); 3977 console.log("formcatid "+formcatid); 3978 // require: govhk_form_catalogue_domain (global) 3979 var url_json = govhk_form_catalogue_domain+'/json/form/'+formcatid+'.json'; 3980 3981 $.ajax({ 3982 async: true, 3983 type: 'GET', 3984 dataType: 'json', 3985 url: url_json, 3986 success: eformJsonClusterDisplay, 3987 error: eformJsonClusterError 3988 3989 }); 3990 3991 }); 3992 3993} 3994 3995 3996 3997 3998// 11:01 2021-02-25 add 3999function eformJsonClusterDisplay(json) { 4000 4001 /* debug 4002 var title_en = json.form.title_en; 4003 var url_en = json.form.url[0].urlEn; 4004 */ 4005 4006 var prop = { 4007 'en' : {'title':json.form.title_en, 'url':json.form.url[0].urlEn}, 4008 'tc' : {'title':json.form.title_tc, 'url':json.form.url[0].urlTc}, 4009 'sc' : {'title':json.form.title_sc, 'url':json.form.url[0].urlSc} 4010 }; 4011 4012 var json_title = prop[feedin_lang].title; 4013 var json_url1 = prop[feedin_lang].url; 4014 4015 var vars = parseUrlVars(json_url1); 4016 var formcatid = vars['formcatid']; 4017 4018 // 10:21 2021-03-02 add param for eform item on cluster page 4019 // 15:39 2021-03-10 remove "cluster=1" to align old method 4020 //var json_url9 = json_url1+"&cluster=1"; 4021 var json_url9 = json_url1; 4022 4023 console.log("json_url9" + json_url9); 4024 console.log("json_title" + json_title); 4025 console.log("formcatid" + formcatid); 4026 4027 $('a[data-formcatid='+formcatid+']').attr('title',json_title); 4028 $('a[data-formcatid='+formcatid+']').attr('href',json_url9); 4029 $('a[data-formcatid='+formcatid+']').html(json_title); 4030 4031 // if all eform json processed, handle those cannot display 4032 eformJsonClusterPostHandling(); 4033} 4034 4035// 10:53 2021-03-02 count++ as if error, will not call function eformJsonClusterDisplay 4036function eformJsonClusterError() { 4037 // if all eform json processed, handle those cannot display 4038 eformJsonClusterPostHandling(); 4039} 4040 4041 4042// 10:47 2021-03-02 added 4043function eformJsonClusterPostHandling() { 4044 4045 // NOTE: count++ first, when go here 4046 feedin_eform_processed++; 4047 console.log("feedin_eform_processed " + feedin_eform_processed); 4048 console.log("feedin_eform_total " + feedin_eform_total); 4049 4050 // if all eform json processed, handle those cannot display 4051 if ( feedin_eform_processed >= feedin_eform_total ) { 4052 4053 // 09:30 2021-03-15 if href is still start with "#", means cannot find the fromcatid from system, so hide it 4054 $('a[data-formcatid][href^="#"]').each(function(){ 4055 4056 var formcatid = $(this).attr('data-formcatid'); 4057 console.log("feedin_eform error: formcatid "+formcatid); 4058 // 14:00 2021-03-19 change hide to remove 4059 // 11:00 2021-03-02 it is "li a", so remove "li" 4060 //$(this).parent().hide(); 4061 $(this).parent().remove(); 4062 4063 }); 4064 4065 // 13:56 2021-03-19 if at least have one formcatid 4066 if ( $('a[data-formcatid]').length ) { 4067 // 09:27 2021-03-15 popup eform 4068 popGenericWindow(" #block__top_online_forms "); 4069 4070 if (typeof tagBlockHeighthandler === "function") { 4071 // safe call 4072 tagBlockHeighthandler(); 4073 } 4074 } else {
4075 // 13:57 2021-03-19 remove "div TGF pervious (TGF title)" and TGF (the list) 4076 $("#block__top_online_forms").prev('div').remove(); 4077 $("#block__top_online_forms").remove(); 4078 4079 // 14:18 2021-03-19 remove block need to "resize" whole page 4080 resize(); 4081 4082 } 4083 4084 } 4085 4086} 4087 4088/* 4089lang_redirect 409013:29 2021-06-07 just do redirect 4091*/ 4092 4093function lang_redirect(path_without_lang) { 4094 4095 console.log("lang_redirect 14:14 2022-12-08"); 4096 4097 // 20141203: use local function as run before govhklite.js 4098 function fixEmpty2(val, initialValue){ 4099 if (typeof(val)===undefined || val == null ) { val = initialValue; } 4100 return val; 4101 } 4102 4103 // 10:54 2021-06-07 replace host to "www.gov.hk" for easy compare 4104 var url2 = location.href.replace(location.hostname,"www.gov.hk"); 4105 console.log("url2="+url2); 4106 4107 // 10:49 2021-06-07: except "www.gov.hk/?", skip landing page and other redirection page 4108 // 20141105: note: skip landing page if possible 4109 if (url2.indexOf('gov.hk/?') >= 0) {} 4110 else { 4111 4112 var skiplang1 = fixEmpty2($.cookie('language'),''); 4113 var skiplang2 = ''; // Cookie -> user agent -> en -> default tc 2022-12-14 - new logic 4114 console.log("cookie = "+skiplang1); 4115 4116 // 20141203:check if skiplang1 exist (is not empty string) 4117 if (skiplang1) { 4118 // get lang from cookie 4119 //skiplang2 = skiplang1.substr(9,2); 4120 skiplang2 = skiplang1.slice(-2); 4121 } 4122 4123 if (skiplang2=='en' || skiplang2=='tc' || skiplang2=='sc') { 4124 // do nothing 4125 console.log("language ok = "+skiplang2); 4126 } else { 4127 console.log("language not ok "); 4128 // get lang from user agent 4129 var b1 = navigator.language || navigator.userLanguage; 4130 if( b1 ) { 4131 // 2022-12-14: default value base on browser setting 4132 skiplang2 = 'en'; 4133 } else { 4134 skiplang2 = 'tc'; 4135 } 4136 var b2 = b1.toLowerCase(); 4137 console.log("navigator language = "+b2); 4138 if (b2.indexOf('en')>=0 ) skiplang2 = 'en'; 4139 if (b2.indexOf('cn')>=0 ) skiplang2 = 'sc'; 4140 if (b2.indexOf('hk')>=0 || b2.indexOf('tw')>=0) skiplang2 = 'tc'; 4141 if (b2.indexOf('en-hk')>=0 || b2.indexOf('en_hk')>=0) skiplang2 = 'en'; 4142 } 4143 4144 console.log("skiplang1 = "+skiplang1); 4145 console.log("skiplang2 = "+skiplang2); 4146 4147 // 14:11 2021-06-07 cookie for full site 4148 $.cookie('language', 'language-'+skiplang2, {expires:60, path:'/'}); 4149 4150 //2022-12-15 - fixing duplicated language record in cookie 4151 $.cookie('language', 'language-'+skiplang2, {expires:1, path:'/', domain:'.'+location.host }); 4152 4153 var search = location.search; 4154 var url3 = '/'+skiplang2 + path_without_lang + search; 4155 console.log( 'url3 = '+url3); 4156 4157 //XSS protection 4158 var filtered_url =sanitize(url3); 4159 // go to target 4160 location.href = filtered_url; 4161 4162 } 4163 4164} 4165 4166// 14:36 2021-06-07 added 4167function feedin_lang_cookie() { 4168 4169 //save clicked language to cookie 4170 $('#en, #tc, #sc, #ws-earth-lang-en, #ws-earth-lang-tc, #ws-earth-lang-sc, #ws-desktop-lang-en, #ws-desktop-lang-tc, #ws-desktop-lang-sc').click(function(e){ 4171 4172 console.log("en tc sc clicked"); 4173 4174 // 14:30 2021-06-07 lang is last 2 characters 4175 // 11:08 2021-06-18 should add "language-" before 2 char 4176 // $.cookie('language', $(this).attr('id').slice(-2), {expires:60, path:'/'}); 4177 $.cookie('language', "language-"+$(this).attr('id').slice(-2), {expires:60, path:'/'}); 4178 4179 //2022-12-15 - fixing duplicated language record in cookie 4180 $.cookie('language', "language-"+$(this).attr('id').slice(-2), {expires:1, path:'/', domain:'.'+location.host }); 4181 4182 }); 4183 4184} 4185 4186 4187// 2023-08-11 - Popup Banner - ISD 2023 4188function initIdsPopupBanner() { 4189 4190 var dataUnit = 33; 4191 // Prod 4192 switch (feedin_ui_lang) { 4193 case 'zh-hk': 4194 dataUnit = 33; 4195 break; 4196 case 'zh-cn': 4197 dataUnit = 35; 4198 break; 4199 default: 4200 dataUnit = 34; 4201 } 4202 //stg 4203 // switch (feedin_ui_lang) { 4204 // case 'zh-hk': 4205 // dataUnit = 105; 4206 // break; 4207 // case 'zh-cn': 4208 // dataUnit = 107; 4209 // break; 4210 // default: 4211 // dataUnit = 106; 4212 // } 4213 //stg 4214 //let addDiv = "<div class='isd-promotion' data-unit='"+dataUnit+"' data-template='pop-up'></div>"; 4215 4216 //var windowWidth = $(window).width(); 4217 //if ($(window).width() > 767 && $(window).height() > 700) { 4218 // dataUnit -=3; 4219 //} 4220 4221 //Prod 4222 let addDiv = "<div class='isd-promotion' data-prod-unit='"+dataUnit+"' data-border-radius='10' data-template='pop-up'></div>"; 4223 let hotform = $("body"); 4224 hotform.append(addDiv); 4225 4226 let script = document.createElement('script'); 4227 //uat 4228 //script.src = "https://stg-promotion.isd.gov.hk/resources/isd-ps-sdk.min.js"; 4229 // prod 4230 script.src = "https://promotion.isd.gov.hk/resources/isd-ps-sdk.min.js"; 4231 //dev 4232 //script.src = "/js/isd-ps-sdk.min.js"; 4233 script.integrity = 'sha384-IWG5Vjhx7Vf8gqsV00y+9VpPvDT3XFlwBa895XJi8Lznf2ePnfgg7QYoyDNyyUh7%'; // integrity hash 4234 script.crossorigin = 'anonymous'; 4235 hotform.append(script); 4236} 4237 4238 4239// 2024-02-22 : To be removed: map.gov.hk js 4240function showPopupAdvancedMap( gmid, lang ) { 4241 4242 var lang2 = lang; 4243 4244 if ( lang != "en" ) { 4245 4246 lang2 = "tc"; 4247 } 4248 4249 var url = "https://www.map.gov.hk/gm/gmid/" + gmid + "?lg=" + lang2; 4250 4251 window.open( url, "_blank" ); 4252 4253 //2024-02-22 : check govmap stat 4254 var rdtype = 'R4-GovMap-Advanced='; 4255 var tmp_href = fixEmpty($(this).attr('href'),""); 4256 var tmp_id = fixEmpty($(this).attr('id'),""); 4257 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 4258 var tmp_linktext = fixEmpty($(this).text(),""); 4259 var tmp_target = ws_target_desc(tmp_href,1,tmp_id,tmp_linktext,tmp_linktitle); 4260 4261 var rdtitle = rdpx + rdtype + qq_url + tpat + tmp_target; 4262 4263 // switch to new id 4264 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 4265 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 4266 pTracker2.setCustomUrl(tp2+rdtype); 4267 pTracker2.setDocumentTitle(rdtitle); 4268 pTracker2.trackPageView(); 4269 // back to org id 4270 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 4271} 4272 4273function showPopupStaticMap( gmid, lang ) { 4274 4275 var lang2 = lang; 4276 4277 if ( lang != "en" ) { 4278 4279 lang2 = "tc"; 4280 } 4281 4282 var url = "https://www.map.gov.hk/mapviewer/map.do?gmid=" + gmid + "&lg=" + lang2; 4283 4284 window.open( url, "_blank" ); 4285 4286 //2024-02-22 : check govmap stat 4287 var rdtype = 'R4-GovMap-Static='; 4288 var tmp_href = fixEmpty($(this).attr('href'),""); 4289 var tmp_id = fixEmpty($(this).attr('id'),""); 4290 var tmp_linktitle = fixEmpty($(this).attr('title'),""); 4291 var tmp_linktext = fixEmpty($(this).text(),""); 4292 var tmp_target = ws_target_desc(tmp_href,1,tmp_id,tmp_linktext,tmp_linktitle); 4293 4294 var rdtitle = rdpx + rdtype + qq_url + tpat + tmp_target; 4295 4296 // switch to new id 4297 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 4298 pTracker2.setUserId(ws_userid); // 9:23 2018-02-05 added 4299 pTracker2.setCustomUrl(tp2+rdtype); 4300 pTracker2.setDocumentTitle(rdtitle); 4301 pTracker2.trackPageView(); 4302 // back to org id 4303 pTracker1 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siteid); 4304} 4305
4306//17:36 2024-11-21 XSS prevention 4307function sanitize(string) { 4308 //var filtered_url = url3.replace(/[^A-Za-z0-9 ?#|=,/._-]/g, ''); 4309 const map = { 4310 '&': '&', 4311 '<': '', 4312 '>': '', 4313 '"': '', 4314 "'": '', 4315 ";": '', 4316 }; 4317 const reg = /[<>"';]/ig; 4318 //var filtered_url = string.replace(reg, (match)=>(map[match])); // IE problem 4319 var filtered_url = string.replace(reg, ''); 4320 //return filtered_url.replaceAll('<', '').replaceAll('>', '').replaceAll('"', '').replaceAll('%22', '').replaceAll('%3C', '').replaceAll('%3E', ''); //not work in IE 4321 return filtered_url.replace(/</gi, '').replace(/>/gi, '').replace(/"/gi, '').replace(/%22/gi, '').replace(/%3C/gi, '').replace(/%3E/gi, ''); 4322} 4323 4324// This does not work only in IE 4325/*function escapingxss(string) { 4326 //var filtered_url = url3.replace(/[^A-Za-z0-9 ?#|=,/._-]/g, ''); 4327 const map = { 4328 '&': '&', 4329 '<': '<', 4330 '>': '>', 4331 '"': '"', 4332 "'": ''', 4333 "/": '/', 4334 ";": '', 4335 }; const reg = /[&<>"'/;]/ig; 4336 return string.replace(reg, (match)=>(map[match])); 4337}*/ 4338 4339function filterUntrustedChar(string) { 4340 return string.replace(/[^A-Za-z0-9 ?#|=,/._-]/g, ''); 4341} 4342 4343function checkOldBrowser() { 4344 var ua = navigator.userAgent.toLowerCase(); 4345 // 檢æ¥IE (å æ¬IE11以ä¸) 4346 if (ua.indexOf('msie') > -1 || ua.indexOf('trident') > -1) { 4347 $(".browser-warning").css("display", "block"); 4348 4349 //Disable popup 4350 return true; 4351 4352 /* Microsoft Internet Explorer detected in. */ 4353 var uilang = document.documentElement.getAttribute("lang"); 4354 var alertStr = 'ä½ æ£å¨ä½¿ç¨Internet Explorerç覽å¨ãåºæ¼å®å ¨çç±ï¼å»ºè°ä½ ä»¥ææ°çæ¬çç覽å¨é±è®ã馿¸¯æ¿åºä¸ç«éãã'; 4355 4356 switch (uilang) { 4357 case 'zh-hk': 4358 alertStr = 'ä½ æ£å¨ä½¿ç¨Internet Explorerç覽å¨ãåºæ¼å®å ¨çç±ï¼å»ºè°ä½ ä»¥ææ°çæ¬çç覽å¨é±è®ã馿¸¯æ¿åºä¸ç«éãã'; 4359 break; 4360 case 'zh-cn': 4361 alertStr = 'ä½ æ£å¨ä½¿ç¨Internet Exploreræµè§å¨ãåºäºå®å ¨çç±ï¼å»ºè®®ä½ ä»¥ææ°çæ¬çæµè§å¨é 读ã馿¸¯æ¿åºä¸ç«éãã'; 4362 break; 4363 default: 4364 alertStr = 'You are currently using Internet Explorer. For safety reasons, it is recommended to view GovHK with the latest version browser.'; 4365 } 4366 alert(alertStr); 4367 return true; 4368 } 4369 // å¯ä»¥æ·»å å ¶ä»èçè¦½å¨æª¢æ¥ï¼ä¾å¦èçSafariæFirefox 4370 // if (ua.indexOf('firefox') > -1 && parseInt(ua.split('firefox/')[1]) < 50) return true; 4371 return false; 4372} 4373 4374 4375 4376 4377/* 4378 added: detection for google translation 4379*/ 4380 4381$(document).ready(function() { 4382 var initialLang = $('html').attr('lang'); 4383 var translationTracked = false; 4384 var translateObserver = null; 4385 4386 function handleLangChange(currentLang) { 4387 if (translationTracked || currentLang === initialLang) return; 4388 4389 translationTracked = true; 4390 4391 console.log("Language changed from " + initialLang + " to " + currentLang + " (tracked)"); 4392 4393 //2026-06-19 Track 4394 var rdtype = 'GovHK-Translate='; 4395 var tmp_href1 = filterUntrustedChar(location.pathname); 4396 var tmp_href2 = tmp_href1.replace(/\//g,"::"); 4397 4398 var rdtitle = rdpx + rdtype + qq + initialLang + qq + currentLang + tpat + tmp_href2; 4399 4400 4401 pTracker2 = Piwik.getTracker("https://"+ws_server+"/piwik/piwik.php", ws_siterdid); 4402 pTracker2.setUserId(ws_userid); 4403 pTracker2.setCustomUrl(tp2+rdtype); 4404 pTracker2.setDocumentTitle(rdtitle); 4405 pTracker2.trackPageView(); 4406 4407 // Clear 4408 if (translateObserver) { 4409 translateObserver.disconnect(); 4410 translateObserver = null; 4411 console.log("Translation observer disconnected."); 4412 } 4413 } 4414 4415 translateObserver = new MutationObserver(function(mutations) { 4416 mutations.forEach(function(mutation) { 4417 if (mutation.attributeName === "lang") { 4418 var currentLang = $('html').attr('lang'); 4419 4420 handleLangChange(currentLang); 4421 } 4422 }); 4423 }); 4424 4425 translateObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['lang'] }); 4426 4427 // Clear 4428 $(window).on('beforeunload', function() { 4429 if (translateObserver) { 4430 translateObserver.disconnect(); 4431 } 4432 }); 4433}); 4434/* 4435 end: detection for google translation 4436*/ 4437 4438/* 4439--------- 444014:18 2020-01-02 for etax faq ie11 expand support 444115:17 2020-01-06 webcast R42 444217:03 2020-01-20 if os,of,govdir, not do submenu highlight (active), as govdir on all 3 usergroups
44438:55 2020-01-22 as discuss, still do highlight on os, of, govdir 444416:45 2020-02-25 move feedbackFormWrapper by js (for preview site) 444517:25 2020-02-26 giveFeedback is old element, remove if exist 444614:13 2020-03-06 update feedin_lang by location.pathname 444716:52 2020-03-09 update for ten folders 44488:36 2020-04-08 change to pathname for win refresh 444915:44 2020-06-11 hide showEServiceSurvey as already redefine in uss_govhk.js 445016:05 2020-06-11 blindly add needEServiceSurvey class here for default USS case 445115:57 2020-07-06 change HTML to not run rotating_banner_dom_fix gradually 445216:43 2020-09-08 remark: apps pop USS by JSON only 445310:57 2020-09-17 fix leftmenu for "/en/theme/bf/smart" highlight 445416:47 2020-11-25 CSP for webcast update 445511:31 2020-11-27 if dropmenu_title(2) still empty, use default text 445616:59 2020-12-10 jquery3 fix, fix (load),(size) 445709:41 2020-12-15 add matomo for chatbot first (updated) 445815:46 2020-12-22 if this item is fundraising audit report, NOT remove www.gov.hk (return) (2 areas) 445908:54 2020-12-31 osof_fix for iamsmart 4460--------- 4461*/
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.