true
if language is right-to-left. */
regionalOptions: { // Available regional settings, indexed by language/country code
@@ -1756,6 +1758,8 @@
closeText: 'Close',
closeStatus: 'Close the datepicker',
yearStatus: 'Change the year',
+ earlierText: ' ▲',
+ laterText: ' ▼',
monthStatus: 'Change the month',
weekText: 'Wk',
weekStatus: 'Week of the year',
@@ -2123,7 +2127,10 @@
}
}
if (inst.inline) {
+ var index = $('a, :input', elem).index($(':focus', elem));
elem.html(this._generateContent(elem[0], inst));
+ var focus = elem.find('a, :input');
+ focus.eq(Math.max(Math.min(index, focus.length - 1), 0)).focus();
}
else if (plugin.curInst === inst) {
if (!inst.div) {
@@ -2305,10 +2312,10 @@
@param event {KeyEvent} The keystroke.
@return {boolean} true
if not handled, false
if handled. */
_keyDown: function(event) {
- var elem = event.target;
+ var elem = (event.data && event.data.elem) || event.target;
var inst = plugin._getInst(elem);
var handled = false;
- if (inst.div) {
+ if (inst.inline || inst.div) {
if (event.keyCode === 9) { // Tab - close
plugin.hide(elem);
}
@@ -2356,7 +2363,7 @@
@param event {KeyEvent} The keystroke.
@return {boolean} true
if allowed, false
if not allowed. */
_keyPress: function(event) {
- var inst = plugin._getInst(event.target);
+ var inst = plugin._getInst((event.data && event.data.elem) || event.target);
if (!$.isEmptyObject(inst) && inst.options.constrainInput) {
var ch = String.fromCharCode(event.keyCode || event.charCode);
var allowedChars = plugin._allowedChars(inst);
@@ -2419,7 +2426,7 @@
@param event {KeyEvent} The keystroke.
@return {boolean} true
if allowed, false
if not allowed. */
_keyUp: function(event) {
- var elem = event.target;
+ var elem = (event.data && event.data.elem) || event.target;
var inst = plugin._getInst(elem);
if (!$.isEmptyObject(inst) && !inst.ctrlKey && inst.lastVal !== inst.elem.val()) {
try {
@@ -2702,7 +2709,7 @@
else {
inst.selectedDates = [date];
}
- inst.prevDate = date.newDate();
+ inst.prevDate = inst.drawDate = date.newDate();
this._updateInput(elem);
if (inst.inline || inst.pickingRange || inst.selectedDates.length <
(inst.options.multiSelect || (inst.options.rangeSelect ? 2 : 1))) {
@@ -2770,18 +2777,17 @@
}
// Add datepicker behaviour
var self = this;
+ function removeHighlight() {
+ (inst.inline ? $(this).closest('.' + self._getMarker()) : inst.div).
+ find(inst.options.renderer.daySelector + ' a').
+ removeClass(inst.options.renderer.highlightedClass);
+ }
picker.find(inst.options.renderer.daySelector + ' a').hover(
function() {
- (inst.inline ? $(this).closest('.' + self._getMarker()) : inst.div).
- find(inst.options.renderer.daySelector + ' a').
- removeClass(inst.options.renderer.highlightedClass);
+ removeHighlight.apply(this);
$(this).addClass(inst.options.renderer.highlightedClass);
},
- function() {
- (inst.inline ? $(this).closest('.' + self._getMarker()) : inst.div).
- find(inst.options.renderer.daySelector + ' a').
- removeClass(inst.options.renderer.highlightedClass);
- }).
+ removeHighlight).
click(function() {
self.selectDate(elem, this);
}).end().
@@ -2813,6 +2819,9 @@
inst.elem.focus();
}
});
+ // Add keyboard handling
+ var data = {elem: inst.elem[0]};
+ picker.keydown(data, this._keyDown).keypress(data, this._keyPress).keyup(data, this._keyUp);
// Add command behaviour
picker.find('.' + inst.options.renderer.commandClass).click(function() {
if (!$(this).hasClass(inst.options.renderer.disabledClass)) {
@@ -2916,7 +2925,7 @@
(dateInfo.title || (inst.options.dayStatus && selectable) ? ' title="' +
(dateInfo.title || drawDate.formatDate(inst.options.dayStatus)) + '"' : '') + '>' +
(inst.options.showOtherMonths || drawDate.month() === month ?
- dateInfo.content || drawDate.day() : ' ') +
+ dateInfo.content || drawDate.day() : ' ') +
(selectable ? '' : ''));
drawDate.add(1, 'd');
jd++;
@@ -3011,27 +3020,41 @@
'" title="' + inst.options.yearStatus + '">';
start = calendar.newDate(start + 1, calendar.firstMonth, calendar.minDay).add(-1, 'd');
end = calendar.newDate(end, calendar.firstMonth, calendar.minDay);
- var addYear = function(y) {
+ var addYear = function(y, yDisplay) {
if (y !== 0 || calendar.hasYearZero) {
selector += '';
+ (yDisplay || y) + '';
}
};
if (start.toJD() < end.toJD()) {
start = (minDate && minDate.compareTo(start) === +1 ? minDate : start).year();
end = (maxDate && maxDate.compareTo(end) === -1 ? maxDate : end).year();
+ var earlierLater = Math.floor((end - start) / 2);
+ if (!minDate || minDate.year() < start) {
+ addYear(start - earlierLater, inst.options.earlierText);
+ }
for (var y = start; y <= end; y++) {
addYear(y);
}
+ if (!maxDate || maxDate.year() > end) {
+ addYear(end + earlierLater, inst.options.laterText);
+ }
}
else {
start = (maxDate && maxDate.compareTo(start) === -1 ? maxDate : start).year();
end = (minDate && minDate.compareTo(end) === +1 ? minDate : end).year();
+ var earlierLater = Math.floor((start - end) / 2);
+ if (!maxDate || maxDate.year() > start) {
+ addYear(start + earlierLater, inst.options.earlierText);
+ }
for (var y = start; y >= end; y--) {
addYear(y);
}
+ if (!minDate || minDate.year() < end) {
+ addYear(end - earlierLater, inst.options.laterText);
+ }
}
selector += '';
}
diff --git a/jquery.calendars.all.min.js b/jquery.calendars.all.min.js
index 87d771c..6a6c967 100644
--- a/jquery.calendars.all.min.js
+++ b/jquery.calendars.all.min.js
@@ -1,6 +1,6 @@
/* http://keith-wood.name/calendars.html
- Calendars for jQuery v2.0.0.
+ Calendars for jQuery v2.0.1.
Written by Keith Wood (kbwood{at}iinet.com.au) August 2009.
- Available under the MIT (https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt) license.
+ Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
-(function($){function Calendars(){this.regionalOptions=[];this.regionalOptions['']={invalidCalendar:'Calendar {0} not found',invalidDate:'Invalid {0} date',invalidMonth:'Invalid {0} month',invalidYear:'Invalid {0} year',differentCalendars:'Cannot mix {0} and {1} dates'};this.local=this.regionalOptions[''];this.calendars={};this._localCals={}}$.extend(Calendars.prototype,{instance:function(a,b){a=(a||'gregorian').toLowerCase();b=b||'';var c=this._localCals[a+'-'+b];if(!c&&this.calendars[a]){c=new this.calendars[a](b);this._localCals[a+'-'+b]=c}if(!c){throw(this.local.invalidCalendar||this.regionalOptions[''].invalidCalendar).replace(/\{0\}/,a)}return c},newDate:function(a,b,c,d,e){d=(a!=null&&a.year?a.calendar():(typeof d==='string'?this.instance(d,e):d))||this.instance();return d.newDate(a,b,c)}});function CDate(a,b,c,d){this._calendar=a;this._year=b;this._month=c;this._day=d;if(this._calendar._validateLevel===0&&!this._calendar.isValid(this._year,this._month,this._day)){throw($.calendars.local.invalidDate||$.calendars.regionalOptions[''].invalidDate).replace(/\{0\}/,this._calendar.local.name)}}function pad(a,b){a=''+a;return'000000'.substring(0,b-a.length)+a}$.extend(CDate.prototype,{newDate:function(a,b,c){return this._calendar.newDate((a==null?this:a),b,c)},year:function(a){return(arguments.length===0?this._year:this.set(a,'y'))},month:function(a){return(arguments.length===0?this._month:this.set(a,'m'))},day:function(a){return(arguments.length===0?this._day:this.set(a,'d'))},date:function(a,b,c){if(!this._calendar.isValid(a,b,c)){throw($.calendars.local.invalidDate||$.calendars.regionalOptions[''].invalidDate).replace(/\{0\}/,this._calendar.local.name)}this._year=a;this._month=b;this._day=c;return this},leapYear:function(){return this._calendar.leapYear(this)},epoch:function(){return this._calendar.epoch(this)},formatYear:function(){return this._calendar.formatYear(this)},monthOfYear:function(){return this._calendar.monthOfYear(this)},weekOfYear:function(){return this._calendar.weekOfYear(this)},daysInYear:function(){return this._calendar.daysInYear(this)},dayOfYear:function(){return this._calendar.dayOfYear(this)},daysInMonth:function(){return this._calendar.daysInMonth(this)},dayOfWeek:function(){return this._calendar.dayOfWeek(this)},weekDay:function(){return this._calendar.weekDay(this)},extraInfo:function(){return this._calendar.extraInfo(this)},add:function(a,b){return this._calendar.add(this,a,b)},set:function(a,b){return this._calendar.set(this,a,b)},compareTo:function(a){if(this._calendar.name!==a._calendar.name){throw($.calendars.local.differentCalendars||$.calendars.regionalOptions[''].differentCalendars).replace(/\{0\}/,this._calendar.local.name).replace(/\{1\}/,a._calendar.local.name)}var c=(this._year!==a._year?this._year-a._year:this._month!==a._month?this.monthOfYear()-a.monthOfYear():this._day-a._day);return(c===0?0:(c<0?-1:+1))},calendar:function(){return this._calendar},toJD:function(){return this._calendar.toJD(this)},fromJD:function(a){return this._calendar.fromJD(a)},toJSDate:function(){return this._calendar.toJSDate(this)},fromJSDate:function(a){return this._calendar.fromJSDate(a)},toString:function(){return(this.year()<0?'-':'')+pad(Math.abs(this.year()),4)+'-'+pad(this.month(),2)+'-'+pad(this.day(),2)}});function BaseCalendar(){this.shortYearCutoff='+10'}$.extend(BaseCalendar.prototype,{_validateLevel:0,newDate:function(a,b,c){if(a==null){return this.today()}if(a.year){this._validate(a,b,c,$.calendars.local.invalidDate||$.calendars.regionalOptions[''].invalidDate);c=a.day();b=a.month();a=a.year()}return new CDate(this,a,b,c)},today:function(){return this.fromJSDate(new Date())},epoch:function(a){var b=this._validate(a,this.minMonth,this.minDay,$.calendars.local.invalidYear||$.calendars.regionalOptions[''].invalidYear);return(b.year()<0?this.local.epochs[0]:this.local.epochs[1])},formatYear:function(a){var b=this._validate(a,this.minMonth,this.minDay,$.calendars.local.invalidYear||$.calendars.regionalOptions[''].invalidYear);return(b.year()<0?'-':'')+pad(Math.abs(b.year()),4)},monthsInYear:function(a){this._validate(a,this.minMonth,this.minDay,$.calendars.local.invalidYear||$.calendars.regionalOptions[''].invalidYear);return 12},monthOfYear:function(a,b){var c=this._validate(a,b,this.minDay,$.calendars.local.invalidMonth||$.calendars.regionalOptions[''].invalidMonth);return(c.month()+this.monthsInYear(c)-this.firstMonth)%this.monthsInYear(c)+this.minMonth},fromMonthOfYear:function(a,b){var m=(b+this.firstMonth-2*this.minMonth)%this.monthsInYear(a)+this.minMonth;this._validate(a,m,this.minDay,$.calendars.local.invalidMonth||$.calendars.regionalOptions[''].invalidMonth);return m},daysInYear:function(a){var b=this._validate(a,this.minMonth,this.minDay,$.calendars.local.invalidYear||$.calendars.regionalOptions[''].invalidYear);return(this.leapYear(b)?366:365)},dayOfYear:function(a,b,c){var d=this._validate(a,b,c,$.calendars.local.invalidDate||$.calendars.regionalOptions[''].invalidDate);return d.toJD()-this.newDate(d.year(),this.fromMonthOfYear(d.year(),this.minMonth),this.minDay).toJD()+1},daysInWeek:function(){return 7},dayOfWeek:function(a,b,c){var d=this._validate(a,b,c,$.calendars.local.invalidDate||$.calendars.regionalOptions[''].invalidDate);return(Math.floor(this.toJD(d))+2)%this.daysInWeek()},extraInfo:function(a,b,c){this._validate(a,b,c,$.calendars.local.invalidDate||$.calendars.regionalOptions[''].invalidDate);return{}},add:function(a,b,c){this._validate(a,this.minMonth,this.minDay,$.calendars.local.invalidDate||$.calendars.regionalOptions[''].invalidDate);return this._correctAdd(a,this._add(a,b,c),b,c)},_add:function(c,f,g){this._validateLevel++;if(g==='d'||g==='w'){var h=c.toJD()+f*(g==='w'?this.daysInWeek():1);var d=c.calendar().fromJD(h);this._validateLevel--;return[d.year(),d.month(),d.day()]}try{var y=c.year()+(g==='y'?f:0);var m=c.monthOfYear()+(g==='m'?f:0);var d=c.day();var i=function(a){while(m