PageSourceSearch

https://www.thehonest.ai/js/calendar_beans_v2.0.js

js thehonest.ai collected 2026-10-05 14:37:56 UTC 16,171 bytes, 406 lines download raw bytes

1/*
2*	2011.11.13 make by beans9([email protected])
3*	http://beans9.tistory.com
4*/
5
6var cssAddFlag = true;
7function CalAddCss(){
8		var cssHtml = "<style type='text/css'>";
9		cssHtml += ".calLayout{	border:1px solid #DDDDDD; background-color:#ECEADF;	position:absolute;padding:2px;display:none;z-index:9999	}";			
10		cssHtml += ".calTitle{ border:1px solid #D4D1BF; background-color: #ffffff; width:99%;	font-size:9pt;}";			
11		cssHtml += ".calHeader{	padding:2px; padding-bottom:0px;text-align:center;}";
12		cssHtml += ".calBody{padding:2px;padding-top:0px;text-align:center;	}";
13		cssHtml += ".calDay{background-color: #FBFBFB;border:1px solid #CBC7BD;	width:20px;float:left;font-size:8pt;padding-top:3px;padding-bottom:2px;cursor:pointer;}";
14		cssHtml += ".calSunDay{	background-color: #FBFBFB;border:1px solid #CBC7BD;	width:20px;float:left;font-size:8pt;padding-top:3px;padding-bottom:2px;cursor:pointer;color:red;}";
15		cssHtml += ".calSatDay{ background-color: #FBFBFB;border:1px solid #CBC7BD;	width:20px;float:left;font-size:8pt;padding-top:3px;padding-bottom:2px;cursor:pointer;	color:blue;}";
16		cssHtml += ".calOtherDay{background-color: #FBFBFB;	border:1px solid #CBC7BD;width:20px;float:left;font-size:8pt;padding-top:3px;padding-bottom:2px;cursor:pointer;color:#CBC7BD;}";
17		cssHtml += ".dayToday{background-color: #368CFE;border:1px solid #CBC7BD;font-weight:bold;font-weight:bold;width:20px;float:left;font-size:8pt;padding-top:3px;padding-bottom:2px;cursor:pointer;color:white;	}";
18		cssHtml += ".calSelDay{	background-color: #CF4040;border:1px solid #CBC7BD;font-weight:bold;width:20px;float:left;font-size:8pt;padding-top:3px;padding-bottom:2px;cursor:pointer;text-decoration:underline;color:white;}";
19		cssHtml += ".dayEvMon{font-size:8pt;width:25px;	height:15px;background-color: #FBFBFB;border:1px solid #CBC7BD;	padding:4px 4px 0px 3px;float:left;cursor:pointer;}";		
20		cssHtml += ".MonToday{font-size:8pt;width:25px;	height:15px;background-color: #368CFE;border:1px solid #CBC7BD;	font-weight:bold;padding:4px 4px 0px 3px;color:white;cursor:pointer;}";
21		cssHtml += ".selMon{font-size:8pt;width:25px;height:15px;background-color: #CF4040;border:1px solid #CBC7BD;font-weight:bold;padding:4px 4px 0px 3px;text-decoration:underline;color:white;}";
22		cssHtml += ".calOnDay{background-color: #006060;border:1px solid #4B22C0;float:left;cursor:pointer;color:white;}";
23		cssHtml += ".calDaySpace{padding:1px;float:left;}";
24		cssHtml += ".calDayBr{clear:both;height:2px;}";
25		cssHtml += ".calDayTitle{padding-top:2px;width:22px;float:left;	font-size:8pt;}";			
26		cssHtml += ".divHeadOnRigth{color:#18CCA8;cursor:pointer;}";
27		cssHtml += ".todayBtn{clear:both;text-align: center;font-size:8pt;cursor:pointer;background-color: #FBFBFB;border:1px solid #CBC7BD;padding:4px 4px 0px 3px;height:15px;}";
28		cssHtml += ".todayLay{padding-left:2px;}</style>";
29		jQuery("head").append(cssHtml);
30}
31
32// 초기화			
33function initCal(obj){
34	if( cssAddFlag == true ){
35		CalAddCss();
36		cssAddFlag = false;
37	}
38	
39	// id 정의
40	var calId = "Cal" + obj.id;				
41	
42	// calendar type (day,mon)
43	var calType = obj.type == null ? "day" : obj.type;				
44	if( calType.toLowerCase() != "day" && calType.toLowerCase() != "mon"){
45		calType = "day";
46	}
47	
48	// 최소년도, 최대년도 
49	var minYear 	= obj.min == null ? "2000" : obj.min;
50	// maxYear 최대 년도 설정
51	var maxYear 	= obj.max == null ? new Date().getFullYear() + 2: obj.max;
52	var splitKey 	= obj.splitKey == null ? "-" : obj.splitKey; 
53	var todayYN		= obj.today == null ? "n" : "y";
54	var iconYN		= obj.icon  == null ? "n" : "y";
55	var iconUrl    = obj.iconUrl == null ? "/manage/img/calendar_btn.gif" : obj.iconUrl ;
56	var timeYN		= obj.timeYN == null ? "n" : "y";
57
58	// 달력 레이아웃(전체틀+월선택)그리기
59	drawCalForm(calId,obj.id,calType,minYear,maxYear,todayYN,iconYN,iconUrl);
60	
61	if( calType == "day"){
62		jQuery("#"+obj.id).attr("maxlength",timeYN == "y" ? 21 : 8);
63		jQuery("#"+calId).css("width","170px");
64		jQuery("#"+calId +"btn.todayBtn").css("width","157px");							
65	}else{
66		jQuery("#"+obj.id).attr("maxlength",7);
67		jQuery("#"+calId).css("width","146px");
68		jQuery("#"+calId +"btn.todayBtn").css("width","133px");
69	}
70
71	
72	// input box에 click event 
73	jQuery("#"+ calId + "Icon").click(function(event){	
74		var datesVal = jQuery("#"+obj.id).val();
75		if( calType == "mon") datesVal += splitKey + '1';
76		
77		var dates = isValidCheck(datesVal ,splitKey, timeYN);
78		if( calType == "day"){
79			makeCal(calId,dates,splitKey,timeYN);
80		}else{
81			makeCalMon(calId,dates,splitKey);
82		}
83		calPosition(obj.id,calId);																					
84		jQuery("#"+calId).show();
85		
86	});
87	
88	// 외부 화면 클릭시 달력감추기
89	jQuery(document).click(function(event){
90		var parentEls = jQuery( event.target).parents().map(function () { return this.id; }).get().join(", ");
91		if(parentEls.indexOf(calId+",") == -1 && event.target.id != obj.id && parentEls.indexOf(calId+"Icon,")){
92			jQuery("#"+calId).hide();
93		}
94	});
95	
96	jQuery(window).resize(function(event){
97		calPosition(obj.id,calId);
98	});
99	
100	// 달력상단 이전/다음 버튼 처리
101	jQuery("#"+calId+"before,#"+calId+"next").click(function(event){
102		var plus = -1;
103		if(this.id.indexOf("next") > -1){ var plus = 1; }
104		
105		if( calType == "day"){
106			var dates = calDate(jQuery("#"+ calId + "selYear").val(),jQuery("#"+calId + "selMon").val(),plus,isValidCheck(jQuery("#"+obj.id).val(),splitKey, timeYN));					
107			if((dates[0] >= minYear && plus == -1) || (dates[0] <= maxYear && plus == 1)){
108				makeCal(calId,dates,splitKey,timeYN);
109			}	
110		}else{
111			var dates = calDate(jQuery("#"+ calId + "selYear").val(),'1',plus*12,isValidCheck(jQuery("#"+obj.id).val()+splitKey+'1',splitKey, timeYN));
112			if((dates[0] >= minYear && plus == -1) || (dates[0] <= maxYear && plus == 1)){
113				makeCalMon(calId,dates,splitKey);
114			}
115		}					 
116	}).mouseover(function(){
117		jQuery(this).addClass("divHeadOnRigth");
118	}).mouseout(function(){
119		jQuery(this).removeClass("divHeadOnRigth");
120	});;
121	
122	// 월별선택시 필요없음
123	if( calType == "day"){
124		// 년도,월 selectbox 선택시 이벤트
125		jQuery("#"+calId+"selYear,#"+calId+"selMon").change(function(event){
126			var dates = calDate(jQuery("#"+ calId + "selYear").val(),jQuery("#"+calId + "selMon").val(),0,isValidCheck(jQuery("#"+obj.id).val(),splitKey, timeYN));
127			makeCal(calId,dates,splitKey, timeYN);
128		});	
129	}else{
130		jQuery("#"+calId+"selYear").change(function(event){
131			var dates = calDate(jQuery("#"+ calId + "selYear").val(),1,0,isValidCheck(jQuery("#"+obj.id).val()+splitKey+'1',splitKey, timeYN));					
132			makeCalMon(calId,dates,splitKey);
133		});	
134	}
135	
136	jQuery("#"+calId+"btn").click(function(){
137		jQuery("#"+obj.id).val("");
138		var dates = isValidCheck('',splitKey, timeYN);
139		if( calType == 'day'){
140			makeCal(calId,dates,splitKey,timeYN);
141		}else{
142			makeCalMon(calId,dates,splitKey);
143		}
144	});
145	
146	calPosition(obj.id,calId);
147}
148
149//클릭 이벤트
150function calClickEvent(id){
151	jQuery("#" + id + " .calOtherDay,.calDay,.calSunDay,.calSatDay,.MonToday,.selMon,.dayEvMon").click(function(event) {
152        jQuery("#" + id.substring(3)).val(this.id.replace(id,""));
153		jQuery("#" + id).hide();
154	}).mouseover(function(){
155		jQuery(this).addClass("calOnDay");
156	}).mouseout(function(){
157		jQuery(this).removeClass("calOnDay");
158	});
159} 
160
161// 달력 폼 그리기 
162function drawCalForm(id,tId,calType,min,max,todayYN,iconYN,imageUrl){ // tId = 입력창ID					
163	
164	if(iconYN == "y"){
165		jQuery(document.body).append("<div id='"+ id +"Icon' style='position:absolute; cursor:pointer; z-index:10000;'><img id='"+ id +"IconImg' src='"+ imageUrl +"'><div>");
166	}
167	
168	// layout
169	jQuery(document.body).append("<div id='"+ id +"' onselectstart='return false' class='calLayout'><div>");
170	
171	// 상단 년,달 이동 
172	var html  = "<div class='calTitle'><table width='100%'><tr><td id='"+ id +"before' width='10%'  style='font-size: 10px'>◀</td><td width='80%' align='center'>";
173		
174	// 년선택
175	html += "<select id='"+ id +"selYear'>";
176    for(var i=min;i<=max;i++){ html += "<option value=" + i + ">" + i + "</option>"; }
177	html += "</select>"
178	
179	// 월선택 (일별달력일 경우에만)
180	if( calType == "day"){
181		html += "<select id='"+ id +"selMon'>";
182	    for(var i=1;i<=12;i++){ html += "<option value=" + i + ">" + i + "월</option>"; }
183		html += "</select>"						
184	}
185	
186	html += "</td><td id='"+ id +"next' width='10%' style='font-size: 10px'>▶</td></tr></table></div>";
187	if( calType == "day" )html += "<div id='" + id + "Header' class='calHeader'></div>";
188	html += "<div id='" + id + "Content' class='calBody'></div>";
189	
190	if( todayYN == "y"){
191		html += "<div class='todayLay'><div id='" + id + "btn' class='todayBtn'>Today</div></div>";
192	}
193		
194	jQuery("#"+id).html(html);				
195	
196	// 월선택 (일별달력일 경우에만)
197	if (calType == "day") {
198		var tempHtml = ""; 
199		var yoil = ["일", "월", "화", "수", "목", "금", "토"];
200		for (i = 0; i < 7; i++) {
201			tempHtml += "<div class='calDayTitle'>" + yoil[i] + "</div>";
202			if (i == 6) { tempHtml += "<div class='calDayBr'></div>"; }
203			else { tempHtml += "<div class='calDaySpace'></div>"; }
204		}
205		jQuery("#" + id + "Header").append(tempHtml);
206	}		
207	
208		
209}
210
211// 날짜변경(달변경) 달력내용 그리기
212function makeCal(id,dates,splitKey,timeYN){				
213	var timeTF = timeYN == "y" ? true : false;
214	
215	// 이번달 시작날짜,마지막날짜 
216	var firstDay  = new Date(dates[0],eval(dates[1]-1),1).getDay();
217	
218	// 이번달 마지막날짜
219	var lastDate 	= new Date(dates[0],eval(dates[1]),0);
220	var lastDateNum = lastDate.getDate();
221	var lastDay     = lastDate.getDay();
222	
223	// 이전달 마지막날짜
224	var beforeMonDate	= new Date(dates[0],eval(dates[1]-1),0);
225	var beforeMonLastDay = beforeMonDate.getDate();
226	var beforeYearMonText = beforeMonDate.getFullYear() + splitKey + strFormat(beforeMonDate.getMonth()+1) + splitKey;
227	
228	var nextMonDate	= new Date(dates[0],eval(dates[1]),1);
229	var nextYearMonText = nextMonDate.getFullYear() + splitKey + strFormat(nextMonDate.getMonth()+1) + splitKey;
230	  
231	var nowYearMonText = dates[0] + splitKey + strFormat(dates[1]) + splitKey;
232	
233	var ndate = new Date();
234	var today;
235	if(timeTF){
236		today = ndate.getFullYear() + splitKey + strFormat(ndate.getMonth()+1) + splitKey + strFormat(ndate.getDate()) + " " + strFormat(ndate.getHours()) + ":" + strFormat(ndate.getMinutes()) + ":" + strFormat(ndate.getSeconds()) + ".0";
237	} else {
238		today = ndate.getFullYear() + splitKey + strFormat(ndate.getMonth()+1) + splitKey + strFormat(ndate.getDate());
239	}
240
241	//-----------------------------------------------------	
242	var html = "";				
243	var brCount = 1; // 줄넘김 count
244	
245	// before month
246	for( i = 1; i<=firstDay; i++){
247		html += "<div class='calOtherDay' id='"+ id + beforeYearMonText + (beforeMonLastDay-(firstDay-i)) +"'>"+ (beforeMonLastDay-(firstDay-i)) + "</div><div class='calDaySpace'></div>";
248		brCount ++;					
249	}	
250					
251	// now month
252	for (i = 1; i <= lastDateNum; i++) {					
253		var dayCss = "calDay";				
254		if (brCount % 7 == 1) { dayCss = "calSunDay" ; }
255		else if(brCount % 7 == 0){ dayCss = "calSatDay" ; }
256		
257		if(timeTF){
258			html += "<div class='"+ dayCss +"' id='"+ id + nowYearMonText + strFormat(i) + " " + strFormat(ndate.getHours()) + ":" + strFormat(ndate.getMinutes()) + ":" + strFormat(ndate.getSeconds()) + ".0" +"'>" + i + "</div>";
259		}else{
260			html += "<div class='"+ dayCss +"' id='"+ id + nowYearMonText + strFormat(i) +"'>" + i + "</div>";
261		}
262		
263		if( brCount %7 == 0 && i != lastDateNum ){ html += "<div class='calDayBr'></div>"; }
264		else{ html += "<div class='calDaySpace'></div>"; }
265		brCount ++;
266	}
267	
268	// next month
269	var nexyStartDay = 1;
270	for( i = lastDay; i<6; i++){
271		html += "<div class='calOtherDay' id='" +id + nextYearMonText + strFormat(nexyStartDay) +"'>"+ nexyStartDay++ + "</div><div class='calDaySpace'></div>";
272	}
273	
274	// 내용 삽입
275	jQuery("#" + id + "Content").html(html);
276	
277	// 년도 select 설정
278	jQuery("#" + id + "selYear").val(dates[0]);
279	
280	// 일별달력일 경우 월 select 선정
281	jQuery("#" + id + "selMon").val(eval(dates[1]));
282	
283	// 오늘날짜 체크
284	jQuery("#" + id+ today).addClass("dayToday");
285	
286	// 입력날짜 체크
287	if(dates[4] == true){
288		jQuery("#" +id + dates[3]).addClass("calSelDay");					
289		// 입력날짜가 유효한 날짜면 input쪽 데이터를 형식에 맞게 변경
290		jQuery("#" + id.substring(3)).val(dates[3]);
291	} 
292	
293	calClickEvent(id);
294}
295
296function makeCalMon(id,dates,splitKey){
297	var nowYeaText = dates[0] + splitKey;
298	
299	var ndate = new Date();
300	var today = ndate.getFullYear() + splitKey + strFormat(ndate.getMonth()+1);
301	
302	var html = "<div class='calDayBr'></div><div class='calDayBr'></div>";				
303	for(var i=1;i<13;i++){
304		html += "<div class='dayEvMon' id='"+ id + nowYeaText + strFormat(i) +"'>" + i + "</div>";
305		if( i %4 == 0 && i != 12){ html += "<div class='calDayBr'></div>"; }
306		else{
307			html += "<div class='calDaySpace'></div>"; 
308		}
309	}				
310	// 내용 삽입
311	jQuery("#" + id + "Content").html(html);				
312	// 년도 select 설정
313	jQuery("#" + id + "selYear").val(dates[0]);
314	
315	// 오늘날짜 체크
316	jQuery("#" + id + today).addClass("MonToday");
317	
318	// 입력날짜 체크
319	if(dates[4] == true){
320		jQuery("#" +id + dates[3].substring(0,7)).addClass("selMon");
321		
322		// 입력날짜가 유효한 날짜면 input쪽 데이터를 형식에 맞게 변경
323		jQuery("#" + id.substring(3)).val( dates[3].substring(0,7));
324	} 
325	
326	calClickEvent(id);
327}
328
329// 날짜 유효성 체크
330function isValidCheck(strDate,splitKey,timeYN,todayCheck){
331	var timeTF = timeYN == "y" ? true : false;
332	
333	var date = strDate;
334
335	var dates;
336	var times;
337	if(timeTF){
338		times = date.substr(date.indexOf(" ")+1,8).split(":");
339		dates = date.substr(0,date.indexOf(" ")).split(splitKey);
340	} else {
341		dates = date.split(splitKey);
342	}
343
344	var idate;
345	if(timeTF){
346		idate = new Date(dates[0],eval(dates[1])-1,eval(dates[2]),times[0],times[1],times[2],0);
347	} else {
348		idate = new Date(dates[0],eval(dates[1])-1,eval(dates[2]));
349	}
350	var ndate = new Date();
351	
352	var isValid = true;
353	if( dates[0] != idate.getFullYear()) isValid = false;  
354	else if( eval(dates[1])-1 != idate.getMonth()) isValid = false; 
355	else if( eval(dates[2]) != idate.getDate()) isValid = false;
356	if(timeTF){
357		if( times[0] != idate.getHours()) isValid = false;  
358		else if( times[1] != idate.getMinutes()) isValid = false; 
359		else if( times[2] != idate.getSeconds()) isValid = false;
360	}
361
362	if( isValid == false ){
363		dates[0] = ndate.getFullYear();
364		dates[1] = strFormat(ndate.getMonth()+1);
365		dates[2] = strFormat(ndate.getDate());
366		if(timeTF){
367			times[0] = strFormat(ndate.getHours());
368			times[1] = strFormat(ndate.getMinutes());
369			times[2] = strFormat(ndate.getSeconds());
370		}
371	}	
372	
373	if(timeTF){
374		dates[3] = dates[0] +splitKey + strFormat(dates[1]) + splitKey + strFormat(dates[2]) + " " + strFormat(times[0]) + ":" + strFormat(times[1]) + ":" + strFormat(times[2]) + ".0";
375	}else{
376		dates[3] = dates[0] +splitKey + strFormat(dates[1]) + splitKey + strFormat(dates[2]);
377	}
378	dates[4] = isValid;
379	return dates;
380}	
381
382function calDate(year,month,adjust,isValidDate){
383	var date = new Date(year,(month-1)+adjust,1);
384	var dates = [date.getFullYear(),date.getMonth()+1,date.getDate(),isValidDate[3],isValidDate[4]];
385	return dates;
386}
387
388// 날짜 format 맞추기
389function strFormat(str){
390	if((str+"").length == 1) str = "0" + str;
391	return str;				
392}
393
394// 달력위치변경		
395function calPosition(target,id){
396	var tInput  = jQuery("#" + target).offset();
397	var tHeight = jQuery("#" + target).outerHeight();
398	var tWidth 	= jQuery("#" + target).outerWidth();
399	
400	var calHeight 	= jQuery("#" + id).outerHeight();
401	
402	if( tInput != null){
403		jQuery("#" + id).css({"top":tInput.top+tHeight , "left":tInput.left});
404		jQuery("#" + id + "Icon").css({"top":tInput.top+1,"left":tInput.left+tWidth+2});
405	}
406}

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.