var DatePicker = function () { var $ = function (i) {return document.getElementById(i)}, addEvent = function (o, e, f) {o.addEventListener ? o.addEventListener(e, f, false) : o.attachEvent('on' e, function(){f.call(o)})}, getPos = function (el) { for (var pos = {x:0, y:0}; el = el.offsetParent) { pos.x = el.offsetLeft; pos.y = el.offsetTop; } pos を返します。 }
var init = function (n, config) { window[n] = this; Date.prototype._fd = function () {var d = new Date(this); d.setDate(1);戻り値 d.getDay()}; Date.prototype._fc = function () {var d1 = 新しい日付 (この), d2 = 新しい日付 (この); d1.setDate(1); d2.setDate(1); d2.setMonth(d2.getMonth() 1);戻り値 (d2-d1)/86400000;}; this.n = n; this.config = 設定; this.D = 新しい日付; this.el = $(config.inputId); this.el.title = this.n 'DatePicker';
this.update(); this.bind(); } init.prototype = {
update : function (y, m) { var con = [], week = ['Su','Mo','Tu' ,'We','Th','Fr','Sa'], D = this.D, _this = this; fn = function (a, b) {return '
'}, _html = '
'; y && D.setyear(D.getFull Year() y); m && D.setMonth(D.getMonth() m); var 年 = D.getFull Year()、月 = D.getMonth() 1、日付 = D.getDate(); for (var i=0; i'); for (var i=0; i>for (var i=0; i' (i 1) ''); var toend = con.length%7; if (toend != 0) for (var i=0; i<7-toend; i ) con.push('
'); _html = '
' fn("-1, null", "<<") fn("null, -1", "<") '
年 '/' 月 '/' 日付 '
' fn("null, 1", ">") fn("1, null", ">>") '
'; for (var i=0; i' : i%7==0 ? '
' : '') con[i] (i == con.length-1 ? '
' : ''); !!このボックス ? this.box.innerHTML = _html : this.createBox(_html); }, fillInput : function (y, m, d) { var s = this.config.seprator || '/'; this.el.value = y s m s d; this.box.style.display = 'none'; }, show : function () { var s = this.box.style, is = this.mask.style; s['left'] = is['left'] = getPos(this.el).x 'px'; s['top'] = is['top'] = getPos(this.el).y this.el.offsetHeight 'px'; s['表示'] = is['表示'] = 'ブロック'; is['width'] = this.box.offsetWidth - 2 'px'; is['height'] = this.box.offsetHeight - 2 'px'; }, hide : function () { this.box.style.display = 'none'; this.mask.style.display = 'none'; }, bind : function () { var _this = this; addEvent(document, 'click', function (e) { e = e || window.event; var t = e.target || e.srcElement; if (t. title != _this.n 'DatePicker') {_this.hide()} else {_this.show()} }) }, createBox : function (html) { var box = this.box = document.createElement('div')、マスク = this.mask = document.createElement('iframe'); box.className = this.config.className || '日付ピッカー'; mask.src = 'javascript:false'; マスク.フレームボーダー = 0; box.style.cssText = '位置:絶対;表示:なし;z-index:9999'; mask.style.cssText = '位置:絶対;表示:なし;z-index:9998'; box.title = this.n 'DatePicker'; box.innerHTML = html; document.body.appendChild(box); document.body.appendChild(マスク);