Skip to content

Commit

Permalink
Timepicker: Quick updates from code review.
Browse files Browse the repository at this point in the history
* Remove docs link.
* remove button from depends
* move destroy method under _create - make _destroy
* comment in _trimValue describing purpose
* _trimValue becomes _adjustValue
* don't set the ampm option from culture dependency
* reordering methods
* rsingleh / rlowerhg (rename)
  • Loading branch information
gnarf committed Oct 13, 2011
1 parent 8becf44 commit 912b8b2
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions ui/jquery.ui.timepicker.js
Expand Up @@ -5,12 +5,9 @@
* Dual licensed under the MIT or GPL Version 2 licenses. * Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license * http://jquery.org/license
* *
* http://docs.jquery.com/UI/Timepicker
*
* Depends: * Depends:
* jquery.ui.core.js * jquery.ui.core.js
* jquery.ui.widget.js * jquery.ui.widget.js
* jquery.ui.button.js
* jquery.ui.spinner.js * jquery.ui.spinner.js
* jquery.ui.mask.js * jquery.ui.mask.js
* *
Expand Down Expand Up @@ -96,7 +93,9 @@ $.widget( "ui.timepicker", {
$.extend( this.spinner, { $.extend( this.spinner, {
_parse: $.proxy( this, "_spinnerParse" ), _parse: $.proxy( this, "_spinnerParse" ),
_value: $.proxy( this, "_spinnerValue" ), _value: $.proxy( this, "_spinnerValue" ),
_trimValue: function( value ) { _adjustValue: function( value ) {

// if under min, return max - if over max, return min
if ( value < this.options.min ) { if ( value < this.options.min ) {
return this.options.max; return this.options.max;
} }
Expand All @@ -109,39 +108,13 @@ $.widget( "ui.timepicker", {
this._setField( 0 ); this._setField( 0 );
this._bind( this._events ); this._bind( this._events );
}, },
_generateMask: function() { _destroy: function() {
var mask = ""; this.element.mask( "destroy" );

this.element.spinner( "destroy" );
if ( window.Globalize ) {
mask = Globalize.culture().calendars.standard.patterns[ this.options.seconds ? "T" : "t" ];
mask = mask.replace( rsingleh, "_$1" );

// if the culture doesn't understand AM/PM - don't let timepickers understand it either.
if ( mask.indexOf( "tt" ) == -1 ) {
this.options.ampm = false;
} else if ( !this.options.ampm ) {
mask = mask.replace( rlowerhg, "H" ).replace( " tt", "" );
}

return mask;
}

mask += this.options.ampm ? "hh" : "HH";
mask += ":mm";
if ( this.options.seconds ) {
mask += ":ss";
}
if ( this.options.ampm ) {
mask += " tt";
}
return mask;
}, },
_events: { _events: {
keydown: "_checkPosition", blur: function() {
mousedown: function( event ) { this._focusing = false;
if ( document.activeElement !== this.element[0] ) {
this._focusing = true;
}
}, },
click: function() { click: function() {
if ( this._focusing ) { if ( this._focusing ) {
Expand All @@ -152,8 +125,11 @@ $.widget( "ui.timepicker", {
this._setPosition(); this._setPosition();
} }
}, },
blur: function() { keydown: "_checkPosition",
this._focusing = false; mousedown: function( event ) {
if ( document.activeElement !== this.element[0] ) {
this._focusing = true;
}
} }
}, },
_checkPosition: function( event ) { _checkPosition: function( event ) {
Expand All @@ -170,20 +146,41 @@ $.widget( "ui.timepicker", {
this.mask._caret( 0, 2 ); this.mask._caret( 0, 2 );
} }
}, },
_setPosition: function( field ) { _generateMask: function() {
if ( field == null ) { var mask = "";
field = this.currentField;
} else { if ( window.Globalize ) {
this._setField( field ); mask = Globalize.culture().calendars.standard.patterns[ this.options.seconds ? "T" : "t" ];
mask = mask.replace( rsingleh, "_$1" );

if ( !this.options.ampm ) {
mask = mask.replace( rlowerhg, "H" ).replace( " tt", "" );
}

return mask;
}

mask += this.options.ampm ? "hh" : "HH";
mask += ":mm";
if ( this.options.seconds ) {
mask += ":ss";
}
if ( this.options.ampm ) {
mask += " tt";
} }
this.mask._caret( field * 3, field * 3 + 2 ); return mask;
}, },
_setField: function( field ) { _setField: function( field ) {
this.currentField = field; this.currentField = field;
switch( field ) { switch( field ) {
case 0: case 0:
this.spinner.options.min = this.options.ampm ? 1 : 0; if ( this.options.ampm && this.mask.options.mask.indexOf( "h" ) ) {
this.spinner.options.max = this.options.ampm ? 12 : 23; this.spinner.options.min = 1;
this.spinner.options.max = 12;
} else {
this.spinner.options.min = 0;
this.spinner.options.max = 23;
}
break; break;
case 1: case 1:
case this.options.seconds ? 2 : -1 : case this.options.seconds ? 2 : -1 :
Expand Down Expand Up @@ -250,6 +247,14 @@ $.widget( "ui.timepicker", {
this.element.mask( "option", "mask", this._generateMask() ); this.element.mask( "option", "mask", this._generateMask() );
} }
}, },
_setPosition: function( field ) {
if ( field == null ) {
field = this.currentField;
} else {
this._setField( field );
}
this.mask._caretSelect( field * 3 );
},
_spinnerParse: function( val ) { _spinnerParse: function( val ) {
val = this.mask.buffer[ this.currentField * 3 ].value; val = this.mask.buffer[ this.currentField * 3 ].value;
if ( this.currentField === ( this.options.seconds ? 3 : 2 ) ) { if ( this.currentField === ( this.options.seconds ? 3 : 2 ) ) {
Expand All @@ -266,11 +271,6 @@ $.widget( "ui.timepicker", {
this.mask._paint(); this.mask._paint();
this.spinner._refresh(); this.spinner._refresh();
this.mask._caretSelect( this.currentField * 3 ); this.mask._caretSelect( this.currentField * 3 );
},
destroy: function() {
this.element.mask( "destroy" );
this.element.spinner( "destroy" );
this._super( "destroy" );
} }
}); });


Expand Down

0 comments on commit 912b8b2

Please sign in to comment.