Skip to content

Commit

Permalink
Better method for calling declared picker callbacks in overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Jun 23, 2016
1 parent e3940a0 commit 14a4bf1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions js/cmb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ window.CMB2 = (function(window, document, $, undefined){
};

cmb.datePickerSetupOpts = function( fieldOpts, options, method ) {
var existing = $.extend( {}, options );

options.beforeShow = function( input, inst ) {
if ( 'timepicker' === method ) {
Expand All @@ -742,8 +743,8 @@ window.CMB2 = (function(window, document, $, undefined){
$id( 'ui-datepicker-div' ).addClass( 'cmb2-element' );

// Let's be sure to call beforeShow if it was added
if ( 'function' === typeof fieldOpts.beforeShow ) {
fieldOpts.beforeShow( input, inst );
if ( 'function' === typeof existing.beforeShow ) {
existing.beforeShow( input, inst );
}
};

Expand All @@ -752,8 +753,8 @@ window.CMB2 = (function(window, document, $, undefined){
cmb.addTimePickerClasses( inst.dpDiv );

// Let's be sure to call onChangeMonthYear if it was added
if ( 'function' === typeof fieldOpts.onChangeMonthYear ) {
fieldOpts.onChangeMonthYear( year, month, inst, picker );
if ( 'function' === typeof existing.onChangeMonthYear ) {
existing.onChangeMonthYear( year, month, inst, picker );
}
};
}
Expand All @@ -763,8 +764,8 @@ window.CMB2 = (function(window, document, $, undefined){
$id( 'ui-datepicker-div' ).removeClass( 'cmb2-element' ).hide();

// Let's be sure to call onClose if it was added
if ( 'function' === typeof fieldOpts.onClose ) {
fieldOpts.onClose( dateText, inst );
if ( 'function' === typeof existing.onClose ) {
existing.onClose( dateText, inst );
}
};

Expand Down

0 comments on commit 14a4bf1

Please sign in to comment.