PageSourceSearch

https://www.gov.hk/js/home-enhancement.js?20240112.153600

js www.gov.hk collected 2026-09-24 08:29:54 UTC 12,658 bytes, 367 lines download raw bytes

1
2
3/*
4function initSwiperSlider(){
5   return false;
6}
7*/
8
9function initHmNewCards(){
10   var $hmNewCards = $('.hmNewCards');
11   if (!$hmNewCards.length) {
12      return false;
13   }
14   $hmNewCards.each(function(){
15      var $this = $(this);
16      var $thisSlider = $this.find('.hmNewCards__slider');
17      var $thisSlides = $this.find('.hmNewCards__card');
18      var $thisSliderPages = $this.find('.hmNewCards__pages');
19      var $thisSliderControl = $this.find('.hmNewCards__control');
20      var slideCount = $thisSlides.length;
21      if($thisSlider.length){
22         var thisSliderEl = $thisSlider.get(0);
23         var options = {
24            slidesPerView: 4,
25            slidesPerGroup: 4,
26            spaceBetween:20,
27            breakpoints: {
28              // when window width is <= 1200px
29              1200: {
30                slidesPerView: 3,
31                slidesPerGroup: 3
32              },
33              // when window width is <= 640px
34              640: {
35                slidesPerView: 2,
36                slidesPerGroup: 2
37              },
38              // when window width is <= 480px
39              480: {
40                slidesPerView: 1,
41                slidesPerGroup: 1
42              }
43            },
44            onInit: function(swiper){
45              $thisSlider.addClass('swiper-container-initialized');
46            }
47         }
48         if($thisSliderPages.length){
49            var thisPagesEl = $thisSliderPages.get(0);
50            options['pagination'] = thisPagesEl;
51            options['paginationClickable'] = true;
52            options['paginationBulletRender'] = function (swiper, index, className) {
53                var slideIndex = (index + 1);
54                var btnTxt = getTxtByLang(['Go to slide '+slideIndex, '跳至第'+slideIndex+'頁', '跳至第'+slideIndex+'页']);
55                return '<button class="' + className + '"><span class="access">' + btnTxt + '</span></button>';
56             }
57            /*
58            options['pagination'] = {
59               el: thisPagesEl,
60               clickable: true,
61               renderBullet: function (index, className) {
62                  var slideIndex = (index + 1);
63                  var btnTxt = getTxtByLang(['Go to slide '+slideIndex, '跳至第'+slideIndex+'頁', '跳至第'+slideIndex+'页']);
64                  return '<button class="' + className + '"><span class="access">' + btnTxt + '</span></button>';
65               }
66            }
67            */
68         }
69         if($thisSliderControl.length){
70            var $thisSliderBtnNext = $this.find('.hmNewCards__btn-next');
71            var $thisSliderBtnPrev = $this.find('.hmNewCards__btn-prev');
72            var thisSliderBtnNextEl = $thisSliderBtnNext.get(0);
73            var thisSliderBtnPrevEl = $thisSliderBtnPrev.get(0);
74            options['nextButton'] = thisSliderBtnNextEl;
75            options['prevButton'] = thisSliderBtnPrevEl;
76            /*
77            options['navigation'] = {
78               nextEl: thisSliderBtnNextEl,
79               prevEl: thisSliderBtnPrevEl
80            }
81            */
82         }
83         var swiper = new Swiper(thisSliderEl, options);
84         /*
85         swiper.on('resize', function () {
86            resizeSlider();
87         });
88         */
89         resizeSlider();
90         $(window).resize(function(){
91            resizeSlider();
92         });
93         function resizeSlider(){
94            var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
95            var enableTouch = true;
96            if(windowWidth>1200 && slideCount<=4) {
97               enableTouch = false;
98            } else if(windowWidth>640 && slideCount<=3) {
99               enableTouch = false;
100            } else if(windowWidth>480 && slideCount<=2) {
101               enableTouch = false;
102            } else if(slideCount<2) {
103               enableTouch = false;
104            }
105            if(enableTouch){
106               $thisSlider.removeClass('swiper-no-swiping');
107            } else {
108               $thisSlider.addClass('swiper-no-swiping');
109            }
110         }
111      }
112   });
113}
114
115function initHmNewMobTabs(){
116   var $hmNewMobTabs = $('.hmNewMobTabs');
117   if (!$hmNewMobTabs.length) {
118      return false;
119   }
120   $hmNewMobTabs.each(function(){
121      var $this = $(this);
122      var $thisTab = $this.find('.hmNewMobTabs__tab');
123      var thisTabTxt = $thisTab.html();
124      var $thisToggle = $('<a href="#" class="hmNewMobTabs__tabToggle">'+thisTabTxt+'<span class="hmNewMobTabs__toggleGraphic"></span></a>');
125      $thisToggle.insertAfter($thisTab);
126      $thisToggle.on('click', function(e){
127         e.preventDefault();
128         if(!$this.hasClass('isActive')){
129            $this.addClass('isActive')
130         } else {
131            $this.removeClass('isActive')
132         }
133      });
134   });
135}
136
137$(document).ready(function(){
138   hmNewtitleFix();
139   initHmNewCards();
140   initHmNewMobTabs();
141   initHmNewBWVer();
142   initHmNewLifeEvent()
143   menuShadowHandler();
144   titleExtraSpaceFix();
145   fixBodyClass();
146});
147$(window).on('scroll', function(){
148   menuShadowHandler();
149});
150
151function fixedMenuHandler() {
152   return false;
153}
154function menuShadowHandler(){
155   var fromTop = $(document).scrollTop();
156   var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
157   //console.log('?????');
158   if (windowWidth <= 1200 && fromTop > windowHeight * 0.05) {
159      $('header .menuBar').addClass("shadow");
160   } else {
161      $('header .menuBar').removeClass("shadow");
162   }
163}
164
165function titleExtraSpaceFix(){
166   var $title = $('[title]');
167   if (!$title.length) {
168      return false;
169   }
170   for (var i = 0; i < $title.length; ++i) {
171     var $thisTitle = $title.eq(i);
172     var thisTitle = $thisTitle.attr('title').replace(/(\r\n|\n|\r)/gm, "").replace(/\s+/g, ' ').trim();
173     $thisTitle.attr('title',thisTitle);
174   }
175}
176
177
178function initHmNewBWVer(){
179   var test = getParameterByName('test');
180   if(test == 'BW' || $('body').hasClass('bwVer')){
181      if ($('body').hasClass('trident')) {
182         var $itemThumbs = $('.hmNewInfoService__itemThumb');
183         if ($itemThumbs.length) {
184            $itemThumbs.each(function(){
185               var $this = $(this);
186               var srcOri = $this.css('background-image');
187               var srcBW = srcOri.replace(/orange/g, 'bw');
188               $this.attr('data-bw-img', srcBW).data('bw-img', srcBW);
189            });
190         }
191         grayscale($('body'));
192         $('body').addClass('bwVer');
193         if ($itemThumbs.length) {
194            $itemThumbs.each(function(){
195               var $this = $(this);
196               var srcBW = $this.data('bw-img');
197               $this.css('background-image', srcBW);
198            });
199         }
200      } else {
201         $('body').addClass('bwVer');
202      }
203   }
204}
205
206function hmNewtitleFix(){
207   var $searchInput = $('input[type="search"], .searchBar');
208   if($searchInput.length){
209      $searchInput.each(function(){
210         var $this = $(this);
211         var thisTitleTxt = $this.attr('placeholder');
212         $this.attr('title', thisTitleTxt);
213      });
214   }
215   
216   var $hmHewCards = $('.hmNewCards__card');
217   if($hmHewCards.length){
218      $hmHewCards.each(function(){
219         var $this = $(this);
220         var thisTitleTxt = $this.find('.hmNewCards__cardTitle').text();
221         $this.attr('title', thisTitleTxt);
222      });
223   }
224   
225   var $hmNewLinkListTitle =  $('.hmNewLinkList__title');
226   if($hmNewLinkListTitle.length){
227      $hmNewLinkListTitle.each(function(){
228         var $this = $(this);
229         if($this.parent('a').length){
230            $this.unwrap();
231         }
232      });
233   }
234   
235}
236
237function getParameterByName(name, url) {
238    if (!url) url = window.location.href;
239    name = name.replace(/[\[\]]/g, "\\$&");
240    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
241        results = regex.exec(url);
242    if (!results) return null;
243    if (!results[2]) return '';
244    return decodeURIComponent(results[2].replace(/\+/g, " "));
245}
246
247function fixBodyClass(){
248   if($('body').hasClass('pageBusiness')){
249      $('body.pageBusiness').removeClass('pageResidents');
250      $('#residentsChildDir').removeClass('now');
251      $('#businessTradeChildDir').addClass('now');
252      $('#nonResidentsChildDir').removeClass('now');
253   }
254   if($('body').hasClass('pageNonResidents')){
255      $('body.pageNonResidents').removeClass('pageResidents');
256      $('#residentsChildDir').removeClass('now');
257      $('#businessTradeChildDir').removeClass('now');
258      $('#nonResidentsChildDir').addClass('now');
259   }
260}
261
262
263function initHmNewLifeEvent(){
264   var $hmNewCards = $('.hmNewLifeEvent__container');
265   if (!$hmNewCards.length) {
266      return false;
267   }
268   $hmNewCards.each(function(){
269      var $this = $(this);
270      var $thisSlider = $this.find('.hmNewLifeEvent__slider');
271      var $thisSlides = $this.find('.hmNewLifeEvent__item');
272      var $thisSliderPages = $this.find('.hmNewCards__pages');
273      var $thisSliderControl = $this.find('.hmNewLifeEvent__control');
274      var slideCount = $thisSlides.length;
275      if($thisSlider.length){
276         var thisSliderEl = $thisSlider.get(0);
277         var options = {
278            slidesPerView: 6,
279            slidesPerGroup: 3,
280            spaceBetween:20,
281            breakpoints: {
282              // when window width is <= 1200px
283              1200: {
284                slidesPerView: 4,
285                slidesPerGroup: 4
286              },
287              // when window width is <= 640px
288              640: {
289                slidesPerView: 3,
290                slidesPerGroup: 3
291              },
292              // when window width is <= 480px
293              480: {
294                slidesPerView: 2,
295                slidesPerGroup: 2
296              }
297            },
298            onInit: function(swiper){
299              $thisSlider.addClass('swiper-container-initialized');
300            }
301         }
302         if($thisSliderPages.length){
303            var thisPagesEl = $thisSliderPages.get(0);
304            options['pagination'] = thisPagesEl;
305            options['paginationClickable'] = true;
306            options['paginationBulletRender'] = function (swiper, index, className) {
307                var slideIndex = (index + 1);
308                var btnTxt = getTxtByLang(['Go to slide '+slideIndex, '跳至第'+slideIndex+'頁', '跳至第'+slideIndex+'页']);
309                return '<button class="' + className + '"><span class="access">' + btnTxt + '</span></button>';
310             }
311            /*
312            options['pagination'] = {
313               el: thisPagesEl,
314               clickable: true,
315               renderBullet: function (index, className) {
316                  var slideIndex = (index + 1);
317                  var btnTxt = getTxtByLang(['Go to slide '+slideIndex, '跳至第'+slideIndex+'頁', '跳至第'+slideIndex+'页']);
318                  return '<button class="' + className + '"><span class="access">' + btnTxt + '</span></button>';
319               }
320            }
321            */
322         }
323         if($thisSliderControl.length){
324            var $thisSliderBtnNext = $this.find('.hmNewLifeEvent__btn-next');
325            var $thisSliderBtnPrev = $this.find('.hmNewLifeEvent__btn-prev');
326            var thisSliderBtnNextEl = $thisSliderBtnNext.get(0);
327            var thisSliderBtnPrevEl = $thisSliderBtnPrev.get(0);
328            options['nextButton'] = thisSliderBtnNextEl;
329            options['prevButton'] = thisSliderBtnPrevEl;
330            /*
331            options['navigation'] = {
332               nextEl: thisSliderBtnNextEl,
333               prevEl: thisSliderBtnPrevEl
334            }
335            */
336         }
337         var swiper = new Swiper(thisSliderEl, options);
338         /*
339         swiper.on('resize', function () {
340            resizeSlider();
341         });
342         */
343         resizeSlider();
344         $(window).resize(function(){
345            resizeSlider();
346         });
347         function resizeSlider(){
348            var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
349            var enableTouch = true;
350            if(windowWidth>1200 && slideCount<=4) {
351               enableTouch = false;
352            } else if(windowWidth>640 && slideCount<=3) {
353               enableTouch = false;
354            } else if(windowWidth>480 && slideCount<=2) {
355               enableTouch = false;
356            } else if(slideCount<2) {
357               enableTouch = false;
358            }
359            if(enableTouch){
360               $thisSlider.removeClass('swiper-no-swiping');
361            } else {
362               $thisSlider.addClass('swiper-no-swiping');
363            }
364         }
365      }
366   });
367}

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.