Skip to content
Browse files

Timepicker: _setOption for ampm / seconds

  • Loading branch information...
1 parent dcf1499 commit 1e7b13594beb4d073e58e26ac19e96bc5759b302 @gnarf gnarf committed Sep 14, 2011
Showing with 32 additions and 0 deletions.
  1. +32 −0 ui/jquery.ui.timepicker.js
View
32 ui/jquery.ui.timepicker.js
@@ -124,6 +124,38 @@ $.widget( "ui.timepicker", {
break;
}
},
+ _setOption: function( key, value ) {
+ this._super( "_setOption", key, value );
+ console.log( key, value );
+ if ( key === "ampm" ) {
+ var i, buffer, currentHour, currentPP;
+ buffer = this.mask.buffer;
+ currentHour = parseInt( buffer[ 0 ].value, 10 );
+ for ( i = 0; i < buffer.length; i += 3 ) {
+ if ( buffer[ i ].valid === maskDefinitions.pp ) {
+ currentHour %= 12;
+ if ( buffer[ i ].value === "pm" ) {
+ currentHour += 12;
+ }
+ }
+ }
+ if ( value ) {
+ currentPP = currentHour > 11 ? "pm" : "am";
+ currentHour = ( currentHour % 12 ) || 12;
+ buffer[ 0 ].value = ( currentHour < 10 ? "0" : "" ) + currentHour;
+ this.mask._paint();
+ this.element.val( this.element.val() + " " + currentPP );
+ } else {
+ currentHour = currentHour % 24;
+ buffer[ 0 ].value = ( currentHour < 10 ? "0" : "" ) + currentHour;
+ this.mask._paint();
+ }
+ this.element.mask( "option", "mask", this._generateMask() );
+ }
+ if ( key === "seconds" ) {
+ this.element.mask( "option", "mask", this._generateMask() );
+ }
+ },
_spinnerParse: function( val ) {
val = this.mask.buffer[ this.currentField * 3 ].value;
if ( this.currentField === ( this.options.seconds ? 3 : 2 ) ) {

0 comments on commit 1e7b135

Please sign in to comment.
Something went wrong with that request. Please try again.