PageSourceSearch

https://busan.com/nas/wcms/public/pc/js/dcalendar.picker.js

js busan.com collected 2026-09-24 09:16:22 UTC 10,311 bytes, 249 lines download raw bytes

1if (typeof jQuery === 'undefined') { throw new Error('DCalendar.Picker: This plugin requires jQuery'); }
2 
3+function ($) {
4
5	Date.prototype.getDays = function() { return new Date(this.getFullYear(), this.getMonth() + 1, 0).getDate(); };
6	// Date.prototype.getWeeks = function(){ var d = new Date(this), l = this.getDays(); d.setDate(1); l += d.getDay(); return Math.ceil(l/7) };
7	var months = ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
8		short_months = ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
9		daysofweek = ['일요일','월요일','화요일','수요일','목요일','금요일','토요일'];
10
11	var DCalendar = function(elem, options) {
12	    this.calendar = $(elem);
13		this.today = new Date();	//system date
14		this.date = this.today;		//current selected date, default is today
15		this.viewMode = 'days';
16		this.options = options;
17		this.selected = this.date.getFullYear()  + "/" + this.date.getMonth().toString() + "/" + this.date.getDate();
18		if(options.mode == 'calendar')
19			this.tHead = $('<thead><tr><th id="prev">&lsaquo;</th><th colspan="5" id="currM"></th><th id="next">&rsaquo;</th></tr><tr><th>일</th><th>월</th><th>화</th><th>수</th><th>목</th><th>금</th><th>토</th></tr></thead>');
20		else if (options.mode == 'datepicker')
21			this.tHead = $('<thead><tr><th id="prev">&lsaquo;</th><th colspan="5" id="currM"></th><th id="next">&rsaquo;</th></tr><tr><th>일</th><th>월</th><th>화</th><th>수</th><th>목</th><th>금</th><th>토</th></tr></thead>');
22		this.tHead.find('#currM').text(months[this.today.getMonth()] +" " + this.today.getFullYear());
23		this.calendar.prepend(this.tHead);
24		var that = this;
25
26		this.calendar.on('click', '#next', function(){ initCreate('next'); })
27			.on('click', '#prev', function(){ initCreate('prev'); })
28			.on('click', '#today', function(){
29				that.viewMode = 'days';
30				var curr = new Date(that.date),
31					sys = new Date(that.today);
32				if(curr.toString() != sys.toString()) { that.date = sys; that.create(that.viewMode); }
33			}).on('click', '.date', function(){
34				that.selected = that.date.getMonth() + 1 + "/" + $(this).text() + "/" + that.date.getFullYear();
35				if(that.options.mode == 'datepicker') {
36					that.calendar.find('td').removeClass('selected');
37					$(this).addClass('selected');
38				}
39				selectDate();
40				return true;
41			}).on('click', '.pMDate', function(){
42				that.selected = (that.date.getMonth() == 0 ? '12' : that.date.getMonth()) + "/" + $(this).text() + "/" + (that.date.getMonth() == 0 ? that.date.getFullYear()-1 : that.date.getFullYear());
43				if(that.options.mode == 'datepicker') {
44					that.calendar.find('td').removeClass('selected');
45					$(this).addClass('selected');
46				}
47				selectDate();
48				return true;
49			}).on('click', '.nMDate', function(){
50				that.selected = (that.date.getMonth()+2 == 13 ? '1' : that.date.getMonth()+2) + "/" + $(this).text() + "/" + (that.date.getMonth()+2 == 13 ? that.date.getFullYear()+1 : that.date.getFullYear());
51				if(that.options.mode == 'datepicker') {
52					that.calendar.find('td').removeClass('selected');
53					$(this).addClass('selected');
54				}
55				selectDate();
56				return true;
57			}).on('click', '#currM', function(){
58				that.viewMode = 'months';
59				that.create(that.viewMode);
60			}).on('click', '.month', function(e){
61				that.viewMode = 'days';
62				var curr = new Date(that.date), y = that.calendar.find('#currM').text();
63				curr.setMonth($(e.currentTarget).attr('num'));
64				that.date = curr;
65				that.create(that.viewMode);
66			});
67
68		function selectDate () {
69			var newDate = formatDate(that.options.format);
70			var e = $.Event('selectdate',{date: newDate});
71			that.calendar.trigger(e);
72		}
73
74		function formatDate (format) {
75			var d = new Date(that.selected), day = d.getDate(), m = d.getMonth(), y = d.getFullYear();
76			return format.replace(/(yyyy|yy|mmmm|mmm|mm|m|dd|d)/gi, function (e) {
77				switch(e.toLowerCase()){
78					case 'd': return day;
79					case 'dd': return (day < 10 ? "0"+day: day);
80					case 'm': return m+1;
81					case 'mm': return (m+1 < 10 ? "0"+(m+1): (m+1));
82					case 'mmm': return short_months[m];
83					case 'mmmm': return months[m];
84					case 'yy': return y.toString().substr(2,2);
85					case 'yyyy': return y;
86				}
87			});
88		}
89
90		function initCreate(o){
91			var curr = new Date(that.date);
92			if(that.viewMode == 'days')
93				o == 'next' ? curr.setMonth(curr.getMonth() + 1) : curr.setMonth(curr.getMonth() - 1);
94			else
95				o == 'next' ? curr.setFullYear(curr.getFullYear() + 1) : curr.setFullYear(curr.getFullYear() - 1);
96			curr.setDate(1);
97			that.date = curr;
98			that.create(that.viewMode);
99		}
100
101		this.create(this.viewMode);
102	}
103
104	DCalendar.prototype = {
105
106		constructor : DCalendar, 
107
108		//setDate : function(){},
109
110		create : function(mode){
111			var that = this, cal = [], tBody = $('<tbody></tbody>'), d = new Date(that.date), days = that.date.getDays(), day = 1, nStartDate = 1, selDate = that.selected.split('/');
112			that.calendar.empty();
113			if(mode == "days"){
114				if(that.options.mode == 'calendar')
115					that.tHead = $('<thead><tr><th id="prev">&lsaquo;</th><th colspan="5" id="currM"></th><th id="next">&rsaquo;</th></tr><tr><th>일</th><th>월</th><th>화</th><th>수</th><th>목</th><th>금</th><th>토</th></tr></thead>');
116				else if (that.options.mode == 'datepicker')
117					that.tHead = $('<thead><tr><th id="prev">&lsaquo;</th><th colspan="5" id="currM"></th><th id="next">&rsaquo;</th></tr><tr><th>일</th><th>월</th><th>화</th><th>수</th><th>목</th><th>금</th><th>토</th></tr></thead>');
118				that.tHead.find('#currM').text( that.date.getFullYear()+"년"+" " + months[that.date.getMonth()]);
119				that.calendar.append(that.tHead);
120				for(var i=1; i<=6; i++){
121					var temp = [$('<td></td>'),$('<td></td>'),$('<td></td>'),$('<td></td>'),$('<td></td>'),$('<td></td>'),$('<td></td>')];
122
123					while(day<=days){
124						d.setDate(day);
125						var dayOfWeek = d.getDay();
126						if(day == that.today.getDate() && d.getMonth() == that.today.getMonth() && d.getFullYear() == that.today.getFullYear()) {
127							temp[dayOfWeek].attr('class', 'currDay');
128						} else if(that.options.mode == 'datepicker' && (day == selDate[1] && d.getMonth() == (selDate[0]-1) && d.getFullYear() == selDate[2])){
129							temp[dayOfWeek].addClass('selected');
130						}
131						if(i == 1 && dayOfWeek == 0){
132							break;
133						} else if(dayOfWeek < 6){
134							temp[dayOfWeek].html('<span>'+(day++)+'</span>').addClass('date');
135						} else {
136							temp[dayOfWeek].html('<span>'+(day++)+'</span>').addClass('date');
137							break;
138						}
139					}
140					if(i == 1 || i > 4){
141						var p = new Date(that.date);
142						p.setMonth(p.getMonth()+(i==1?-1:1));
143						var pDays = p.getDays();
144						for(var a=(i==1?6:0); (i==1?(a>=0):(a<=6)); (i==1?a--:a++)){
145							if(temp[a].text() == ''){
146								temp[a].html('<span>'+((i==1?pDays--:nStartDate++))+'</span>').addClass((i==1?'pMDate':'nMDate'));
147								if(that.options.mode == 'datepicker' && ((i==1?(pDays+1):(nStartDate-1)) == selDate[1] && p.getMonth() == (selDate[0]-1) && p.getFullYear() == selDate[2])){
148									temp[a].addClass('selected');
149								}
150							}
151						}
152					}
153					cal.push(temp);
154				}
155
156				$.each(cal, function(i, v){
157					var row = $('<tr></tr>'), l = v.length;
158					for(var i=0;i<l;i++){ row.append(v[i]); }
159					tBody.append(row);
160				});
161
162				var sysDate = "Today : " + that.today.getFullYear()  + "년 , "+ months[that.today.getMonth()] + " " + that.today.getDate() + "일 , " + daysofweek[that.today.getDay()];
163				tBody.append('<tr><td colspan="7" id="today">'+sysDate+'</td></tr>').appendTo(that.calendar);
164			} else {
165				this.tHead = $('<thead><tr><th id="prev">&lsaquo;</th><th colspan="2" id="currM"></th><th id="next">&rsaquo;</th></tr>');
166				that.tHead.find('#currM').text(that.date.getFullYear());
167				that.tHead.appendTo(that.calendar);
168				var currI = 0;
169				for (var i = 0; i < 3; i++) {
170					var row = $('<tr></tr>');
171					for (var x = 0; x < 4; x++) {
172						var col = $('<td align="center"></td>');
173						var m = $('<span class="month" num="'+currI+'">'+short_months[currI]+'</span>');
174						col.append(m).appendTo(row);
175						currI++;
176					}
177					tBody.append(row);
178				}
179				var sysDate ="Today : " + that.today.getFullYear()  + "년 , "+ months[that.today.getMonth()] + " " + that.today.getDate() + "일 , " + daysofweek[that.today.getDay()];
180				tBody.append('<tr><td colspan="4" id="today">'+sysDate+'</td></tr>').appendTo(that.calendar);
181			}
182		}
183	}
184
185	/* DEFINITION FOR DCALENDAR */
186	$.fn.dcalendar = function(opts){
187		return $(this).each(function(index, elem){
188			var that = this;
189 			var $this = $(that),
190 				data = $(that).data('dcalendar'),
191 				options = $.extend({}, $.fn.dcalendar.defaults, $this.data(), typeof opts == 'object' && opts);
192 			if(!data){
193 				$this.data('dcalendar', (data = new DCalendar(this, options)));
194 			}
195 			if(typeof opts == 'string') data[opts]();
196		});
197	}
198
199	$.fn.dcalendar.defaults = {
200		mode : 'calendar',
201        format: 'yyyy-mm-dd',
202	};
203
204	$.fn.dcalendar.Constructor = DCalendar;
205
206	/* DEFINITION FOR DCALENDAR PICKER */
207	$.fn.dcalendarpicker = function(opts){
208		return $(this).each(function(){
209			var that = $(this);
210			var cal = $('<table id="calendar"></table>'), hovered = false, selectedDate = false;
211			that.wrap($('<div class="datepicker" style="display:inline-block;position:relative;"></div>'));
212			cal.css({
213				position:'absolute',
214				left:0, display:'none',
215				'box-shadow':'0 0 4px rgba(0,0,0,0.15)',
216				width:'220px',
217			}).appendTo(that.parent());
218			if(opts){
219				opts.mode = 'datepicker';
220				cal.dcalendar(opts);
221			}
222			else
223				cal.dcalendar({mode: 'datepicker'});
224			cal.hover(function(){
225				hovered = true;
226			}, function(){
227				hovered = false;
228			}).on('click', function(){
229				if(!selectedDate)
230					that.focus();
231				else {
232					selectedDate = false;
233					$(this).hide();
234				}
235			}).on('selectdate', function(e){
236				that.val(e.date);
237			    that.trigger($.Event('dateselected',{date: e.date, elem: that}));
238				selectedDate = true;
239			});
240			that.on('keydown', function(e){ if(e.which) return false; })
241				.on('focus', function(){
242					$('.datepicker').find('#calendar').not(cal).hide();
243					cal.show();
244				})
245				.on('blur', function(){ if(!hovered) cal.hide(); });
246		});
247	}
248
249}(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.