PageSourceSearch

https://www.yamadashika.jp/contact/fmail.lib/gcalendar-holidays.js

js yamadashika.jp collected 2026-10-05 11:16:25 UTC 6,548 bytes, 164 lines download raw bytes

1/**
2 *  GCalendar Holidays - Googleカレンダーから日本の祝日を取得
3 *  @see       http://0-oo.net/sbox/javascript/google-calendar-holidays
4 *  @version   0.6.0
5 *  @copyright 2008-2014 [email protected]
6 *  @license   http://0-oo.net/pryn/MIT_license.txt (The MIT license)
7 */
8var GCalHolidays = {
9    /** Google Calendarから情報を取得するAPIのURL */
10    apiUrl: "https://gcalendar-holidays.appspot.com/",
11
12    /** jQuery UI Datepicker用のstyle(Themeに合わせてお好みで上書きして使う) */
13    datepickerStyles: {
14        sunday:   "background-image: url(./fmail.lib/smoothness/images/daySun.png); background-color: #f99", //日曜日
15        saturday: "background-image: url(./fmail.lib/smoothness/images/daySat.png); background-color: #6cf", //土曜日
16        holiday:  "background-image: url(./fmail.lib/smoothness/images/dayHoli.png); background-color: #f99;",  //祝日
17        special:  "background-image: url(./fmail.lib/smoothness/images/daySpecial.png); background-color: #6fc;"  //指定日
18    }
19};
20/**
21 *  祝日を取得する
22 *  @param  Function    callback    データ取得時に呼び出されるfunction
23 *  @param  Number      year        (optional) 年(指定しなければ今年)
24 *  @param  Number      month       (optional) 月(1~12 指定しなければ1年の全て)
25 */
26GCalHolidays.get = function(callback, year, month) {
27    //日付範囲
28    var padZero = function(value) { return ("0" + value).slice(-2); };
29    var y = year || new Date().getFullYear();
30    var start = [y, padZero(month || 1), "01"].join("-");
31    var m = month || 12;
32    var end = [y, padZero(m), padZero(new Date(y, m, 0).getDate())].join("-");
33
34    this._caches = (this._caches || {});
35    this._userCallback = callback;
36
37    var cache = this._caches[start + ".." + end];
38
39    if (cache) {    //取得済みの場合はそれを使う
40        callback(cache, 0);
41        return;
42    }
43
44    //URL作成
45    var url = GCalHolidays.apiUrl + "?timeMin=" + start + "&timeMax=" + end;
46
47    //scriptタグ生成
48    var script = document.createElement("script");
49    script.type = "text/javascript";
50    script.src = url;
51    script.charset = "UTF-8";
52    document.body.appendChild(script);
53};
54/**
55 *  JSONPによりGoogle Calendar API経由で呼び出されるfunction
56 *  @param  Object  gdata   カレンダーデータ
57 *  @param  String  start   開始日付
58 *  @param  String  end     終了日付
59 */
60GCalHolidays.decode = function(gdata, start, end) {
61    var days = GCalHolidays._entries2days(gdata.items);
62
63    //キャッシュする
64    this._caches[start + ".." + end] = days;
65
66    //コールバック
67    this._userCallback(days, 0);    // 第2引数は過去バージョンの遺産
68};
69/**
70 *  JSONPで取得したデータから日付情報を取り出す
71 *  @param  Array   entries スケジュール
72 *  @return Array   日付情報(year, month, date, title)
73 */
74GCalHolidays._entries2days = function(entries) {
75    var days = [];
76    var cnt = 0;
77
78    if (!entries) {
79        return days;
80    }
81
82    //シンプルな器に移す
83    for (var i = 0, len = entries.length; i < len; i++) {
84        var entry = entries[i];
85        var ymd = entry.start.date.split("T")[0].split("-");
86
87        days[cnt] = { //年月日は使いやすいように数値にする
88            year: ymd[0] * 1,
89            month: ymd[1] * 1,
90            date: ymd[2] * 1,
91            title: entry.summary
92        };
93        cnt++;
94    }
95
96    return days;
97};
98
99/**
100 *  jQuery UI Datepickerのカレンダーに祝日を表示する
101 *  @param  Number  year    表示する年
102 *  @param  Number  month   表示する月
103 *  @param  Object  inst    Datepicker
104 *  @see http://jqueryui.com/demos/datepicker/
105 */
106GCalHolidays.datepicker = function(year, month, inst) {
107    setTimeout(function() { //処理後に対象のdivが再構築されるケースを回避
108        for (var i = 0, len = (inst.settings.numberOfMonths || 1); i < len; i++) {
109            GCalHolidays.get(function(holidays) {
110                for (var j = 0, len2 = holidays.length; j < len2; j++) {
111                    var h = holidays[j];
112                    var s = "[data-year=" + h.year + "][data-month=" + (h.month - 1) + "] a"
113
114                    inst.dpDiv.find(s).each(function() {
115                        if ($(this).text() == h.date) {
116                            $(this).addClass("gcal-holiday").attr("title", h.title);
117                            
118                            // 祝日の無効化カスタマイズ
119                            if (flag_holiday == '0') {
120                            	// datepicker.jsでフラグ管理
121	                          	$(this).parent("td").removeAttr("class").removeAttr("data-handler").removeAttr("data-event").removeAttr("data-month").removeAttr("data-year");
122	                          	$(this).parent("td").attr("class"," ui-datepicker-unselectable ui-state-disabled gcal-sunday");
123	                          	$(this).parent("td").html("<span class=\"ui-state-default\">" + h.date + "</span>");
124                            }
125                            
126                            return false;
127                        }
128                    });
129                }
130            }, year, month);
131            
132            month++;
133            
134            if (month > 12) {
135                year++;
136                month = 1;
137            }
138        }
139    }, 1);
140};
141/**
142 *  jQuery UI Datepickerが有効な場合はイベントハンドラとstyleをセットする
143 */
144if (window.$ && $.datepicker && $.datepicker.setDefaults) {
145    $.datepicker.setDefaults({
146        beforeShow: function(input, inst) {
147            var date = $(input).datepicker("getDate") || new Date();
148            GCalHolidays.datepicker(date.getFullYear(), date.getMonth() + 1, inst);
149        },
150        beforeShowDay: function(date) { //土日のclass属性
151            return [true, { 0: "gcal-sunday", 6: "gcal-saturday" }[date.getDay()] || ""];
152        },
153        onChangeMonthYear: GCalHolidays.datepicker
154    });
155
156    $(function() {  //ページ表示後に土日・祝日用のstyleをセット
157        var styles = GCalHolidays.datepickerStyles;
158        var css = "";
159        css += ".gcal-sunday   .ui-state-default { " + styles.sunday + " } ";
160        css += ".gcal-saturday .ui-state-default { " + styles.saturday + " } ";
161        css += ".ui-widget-content .gcal-holiday { " + styles.holiday + " }";
162        $("head").append($('<style type="text/css">' + css + "</style>"));
163    });
164}

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.