Jquery Datepicker-2 1 2 Js
Jquery Datepicker-2 1 2 Js
$createIn
.append(
$('<div></div>')
.attr(attrs)
.css(cssRules)
.append(
$('<h2></h2>'),
$('<div class="d
p-nav-prev"></div>')
.append(
$('<a class="dp-nav-prev-year" href="#" title="' + $.dpText.TEXT_PREV_YEAR + '">
<<</a>')
.bind(
'click',
function()
{
return c._displayNewMonth.call(c, this, 0, -1);
}
),
$('<a class="dp-nav-prev-month" href="#" title="' + $.dpText.TEXT_PREV_MONTH + '
"><</a>')
.bind(
'click',
function()
{
return c._displayNewMonth.call(c, this, -1, 0);
}
)
),
$('<div class="d
p-nav-next"></div>')
.append(
$('<a class="dp-nav-next-year" href="#" title="' + $.dpText.TEXT_NEXT_YEAR + '">
>></a>')
.bind(
'click',
function()
{
return c._displayNewMonth.call(c, this, 0, 1);
}
),
$('<a class="dp-nav-next-month" href="#" title="' + $.dpText.TEXT_NEXT_MONTH + '
">></a>')
.bind(
'click',
function()
{
return c._displayNewMonth.call(c, this, 1, 0);
}
)
),
$('<div></div>')
.attr('c
lassName', 'dp-calendar')
)
.bgIframe()
);
var $pop = this.inline ? $('.dp-popup', this.con
text) : $('#dp-popup');
if (this.showYearNavigation == false) {
$('.dp-nav-prev-year, .dp-nav-next-year'
, c.context).css('display', 'none');
}
if (this.displayClose) {
$pop.append(
$('<a href="#" id="dp-close">' +
$.dpText.TEXT_CLOSE + '</a>')
.bind(
'click',
function()
{
c._close
Calendar();
return f
alse;
}
)
);
}
c._renderCalendar();
$(this.ele).trigger('dpDisplayed', $pop);
if (!c.inline) {
if (this.verticalPosition == $.dpConst.P
OS_BOTTOM) {
$pop.css('top', eleOffset.top +
$ele.height() - $pop.height() + c.verticalOffset);
}
if (this.horizontalPosition == $.dpConst
.POS_RIGHT) {
$pop.css('left', eleOffset.left
+ $ele.width() - $pop.width() + c.horizontalOffset);
}
$(document).bind('mousedown', this._chec
kMouse);
}
},
setRenderCallback : function(a)
{
if (a == null) return;
if (a && typeof(a) == 'function') {
a = [a];
}
this.renderCallback = this.renderCallback.concat
(a);
},
cellRender : function ($td, thisDate, month, year) {
var c = this.dpController;
var d = new Date(thisDate.getTime());
// add our click handlers to deal with it when t
he days are clicked...
$td.bind(
'click',
function()
{
var $this = $(this);
if (!$this.is('.disabled')) {
c.setSelected(d, !$this.
is('.selected') || !c.selectMultiple, false, true);
if (c.closeOnSelect) {
c._closeCalendar
();
}
}
}
);
if (c.isSelected(d)) {
$td.addClass('selected');
}
// call any extra renderCallbacks that were pass
ed in
for (var i=0; i<c.renderCallback.length; i++) {
c.renderCallback[i].apply(this, argument
s);
}
},
// ele is the clicked button - only proceed if it doesn'
t have the class disabled...
// m and y are -1, 0 or 1 depending which direction we w
ant to go in...
_displayNewMonth : function(ele, m, y)
{
if (!$(ele).is('.disabled')) {
this.setDisplayedMonth(this.displayedMon
th + m, this.displayedYear + y, true);
}
ele.blur();
return false;
},
_rerenderCalendar : function()
{
this._clearCalendar();
this._renderCalendar();
},
_renderCalendar : function()
{
// set the title...
$('h2', this.context).html(Date.monthNames[this.
displayedMonth] + ' ' + this.displayedYear);
// render the calendar...
$('.dp-calendar', this.context).renderCalendar(
{
month : this.d
isplayedMonth,
year : this.d
isplayedYear,
renderCallback : this.cellRende
r,
dpController : this,
hoverClass : this.h
overClass
}
);
// update the status of the control buttons and
disable dates before startDate or after endDate...
// TODO: When should the year buttons be disable
d? When you can't go forward a whole year from where you are or is that annoying
?
if (this.displayedYear == this.startDate.getFull
Year() && this.displayedMonth == this.startDate.getMonth()) {
$('.dp-nav-prev-year', this.context).add
Class('disabled');
$('.dp-nav-prev-month', this.context).ad
dClass('disabled');
$('.dp-calendar td.other-month', this.co
ntext).each(
function()
{
var $this = $(this);
if (Number($this.text())
> 20) {
$this.addClass('
disabled');
}
}
);
var d = this.startDate.getDate();
$('.dp-calendar td.current-month', this.
context).each(
function()
{
var $this = $(this);
if (Number($this.text())
< d) {
$this.addClass('
disabled');
}
}
);
} else {
$('.dp-nav-prev-year', this.context).rem
oveClass('disabled');
$('.dp-nav-prev-month', this.context).re
moveClass('disabled');
var d = this.startDate.getDate();
if (d > 20) {
// check if the startDate is las
t month as we might need to add some disabled classes...
var sd = new Date(this.startDate
.getTime());
sd.addMonths(1);
if (this.displayedYear == sd.get
FullYear() && this.displayedMonth == sd.getMonth()) {
$('dp-calendar td.other-
month', this.context).each(
function()
{
var $thi
s = $(this);
if (Numb
er($this.text()) < d) {
$this.addClass('disabled');
}
}
);
}
}
}
if (this.displayedYear == this.endDate.getFullYe
ar() && this.displayedMonth == this.endDate.getMonth()) {
$('.dp-nav-next-year', this.context).add
Class('disabled');
$('.dp-nav-next-month', this.context).ad
dClass('disabled');
$('.dp-calendar td.other-month', this.co
ntext).each(
function()
{
var $this = $(this);
if (Number($this.text())
< 14) {
$this.addClass('
disabled');
}
}
);
var d = this.endDate.getDate();
$('.dp-calendar td.current-month', this.
context).each(
function()
{
var $this = $(this);
if (Number($this.text())
> d) {
$this.addClass('
disabled');
}
}
);
} else {
$('.dp-nav-next-year', this.context).rem
oveClass('disabled');
$('.dp-nav-next-month', this.context).re
moveClass('disabled');
var d = this.endDate.getDate();
if (d < 13) {
// check if the endDate is next
month as we might need to add some disabled classes...
var ed = new Date(this.endDate.g
etTime());
ed.addMonths(-1);
if (this.displayedYear == ed.get
FullYear() && this.displayedMonth == ed.getMonth()) {
$('.dp-calendar td.other
-month', this.context).each(
function()
{
var $thi
s = $(this);
if (Numb
er($this.text()) > d) {
$this.addClass('disabled');
}
}
);
}
}
}
},
_closeCalendar : function(programatic, ele)
{
if (!ele || ele == this.ele)
{
$(document).unbind('mousedown', this._ch
eckMouse);
this._clearCalendar();
$('#dp-popup a').unbind();
$('#dp-popup').empty().remove();
if (!programatic) {
$(this.ele).trigger('dpClosed',
[this.getSelected()]);
}
}
},
// empties the current dp-calendar div and makes sure th
at all events are unbound
// and expandos removed to avoid memory leaks...
_clearCalendar : function()
{
// TODO.
$('.dp-calendar td', this.context).unbind();
$('.dp-calendar', this.context).empty();
}
}
);
// static constants
$.dpConst = {
SHOW_HEADER_NONE : 0,
SHOW_HEADER_SHORT : 1,
SHOW_HEADER_LONG : 2,
POS_TOP : 0,
POS_BOTTOM : 1,
POS_LEFT : 0,
POS_RIGHT : 1
};
// localisable text
$.dpText = {
TEXT_PREV_YEAR : 'Previous year',
TEXT_PREV_MONTH : 'Previous month',
TEXT_NEXT_YEAR : 'Next year',
TEXT_NEXT_MONTH : 'Next month',
TEXT_CLOSE : 'Close',
TEXT_CHOOSE_DATE : 'Choose date'
};
// version
$.dpVersion = '$Id: jquery.datePicker.js 15 2008-12-17 04:40:18Z kelvin.
luck $';
$.fn.datePicker.defaults = {
month : undefined,
year : undefined,
showHeader : $.dpConst.SHOW_HEADER_SHORT,
startDate : undefined,
endDate : undefined,
inline : false,
renderCallback : null,
createButton : true,
showYearNavigation : true,
closeOnSelect : true,
displayClose : false,
selectMultiple : false,
clickInput : false,
verticalPosition : $.dpConst.POS_TOP,
horizontalPosition : $.dpConst.POS_LEFT,
verticalOffset : 0,
horizontalOffset : 0,
hoverClass : 'dp-hover'
};
function _getController(ele)
{
if (ele._dpId) return $.event._dpCache[ele._dpId];
return false;
};
// make it so that no error is thrown if bgIframe plugin isn't included
(allows you to use conditional
// comments to only include bgIframe where it is needed in IE without br
eaking this plugin).
if ($.fn.bgIframe == undefined) {
$.fn.bgIframe = function() {return this; };
};
// clean-up
$(window)
.bind('unload', function() {
var els = $.event._dpCache || [];
for (var i in els) {
$(els[i].ele)._dpDestroy();
}
});
})(jQuery);