PageSourceSearch

https://www.forestkitchen-outdoor.com/common/family-gathering/assets/js/jquery.holiday.js

js forestkitchen-outdoor.com collected 2026-10-07 19:28:19 UTC 8,501 bytes, 302 lines download raw bytes

1(function($) {
2	var settings = {};
3	var css = {};
4	var holidays = {};
5	var prepared = {};
6	
7	var methods = {
8		//初期処理
9		init : function( options ) {
10			//datepicker ロードチェック
11			if (!$.fn['datepicker']) {
12				return this;
13			}
14
15			//オプション設定
16			settings = $.extend( {
17				//曜日、祝祭日のCSSスタイルクラス
18				'css': [
19					{'day':0, 'class':'day-sunday'}, //日曜日
20					{'day':6, 'class':'day-saturday'}, //土曜日
21					{'day':'holiday', 'class':'day-holiday'}, //祝祭日
22					{'day':'anniversary', 'class':'day-anniversary'} //記念日
23				],
24				//追加する記念日 [{date:年月日, name:名称, class:CSSクラス}]
25				'anniversary': []
26			}, options);
27			
28			//スタイルの登録
29			$.each(settings.css, function(key, val) {
30				if (typeof val['class']!="undefined") {
31					css[val['day']] = val['class'];
32				}
33			});
34			
35			//記念日の追加
36			var attr;
37			$.each (settings.anniversary, function(key, val){
38				attr = {};
39				attr['name'] = val['name'];
40				if (typeof val['class']!="undefined") {
41					attr['class'] = val['class'];
42				} else if (typeof css['anniversary']!="undefined") {
43					attr['class'] = css['anniversary'];
44				}
45				holidays[val['date']] = attr;
46			});
47			
48			return this.each(function() {
49				if (typeof $(this).datepicker!="function") {
50					return true;
51				}
52				//初期化済みチェック
53				if ($(this).data("holiday")) {
54					return true;
55				}
56				//初期化データ設定
57				$(this).data("holiday", {init: true});
58			
59				//祝祭日と日付スタイルの設定
60				$(this).datepicker("option", "beforeShowDay", function(day) {
61					var $self = $.fn.holiday;
62					var attr = $self("attr", day);
63					var dow = day.getDay();
64					var title = "";
65					if (typeof attr['name']!="undefined") {
66						title = attr['name'];
67					}
68					var style = "";
69					if (title && typeof attr['class']!="undefined") {
70						style = attr['class']; //祝祭日、記念日のスタイル
71					} else if (typeof css[dow]!="undefined") {
72						style = css[dow]; //曜日のスタイル
73					}
74
75					return [true, style, title];
76				});
77			});
78
79		},
80		
81		//終了処理
82		destroy : function( ) {
83			return this.each(function() {
84				if (typeof $(this).datepicker!="function") {
85					return true;
86				}
87				//祝祭日と日付スタイルの除去
88				$(this).datepicker("option", "beforeShowDay", null);
89				//初期化済みデータ消去
90				$(this).removeData("holiday");
91			});
92		},
93		
94		//祝祭日の属性の取得
95		attr : function( day ) {
96			//日付が文字の場合はDate型に変換する。
97			if (typeof day=="string") {
98				var match = day.match(/^(20\d{2})(\d{2})(\d{2})$/);
99				if (match) {
100					match.shift();
101					day = new Date(match.join("/"));
102				} else {
103					day = new Date(day);
104				}
105			}
106			//祝祭日の計算
107			var Y = day.getFullYear();
108			var M = padzero(day.getMonth()+1);
109			if (typeof prepared[Y+M]=="undefined") {
110				prepare(Y, M);
111			}
112			//祝祭日のチェック
113			var YMD = day.getFullYear()+padzero(day.getMonth()+1)+padzero(day.getDate());
114			if (typeof holidays[YMD]!="undefined") {
115				return holidays[YMD];
116			} else {
117				return {};
118			}
119		},
120		
121		//祝祭日名の取得
122		name : function( day ) {
123			var attr = $.fn.holiday('attr', day);
124			if (typeof attr['name']=="undefined") {
125				return "";
126			} else {
127				return attr['name'];
128			}
129		},
130		
131		//祝祭日一覧
132		list : function() {
133			return holidays;
134		},
135		
136		//祝祭日データ設定
137		setRegionData : function(obj) {
138			if (typeof obj=="object") {
139				if (typeof obj['annual']=="object") {
140					annual = obj['annual'];
141				}
142				if (typeof obj['individual']=="object") {
143					individual = obj['individual'];
144				}
145				if (typeof obj['words']=="object") {
146					words = obj['words'];
147				}
148			}
149		}
150	};
151
152	$.fn.holiday = function( method ) {
153		if ( methods[method] ) {
154			return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
155		} else if ( typeof method === 'object' || ! method ) {
156			return methods.init.apply( this, arguments );
157		} else {
158			$.error( 'Method ' +  method + ' does not exist on jQuery.holiday' );
159		}
160	};
161	
162	//ゼロサプレス
163	var padzero = function(val) {
164		return ('0'+val).slice(-2);
165	}
166	
167	//祝祭日計算
168	var prepare = function(Y, M) {
169		//作成済みチェック
170		if (typeof prepared[Y+M]!="undefined") {
171			return true;
172		}
173		
174		//年間の祝祭日の計算
175		var attr, substitutes = {};
176		if (typeof annual[M]!="undefined") {
177			var d, dayyear;
178			$.each(annual[M], function(key, val){
179				d = null;
180				if (isFinite(val['day'])) {
181					//日付固定
182					d = val['day'];
183				} else if (val['day']=="spring equinox") {
184					//春分の日
185					d = parseInt(20.69115 + (Y - 2000) * 0.2421904 - parseInt((Y - 2000) / 4));
186				} else if (val['day']=="autumnal equinox") {
187					//秋分の日
188					d = parseInt(23.09 + (Y - 2000) * 0.2421904 - parseInt((Y - 2000) / 4));
189				} else if (val['day'].match(/\//)) {
190					//ハッピーマンデー
191					d = padzero(nthday(Y, M, val['day']));
192				} else if (val.day.match(/\</)){
193					//特定年以前
194					dayyear = val['day'].split('<');
195					if (Y<=dayyear[1]) {
196					  d = padzero(dayyear[0]);
197					}
198				} else if (val.day.match(/\>/)) {
199					//特定年以降
200					dayyear = val['day'].split('>');
201					if (Y>=dayyear[1]) {
202						d = padzero(dayyear[0]);
203					}
204				}
205				
206				if (d==null) {
207					return true; //continue;
208				}
209
210				//祝祭日をリストに設定
211				attr = {};
212				attr['name'] = val['name'];
213				if (typeof val['class']!="undefined") {
214					attr['class'] = val['class'];
215				} else if (typeof css['holiday']!="undefined") {
216					attr['class'] = css['holiday'];
217				} else {
218					attr['class'] = "";
219				}
220
221				holidays[Y + M + d] = attr;
222				
223				//振替休日のチェック
224				d = new Date(Y, M-1, d);
225				if (d.getDay()==0) {
226					d = padzero(d.getDate() + 1);
227					attr['name'] = words['substitute']+"("+val['name']+")";
228					substitutes[Y +"/"+ M +"/"+ d] = attr;
229				}
230			});
231			
232			//振替休日の補正
233			$.each (substitutes, function(key, val) {
234				key = new Date(key);
235				d = key.getFullYear()+padzero(key.getMonth()+1)+padzero(key.getDate());
236				while (typeof holidays[d]!="undefined") {
237					key.setDate(key.getDate() + 1);
238					d = key.getFullYear()+padzero(key.getMonth()+1)+padzero(key.getDate());
239				}
240				holidays[d] = val;
241			});
242		}
243		
244		//個別の祝祭日の追加
245		if (typeof individual[Y+M]!="undefined") {
246			$.each(individual[Y+M], function(key, val) {
247				attr = {};
248				attr['name'] = val['name'];
249				if (typeof val['class']!="undefined") {
250					attr['class'] = val['class'];
251				} else if (typeof css['holiday']!="undefined") {
252					attr['class'] = css['holiday'];
253				} else {
254					attr['class'] = "";
255				}
256				holidays[Y+M+val.day] = attr;
257			});
258		};
259		
260		prepared[Y+M] = true;
261		return true;
262	}
263
264	//月の第n番目のm曜日
265	var nthday = function(y, m, val) {
266		var dayOfWeek = val.split('/');
267		var firstDay = new Date(y, m - 1, 1);
268		var adjust = dayOfWeek[1] - firstDay.getDay();
269		if (adjust < 0)
270			adjust += 7;
271		//第n番目のm曜日
272		return 1 + adjust + (dayOfWeek[0] -1 ) * 7;
273	}
274	
275	//年間の祝祭日データ
276	var annual = {
277		'01': [{'day':'01','name':'元旦'}, {'day':'2/1','name':'成人の日'}],
278		'02': [{'day':'11','name':'建国記念日'}],
279		'03': [{'day':'spring equinox','name':'春分の日'}],
280		'04': [{'day':'29','name':'昭和の日'}],
281		'05': [{'day':'03','name':'憲法記念日'}, {'day':'04','name':'みどりの日'}, {'day':'05','name':'こどもの日'}],
282		'07': [{'day':'3/1','name':'海の日'}],
283		'08': [{'day':'11>2016','name':'山の日'}], //2016年以降
284		'09': [{'day':'3/1','name':'敬老の日'}, {'day':'autumnal equinox','name':'秋分の日'}],
285		'10': [{'day':'2/1','name':'体育の日'}],
286		'11': [{'day':'03','name':'文化の日'}, {'day':'23','name':'勤労感謝の日'}],
287		'12': [{'day':'23<2018','name':'天皇誕生日'}] //2018年迄
288	};
289	//個別の祝祭日データ
290	var individual = {
291		'201509': [{'day':'22','name':'国民の休日'}],
292		'201905': [{'day':'01','name':'新天皇即位日'}], //2019年以降
293		'202609': [{'day':'22','name':'国民の休日'}], //2015年時点の推定
294		'203209': [{'day':'21','name':'国民の休日'}], //2015年時点の推定
295		'203709': [{'day':'22','name':'国民の休日'}] //2015年時点の推定
296	};
297	//言語対応
298	var words = {
299		'substitute': '振替休日'
300	};
301		
302})(jQuery);

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.