/* sky.calendar.js 2007-12-11 ~ Seo, Jaehan @dependence sky.base.js @dependence sky.ajax.js # 날짜, 시간 선택 가능. 선택 항목 지정 가능 (date, time, datetime) # 시간선택 - select, spin, 시계 모양(?보류) # 결과물 포맷 지정 가능 (php date() style) */ if (typeof Calendar == 'undefined') { var Calendar = Class({ init : function(options) { Class.extend(this, { path : Util.getJSPath('sky.calendar.js'), id : '__calendar__', language: LANG_CODE || 'ko', languageText: [], skin : 'sunny', theme : 'default', format : 'Y-m-d', applyCallback : null, useImageYear : false, // can be changed by use_image_year attibute of #__calendar_box object useImageMonth : false, // can be changed by use_image_month attibute of #__calendar_box object useImageDay : false, // can be changed by use_image_day attibute of #__calendar_box object imgBase : '', // can be changed by image_base attibute of #__calendar_box object todayApply : false, yearMinTerms : 100 }, options); this.today = new Date(); this.todayYmd = this.formatDate(this.today, this.format == 'Y-m-d H:i:s' ? 'YmdHis' : 'Ymd'); //this.todayYmd = this.today.getFullYear() + ('0'+(this.today.getMonth()+1)).slice(-2) + ('0'+this.today.getDate()).slice(-2); //if (this.format == 'Y-m-d H:i:s') { // this.todayYmd += ('0'+(this.today.getHours())).slice(-2) + ('0'+this.today.getMinutes()).slice(-2) + ('0'+this.today.getSeconds()).slice(-2); //} this.setDate(this.today); // event bind this.evtPrevYear = this.prevYear.bindForEvent(this); this.evtNextYear = this.nextYear.bindForEvent(this); this.evtPrevMonth = this.prevMonth.bindForEvent(this); this.evtNextMonth = this.nextMonth.bindForEvent(this); this.evtJumpTo = this.jumpTo.bindForEvent(this); this.evtApply = this.apply.bindForEvent(this); //this.evtApplyDateTime = this.apply_dt.bindForEvent(this); this.evtOpen = this.open.bindForEvent(this); this.evtClose = this.close.bindForEvent(this); // make layer object this.initLayer(); }, attach : function(object, handler) { if (object instanceof Array) { for (var i=0; i=min; i--) { var option = new Option; option.value = i; option.text = i; if (i == value) { option.selected = true; } object.options.add(option); } } else { for (var i=0; i'; } else { value = ('0'+value).slice(-2); if (Element.classExists(object, 'today')) { object.innerHTML = ''; } else if (wday == 0) { object.innerHTML = ''; } else if (wday == 6) { object.innerHTML = ''; } else { object.innerHTML = ''; } } }, prevYear : function() { this.year--; this.display(); }, prevMonth : function() { this.month--; if (this.month <= 0) { this.year--; this.month += 12; } this.display(); }, nextMonth : function() { this.month++; if (this.month > 12) { this.year++; this.month -= 12; } this.display(); }, nextYear : function() { this.year++; this.display(); }, jumpTo : function() { if (this.skin == 'datetime') return; var year = this.getValue($id('__calendar_year')); var month = this.getValue($id('__calendar_month')); if ((year && year != this.year) || (month && month != this.month)) { this.year = year; this.month = month; this.display(); } }, initLayer : function() { if ($id(this.id)) { this.layer = $id(this.id); this.layer.attachBlocker('calendar'); return this.layer; } this.layer = $e($c('div')); this.layer.id = this.id; if ( this.target != void 0 ) { document.querySelector(this.target).appendChild(this.layer); } else { document.body.appendChild(this.layer); } this.layer.setStyle({ position : 'absolute', display : 'none', zIndex : 10 }); this.layer.attachBlocker('calendar'); var self = this; var ajax = new Ajax({ url : '/common/js/calendar/' + this.skin + '/calendar.html?dummy=' + Util.random(1, 999), calendar : this, callback : function(response) { if (response.isSuccess()) { self.layer.innerHTML = response.value; self.initLayerEvent.call(self); var langText = self.langText(self.language || 'ko'); if (langText instanceof Array && langText.length === 7) { langText.forEach(function(text, i) { self.layer.querySelector('.day' + i).innerHTML = text; }); } var box = $id('__calendar_box'); if (box) { if (box.getAttribute('use_image_year') == 'true') { self.useImageYear = true; } if (box.getAttribute('use_image_month') == 'true') { self.useImageMonth = true; } if (box.getAttribute('use_image_day') == 'true') { self.useImageDay = true; } if (box.getAttribute('img_base')) { self.imgBase = box.getAttribute('img_base'); } } } } }); var css = '/common/js/calendar/' + this.skin + '/' + this.theme + '.css' + '?dummy=' + Util.random(1, 999); Util.linkCSS(css, '__calendar_css'); return this.layer; }, initLayerEvent : function() { if ($id('__calendar_prev_year')) $l($id('__calendar_prev_year'), 'click', this.evtPrevYear); if ($id('__calendar_prev_month')) $l($id('__calendar_prev_month'), 'click', this.evtPrevMonth); if ($id('__calendar_next_month')) $l($id('__calendar_next_month'), 'click', this.evtNextMonth); if ($id('__calendar_next_year')) $l($id('__calendar_next_year'), 'click', this.evtNextYear); if ($id('__calendar_year')) { var el = $id('__calendar_year'); var evtType = (el.tagName.search(/select/i) != -1) ? 'change' : 'blur'; $l(el, 'change', this.evtJumpTo); } if ($id('__calendar_month')) { var el = $id('__calendar_month'); var evtType = (el.tagName.search(/select/i) != -1) ? 'change' : 'blur'; $l(el, 'change', this.evtJumpTo); } if ($id('__calendar_today')) $l($id('__calendar_today'), 'click', this.evtApply); //if ($id('__calendar_apply')) $l($id('__calendar_apply'), 'click', this.evtApplyDateTime); if ($id('__calendar_apply')) $l($id('__calendar_apply'), 'click', this.evtApply); if ($id('__calendar_close')) $l($id('__calendar_close'), 'click', this.evtClose); $l($$('__calendar_day##'), 'click', this.evtApply); }, langText : function(language) { if (this.languageText instanceof Array && this.languageText.length === 7) { return this.languageText; } else if (language === 'cn' || language === 'jp') { return ['日', '月', '火', '水', '木', '金', '土']; } else if (language !== 'ko') { return ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; } } }); }