');
}
clsName = '';
@@ -204,11 +161,11 @@
} else if (prevMonth.getMonth() > month) {
clsName += ' new';
}
- if (prevMonth.valueOf() === currentDate) {
+ if (prevMonth.valueOf() == currentDate) {
clsName += ' active';
}
html.push(''+prevMonth.getDate() + ' | ');
- if (prevMonth.getDay() === this.weekEnd) {
+ if (prevMonth.getDay() == this.weekEnd) {
html.push('');
}
prevMonth.setDate(prevMonth.getDate()+1);
@@ -221,7 +178,7 @@
.text(year)
.end()
.find('span').removeClass('active');
- if (currentYear === year) {
+ if (currentYear == year) {
months.eq(this.date.getMonth()).addClass('active');
}
@@ -234,17 +191,34 @@
.find('td');
year -= 1;
for (var i = -1; i < 11; i++) {
- html += ''+year+'';
+ html += ''+year+'';
year += 1;
}
yearCont.html(html);
},
- click: function(e) {
+ blur:function(e) {
+ },
+
+ hide: function(e){
+ this.picker.hide();
+ $(window).off('resize.Datepicker', this.place);
+ this.viewMode = 0;
+ this.showMode();
+ if (!this.isInput) {
+ $(document).off('mousedown.Datepicker', this.hide);
+ }
+ $('body').off('click.Datepicker',$.proxy(this.click, this));
+ },
+ click:function(e) {
+ e.stopPropagation();
+ e.preventDefault();
+ },
+ mousedown: function(e) {
e.stopPropagation();
e.preventDefault();
var target = $(e.target).closest('span, td, th');
- if (target.length === 1) {
+ if (target.length == 1) {
switch(target[0].nodeName.toLowerCase()) {
case 'th':
switch(target[0].className) {
@@ -256,10 +230,9 @@
this.viewDate['set'+DPGlobal.modes[this.viewMode].navFnc].call(
this.viewDate,
this.viewDate['get'+DPGlobal.modes[this.viewMode].navFnc].call(this.viewDate) +
- DPGlobal.modes[this.viewMode].navStep * (target[0].className === 'prev' ? -1 : 1)
+ DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1)
);
this.fill();
- this.set();
break;
}
break;
@@ -271,17 +244,8 @@
var year = parseInt(target.text(), 10)||0;
this.viewDate.setFullYear(year);
}
- if (this.viewMode !== 0) {
- this.date = new Date(this.viewDate);
- this.element.trigger({
- type: 'changeDate',
- date: this.date,
- viewMode: DPGlobal.modes[this.viewMode].clsName
- });
- }
this.showMode(-1);
this.fill();
- this.set();
break;
case 'td':
if (target.is('.day')){
@@ -294,42 +258,43 @@
}
var year = this.viewDate.getFullYear();
this.date = new Date(year, month, day,0,0,0,0);
- this.viewDate = new Date(year, month, Math.min(28, day),0,0,0,0);
+ this.viewDate = new Date(year, month, day,0,0,0,0);
this.fill();
- this.set();
+ this.setValue();
this.element.trigger({
type: 'changeDate',
- date: this.date,
- viewMode: DPGlobal.modes[this.viewMode].clsName
+ date: this.date
});
+ this.hide();
}
break;
}
}
},
-
- mousedown: function(e){
- e.stopPropagation();
- e.preventDefault();
- },
-
+ keydown:function(e) {
+ var keyCode = e.keyCode || e.which;
+ if (keyCode == 9) this.hide(); // when hiting TAB, for accessibility
+ },
+
showMode: function(dir) {
if (dir) {
- this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
+ this.viewMode = Math.max(0, Math.min(2, this.viewMode + dir));
}
this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
- }
+ },
+
+ destroy: function() { this.element.removeData("datepicker").off(".Datepicker"); this.picker.remove() }
};
- $.fn.datepicker = function ( option, val ) {
+ $.fn.datepicker = function ( option ) {
return this.each(function () {
var $this = $(this),
data = $this.data('datepicker'),
- options = typeof option === 'object' && option;
+ options = typeof option == 'object' && option;
if (!data) {
$this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
}
- if (typeof option === 'string') data[option](val);
+ if (typeof option == 'string') data[option]();
});
};
@@ -368,22 +333,20 @@
return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
},
parseFormat: function(format){
- var separator = format.match(/[.\/\-\s].*?/),
+ var separator = format.match(/[.\/-].*?/),
parts = format.split(/\W+/);
- if (!separator || !parts || parts.length === 0){
+ if (!separator || !parts || parts.length == 0){
throw new Error("Invalid date format.");
}
return {separator: separator, parts: parts};
},
parseDate: function(date, format) {
+ var today=new Date();
+ if (!date) date="";
var parts = date.split(format.separator),
- date = new Date(),
+ date = new Date(today.getFullYear(),today.getMonth(),today.getDate(),0,0,0),
val;
- date.setHours(0);
- date.setMinutes(0);
- date.setSeconds(0);
- date.setMilliseconds(0);
- if (parts.length === format.parts.length) {
+ if (parts.length == format.parts.length) {
for (var i=0, cnt = format.parts.length; i < cnt; i++) {
val = parseInt(parts[i], 10)||1;
switch(format.parts[i]) {
@@ -423,9 +386,9 @@
},
headTemplate: ''+
''+
- '‹ | '+
+ ' | '+
' | '+
- '› | '+
+ ' | '+
'
'+
'',
contTemplate: ' |
'
diff --git a/src/html/index.html b/src/html/index.html
index 4167fc6..3421ffa 100644
--- a/src/html/index.html
+++ b/src/html/index.html
@@ -103,12 +103,12 @@
+
+
+
@@ -147,6 +150,7 @@
+