mirror of
https://github.com/jquery/jquery-ui.git
synced 2026-04-20 03:02:41 -04:00
Spinner: Added culture option.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
<script src="../../jquery.js"></script>
|
||||
<script src="../../../external/jquery.mousewheel-3.0.4.js"></script>
|
||||
<script src="../../../external/globalize.js"></script>
|
||||
<script src="../../../external/globalize.culture.ja-JP.js"></script>
|
||||
<script src="../../../ui/jquery.ui.core.js"></script>
|
||||
<script src="../../../ui/jquery.ui.widget.js"></script>
|
||||
<script src="../../../ui/jquery.ui.button.js"></script>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
commonWidgetTests( "spinner", {
|
||||
defaults: {
|
||||
culture: null,
|
||||
disabled: false,
|
||||
incremental: true,
|
||||
max: null,
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module( "spinner: options" );
|
||||
|
||||
// culture is tested after numberFormat, since it depends on numberFormat
|
||||
|
||||
test( "incremental, false", function() {
|
||||
expect( 100 );
|
||||
|
||||
@@ -91,6 +93,29 @@ test( "numberFormat, currency", function() {
|
||||
equal( element.val(), "$1.00", "formatted after step" );
|
||||
});
|
||||
|
||||
test( "culture, null", function() {
|
||||
expect( 2 );
|
||||
Globalize.culture( "ja-JP" );
|
||||
var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "C" });
|
||||
equal( element.val(), "¥0", "formatted on init" );
|
||||
element.spinner( "stepUp" );
|
||||
equal( element.val(), "¥1", "formatted after step" );
|
||||
|
||||
// reset culture
|
||||
Globalize.culture( "default" );
|
||||
});
|
||||
|
||||
test( "currency, ja-JP", function() {
|
||||
expect( 2 );
|
||||
var element = $( "#spin" ).val( 0 ).spinner({
|
||||
numberFormat: "C",
|
||||
culture: "ja-JP"
|
||||
});
|
||||
equal( element.val(), "¥0", "formatted on init" );
|
||||
element.spinner( "stepUp" );
|
||||
equal( element.val(), "¥1", "formatted after step" );
|
||||
});
|
||||
|
||||
test( "max", function() {
|
||||
expect( 3 );
|
||||
var element = $( "#spin" ).val( 1000 ).spinner({ max: 100 });
|
||||
|
||||
6
ui/jquery.ui.spinner.js
vendored
6
ui/jquery.ui.spinner.js
vendored
@@ -30,6 +30,7 @@ $.widget( "ui.spinner", {
|
||||
defaultElement: "<input>",
|
||||
widgetEventPrefix: "spin",
|
||||
options: {
|
||||
culture: null,
|
||||
incremental: true,
|
||||
max: null,
|
||||
min: null,
|
||||
@@ -320,7 +321,8 @@ $.widget( "ui.spinner", {
|
||||
|
||||
_parse: function( val ) {
|
||||
if ( typeof val === "string" && val !== "" ) {
|
||||
val = window.Globalize && this.options.numberFormat ? Globalize.parseFloat( val ) : +val;
|
||||
val = window.Globalize && this.options.numberFormat ?
|
||||
Globalize.parseFloat( val, 10, this.options.culture ) : +val;
|
||||
}
|
||||
return val === "" || isNaN( val ) ? null : val;
|
||||
},
|
||||
@@ -330,7 +332,7 @@ $.widget( "ui.spinner", {
|
||||
return "";
|
||||
}
|
||||
return window.Globalize && this.options.numberFormat ?
|
||||
Globalize.format( value, this.options.numberFormat ) :
|
||||
Globalize.format( value, this.options.numberFormat, this.options.culture ) :
|
||||
value;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user