]> source.dussan.org Git - jquery-ui.git/commitdiff
Spinner: Added culture option.
authorScott González <scott.gonzalez@gmail.com>
Wed, 28 Sep 2011 22:30:58 +0000 (18:30 -0400)
committerScott González <scott.gonzalez@gmail.com>
Wed, 28 Sep 2011 22:30:58 +0000 (18:30 -0400)
tests/unit/spinner/spinner.html
tests/unit/spinner/spinner_defaults.js
tests/unit/spinner/spinner_options.js
ui/jquery.ui.spinner.js

index ddfb03d91dbb117c9c0dbae7f6fff08e74bcadcd..321c16b4cbf11e572aa27feee9eedb1cb44e037c 100644 (file)
@@ -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>
index 3321f87336cb856d46977ad58f44255e786486f4..0a4e7c2360a06c4002545b6972c0c794cbd21f40 100644 (file)
@@ -1,5 +1,6 @@
 commonWidgetTests( "spinner", {
        defaults: {
+               culture: null,
                disabled: false,
                incremental: true,
                max: null,
index 2b557cb698fe55e0f75670cf93e7fd3fb172860d..8be57c78517de43a2e1cb66a32a688b8a0714ec6 100644 (file)
@@ -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 });
index 09df97be7b90270ce3882cef38ae96fb6b01f385..31de2c9da22a84406986b0a3f498818668409f6a 100644 (file)
@@ -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;
        },