PageSourceSearch

https://www.gov.taipei/Scripts/jUtil.js

js gov.taipei collected 2026-10-01 08:56:40 UTC 12,251 bytes, 364 lines download raw bytes

1function getParameterByName(name) {
2    var url = encodeURI(window.location.toString());
3    var str = "";
4    var str_value = "";
5    if (url.indexOf("?") != -1) {
6        var ary = url.split("?")[1].split("&");
7        for (var i in ary) {
8            str = ary[i].toString().split("=")[0];
9            if (str == name) {
10                str_value = ary[i].toString().split("=")[1];
11            }
12        }
13    }
14    return str_value;
15}
16//Jason 設定選單
17$(function () {
18    var sNode = getParameterByName('n');
19    $('.minor-nav').find('ul').find('a').each(function () {
20        if (sNode == '') return;
21        if ($(this).attr('href').indexOf('n=' + sNode) > -1) {
22            $(this).parent().parent().addClass('is-active');
23        }
24    });
25})
26
27//Jason ccms_hitcount 計算點擊數
28$(function () {
29    $('[data-ccms_hitcount]').click(function () {
30        var sUrl = '/Common/GetVisitcount.ashx?s=' + $(this).data('ccms_hitcount') + '&sms=' + getParameterByName('sms');
31        $.ajax({
32            url: sUrl,
33            type: 'POST',
34            success: function (date) {
35                //$('#footer_visitcount_span').html(date);
36            }
37        });
38    })
39
40    $('[data-DefaultModule_hitcount]').unbind('click').click(function () {
41        var sUrl = '/Common/GetVisitcount.ashx?s=' + $(this).data('ccms_hitcount') + '&sms=' + $(this).data('sms');
42        $.ajax({
43            url: sUrl,
44            type: 'POST',
45            success: function (date) {
46                //$('#footer_visitcount_span').html(date);
47            }
48        });
49    })
50
51    $('[data-ccms_hitcount_relfile]').each(function () {
52        $(this).click(function (e) {
53            var sUrl = '/Common/GetVisitcount.ashx?type=relfile&s=' + $(this).data('ccms_hitcount_relfile');
54            $.ajax({
55                url: sUrl,
56                type: 'POST',
57                success: function (date) {
58                    //$('#footer_visitcount_span').html(date);
59                }
60            });
61        })
62    })
63    if (typeof (CCMS_SitesSN_Encryption) != 'undefined') {
64        var sUrl = '/Common/GetVisitcount.ashx?sitessn=' + CCMS_SitesSN_Encryption;
65        if (window.getParameterByName && getParameterByName('n') != '') {
66            sUrl = sUrl + '&n=' + getParameterByName('n') + '&sms=' + getParameterByName('sms') + '&s=' + getParameterByName('s')
67        }
68        $.ajax({
69            url: sUrl,
70            type: 'POST',
71            success: function (date) {
72                if ($('#footer_visitcount_span')) {
73                    $('#footer_visitcount_span').text(date);
74                }
75            }
76        });
77    }
78})
79
80
81//data-fancyboxOpen 用fancybox 打開連結
82$(function () {
83    //$('[data-fancyboxOpen]').click(function (e) {
84    //    e.preventDefault();
85    //    var Src = $(this).data('fancyboxopen');
86    //    $.fancybox.open({
87    //        href: Src,
88    //        type: 'iframe',
89    //        padding: 20,
90    //        autoSize: false,
91    //        height: 150
92    //    });
93    //})
94
95    $('[data-fancyboxOpen]').click(function (e) {
96        e.preventDefault();
97        var index = $('[data-fancyboxOpen]').index(this);
98        var Src = $(this).data('fancyboxopen');
99        $.fancybox.open({
100            href: Src,
101            type: 'iframe',
102            padding: 20,
103            autoSize: false,
104            height: 150,
105            afterShow: function () {
106                $(this.content).focus();
107            },
108            beforeClose: function () {
109                $("[data-fancyboxOpen]").eq(index).focus();
110            }
111        });
112    });
113
114    $(document).on('keydown', '.fancybox-close', function (event) {
115        if (event.keyCode == 9) {
116            event.stopPropagation();
117            event.preventDefault();
118            $.fancybox.close();
119        }
120    });
121})
122
123//文字轉注音
124$(function () {
125    $('.bopomofo').click(function (e) {
126        e.preventDefault();
127        ShowPhonetic(this);
128    })
129    function ShowPhonetic(that) {
130        var IsActive = $(that).hasClass('active');
131        var Select = '.page-content';
132        var ExSelector = '.page-select,.xxxx';
133        if (!IsActive) {
134            if (!$.fn.JPhonetic) {
135                $.getScript('/scripts/JPhonetic.js', function (data, textStatus, jqxhr) {
136                    $.fn.JPhonetic({
137                        'Selector': Select,
138                        'ExSelector': ExSelector
139                    });
140                });
141            } else {
142                $.fn.JPhonetic({
143                    'Selector': Select,
144                    'ExSelector': ExSelector
145                });
146            }
147            $(that).addClass('active')
148            $('#abopomofo').attr('aria-pressed', 'true');
149        } else {
150            $.fn.JPhoneticRecovery({
151                'Selector': Select
152            });
153            $(that).removeClass('active');
154            $('#abopomofo').attr('aria-pressed', 'false');
155        }
156    }
157})
158function doSearch(that) {
159    var KeyWord = that.closest('div').find('[data-search="' + that.attr("data-search") + '"]').val();
160    window.location.href = "Advanced_Search.aspx?q=" + htmlEncode(KeyWord);
161}
162
163
164function doSearchM(that) {
165
166    var KeyWord = $('#txt_SearchM').val();
167    //var SiteSN = $('#SitesSNM').val();
168    //var Lang = $('#SiteLang').val();
169    //var IP = '';
170    //window.location.href = "Advanced_Search.aspx?q=" + KeyWord;
171    //window.open("Advanced_Search.aspx?q=" + KeyWord);
172    window.location.href = "Advanced_Search.aspx?q=" + htmlEncode(KeyWord);
173    //$('#SearchItem').html("");
174    //$('#SearchItem').hide();
175    //if (KeyWord.length > 1) {
176    //    $.ajax({
177    //        type: 'GET',
178    //        async: true,
179    //        dataType: 'html',
180    //        data: { 'SiteSN': SiteSN, 'q': KeyWord, 'format': 'json', 'start': 0, 'rows': 10, 'UserIP': IP },
181    //        url: '/Common/Extern/GetSearchResult.ashx',
182    //    }).done(function (data) {
183    //        //console.log(data);
184    //        if (data !== "") {
185    //            $('#SearchItem').html(data);
186    //            $('#SearchItem').show();
187    //            $('.group.default.search-area').addClass('is-open');
188    //        }
189
190    //    });
191    //}
192    //else {
193    //    $('.group.default.search-area').removeClass('is-open');
194    //    $('#SearchItem').hide();
195    //}
196}
197
198function doSearchWindows(that) {
199
200    var KeyWord = $('#txt_SearchM').val();
201    var SiteSN = $('#SitesSNM').val();
202    var Lang = CCMS_LanguageSN;
203    //window.location.href = "Advanced_Search.aspx?q=" + KeyWord;
204    var url = "Advanced_Search.aspx?q=" + KeyWord;
205
206    console.log(Lang);
207    if (Lang != "1")
208        url = url + "&hl=en-US";
209
210    //window.open(url);
211    window.location.href = url;
212}
213
214
215//全文索引按鈕
216$(function () {
217    $('.CCMS_SearchBtn').each(function () {
218        $(this).click(function () {
219            doSearch($(this));
220        })
221    })
222
223    //jPager GO按鈕
224    $('.C_Pager').each(function () {
225        var path = $(this).data('path');
226        var $PageSize = $(this).find('select');
227        var $button = $(this).find('.btn');
228        $button.click(function () {
229            var PageSize = $PageSize.val();
230            window.location = path + '&page=1&PageSize=' + PageSize + '';
231        })
232    })
233})
234
235//判斷是否點擊後台地球
236//$(function () {
237//    if (getParameterByName('ccms_cs') == '1') {
238//        $('a').each(function () {
239//            var sHref = $(this).attr('href');
240//            if (typeof (sHref) != "undefined" && sHref.indexOf("mailto") == -1 && sHref.indexOf('javascript') == -1) {
241//                if (sHref && sHref.indexOf('?') > -1) {
242//                    $(this).attr('href', sHref + '&ccms_cs=1');
243//                } else {
244//                    $(this).attr('href', sHref + '?ccms_cs=1');
245//                }
246//            }
247//        })
248//    }
249//})
250
251//Apps 用fancybox 打開連結
252//開啟責任聲明
253function OpenLiabilityView(url) {
254    jQuery.fancybox({
255        href: 'Apps_Liability.aspx?rd=' + url,
256        type: 'iframe',
257        width: '85%',
258        height: '85%',
259        autoSize: false
260    });
261};
262
263//日期檢查
264$(function () {
265    $('input.dynDateTime').on('input focusin', function () {
266        var $Input = $(this); 
267        if ($Input.val().length > 0 && !IsDateFormat($Input.val())) { 
268            //$("#" + $Input.attr('name') + '_err').show();
269            $("#" + $Input.attr("name") + '_err').remove();
270            if (CCMS_LanguageSN == 1)
271                $Input.after('<font id="' + $Input.attr("name") + '_err" color="ff0000">格式錯誤: 民國年/月/日 (ex: 105/12/31)</font>');
272            else
273                $Input.after('<font id="' + $Input.attr("name") + '_err" color="ff0000">Wrong format: yyyy/mm/day (ex: 2019/12/31)</font>');
274        } else {
275            $("#" + $Input.attr("name") + '_err').remove(); 
276        }
277    });
278
279    function IsDateFormat(str) {
280        var reg = /^(\d{2,4})\/(\d{2})\/(\d{2})$/;
281        if (str == "") return true;
282        if (!reg.test(str)) {
283            return false;
284        }
285        else {
286            return true;
287        }
288    }
289})
290
291//取得Covid19確診人數 
292$(function () {
293    if ($('#covid19_num_sick').length > 0) {
294        index_today_covid19();
295        function index_today_covid19() {
296            $.ajax(
297                {
298                    type: "GET",
299                    url: "/GetAPI.ashx?type=covid19",
300                    dataType: 'json',
301                    success: function (data) {
302                        if (data != "") {
303                            if (data['SickNum'] != "") {
304                                $('#covid19_num_sick').html(data['SickNum']);
305                                $('#covid19_num_death').html(data['DeathNum']);
306                                $('#covid19_updatetime').html(data['UpdateTime']);
307                            }
308                        }
309                    }
310                });
311        }
312    }
313});
314
315//另開新視窗的連結加上 rel="noopener noreferrer" 屬性
316$(function () {
317    var links = document.getElementsByTagName("a");
318    for (var i = 0; i < links.length; i++) {
319        var _blank = links[i].target;
320        if (_blank == '_blank') {
321            links[i].setAttribute('rel', 'noopener noreferrer');
322        }
323    }
324})
325
326//居住正義-自動點選
327$(function () {
328    var sCategory = getParameterByName('Category');
329    if (sCategory != 0)
330    {
331        var t = setTimeout("document.getElementById(\"HousesTop_" + sCategory + "\").click(); document.getElementById(\"HousesTop_IsActive\").setAttribute(\"class\",\"is-active\");", 500);        
332    }
333})
334
335//GA 檔案下載事件追蹤
336$(function () {
337    var filelinks = document.getElementsByTagName('a');
338    for (i = 0; i < filelinks.length; i++) {
339        if (filelinks[i].href != null) {
340            var index = filelinks[i].href.indexOf("//www-ws.gov.taipei/Download.ashx?");
341            if (index != -1) {
342                if (filelinks[i].href.match(/^https?:\/\/.+.(txt|pdf|ppt|xls|pptx|xlsx|odf|mp3|odt|wma|odp|ods|rtf|wdl|xlsm|csv|odg|psd|ai|xd|sketch)$/i)) {
343                    filelinks[i].setAttribute('target', '_blank');
344                    filelinks[i].onclick = function () {
345                        gtag('event', 'Downloads', {
346                            'event_category': 'relfile',
347                            'event_label': this.getAttribute('title').replace(/^\[.*?\]/g, ''),
348                            'value': this.getAttribute('href')
349                        });
350                    };
351                }
352            }
353        }
354    }
355});
356
357/**
358 * @summary 提供JS在append字串時,防止Client Potential XSS類別風險
359 * @param {string} value 未處理的不安全字串
360 */
361function htmlEncode(value) {
362    // 建立一個暫存的div元素,並使用text()將內容存成html編碼文字後再用html()取出
363    return $('<div/>').text(value).html();
364}

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.