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.unbind('blur',this.hBlur);
this.inp.unbind('click',this.hClick);
this.inp.unbind('focus',this.hFocus);
this.inp.unbind('keydown',this.hKeydown);
this.inp.unbind('keypress',this.hKeypress);
this.div.remove();
},
//---------------------------------------------------------------------
// .dismiss() dismisses a popup picker.
//---------------------------------------------------------------------
dismiss: function(event)
{
this.ajax();
this.div.hide();
if ( __iframe )
__iframe.hide();
if ( this.yDiv )
this.dismissYDiv();
if ( this.oDiv )
this.dismissODiv();
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.AnyTime_height(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 t = null;
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
{
var 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
{
var 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') )
this.keyDateChange(new Date(this.time.getTime()-__oneDay));
else
this.keyBack();
}
else if ( key == 38 ) // up arrow
{
if ( this.fBtn.hasClass('AnyTime-dom-btn') )
this.keyDateChange(new Date(this.time.getTime()-(7*__oneDay)));
else
this.keyBack();
}
else if ( key == 39 ) // right arrow
{
if ( this.fBtn.hasClass('AnyTime-dom-btn') )
this.keyDateChange(new Date(this.time.getTime()+__oneDay));
else
this.keyAhead();
}
else if ( key == 40 ) // down arrow
{
if ( this.fBtn.hasClass('AnyTime-dom-btn') )
this.keyDateChange(new Date(this.time.getTime()+(7*__oneDay)));
else
this.keyAhead();
}
else if ( ( ( key == 86 ) || ( key == 118 ) ) && event.ctrlKey )
{
this.inp.val("").change();
var _this = this;
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();
},
//---------------------------------------------------------------------
// .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 and,
// if IE6, after the iframe has been created.
//---------------------------------------------------------------------
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.AnyTime_width(true);
var wW = this.div.AnyTime_width(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.AnyTime_height(true);
var wH = this.div.AnyTime_height(true);
oOff.top += this.oLab.AnyTime_height(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(!$.browser.safari)-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 ) )
this.time = new Date(this.earliest);
else if ( this.latest && ( t > this.latest ) )
this.time = new Date(this.latest);
else
this.time = newTime;
},
//---------------------------------------------------------------------
// .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);
// IE6 doesn't float popups over
elements unless an
// ";
seg.left = left;
seg.outerWidth = right - left;
}
segmentContainer[0].innerHTML = html; // faster than html()
eventElements = segmentContainer.children();
// retrieve elements, run through eventRender callback, bind handlers
for (i=0; i