mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Datepicker: Add option for onUpdateDatepicker callback
Add a new option named onUpdateDatepicker that allows a custom callback to be provided. If provided, the callback is called at the end of $.datepicker._updateDatepicker.
This commit is contained in:
parent
b864cd103a
commit
17d115b829
@ -813,7 +813,9 @@ var beforeShowThis = null,
|
|||||||
beforeShowInput = null,
|
beforeShowInput = null,
|
||||||
beforeShowInst = null,
|
beforeShowInst = null,
|
||||||
beforeShowDayThis = null,
|
beforeShowDayThis = null,
|
||||||
beforeShowDayOK = true;
|
beforeShowDayOK = true,
|
||||||
|
onUpdateDatepickerThis = null,
|
||||||
|
onUpdateDatepickerInst = null;
|
||||||
|
|
||||||
function beforeAll( input, inst ) {
|
function beforeAll( input, inst ) {
|
||||||
beforeShowThis = this;
|
beforeShowThis = this;
|
||||||
@ -830,8 +832,14 @@ function beforeDay( date ) {
|
|||||||
( date.getDate() % 3 === 0 ? "Divisble by 3" : "" ) ];
|
( date.getDate() % 3 === 0 ? "Divisble by 3" : "" ) ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onUpdateDatepicker( inst ) {
|
||||||
|
onUpdateDatepickerThis = this;
|
||||||
|
onUpdateDatepickerInst = inst;
|
||||||
|
inst.dpDiv.append( $( "<div>" ).addClass( "on-update-datepicker-test" ) );
|
||||||
|
}
|
||||||
|
|
||||||
QUnit.test( "callbacks", function( assert ) {
|
QUnit.test( "callbacks", function( assert ) {
|
||||||
assert.expect( 13 );
|
assert.expect( 16 );
|
||||||
|
|
||||||
// Before show
|
// Before show
|
||||||
var dp, day20, day21,
|
var dp, day20, day21,
|
||||||
@ -860,6 +868,14 @@ QUnit.test( "callbacks", function( assert ) {
|
|||||||
assert.ok( !day20.attr( "title" ), "Before show day - title 20" );
|
assert.ok( !day20.attr( "title" ), "Before show day - title 20" );
|
||||||
assert.ok( day21.attr( "title" ) === "Divisble by 3", "Before show day - title 21" );
|
assert.ok( day21.attr( "title" ) === "Divisble by 3", "Before show day - title 21" );
|
||||||
inp.datepicker( "hide" ).datepicker( "destroy" );
|
inp.datepicker( "hide" ).datepicker( "destroy" );
|
||||||
|
|
||||||
|
inp = testHelper.init( "#inp", { onUpdateDatepicker: onUpdateDatepicker } );
|
||||||
|
inst = $.data( inp[ 0 ], "datepicker" );
|
||||||
|
dp = $( "#ui-datepicker-div" );
|
||||||
|
inp.val( "02/04/2008" ).datepicker( "show" );
|
||||||
|
assert.ok( onUpdateDatepickerThis.id === inp[ 0 ].id, "On update datepicker - this OK" );
|
||||||
|
assert.deepEqual( onUpdateDatepickerInst, inst, "On update datepicker - inst OK" );
|
||||||
|
assert.ok( dp.find( "div.on-update-datepicker-test" ).length > 0, "On update datepicker - custom element" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "beforeShowDay - tooltips with quotes", function( assert ) {
|
QUnit.test( "beforeShowDay - tooltips with quotes", function( assert ) {
|
||||||
|
@ -142,6 +142,7 @@ function Datepicker() {
|
|||||||
onSelect: null, // Define a callback function when a date is selected
|
onSelect: null, // Define a callback function when a date is selected
|
||||||
onChangeMonthYear: null, // Define a callback function when the month or year is changed
|
onChangeMonthYear: null, // Define a callback function when the month or year is changed
|
||||||
onClose: null, // Define a callback function when the datepicker is closed
|
onClose: null, // Define a callback function when the datepicker is closed
|
||||||
|
onUpdateDatepicker: null, // Define a callback function when the datepicker is updated
|
||||||
numberOfMonths: 1, // Number of months to show at a time
|
numberOfMonths: 1, // Number of months to show at a time
|
||||||
showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
|
showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
|
||||||
stepMonths: 1, // Number of months to step back/forward
|
stepMonths: 1, // Number of months to step back/forward
|
||||||
@ -857,7 +858,8 @@ $.extend( Datepicker.prototype, {
|
|||||||
numMonths = this._getNumberOfMonths( inst ),
|
numMonths = this._getNumberOfMonths( inst ),
|
||||||
cols = numMonths[ 1 ],
|
cols = numMonths[ 1 ],
|
||||||
width = 17,
|
width = 17,
|
||||||
activeCell = inst.dpDiv.find( "." + this._dayOverClass + " a" );
|
activeCell = inst.dpDiv.find( "." + this._dayOverClass + " a" ),
|
||||||
|
onUpdateDatepicker = $.datepicker._get( inst, "onUpdateDatepicker" );
|
||||||
|
|
||||||
if ( activeCell.length > 0 ) {
|
if ( activeCell.length > 0 ) {
|
||||||
datepicker_handleMouseover.apply( activeCell.get( 0 ) );
|
datepicker_handleMouseover.apply( activeCell.get( 0 ) );
|
||||||
@ -888,6 +890,10 @@ $.extend( Datepicker.prototype, {
|
|||||||
origyearshtml = inst.yearshtml = null;
|
origyearshtml = inst.yearshtml = null;
|
||||||
}, 0 );
|
}, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( onUpdateDatepicker ) {
|
||||||
|
onUpdateDatepicker.apply( ( inst.input ? inst.input[ 0 ] : null ), [ inst ] );
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// #6694 - don't focus the input if it's already focused
|
// #6694 - don't focus the input if it's already focused
|
||||||
|
Loading…
Reference in New Issue
Block a user