PageSourceSearch

https://www.gov.hk/applications/survey_banner/health/survey_banner.js?20240508.155042

js www.gov.hk collected 2026-09-24 08:30:18 UTC 15,850 bytes, 405 lines download raw bytes

1function getCookieByNameByW3School(cname) {
2    var name = cname + "=";
3    var decodedCookie = decodeURIComponent(document.cookie);
4    var ca = decodedCookie.split(';');
5    for (var i = 0; i < ca.length; i++) {
6        var c = ca[i];
7        while (c.charAt(0) == ' ') {
8            c = c.substring(1);
9        }
10        if (c.indexOf(name) == 0) {
11            return c.substring(name.length, c.length);
12        }
13    }
14    return "";
15}
16
17/* Survey Banner Related -- start below */
18
19$(document).ready(function () {
20
21    /* Get Chatbot info function - start */
22    function findChatbotEle() {
23        var possibleChatbotEle = null;
24        var chatbotTCEle = document.getElementById('chatbot_tc');
25        var chatbotMessageEle = document.getElementById('chatbot_message');
26        var chatbotIllEle = document.getElementById('chatbot_ill');
27
28        if (chatbotTCEle !== undefined && chatbotTCEle !== null
29            && chatbotTCEle.offsetHeight > 0 && chatbotTCEle.offsetWidth > 0) {
30            possibleChatbotEle = chatbotTCEle;
31        }
32        else if (chatbotMessageEle !== undefined && chatbotMessageEle !== null
33            && chatbotMessageEle.offsetHeight > 0 && chatbotMessageEle.offsetWidth > 0) {
34            possibleChatbotEle = chatbotMessageEle;
35        }
36        else if (chatbotIllEle !== undefined && chatbotIllEle !== null
37            && chatbotIllEle.offsetHeight > 0 && chatbotIllEle.offsetWidth > 0) {
38            possibleChatbotEle = chatbotIllEle;
39        }
40        return possibleChatbotEle;
41    }
42
43    function setSurveyBannerExtraBottom(chatbotEle, bannerEle) {
44        var surveyBannerExtraBottom = 0;
45        var overlapChatbot = false;
46        var chatbotExist = false;
47
48        var chatbotEleHeight = 0;
49        var chatbotEleWidth = 0;
50        var chatbotEleTop = 0;
51        var chatbotEleRight = 0;
52        var chatbotEleBottom = 0;
53        var chatbotEleLeft = 0;
54
55        if (chatbotEle !== undefined && chatbotEle !== null) {
56            chatbotEleHeight = chatbotEle.offsetHeight;
57            chatbotEleWidth = chatbotEle.offsetWidth;
58            var tempRect = chatbotEle.getBoundingClientRect();
59            chatbotEleTop = tempRect.top;
60            chatbotEleRight = tempRect.right;
61            chatbotEleBottom = tempRect.bottom;
62            chatbotEleLeft = tempRect.left;
63        }
64
65        if (chatbotEleHeight > 0 && chatbotEleWidth > 0) {
66            chatbotExist = true;
67        }
68
69        if (chatbotExist) {
70            var envBoundRect = bannerEle.getBoundingClientRect();
71            var envBoundRectRight = envBoundRect.right;
72
73            if (chatbotEleLeft > 0 && envBoundRectRight >= chatbotEleLeft) {
74                overlapChatbot = true;
75            }
76        }
77
78
79        if (overlapChatbot) {
80            if (chatbotEleHeight > 0 && chatbotEleBottom > 0) {
81                if ((chatbotEleTop + 1) < bannerEle.offsetHeight) {
82                    surveyBannerExtraBottom = window.innerHeight - bannerEle.offsetHeight;
83                } else {
84                    surveyBannerExtraBottom = chatbotEleHeight + (window.innerHeight - chatbotEleBottom);
85                }
86            }
87        }
88
89        bannerEle.style.bottom = "".concat(surveyBannerExtraBottom, "px");
90    }
91    /* Get Chatbot info function - end */
92
93    var alignEleCenterHorizontal = function alignEleCenterHorizontal(ele) {
94        if (ele !== undefined && ele !== null) {
95            var eleWidth = ele.offsetWidth;
96
97            if (eleWidth > 0) {
98                ele.style.left = "50vw";
99                ele.style.marginLeft = "-".concat(eleWidth / 2, "px");
100            }
101        }
102    };
103
104    var isHomePage = function isHomePage(locationPathName) {
105        return ("/en/residents/" === locationPathName || "/tc/residents/" === locationPathName || "/sc/residents/" === locationPathName);
106    }
107
108    var isBAndTHomePage = function isBAndTHomePage(locationPathName) {
109        return ("/en/business/" === locationPathName || "/tc/business/" === locationPathName || "/sc/business/" === locationPathName);
110    }
111
112    var isResidentOnlineservicesPage = function isResidentOnlineservicesPage(locationPathName) {
113        return (locationPathName.indexOf("/en/residents/onlineservices/") !== -1
114            || locationPathName.indexOf("/tc/residents/onlineservices/") !== -1
115            || locationPathName.indexOf("/sc/residents/onlineservices/") !== -1);
116    }
117
118    /* Health, Law & Order Cluster Banner Related -- start below */
119
120    var isClusterHealth = function isClusterHealth(cluster) {
121        return "health" === cluster;
122    };
123
124    var showHealthSurveyBanner = function showHealthSurveyBanner() {
125      	
126        var websiteLang = location.href.split('/')[3];
127		// 20240508 Jasper: updated the if condition
128        if ((isHomePage(window.location.pathname) ||  (isClusterHealth(feedin_cluster))) &&
129            ($.cookie("HealthSurveyBannerClickedOrClosed") === undefined) &&
130            ($.cookie("HealthSurveyBannerShowCount") === undefined || parseInt($.cookie("HealthSurveyBannerShowCount")) < 5)
131        ) {
132            return true;
133        } else {
134          	return false;
135        }
136    };
137
138    var createHealthSurveyBannerClickOrCloseCookie = function createHealthSurveyBannerClickOrCloseCookie() {
139        var cookieExpDate = new Date(); // Set to End of Today
140
141        cookieExpDate.setHours(23);
142        cookieExpDate.setMinutes(59);
143        cookieExpDate.setSeconds(59);
144        $.cookie("HealthSurveyBannerClickedOrClosed", "Yes", {
145            expires: cookieExpDate,
146            path: '/'
147        });
148    };
149
150    var createAndOrAddHealthSurveyBannerShowCountCookie = function createAndOrAddHealthSurveyBannerShowCountCookie() {
151        var cookieExpDate = new Date(); // Set to End of Today
152
153        cookieExpDate.setHours(23);
154        cookieExpDate.setMinutes(59);
155        cookieExpDate.setSeconds(59);
156
157        if ($.cookie("HealthSurveyBannerShowCount") !== undefined && $.cookie("HealthSurveyBannerShowCount") !== null) {
158            var esbcVal = parseInt($.cookie("HealthSurveyBannerShowCount"));
159            esbcVal++;
160            $.cookie("HealthSurveyBannerShowCount", esbcVal, {
161                expires: cookieExpDate,
162                path: '/'
163            });
164        } else {
165            $.cookie("HealthSurveyBannerShowCount", 1, {
166                expires: cookieExpDate,
167                path: '/'
168            });
169        }
170    };
171
172    var healthBannerOverallEle = document.getElementById("govhk_survey_pop_health");
173    if (healthBannerOverallEle !== undefined && healthBannerOverallEle !== null) {
174
175        /* Window Rezise Event for align banner in center horizontal -- start */
176        var windowResizeTaskDelay = 1000; // must equal to healthBannerOverallEle.style.transitionDuration
177
178        var resizeTaskTimeout = null;
179        window.addEventListener('resize', function () {
180            if (resizeTaskTimeout !== null) {
181                clearTimeout(resizeTaskTimeout);
182            }
183
184            resizeTaskId = setTimeout(function () {
185                resizeTaskTimeout = null;
186                alignEleCenterHorizontal(healthBannerOverallEle);
187
188                setSurveyBannerExtraBottom(findChatbotEle(), healthBannerOverallEle);
189            }, windowResizeTaskDelay);
190        });
191        /* Window Rezise Event for align banner in center horizontal -- end */
192
193
194        var healthBannerShowAnimation = function healthBannerShowAnimation() {
195            healthBannerOverallEle.style.display = "block"; // must set to block first, otherwise offsetHeight = 0 when display = none
196
197            setTimeout(function () {
198                healthBannerOverallEle.style.bottom = "-".concat(healthBannerOverallEle.offsetHeight, "px");
199                alignEleCenterHorizontal(healthBannerOverallEle);
200            }, 1000);
201            setTimeout(function () {
202                healthBannerOverallEle.style.transitionDuration = "1s";
203                // healthBannerOverallEle.style.bottom = "0";
204                setSurveyBannerExtraBottom(findChatbotEle(), healthBannerOverallEle);
205                healthBannerOverallEle.style.transitionTimingFunction = "ease-out";
206            }, 1050);
207
208            createAndOrAddHealthSurveyBannerShowCountCookie();
209        };
210
211        var healthBannerHideAnimation = function healthBannerHideAnimation() {
212            healthBannerOverallEle.style.transitionDuration = "1s";
213            healthBannerOverallEle.style.transitionTimingFunction = "ease-in";
214            healthBannerOverallEle.style.bottom = "-".concat(healthBannerOverallEle.offsetHeight, "px");
215
216            setTimeout(function () {
217                healthBannerOverallEle.style.display = "none";
218            }, 2000);
219        };
220
221        var healthBannerHideAnimationTimer = null;
222
223        if (showHealthSurveyBanner()) {
224            setTimeout(function () {
225                healthBannerShowAnimation();	// 20240508 it takes 0s to show the whole banner
226            }, 0000);	// delay 2s before showing banner
227            //	It takes total 4s to completely show the banner after page load
228
229            healthBannerHideAnimationTimer = setTimeout(function () {
230                healthBannerHideAnimation();
231            }, 124000);	// Dismiss banner after completely showing banner for 120s
232        }
233
234        var healthBannerCloseEles = document.querySelectorAll('.survey_pop_health_close_btn');
235
236        var healthBannerCloseList = Array.prototype.slice.call(healthBannerCloseEles);
237
238        healthBannerCloseList.forEach(function (healthBannerCloseEle) {
239            healthBannerCloseEle.addEventListener('click', function () {
240                clearTimeout(healthBannerHideAnimationTimer);
241
242                createHealthSurveyBannerClickOrCloseCookie();
243
244                healthBannerHideAnimation();
245            });
246        });
247
248    }
249
250    var healthBannerMainSectionEle = document.querySelector('#survey_pop_health_main');
251
252    var healthBannerMainSectionAEle = document.querySelector('#survey_pop_health_main_a');
253
254    if (typeof healthBannerMainSectionAEle !== undefined && healthBannerMainSectionAEle !== null) {
255        var healthBannerClickCounter = 0;
256
257        healthBannerMainSectionAEle.addEventListener('click', function (event) {
258            event.preventDefault();
259            healthBannerClickCounter++;
260
261            if (healthBannerClickCounter === 1) {
262                clearTimeout(healthBannerHideAnimationTimer);
263
264                healthBannerMainSectionEle.classList.remove('cursorPointer');
265                healthBannerMainSectionEle.classList.add('cursorProgress');
266
267                createHealthSurveyBannerClickOrCloseCookie();
268
269                if (healthBannerMainSectionAEle.hasAttribute("href")) {
270                    var eleHref = healthBannerMainSectionAEle.getAttribute("href");
271
272                    var healthSurveyWin = window.open(eleHref);
273
274                    if (typeof healthSurveyWin !== undefined && healthSurveyWin !== null) {	// IE protective mode
275                        var healthSurveyWinTimer = setInterval(function () {
276                            if (healthSurveyWin.closed) {
277                                clearInterval(healthSurveyWinTimer);
278                                setTimeout(function () {
279                                    healthBannerHideAnimation();
280                                }, 300);
281                            }
282                        }, 1000);
283                    } else {
284                        healthBannerHideAnimation();
285                    }
286                }
287            }
288        });
289    }
290
291
292    var generateHealthSurveyGetURL = function generateHealthSurveyGetURL() {
293        // Get the data -- start
294        var healthSurveyHref = "https://scics.one.gov.hk/scics/Landing";
295        if (window.location.href.indexOf("www.gov.hk") !== -1 || window.location.href.indexOf("www0.gov.hk") !== -1) {
296//        if (window.location.href.indexOf("www.gov.hk") !== -1) {
297            // production url for healthSurveyHref
298             healthSurveyHref = "https://scics.one.gov.hk/scics/Landing";
299			// www0 url for healthSurveyHref
300			// healthSurveyHref = "https://scicsdev.one.gov.hk/scics/Landing";
301        }
302
303        // Initialize form data to empty string
304        var healthSurveyFormDataObj = {
305            applicationId: "",
306            language: "",
307            fb_url: "",
308            fb_id: "",
309            fb_page_type: "",
310            fb_language: "",
311            fb_usergroup: "",
312            fb_cluster: ""
313        };
314
315        healthSurveyFormDataObj.applicationId = "OGCS32";
316
317        healthSurveyFormDataObj.language = "en"
318        if (location.href.split('/').length > 3) {
319            var websiteLang = location.href.split('/')[3];
320            if (websiteLang !== 'en' && websiteLang !== 'tc' && websiteLang !== 'sc') {
321                websiteLang = 'en';
322            }
323            healthSurveyFormDataObj.language = websiteLang;
324            healthSurveyFormDataObj.fb_language = websiteLang;
325        }
326
327        healthSurveyFormDataObj.fb_url = location.href;
328
329
330        if (typeof getCookieByNameByW3School !== undefined && getCookieByNameByW3School !== null) {
331            healthSurveyFormDataObj.fb_id = getCookieByNameByW3School("userid");
332        }
333
334        healthSurveyFormDataObj.fb_page_type = "others";
335        if (typeof getUserExpPageType !== undefined && getUserExpPageType !== null) {
336            // function located in user_exp_common.js
337            var userExpPageType = getUserExpPageType();
338
339            if (userExpPageType !== null && userExpPageType.trim() !== "") {
340                healthSurveyFormDataObj.fb_page_type = userExpPageType;
341            }
342        }
343
344        if (location.href.split('/').length > 4) {
345            healthSurveyFormDataObj.fb_usergroup = location.href.split('/')[4];
346        }
347
348        if (location.href.split('/').length > 5) {
349            healthSurveyFormDataObj.fb_cluster = location.href.split('/')[5];
350        }
351      	//Jasper testing
352      	console.log(healthSurveyFormDataObj)
353        // Get the data -- end
354
355
356        //	Genereate a get string base on healthSurveyHref & healthSurveyFormDataObj
357        var finalFormGetURL = ""
358
359        finalFormGetURL += healthSurveyHref;
360
361        finalFormGetURL += "?"
362
363        var paramPairStrs = ""
364        for (var key in healthSurveyFormDataObj) {
365            if (healthSurveyFormDataObj.hasOwnProperty(key)) {
366                var paramPairStr = "&"
367                    .concat(encodeURIComponent(key), "=")
368                    .concat(encodeURIComponent(healthSurveyFormDataObj[key]));
369                paramPairStrs += paramPairStr;
370            }
371        }
372        if (paramPairStrs.length > 1) {
373            paramPairStrs = paramPairStrs.substr(1);
374        }
375        finalFormGetURL += paramPairStrs;
376
377        return finalFormGetURL;
378      //Jasper testing
379      	console.log(finalFormGetURL)
380    };
381
382    // Replace health & training survey a link href with param -- start
383    var healthSurveyAEles = document.querySelectorAll("a[href='https://scics.one.gov.hk/forms/ogcs32/ogcs32_en.html'], a[href='https://scics.one.gov.hk/forms/ogcs32/ogcs32_tc.html'], a[href='https://scics.one.gov.hk/forms/ogcs32/ogcs32_sc.html']")
384
385    var healthSurveyAList = Array.prototype.slice.call(healthSurveyAEles);
386
387    healthSurveyAList.forEach(function (healthSurveyAEle) {
388        healthSurveyAEle.href = generateHealthSurveyGetURL();
389
390        if (typeof getCookieByNameByW3School !== undefined
391            && getCookieByNameByW3School !== null
392            && "" === getCookieByNameByW3School("userid")) {
393            setTimeout(function () {
394                healthSurveyAEle.href = generateHealthSurveyGetURL();
395            }, 1000);
396        }
397    })
398    // Replace health & training survey a link href with param -- end
399
400    /* Health, Law & Order Banner Related -- End!!! */
401
402
403
404});
405/* Survey Banner Related -- End */

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.