jQuery
// is returned.
//---------------------------------------------------------------------
btn: function( parent, text, handler, classes, title )
{
var tagName = ( (parent[0].nodeName.toLowerCase()=='ul')?'li':'td');
var div$ = '<' + tagName +
' class="AnyTime-btn';
for ( var i = 0 ; i < classes.length ; i++ )
div$ += ' AnyTime-' + classes[i] + '-btn';
var div = $( div$ + ' ui-state-default">' + text + '' + tagName + '>' );
parent.append(div);
div.AnyTime_title = title;
div.click(
function(e)
{
// bind the handler to the picker so "this" is correct
_this.tempFunc = handler;
_this.tempFunc(e);
});
div.dblclick(
function(e)
{
var elem = $(this);
if ( elem.is('.AnyTime-off-off-btn') )
_this.dismissODiv(e);
else if ( elem.is('.AnyTime-mil-btn') || elem.is('.AnyTime-cent-btn') || elem.is('.AnyTime-dec-btn') || elem.is('.AnyTime-yr-btn') || elem.is('.AnyTime-era-btn') )
_this.dismissYDiv(e);
else if ( _this.pop )
_this.dismiss(e);
});
return div;
}, // .btn()
//---------------------------------------------------------------------
// .cleanup() destroys the DOM events and elements associated with
// the picker so it can be deleted.
//---------------------------------------------------------------------
cleanup: function(event)
{
this.
inp.
prop('readonly',this.ro).
off('blur',this.hBlur).
off('click',this.hClick).
off('focus',this.hFocus).
off('keydown',this.hKeydown).
off('keypress',this.hKeypress);
$(window).off('resize',this.hResize);
this.div.remove();
},
//---------------------------------------------------------------------
// .dismiss() dismisses a popup picker.
//---------------------------------------------------------------------
dismiss: function(event)
{
this.ajax();
if ( this.yDiv )
this.dismissYDiv();
if ( this.oDiv )
this.dismissODiv();
this.div.hide();
this.lostFocus = true;
},
//---------------------------------------------------------------------
// .dismissODiv() dismisses the UTC offset selector popover.
//---------------------------------------------------------------------
dismissODiv: function(event)
{
this.oDiv.hide();
this.cloak.hide();
this.setFocus(this.oCur);
},
//---------------------------------------------------------------------
// .dismissYDiv() dismisses the date selector popover.
//---------------------------------------------------------------------
dismissYDiv: function(event)
{
this.yDiv.hide();
this.cloak.hide();
this.setFocus(this.yCur);
},
//---------------------------------------------------------------------
// .setFocus() makes a specified psuedo-button appear to get focus.
//---------------------------------------------------------------------
setFocus: function(btn)
{
if ( ! btn.hasClass('AnyTime-focus-btn') )
{
this.div.find('.AnyTime-focus-btn').removeClass('AnyTime-focus-btn ui-state-focus');
this.fBtn = btn;
btn.removeClass('ui-state-default ui-state-highlight');
btn.addClass('AnyTime-focus-btn ui-state-default ui-state-highlight ui-state-focus');
}
if ( btn.hasClass('AnyTime-off-off-btn') )
{
var oBT = this.oBody.offset().top;
var btnT = btn.offset().top;
var btnH = btn.outerHeight(true);
if ( btnT - btnH < oBT ) // move a page up
this.oBody.scrollTop( btnT + this.oBody.scrollTop() - ( this.oBody.innerHeight() + oBT ) + ( btnH * 2 ) );
else if ( btnT + btnH > oBT + this.oBody.innerHeight() ) // move a page down
this.oBody.scrollTop( ( btnT + this.oBody.scrollTop() ) - ( oBT + btnH ) );
}
},
//---------------------------------------------------------------------
// .key() is invoked when a user presses a key while the picker's
// input has focus. A psuedo-button is considered "in focus" and an
// appropriate action is performed according to the WAI-ARIA Authoring
// Practices 1.0 for datepicker from
// www.w3.org/TR/2009/WD-wai-aria-practices-20091215/#datepicker:
//
// * LeftArrow moves focus left, continued to previous week.
// * RightArrow moves focus right, continued to next week.
// * UpArrow moves focus to the same weekday in the previous week.
// * DownArrow moves focus to same weekday in the next week.
// * PageUp moves focus to same day in the previous month.
// * PageDown moves focus to same day in the next month.
// * Shift+Page Up moves focus to same day in the previous year.
// * Shift+Page Down moves focus to same day in the next year.
// * Home moves focus to the first day of the month.
// * End moves focus to the last day of the month.
// * Ctrl+Home moves focus to the first day of the year.
// * Ctrl+End moves focus to the last day of the year.
// * Esc closes a DatePicker that is opened as a Popup.
//
// The following actions (for multiple-date selection) are NOT
// supported:
// * Shift+Arrow performs continous selection.
// * Ctrl+Space multiple selection of certain days.
//
// The authoring practices do not specify behavior for a time picker,
// or for month-and-year pickers that do not have a day-of-the-month,
// but AnyTime.picker uses the following behavior to be as consistent
// as possible with the defined datepicker functionality:
// * LeftArrow moves focus left or up to previous value or field.
// * RightArrow moves focus right or down to next value or field.
// * UpArrow moves focus up or left to previous value or field.
// * DownArrow moves focus down or right to next value or field
// * PageUp moves focus to the current value in the previous units
// (for example, from ten-minutes to hours or one-minutes to
// ten-minutes or months to years).
// * PageDown moves focus to the current value in the next units
// (for example, from hours to ten-minutes or ten-minutes to
// one-minutes or years to months).
// * Home moves the focus to the first unit button.
// * End moves the focus to the last unit button.
//
// In addition, Tab and Shift+Tab move between units (including to/
// from the Day-of-Month table) and also in/out of the picker.
//
// Because AnyTime.picker sets a value as soon as the button receives
// focus, SPACE and ENTER are not needed (the WAI-ARIA guidelines use
// them to select a value.
//---------------------------------------------------------------------
key: function(event)
{
var mo;
var t = null;
var _this = this;
var elem = this.div.find('.AnyTime-focus-btn');
var key = event.keyCode || event.which;
this.denyTab = true;
if ( key == 16 ) // Shift
{
}
else if ( ( key == 10 ) || ( key == 13 ) || ( key == 27 ) ) // Enter & Esc
{
if ( this.oDiv && this.oDiv.is(':visible') )
this.dismissODiv(event);
else if ( this.yDiv && this.yDiv.is(':visible') )
this.dismissYDiv(event);
else if ( this.pop )
this.dismiss(event);
}
else if ( ( key == 33 ) || ( ( key == 9 ) && event.shiftKey ) ) // PageUp & Shift+Tab
{
if ( this.fBtn.hasClass('AnyTime-off-off-btn') )
{
if ( key == 9 )
this.dismissODiv(event);
}
else if ( this.fBtn.hasClass('AnyTime-mil-btn') )
{
if ( key == 9 )
this.dismissYDiv(event);
}
else if ( this.fBtn.hasClass('AnyTime-cent-btn') )
this.yDiv.find('.AnyTime-mil-btn.AnyTime-cur-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-dec-btn') )
this.yDiv.find('.AnyTime-cent-btn.AnyTime-cur-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-yr-btn') )
this.yDiv.find('.AnyTime-dec-btn.AnyTime-cur-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-era-btn') )
this.yDiv.find('.AnyTime-yr-btn.AnyTime-cur-btn').triggerHandler('click');
else if ( this.fBtn.parents('.AnyTime-yrs').length )
{
if ( key == 9 )
{
this.denyTab = false;
return;
}
}
else if ( this.fBtn.hasClass('AnyTime-mon-btn') )
{
if ( this.dY )
this.yCur.triggerHandler('click');
else if ( key == 9 )
{
this.denyTab = false;
return;
}
}
else if ( this.fBtn.hasClass('AnyTime-dom-btn') )
{
if ( ( key == 9 ) && event.shiftKey ) // Shift+Tab
{
this.denyTab = false;
return;
}
else // PageUp
{
t = new Date(this.time.getTime());
if ( event.shiftKey )
t.setFullYear(t.getFullYear()-1);
else
{
mo = t.getMonth()-1;
if ( t.getDate() > __daysIn[mo] )
t.setDate(__daysIn[mo])
t.setMonth(mo);
}
this.keyDateChange(t);
}
}
else if ( this.fBtn.hasClass('AnyTime-hr-btn') )
{
t = this.dDoM || this.dMo;
if ( t )
t.AnyTime_clickCurrent();
else if ( this.dY )
this.yCur.triggerHandler('click');
else if ( key == 9 )
{
this.denyTab = false;
return;
}
}
else if ( this.fBtn.hasClass('AnyTime-min-ten-btn') )
{
t = this.dH || this.dDoM || this.dMo;
if ( t )
t.AnyTime_clickCurrent();
else if ( this.dY )
this.yCur.triggerHandler('click');
else if ( key == 9 )
{
this.denyTab = false;
return;
}
}
else if ( this.fBtn.hasClass('AnyTime-min-one-btn') )
this.dM.AnyTime_clickCurrent();
else if ( this.fBtn.hasClass('AnyTime-sec-ten-btn') )
{
if ( this.dM )
t = this.dM.find('.AnyTime-mins-ones');
else
t = this.dH || this.dDoM || this.dMo;
if ( t )
t.AnyTime_clickCurrent();
else if ( this.dY )
this.yCur.triggerHandler('click');
else if ( key == 9 )
{
this.denyTab = false;
return;
}
}
else if ( this.fBtn.hasClass('AnyTime-sec-one-btn') )
this.dS.AnyTime_clickCurrent();
else if ( this.fBtn.hasClass('AnyTime-off-btn') )
{
if ( this.dS )
t = this.dS.find('.AnyTime-secs-ones');
else if ( this.dM )
t = this.dM.find('.AnyTime-mins-ones');
else
t = this.dH || this.dDoM || this.dMo;
if ( t )
t.AnyTime_clickCurrent();
else if ( this.dY )
this.yCur.triggerHandler('click');
else if ( key == 9 )
{
this.denyTab = false;
return;
}
}
}
else if ( ( key == 34 ) || ( key == 9 ) ) // PageDown or Tab
{
if ( this.fBtn.hasClass('AnyTime-mil-btn') )
this.yDiv.find('.AnyTime-cent-btn.AnyTime-cur-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-cent-btn') )
this.yDiv.find('.AnyTime-dec-btn.AnyTime-cur-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-dec-btn') )
this.yDiv.find('.AnyTime-yr-btn.AnyTime-cur-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-yr-btn') )
{
t = this.yDiv.find('.AnyTime-era-btn.AnyTime-cur-btn');
if ( t.length )
t.triggerHandler('click');
else if ( key == 9 )
this.dismissYDiv(event);
}
else if ( this.fBtn.hasClass('AnyTime-era-btn') )
{
if ( key == 9 )
this.dismissYDiv(event);
}
else if ( this.fBtn.hasClass('AnyTime-off-off-btn') )
{
if ( key == 9 )
this.dismissODiv(event);
}
else if ( this.fBtn.parents('.AnyTime-yrs').length )
{
t = this.dDoM || this.dMo || this.dH || this.dM || this.dS || this.dO;
if ( t )
t.AnyTime_clickCurrent();
else if ( key == 9 )
{
this.denyTab = false;
return;
}
}
else if ( this.fBtn.hasClass('AnyTime-mon-btn') )
{
t = this.dDoM || this.dH || this.dM || this.dS || this.dO;
if ( t )
t.AnyTime_clickCurrent();
else if ( key == 9 )
{
this.denyTab = false;
return;
}
}
else if ( this.fBtn.hasClass('AnyTime-dom-btn') )
{
if ( key == 9 ) // Tab
{
t = this.dH || this.dM || this.dS || this.dO;
if ( t )
t.AnyTime_clickCurrent();
else
{
this.denyTab = false;
return;
}
}
else // PageDown
{
t = new Date(this.time.getTime());
if ( event.shiftKey )
t.setFullYear(t.getFullYear()+1);
else
{
mo = t.getMonth()+1;
if ( t.getDate() > __daysIn[mo] )
t.setDate(__daysIn[mo])
t.setMonth(mo);
}
this.keyDateChange(t);
}
}
else if ( this.fBtn.hasClass('AnyTime-hr-btn') )
{
t = this.dM || this.dS || this.dO;
if ( t )
t.AnyTime_clickCurrent();
else if ( key == 9 )
{
this.denyTab = false;
return;
}
}
else if ( this.fBtn.hasClass('AnyTime-min-ten-btn') )
this.dM.find('.AnyTime-mins-ones .AnyTime-cur-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-min-one-btn') )
{
t = this.dS || this.dO;
if ( t )
t.AnyTime_clickCurrent();
else if ( key == 9 )
{
this.denyTab = false;
return;
}
}
else if ( this.fBtn.hasClass('AnyTime-sec-ten-btn') )
this.dS.find('.AnyTime-secs-ones .AnyTime-cur-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-sec-one-btn') )
{
if ( this.dO )
this.dO.AnyTime_clickCurrent();
else if ( key == 9 )
{
this.denyTab = false;
return;
}
}
else if ( this.fBtn.hasClass('AnyTime-off-btn') )
{
if ( key == 9 )
{
this.denyTab = false;
return;
}
}
}
else if ( key == 35 ) // END
{
if ( this.fBtn.hasClass('AnyTime-mil-btn') || this.fBtn.hasClass('AnyTime-cent-btn') ||
this.fBtn.hasClass('AnyTime-dec-btn') || this.fBtn.hasClass('AnyTime-yr-btn') ||
this.fBtn.hasClass('AnyTime-era-btn') )
{
t = this.yDiv.find('.AnyTime-ce-btn');
if ( ! t.length )
t = this.yDiv.find('.AnyTime-yr9-btn');
t.triggerHandler('click');
}
else if ( this.fBtn.hasClass('AnyTime-dom-btn') )
{
t = new Date(this.time.getTime());
t.setDate(1);
t.setMonth(t.getMonth()+1);
t.setDate(t.getDate()-1);
if ( event.ctrlKey )
t.setMonth(11);
this.keyDateChange(t);
}
else if ( this.dS )
this.dS.find('.AnyTime-sec9-btn').triggerHandler('click');
else if ( this.dM )
this.dM.find('.AnyTime-min9-btn').triggerHandler('click');
else if ( this.dH )
this.dH.find('.AnyTime-hr23-btn').triggerHandler('click');
else if ( this.dDoM )
this.dDoM.find('.AnyTime-dom-btn-filled:last').triggerHandler('click');
else if ( this.dMo )
this.dMo.find('.AnyTime-mon12-btn').triggerHandler('click');
else if ( this.dY )
this.yAhead.triggerHandler('click');
}
else if ( key == 36 ) // HOME
{
if ( this.fBtn.hasClass('AnyTime-mil-btn') || this.fBtn.hasClass('AnyTime-cent-btn') ||
this.fBtn.hasClass('AnyTime-dec-btn') || this.fBtn.hasClass('AnyTime-yr-btn') ||
this.fBtn.hasClass('AnyTime-era-btn') )
{
this.yDiv.find('.AnyTime-mil0-btn').triggerHandler('click');
}
else if ( this.fBtn.hasClass('AnyTime-dom-btn') )
{
t = new Date(this.time.getTime());
t.setDate(1);
if ( event.ctrlKey )
t.setMonth(0);
this.keyDateChange(t);
}
else if ( this.dY )
this.yCur.triggerHandler('click');
else if ( this.dMo )
this.dMo.find('.AnyTime-mon1-btn').triggerHandler('click');
else if ( this.dDoM )
this.dDoM.find('.AnyTime-dom-btn-filled:first').triggerHandler('click');
else if ( this.dH )
this.dH.find('.AnyTime-hr0-btn').triggerHandler('click');
else if ( this.dM )
this.dM.find('.AnyTime-min00-btn').triggerHandler('click');
else if ( this.dS )
this.dS.find('.AnyTime-sec00-btn').triggerHandler('click');
}
else if ( key == 37 ) // left arrow
{
if ( this.fBtn.hasClass('AnyTime-dom-btn') )
{
t = new Date(this.time.getTime());
t.setDate(t.getDate()-1);
this.keyDateChange(t);
}
else
this.keyBack();
}
else if ( key == 38 ) // up arrow
{
if ( this.fBtn.hasClass('AnyTime-dom-btn') )
{
t = new Date(this.time.getTime());
t.setDate(t.getDate()-7);
this.keyDateChange(t);
}
else
this.keyBack();
}
else if ( key == 39 ) // right arrow
{
if ( this.fBtn.hasClass('AnyTime-dom-btn') )
{
t = new Date(this.time.getTime());
t.setDate(t.getDate()+1);
this.keyDateChange(t);
}
else
this.keyAhead();
}
else if ( key == 40 ) // down arrow
{
if ( this.fBtn.hasClass('AnyTime-dom-btn') )
{
t = new Date(this.time.getTime());
t.setDate(t.getDate()+7);
this.keyDateChange(t);
}
else
this.keyAhead();
}
else if ( ( ( key == 86 ) || ( key == 118 ) ) && event.ctrlKey )
{
this.updVal('');
setTimeout( function() { _this.showPkr(null); }, 100 );
return;
}
else
this.showPkr(null);
event.preventDefault();
}, // .key()
//---------------------------------------------------------------------
// .keyAhead() is called by #key when a user presses the right or
// down arrow. It moves to the next appropriate button.
//---------------------------------------------------------------------
keyAhead: function()
{
if ( this.fBtn.hasClass('AnyTime-mil9-btn') )
this.yDiv.find('.AnyTime-cent0-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-cent9-btn') )
this.yDiv.find('.AnyTime-dec0-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-dec9-btn') )
this.yDiv.find('.AnyTime-yr0-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-yr9-btn') )
this.yDiv.find('.AnyTime-bce-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-sec9-btn') )
{}
else if ( this.fBtn.hasClass('AnyTime-sec50-btn') )
this.dS.find('.AnyTime-sec0-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-min9-btn') )
{
if ( this.dS )
this.dS.find('.AnyTime-sec00-btn').triggerHandler('click');
}
else if ( this.fBtn.hasClass('AnyTime-min50-btn') )
this.dM.find('.AnyTime-min0-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-hr23-btn') )
{
if ( this.dM )
this.dM.find('.AnyTime-min00-btn').triggerHandler('click');
else if ( this.dS )
this.dS.find('.AnyTime-sec00-btn').triggerHandler('click');
}
else if ( this.fBtn.hasClass('AnyTime-hr11-btn') )
this.dH.find('.AnyTime-hr12-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-mon12-btn') )
{
if ( this.dDoM )
this.dDoM.AnyTime_clickCurrent();
else if ( this.dH )
this.dH.find('.AnyTime-hr0-btn').triggerHandler('click');
else if ( this.dM )
this.dM.find('.AnyTime-min00-btn').triggerHandler('click');
else if ( this.dS )
this.dS.find('.AnyTime-sec00-btn').triggerHandler('click');
}
else if ( this.fBtn.hasClass('AnyTime-yrs-ahead-btn') )
{
if ( this.dMo )
this.dMo.find('.AnyTime-mon1-btn').triggerHandler('click');
else if ( this.dH )
this.dH.find('.AnyTime-hr0-btn').triggerHandler('click');
else if ( this.dM )
this.dM.find('.AnyTime-min00-btn').triggerHandler('click');
else if ( this.dS )
this.dS.find('.AnyTime-sec00-btn').triggerHandler('click');
}
else if ( this.fBtn.hasClass('AnyTime-yr-cur-btn') )
this.yNext.triggerHandler('click');
else
this.fBtn.next().triggerHandler('click');
}, // .keyAhead()
//---------------------------------------------------------------------
// .keyBack() is called by #key when a user presses the left or
// up arrow. It moves to the previous appropriate button.
//---------------------------------------------------------------------
keyBack: function()
{
if ( this.fBtn.hasClass('AnyTime-cent0-btn') )
this.yDiv.find('.AnyTime-mil9-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-dec0-btn') )
this.yDiv.find('.AnyTime-cent9-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-yr0-btn') )
this.yDiv.find('.AnyTime-dec9-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-bce-btn') )
this.yDiv.find('.AnyTime-yr9-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-yr-cur-btn') )
this.yPrior.triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-mon1-btn') )
{
if ( this.dY )
this.yCur.triggerHandler('click');
}
else if ( this.fBtn.hasClass('AnyTime-hr0-btn') )
{
if ( this.dDoM )
this.dDoM.AnyTime_clickCurrent();
else if ( this.dMo )
this.dMo.find('.AnyTime-mon12-btn').triggerHandler('click');
else if ( this.dY )
this.yNext.triggerHandler('click');
}
else if ( this.fBtn.hasClass('AnyTime-hr12-btn') )
this.dH.find('.AnyTime-hr11-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-min00-btn') )
{
if ( this.dH )
this.dH.find('.AnyTime-hr23-btn').triggerHandler('click');
else if ( this.dDoM )
this.dDoM.AnyTime_clickCurrent();
else if ( this.dMo )
this.dMo.find('.AnyTime-mon12-btn').triggerHandler('click');
else if ( this.dY )
this.yNext.triggerHandler('click');
}
else if ( this.fBtn.hasClass('AnyTime-min0-btn') )
this.dM.find('.AnyTime-min50-btn').triggerHandler('click');
else if ( this.fBtn.hasClass('AnyTime-sec00-btn') )
{
if ( this.dM )
this.dM.find('.AnyTime-min9-btn').triggerHandler('click');
else if ( this.dH )
this.dH.find('.AnyTime-hr23-btn').triggerHandler('click');
else if ( this.dDoM )
this.dDoM.AnyTime_clickCurrent();
else if ( this.dMo )
this.dMo.find('.AnyTime-mon12-btn').triggerHandler('click');
else if ( this.dY )
this.yNext.triggerHandler('click');
}
else if ( this.fBtn.hasClass('AnyTime-sec0-btn') )
this.dS.find('.AnyTime-sec50-btn').triggerHandler('click');
else
this.fBtn.prev().triggerHandler('click');
}, // .keyBack()
//---------------------------------------------------------------------
// .keyDateChange() is called by #key when an direction key
// (arrows/page/etc) is pressed while the Day-of-Month calendar has
// focus. The current day is adjusted accordingly.
//---------------------------------------------------------------------
keyDateChange: function( newDate )
{
if ( this.fBtn.hasClass('AnyTime-dom-btn') )
{
this.set(newDate);
this.upd(null);
this.setFocus( this.dDoM.find('.AnyTime-cur-btn') );
}
},
//---------------------------------------------------------------------
// .makeCloak() is called by .askOffset() and .askYear() to create
// a cloak div.
//---------------------------------------------------------------------
makeCloak: function()
{
if ( ! this.cloak )
{
this.cloak = $('
');
this.div.append( this.cloak );
this.cloak.click(
function(e)
{
if ( _this.oDiv && _this.oDiv.is(":visible") )
_this.dismissODiv(e);
else
_this.dismissYDiv(e);
});
}
else
this.cloak.show();
},
//---------------------------------------------------------------------
// makeDate() returns a Date object for the parameter as follows.
// Strings are parsed using the converter and numbers are assumed
// to be milliseconds.
//---------------------------------------------------------------------
makeDate: function(time)
{
if ( typeof time == 'number' )
time = new Date(time);
else if ( typeof time == 'string' )
time = this.conv.parse( time );
if ( 'getTime' in time )
return time;
throw 'cannot make a Date from ' + time;
},
//---------------------------------------------------------------------
// .newHour() is called when a user clicks an hour value.
// It changes the date and updates the text field.
//---------------------------------------------------------------------
newHour: function( event )
{
var h;
var t;
var elem = $(event.target);
if ( elem.hasClass("AnyTime-out-btn") )
return;
if ( ! this.twelveHr )
h = Number(elem.text());
else
{
var str = elem.text();
t = str.indexOf('a');
if ( t < 0 )
{
t = Number(str.substr(0,str.indexOf('p')));
h = ( (t==12) ? 12 : (t+12) );
}
else
{
t = Number(str.substr(0,t));
h = ( (t==12) ? 0 : t );
}
}
t = new Date(this.time.getTime());
t.setHours(h);
this.set(t);
this.upd(elem);
}, // .newHour()
//---------------------------------------------------------------------
// .newOffset() is called when a user clicks the UTC offset (timezone)
// (or +/- button) to shift the year. It changes the date and updates
// the text field.
//---------------------------------------------------------------------
newOffset: function( event )
{
if ( event.target == this.oSel[0] )
this.askOffset(event);
else
{
this.upd(this.oCur);
}
},
//---------------------------------------------------------------------
// .newOPos() is called internally whenever a user clicks an offset
// selection value. It changes the date and updates the text field.
//---------------------------------------------------------------------
newOPos: function( event )
{
var elem = $(event.target);
this.offMin = elem[0].AnyTime_offMin;
this.offSI = elem[0].AnyTime_offSI;
var t = new Date(this.time.getTime());
this.set(t);
this.updODiv(elem);
}, // .newOPos()
//---------------------------------------------------------------------
// .newYear() is called when a user clicks a year (or one of the
// "arrows") to shift the year. It changes the date and updates the
// text field.
//---------------------------------------------------------------------
newYear: function( event )
{
var elem = $(event.target);
if ( elem.hasClass("AnyTime-out-btn") )
return;
var txt = elem.text();
if ( ( txt == '<' ) || ( txt == '<' ) )
this.askYear(event);
else if ( ( txt == '>' ) || ( txt == '>' ) )
this.askYear(event);
else
{
var t = new Date(this.time.getTime());
t.setFullYear(Number(txt));
this.set(t);
this.upd(this.yCur);
}
},
//---------------------------------------------------------------------
// .newYPos() is called internally whenever a user clicks a year
// selection value. It changes the date and updates the text field.
//---------------------------------------------------------------------
newYPos: function( event )
{
var elem = $(event.target);
if ( elem.hasClass("AnyTime-out-btn") )
return;
var era = 1;
var year = this.time.getFullYear();
if ( year < 0 )
{
era = (-1);
year = 0 - year;
}
year = AnyTime.pad( year, 4 );
if ( elem.hasClass('AnyTime-mil-btn') )
year = elem.html() + year.substring(1,4);
else if ( elem.hasClass('AnyTime-cent-btn') )
year = year.substring(0,1) + elem.html() + year.substring(2,4);
else if ( elem.hasClass('AnyTime-dec-btn') )
year = year.substring(0,2) + elem.html() + year.substring(3,4);
else
year = year.substring(0,3) + elem.html();
if ( year == '0000' )
year = 1;
var t = new Date(this.time.getTime());
t.setFullYear( era * year );
this.set(t);
this.updYDiv(elem);
}, // .newYPos()
//---------------------------------------------------------------------
// .onReady() initializes the picker after the page has loaded.
//---------------------------------------------------------------------
onReady: function()
{
this.lostFocus = true;
if ( ! this.pop )
this.upd(null);
else
{
if ( this.div.parent() != document.body )
this.div.appendTo( document.body );
}
},
//---------------------------------------------------------------------
// .pos() positions the picker, such as when it is displayed or
// when the window is resized.
//---------------------------------------------------------------------
pos: function(event) // note: event is ignored but this is a handler
{
if ( this.pop )
{
var off = this.inp.offset();
var bodyWidth = $(document.body).outerWidth(true);
var pickerWidth = this.div.outerWidth(true);
var left = off.left;
if ( left + pickerWidth > bodyWidth - 20 )
left = bodyWidth - ( pickerWidth + 20 );
var top = off.top - this.div.outerHeight(true);
if ( top < 0 )
top = off.top + this.inp.outerHeight(true);
this.div.css( { top: String(top)+'px', left: String(left<0?0:left)+'px' } );
}
var wOff = this.div.offset();
if ( this.oDiv && this.oDiv.is(":visible") )
{
var oOff = this.oLab.offset();
if ( this.div.css('position') == 'absolute' )
{
oOff.top -= wOff.top;
oOff.left = oOff.left - wOff.left;
wOff = { top: 0, left: 0 };
}
var oW = this.oDiv.outerWidth(true);
var wW = this.div.outerWidth(true);
if ( oOff.left + oW > wOff.left + wW )
{
oOff.left = (wOff.left+wW)-oW;
if ( oOff.left < 2 )
oOff.left = 2;
}
var oH = this.oDiv.outerHeight(true);
var wH = this.div.outerHeight(true);
oOff.top += this.oLab.outerHeight(true);
if ( oOff.top + oH > wOff.top + wH )
oOff.top = oOff.top - oH;
if ( oOff.top < wOff.top )
oOff.top = wOff.top;
this.oDiv.css( { top: oOff.top+'px', left: oOff.left+'px' } ) ;
}
else if ( this.yDiv && this.yDiv.is(":visible") )
{
var yOff = this.yLab.offset();
if ( this.div.css('position') == 'absolute' )
{
yOff.top -= wOff.top;
yOff.left = yOff.left - wOff.left;
wOff = { top: 0, left: 0 };
}
yOff.left += ( (this.yLab.outerWidth(true)-this.yDiv.outerWidth(true)) / 2 );
this.yDiv.css( { top: yOff.top+'px', left: yOff.left+'px' } ) ;
}
if ( this.cloak )
this.cloak.css( {
top: wOff.top+'px',
left: wOff.left+'px',
height: String(this.div.outerHeight(true)-2)+'px',
width: String(this.div.outerWidth(true)-2)+'px'
} );
}, // .pos()
//---------------------------------------------------------------------
// .set() changes the current time. It returns true if the new
// time is within the allowed range (if any).
//---------------------------------------------------------------------
set: function(newTime)
{
var t = newTime.getTime();
if ( this.earliest && ( t < this.earliest.getTime() ) )
this.time = new Date(this.earliest.getTime());
else if ( this.latest && ( t > this.latest.getTime() ) )
this.time = new Date(this.latest.getTime());
else
this.time = newTime;
},
//---------------------------------------------------------------------
// .setCurrent() changes the current time.
//---------------------------------------------------------------------
setCurrent: function(newTime)
{
this.set(this.makeDate(newTime));
this.upd(null);
},
//---------------------------------------------------------------------
// .setEarliest() changes the earliest time.
//---------------------------------------------------------------------
setEarliest: function(newTime)
{
this.earliest = this.makeDate( newTime );
this.set(this.time);
this.upd(null);
},
//---------------------------------------------------------------------
// .setLatest() changes the latest time.
//---------------------------------------------------------------------
setLatest: function(newTime)
{
this.latest = this.makeDate( newTime );
this.set(this.time);
this.upd(null);
},
//---------------------------------------------------------------------
// .showPkr() displays the picker and sets the focus psuedo-
// element. The current value in the input field is used to initialize
// the picker.
//---------------------------------------------------------------------
showPkr: function(event)
{
try
{
this.time = this.conv.parse(this.inp.val());
this.offMin = this.conv.getUtcParseOffsetCaptured();
this.offSI = this.conv.getUtcParseOffsetSubIndex();
}
catch ( e )
{
this.time = new Date();
}
this.set(this.time);
this.upd(null);
fBtn = null;
var cb = '.AnyTime-cur-btn:first';
if ( this.dDoM )
fBtn = this.dDoM.find(cb);
else if ( this.yCur )
fBtn = this.yCur;
else if ( this.dMo )
fBtn = this.dMo.find(cb);
else if ( this.dH )
fBtn = this.dH.find(cb);
else if ( this.dM )
fBtn = this.dM.find(cb);
else if ( this.dS )
fBtn = this.dS.find(cb);
this.setFocus(fBtn);
this.pos(event);
}, // .showPkr()
//---------------------------------------------------------------------
// .upd() updates the picker's appearance. It is called after
// most events to make the picker reflect the currently-selected
// values. fBtn is the psuedo-button to be given focus.
//---------------------------------------------------------------------
upd: function(fBtn)
{
var cmpLo = new Date(this.time.getTime());
cmpLo.setMonth(0,1);
cmpLo.setHours(0,0,0,0);
var cmpHi = new Date(this.time.getTime());
cmpHi.setMonth(11,31);
cmpHi.setHours(23,59,59,999);
var earliestTime = this.earliest && this.earliest.getTime();
var latestTime = this.latest && this.latest.getTime();
// Update year.
var current = this.time.getFullYear();
if ( this.earliest && this.yPast )
{
cmpHi.setYear(current-2);
if ( cmpHi.getTime() < this.earliestTime )
this.yPast.addClass('AnyTime-out-btn ui-state-disabled');
else
this.yPast.removeClass('AnyTime-out-btn ui-state-disabled');
}
if ( this.yPrior )
{
this.yPrior.text(AnyTime.pad((current==1)?(-1):(current-1),4));
if ( this.earliest )
{
cmpHi.setYear(current-1);
if ( cmpHi.getTime() < this.earliestTime )
this.yPrior.addClass('AnyTime-out-btn ui-state-disabled');
else
this.yPrior.removeClass('AnyTime-out-btn ui-state-disabled');
}
}
if ( this.yCur )
this.yCur.text(AnyTime.pad(current,4));
if ( this.yNext )
{
this.yNext.text(AnyTime.pad((current==-1)?1:(current+1),4));
if ( this.latest )
{
cmpLo.setYear(current+1);
if ( cmpLo.getTime() > this.latestTime )
this.yNext.addClass('AnyTime-out-btn ui-state-disabled');
else
this.yNext.removeClass('AnyTime-out-btn ui-state-disabled');
}
}
if ( this.latest && this.yAhead )
{
cmpLo.setYear(current+2);
if ( cmpLo.getTime() > this.latestTime )
this.yAhead.addClass('AnyTime-out-btn ui-state-disabled');
else
this.yAhead.removeClass('AnyTime-out-btn ui-state-disabled');
}
// Update month.
cmpLo.setFullYear( this.time.getFullYear() );
cmpHi.setFullYear( this.time.getFullYear() );
var i = 0;
current = this.time.getMonth();
$('#'+this.id+' .AnyTime-mon-btn').each(
function()
{
cmpLo.setMonth(i);
cmpHi.setDate(1);
cmpHi.setMonth(i+1);
cmpHi.setDate(0);
$(this).AnyTime_current( i == current,
((!_this.earliest)||(cmpHi.getTime()>=earliestTime)) &&
((!_this.latest)||(cmpLo.getTime()<=latestTime)) );
i++;
} );
// Update days.
cmpLo.setFullYear( this.time.getFullYear() );
cmpHi.setFullYear( this.time.getFullYear() );
cmpLo.setMonth( this.time.getMonth() );
cmpHi.setMonth( this.time.getMonth(), 1 );
current = this.time.getDate();
var currentMonth = this.time.getMonth();
var lastLoDate = -1;
var dow1 = cmpLo.getDay();
if ( this.fDOW > dow1 )
dow1 += 7;
var wom = 0, dow=0;
$('#'+this.id+' .AnyTime-wk').each(
function()
{
dow = _this.fDOW;
$(this).children().each(
function()
{
if ( dow - _this.fDOW < 7 )
{
var td = $(this);
if ( ((wom==0)&&(dow
=earliestTime)) &&
((!_this.latest)||(cmpLo.getTime()<=latestTime)) );
cmpLo.setDate(i+1);
cmpHi.setDate(i+1);
}
}
dow++;
} );
wom++;
} );
// Update hour.
cmpLo.setFullYear( this.time.getFullYear() );
cmpHi.setFullYear( this.time.getFullYear() );
cmpLo.setMonth( this.time.getMonth(), this.time.getDate() );
cmpHi.setMonth( this.time.getMonth(), this.time.getDate() );
var not12 = ! this.twelveHr;
var hr = this.time.getHours();
$('#'+this.id+' .AnyTime-hr-btn').each(
function()
{
var html = this.innerHTML;
var i;
if ( not12 )
i = Number(html);
else
{
i = Number(html.substring(0,html.length-2) );
if ( html.charAt(html.length-2) == 'a' )
{
if ( i == 12 )
i = 0;
}
else if ( i < 12 )
i += 12;
}
cmpLo.setHours(i);
cmpHi.setHours(i);
$(this).AnyTime_current( hr == i,
((!_this.earliest)||(cmpHi.getTime()>=earliestTime)) &&
((!_this.latest)||(cmpLo.getTime()<=latestTime)) );
if ( i < 23 )
cmpLo.setHours( cmpLo.getHours()+1 );
} );
// Update minute.
cmpLo.setHours( this.time.getHours() );
cmpHi.setHours( this.time.getHours(), 9 );
var units = this.time.getMinutes();
var tens = String(Math.floor(units/10));
var ones = String(units % 10);
$('#'+this.id+' .AnyTime-min-ten-btn:not(.AnyTime-min-ten-btn-empty)').each(
function()
{
$(this).AnyTime_current( this.innerHTML == tens,
((!_this.earliest)||(cmpHi.getTime()>=earliestTime)) &&
((!_this.latest)||(cmpLo.getTime()<=latestTime)) );
if ( cmpLo.getMinutes() < 50 )
{
cmpLo.setMinutes( cmpLo.getMinutes()+10 );
cmpHi.setMinutes( cmpHi.getMinutes()+10 );
}
} );
cmpLo.setMinutes( Math.floor(this.time.getMinutes()/10)*10 );
cmpHi.setMinutes( Math.floor(this.time.getMinutes()/10)*10 );
$('#'+this.id+' .AnyTime-min-one-btn:not(.AnyTime-min-one-btn-empty)').each(
function()
{
$(this).AnyTime_current( this.innerHTML == ones,
((!_this.earliest)||(cmpHi.getTime()>=earliestTime)) &&
((!_this.latest)||(cmpLo.getTime()<=latestTime)) );
cmpLo.setMinutes( cmpLo.getMinutes()+1 );
cmpHi.setMinutes( cmpHi.getMinutes()+1 );
} );
// Update second.
cmpLo.setMinutes( this.time.getMinutes() );
cmpHi.setMinutes( this.time.getMinutes(), 9 );
units = this.time.getSeconds();
tens = String(Math.floor(units/10));
ones = String(units % 10);
$('#'+this.id+' .AnyTime-sec-ten-btn:not(.AnyTime-sec-ten-btn-empty)').each(
function()
{
$(this).AnyTime_current( this.innerHTML == tens,
((!_this.earliest)||(cmpHi.getTime()>=earliestTime)) &&
((!_this.latest)||(cmpLo.getTime()<=latestTime)) );
if ( cmpLo.getSeconds() < 50 )
{
cmpLo.setSeconds( cmpLo.getSeconds()+10 );
cmpHi.setSeconds( cmpHi.getSeconds()+10 );
}
} );
cmpLo.setSeconds( Math.floor(this.time.getSeconds()/10)*10 );
cmpHi.setSeconds( Math.floor(this.time.getSeconds()/10)*10 );
$('#'+this.id+' .AnyTime-sec-one-btn:not(.AnyTime-sec-one-btn-empty)').each(
function()
{
$(this).AnyTime_current( this.innerHTML == ones,
((!_this.earliest)||(cmpHi.getTime()>=earliestTime)) &&
((!_this.latest)||(cmpLo.getTime()<=latestTime)) );
cmpLo.setSeconds( cmpLo.getSeconds()+1 );
cmpHi.setSeconds( cmpHi.getSeconds()+1 );
} );
// Update offset (time zone).
if ( this.oConv )
{
this.oConv.setUtcFormatOffsetAlleged(this.offMin);
this.oConv.setUtcFormatOffsetSubIndex(this.offSI);
var tzs = this.oConv.format(this.time);
this.oCur.html( tzs );
}
// Set the focus element, then size the picker according to its
// components, show the changes, and invoke Ajax if desired.
if ( fBtn )
this.setFocus(fBtn);
this.conv.setUtcFormatOffsetAlleged(this.offMin);
this.conv.setUtcFormatOffsetSubIndex(this.offSI);
this.updVal(this.conv.format(this.time));
this.div.show();
if ( this.dO ) // fit offset button
{
this.oCur.css('width','0');
var curW = this.dT.width()-this.oMinW;
if ( curW < 40 )
curW = 40;
this.oCur.css('width',String(curW)+'px');
}
if ( ! this.pop )
this.ajax();
}, // .upd()
//---------------------------------------------------------------------
// .updODiv() updates the UTC offset selector's appearance. It is
// called after most events to make the picker reflect the currently-
// selected values. fBtn is the psuedo-button to be given focus.
//---------------------------------------------------------------------
updODiv: function(fBtn)
{
var cur, matched = false, def = null;
this.oDiv.find('.AnyTime-off-off-btn').each(
function()
{
if ( this.AnyTime_offMin == _this.offMin )
{
if ( this.AnyTime_offSI == _this.offSI )
$(this).AnyTime_current(matched=true,true);
else
{
$(this).AnyTime_current(false,true);
if ( def == null )
def = $(this);
}
}
else
$(this).AnyTime_current(false,true);
} );
if ( ( ! matched ) && ( def != null ) )
def.AnyTime_current(true,true);
// Show change
this.conv.setUtcFormatOffsetAlleged(this.offMin);
this.conv.setUtcFormatOffsetSubIndex(this.offSI);
this.updVal(this.conv.format(this.time));
this.upd(fBtn);
}, // .updODiv()
//---------------------------------------------------------------------
// .updYDiv() updates the year selector's appearance. It is
// called after most events to make the picker reflect the currently-
// selected values. fBtn is the psuedo-button to be given focus.
//---------------------------------------------------------------------
updYDiv: function(fBtn)
{
var i, legal;
var era = 1;
var yearValue = this.time.getFullYear();
if ( yearValue < 0 )
{
era = (-1);
yearValue = 0 - yearValue;
}
yearValue = AnyTime.pad( yearValue, 4 );
var eY = _this.earliest && _this.earliest.getFullYear();
var lY = _this.latest && _this.latest.getFullYear();
i = 0;
this.yDiv.find('.AnyTime-mil-btn').each(
function()
{
legal = ( ((!_this.earliest)||(era*(i+(era<0?0:999))>=eY)) && ((!_this.latest)||(era*(i+(era>0?0:999))<=lY)) );
$(this).AnyTime_current( this.innerHTML == yearValue.substring(0,1), legal );
i += 1000;
} );
i = (Math.floor(yearValue/1000)*1000);
this.yDiv.find('.AnyTime-cent-btn').each(
function()
{
legal = ( ((!_this.earliest)||(era*(i+(era<0?0:99))>=eY)) && ((!_this.latest)||(era*(i+(era>0?0:99))<=lY)) );
$(this).AnyTime_current( this.innerHTML == yearValue.substring(1,2), legal );
i += 100;
} );
i = (Math.floor(yearValue/100)*100);
this.yDiv.find('.AnyTime-dec-btn').each(
function()
{
legal = ( ((!_this.earliest)||(era*(i+(era<0?0:9))>=eY)) && ((!_this.latest)||(era*(i+(era>0?0:9))<=lY)) );
$(this).AnyTime_current( this.innerHTML == yearValue.substring(2,3), legal );
i += 10;
} );
i = (Math.floor(yearValue/10)*10);
this.yDiv.find('.AnyTime-yr-btn').each(
function()
{
legal = ( ((!_this.earliest)||(era*i>=eY)) && ((!_this.latest)||(era*i<=lY)) );
$(this).AnyTime_current( this.innerHTML == yearValue.substring(3), legal );
i += 1;
} );
this.yDiv.find('.AnyTime-bce-btn').each(
function()
{
$(this).AnyTime_current( era < 0, (!_this.earliest) || ( _this.earliest.getFullYear() < 0 ) );
} );
this.yDiv.find('.AnyTime-ce-btn').each(
function()
{
$(this).AnyTime_current( era > 0, (!_this.latest) || ( _this.latest.getFullYear() > 0 ) );
} );
// Show change
this.conv.setUtcFormatOffsetAlleged(this.offMin);
this.conv.setUtcFormatOffsetSubIndex(this.offSI);
this.updVal(this.conv.format(this.time));
this.upd(fBtn);
}, // .updYDiv()
//---------------------------------------------------------------------
// .updVal() updates the input value, but only if it's different
// than the previous value. It also triggers a change() event if
// the value is updated.
//---------------------------------------------------------------------
updVal: function(val)
{
if ( this.inp.val() != val ) {
this.inp.val(val);
this.inp.change();
}
}
}; // __pickers[id] = ...
__pickers[id].initialize(id);
} // AnyTime.picker =
//=============================================================================
// AnyTime.setCurrent()
//
// Updates the current date/time for the picker attached to a specified
// text field. This also sets the value of the text field.
//=============================================================================
AnyTime.setCurrent = function( id, newTime )
{
__pickers[id].setCurrent(newTime)
};
//=============================================================================
// AnyTime.setEarliest()
//
// Updates the earliest date/time for the picker attached to a specified
// text field.
//=============================================================================
AnyTime.setEarliest = function( id, newTime )
{
__pickers[id].setEarliest(newTime)
};
//=============================================================================
// AnyTime.setLatest()
//
// Updates the latest date/time for the picker attached to a specified
// text field.
//=============================================================================
AnyTime.setLatest = function( id, newTime )
{
__pickers[id].setLatest(newTime)
};
})(jQuery); // function($)...
//
// END OF FILE
//
//if(window.location.hostname.length&&(window.location.hostname!='dev.ama3.com')&&(window.location.hostname!='www.ama3.com')&&(!/best.*picker.com$/.test(window.location.hostname)))alert('REMOVE THE LAST LINE FROM anytime.5.1.1.js!');