diff options
author | Alexander Schmitz <arschmitz@gmail.com> | 2015-08-24 08:57:40 -0400 |
---|---|---|
committer | Alexander Schmitz <arschmitz@gmail.com> | 2015-09-11 08:29:07 -0400 |
commit | 23d0884e662b099095688db2c3d05a2d94688ceb (patch) | |
tree | 2e47a26fb3faaff8e69d2697237f017a2246d4bb | |
parent | 6c0bb249184e3ad6f8ce48509b5f9011313a57a3 (diff) | |
download | jquery-ui-23d0884e662b099095688db2c3d05a2d94688ceb.tar.gz jquery-ui-23d0884e662b099095688db2c3d05a2d94688ceb.zip |
Spinner: Style updates
Ref #14246
-rw-r--r-- | tests/unit/spinner/common-deprecated.js | 2 | ||||
-rw-r--r-- | tests/unit/spinner/common.js | 2 | ||||
-rw-r--r-- | tests/unit/spinner/core.js | 72 | ||||
-rw-r--r-- | tests/unit/spinner/events.js | 42 | ||||
-rw-r--r-- | tests/unit/spinner/methods.js | 52 | ||||
-rw-r--r-- | tests/unit/spinner/options.js | 98 | ||||
-rw-r--r-- | ui/widgets/spinner.js | 8 |
7 files changed, 142 insertions, 134 deletions
diff --git a/tests/unit/spinner/common-deprecated.js b/tests/unit/spinner/common-deprecated.js index ece9adeac..9ffc473af 100644 --- a/tests/unit/spinner/common-deprecated.js +++ b/tests/unit/spinner/common-deprecated.js @@ -30,6 +30,6 @@ common.testWidget( "spinner", { start: null, stop: null } -}); +} ); } ); diff --git a/tests/unit/spinner/common.js b/tests/unit/spinner/common.js index ece9adeac..9ffc473af 100644 --- a/tests/unit/spinner/common.js +++ b/tests/unit/spinner/common.js @@ -30,6 +30,6 @@ common.testWidget( "spinner", { start: null, stop: null } -}); +} ); } ); diff --git a/tests/unit/spinner/core.js b/tests/unit/spinner/core.js index 64824e128..23df35da4 100644 --- a/tests/unit/spinner/core.js +++ b/tests/unit/spinner/core.js @@ -21,14 +21,14 @@ test( "markup structure", function( assert ) { equal( up.length, 1, "Spinner contains exactly one up button" ); assert.hasClasses( down, "ui-spinner-button ui-spinner-down ui-widget" ); equal( down.length, 1, "Spinner contains exactly one down button" ); -}); +} ); test( "keydown UP on input, increases value not greater than max", function() { expect( 5 ); - var element = $( "#spin" ).val( 70 ).spinner({ + var element = $( "#spin" ).val( 70 ).spinner( { max: 100, step: 10 - }); + } ); simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( element.val(), 80 ); @@ -40,14 +40,14 @@ test( "keydown UP on input, increases value not greater than max", function() { equal( element.val(), 100 ); simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( element.val(), 100 ); -}); +} ); test( "keydown DOWN on input, decreases value not less than min", function() { expect( 5 ); - var element = $( "#spin" ).val( 50 ).spinner({ + var element = $( "#spin" ).val( 50 ).spinner( { min: 20, step: 10 - }); + } ); simulateKeyDownUp( element, $.ui.keyCode.DOWN ); equal( element.val(), 40 ); @@ -59,14 +59,14 @@ test( "keydown DOWN on input, decreases value not less than min", function() { equal( element.val(), 20 ); simulateKeyDownUp( element, $.ui.keyCode.DOWN ); equal( element.val(), 20 ); -}); +} ); test( "keydown PAGE_UP on input, increases value not greater than max", function() { expect( 5 ); - var element = $( "#spin" ).val( 70 ).spinner({ + var element = $( "#spin" ).val( 70 ).spinner( { max: 100, page: 10 - }); + } ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); equal( element.val(), 80 ); @@ -78,14 +78,14 @@ test( "keydown PAGE_UP on input, increases value not greater than max", function equal( element.val(), 100 ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); equal( element.val(), 100 ); -}); +} ); test( "keydown PAGE_DOWN on input, decreases value not less than min", function() { expect( 5 ); - var element = $( "#spin" ).val( 50 ).spinner({ + var element = $( "#spin" ).val( 50 ).spinner( { min: 20, page: 10 - }); + } ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); equal( element.val(), 40 ); @@ -97,7 +97,7 @@ test( "keydown PAGE_DOWN on input, decreases value not less than min", function( equal( element.val(), 20 ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); equal( element.val(), 20 ); -}); +} ); asyncTest( "blur input while spinning with UP", function() { expect( 3 ); @@ -117,7 +117,7 @@ asyncTest( "blur input while spinning with UP", function() { element.on( "blur", function() { value = element.val(); setTimeout( step3, 750 ); - })[ 0 ].blur(); + } )[ 0 ].blur(); } function step3() { @@ -127,13 +127,13 @@ asyncTest( "blur input while spinning with UP", function() { element[ 0 ].focus(); setTimeout( step1 ); -}); +} ); test( "mouse click on up button, increases value not greater than max", function() { expect( 3 ); - var element = $( "#spin" ).val( 18 ).spinner({ + var element = $( "#spin" ).val( 18 ).spinner( { max: 20 - }), + } ), button = element.spinner( "widget" ).find( ".ui-spinner-up" ); button.trigger( "mousedown" ).trigger( "mouseup" ); @@ -142,13 +142,13 @@ test( "mouse click on up button, increases value not greater than max", function equal( element.val(), 20 ); button.trigger( "mousedown" ).trigger( "mouseup" ); equal( element.val(), 20 ); -}); +} ); test( "mouse click on up button, increases value not greater than max", function() { expect( 3 ); - var element = $( "#spin" ).val( 2 ).spinner({ + var element = $( "#spin" ).val( 2 ).spinner( { min: 0 - }), + } ), button = element.spinner( "widget" ).find( ".ui-spinner-down" ); button.trigger( "mousedown" ).trigger( "mouseup" ); @@ -157,14 +157,14 @@ test( "mouse click on up button, increases value not greater than max", function equal( element.val(), 0 ); button.trigger( "mousedown" ).trigger( "mouseup" ); equal( element.val(), 0 ); -}); +} ); test( "mousewheel on input", function() { expect( 4 ); - var element = $( "#spin" ).val( 0 ).spinner({ + var element = $( "#spin" ).val( 0 ).spinner( { step: 2 - }); + } ); element.trigger( "mousewheel" ); equal( element.val(), 0, "mousewheel event without delta does not change value" ); @@ -176,8 +176,8 @@ test( "mousewheel on input", function() { equal( element.val(), 0 ); element.trigger( "mousewheel", -15 ); - equal(element.val(), -2 ); -}); + equal( element.val(), -2 ); +} ); test( "reading HTML5 attributes", function() { expect( 6 ); @@ -187,19 +187,19 @@ test( "reading HTML5 attributes", function() { equal( element.spinner( "option", "max" ), 100, "max from markup" ); equal( element.spinner( "option", "step" ), 2, "step from markup" ); - element = $( markup ).spinner({ + element = $( markup ).spinner( { min: -200, max: 200, step: 5 - }); + } ); equal( element.spinner( "option", "min" ), -200, "min from options" ); equal( element.spinner( "option", "max" ), 200, "max from options" ); equal( element.spinner( "option", "step" ), 5, "stop from options" ); -}); +} ); test( "ARIA attributes", function() { expect( 9 ); - var element = $( "#spin" ).val( 2 ).spinner({ min: -5, max: 5 }); + var element = $( "#spin" ).val( 2 ).spinner( { min: -5, max: 5 } ); equal( element.attr( "role" ), "spinbutton", "role" ); equal( element.attr( "aria-valuemin" ), "-5", "aria-valuemin" ); @@ -220,7 +220,7 @@ test( "ARIA attributes", function() { element.spinner( "option", "max", null ); equal( element.attr( "aria-valuemax" ), undefined, "aria-valuemax not set when no max" ); -}); +} ); test( "focus text field when pressing button", function() { expect( 2 ); @@ -229,29 +229,29 @@ test( "focus text field when pressing button", function() { ok( element[ 0 ] !== document.activeElement, "not focused before" ); element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" ); ok( element[ 0 ] === document.activeElement, "focused after" ); -}); +} ); test( "don't clear invalid value on blur", function() { expect( 1 ); var element = $( "#spin" ).spinner(); element.trigger( "focus" ).val( "a" ).trigger( "blur" ); equal( element.val(), "a" ); -}); +} ); test( "precision", function() { expect( 2 ); - var element = $( "#spin" ).val( 0.05 ).spinner({ + var element = $( "#spin" ).val( 0.05 ).spinner( { step: 0.0001 - }); + } ); element.spinner( "stepUp" ); equal( element.val(), "0.0501", "precision from step" ); element.val( 1.05 ).spinner( "option", { step: 1, min: -9.95 - }); + } ); element.spinner( "stepDown" ); equal( element.val(), "0.05", "precision from min" ); -}); +} ); } ); diff --git a/tests/unit/spinner/events.js b/tests/unit/spinner/events.js index 8fa409b99..7f88d063a 100644 --- a/tests/unit/spinner/events.js +++ b/tests/unit/spinner/events.js @@ -15,7 +15,7 @@ test( "start", function() { function shouldStart( expectation, msg ) { element.spinner( "option", "start", function() { ok( expectation, msg ); - }); + } ); } shouldStart( true, "key UP" ); @@ -45,7 +45,7 @@ test( "start", function() { shouldStart( false, "value" ); element.spinner( "value", 999 ); -}); +} ); test( "spin", function() { expect( 10 ); @@ -54,7 +54,7 @@ test( "spin", function() { function shouldSpin( expectation, msg ) { element.spinner( "option", "spin", function() { ok( expectation, msg ); - }); + } ); } shouldSpin( true, "key UP" ); @@ -84,7 +84,7 @@ test( "spin", function() { shouldSpin( false, "value" ); element.spinner( "value", 999 ); -}); +} ); test( "stop", function() { expect( 10 ); @@ -93,7 +93,7 @@ test( "stop", function() { function shouldStop( expectation, msg ) { element.spinner( "option", "stop", function() { ok( expectation, msg ); - }); + } ); } shouldStop( true, "key UP" ); @@ -123,7 +123,7 @@ test( "stop", function() { shouldStop( false, "value" ); element.spinner( "value", 999 ); -}); +} ); asyncTest( "change", function() { expect( 12 ); @@ -132,22 +132,22 @@ asyncTest( "change", function() { function shouldChange( expectation, msg ) { element.spinner( "option", "change", function() { ok( expectation, msg ); - }); + } ); } function focusWrap( fn, next ) { - element[0].focus(); + element[ 0 ].focus(); setTimeout( function() { fn(); - setTimeout(function() { - element[0].blur(); + setTimeout( function() { + element[ 0 ].blur(); setTimeout( next ); - }); - }); + } ); + } ); } function step1() { - focusWrap(function() { + focusWrap( function() { shouldChange( false, "key UP, before blur" ); simulateKeyDownUp( element, $.ui.keyCode.UP ); shouldChange( true, "blur after key UP" ); @@ -155,7 +155,7 @@ asyncTest( "change", function() { } function step2() { - focusWrap(function() { + focusWrap( function() { shouldChange( false, "key DOWN, before blur" ); simulateKeyDownUp( element, $.ui.keyCode.DOWN ); shouldChange( true, "blur after key DOWN" ); @@ -163,7 +163,7 @@ asyncTest( "change", function() { } function step3() { - focusWrap(function() { + focusWrap( function() { shouldChange( false, "key PAGE_UP, before blur" ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); shouldChange( true, "blur after key PAGE_UP" ); @@ -171,7 +171,7 @@ asyncTest( "change", function() { } function step4() { - focusWrap(function() { + focusWrap( function() { shouldChange( false, "key PAGE_DOWN, before blur" ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); shouldChange( true, "blur after key PAGE_DOWN" ); @@ -179,7 +179,7 @@ asyncTest( "change", function() { } function step5() { - focusWrap(function() { + focusWrap( function() { shouldChange( false, "many keys, before blur" ); simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); simulateKeyDownUp( element, $.ui.keyCode.UP ); @@ -191,7 +191,7 @@ asyncTest( "change", function() { } function step6() { - focusWrap(function() { + focusWrap( function() { shouldChange( false, "many keys, same final value, before blur" ); simulateKeyDownUp( element, $.ui.keyCode.UP ); simulateKeyDownUp( element, $.ui.keyCode.UP ); @@ -206,7 +206,7 @@ asyncTest( "change", function() { } function step7() { - focusWrap(function() { + focusWrap( function() { shouldChange( false, "button down, before blur" ); element.spinner( "widget" ).find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" ); shouldChange( true, "blur after button down" ); @@ -214,7 +214,7 @@ asyncTest( "change", function() { } function step8() { - focusWrap(function() { + focusWrap( function() { shouldChange( false, "many buttons, same final value, before blur" ); element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" ); element.spinner( "widget" ).find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" ); @@ -258,6 +258,6 @@ asyncTest( "change", function() { } setTimeout( step1 ); -}); +} ); } ); diff --git a/tests/unit/spinner/methods.js b/tests/unit/spinner/methods.js index 6f165b936..3b039ff39 100644 --- a/tests/unit/spinner/methods.js +++ b/tests/unit/spinner/methods.js @@ -12,8 +12,8 @@ test( "destroy", function( assert ) { expect( 1 ); assert.domEqual( "#spin", function() { $( "#spin" ).spinner().spinner( "destroy" ); - }); -}); + } ); +} ); test( "disable", function( assert ) { expect( 15 ); @@ -26,7 +26,7 @@ test( "disable", function( assert ) { element.spinner( "disable" ); assert.hasClasses( wrapper, "ui-state-disabled ui-spinner-disabled" ); ok( !wrapper.attr( "aria-disabled" ), "after: wrapper does not have aria-disabled attr" ); - ok( element.is( ":disabled"), "after: input has disabled attribute" ); + ok( element.is( ":disabled" ), "after: input has disabled attribute" ); simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( 2, element.val(), "keyboard - value does not change on key UP" ); @@ -47,7 +47,7 @@ test( "disable", function( assert ) { equal( 2, element.val(), "mouse - value does not change on clicking down button" ); element.spinner( "stepUp", 6 ); - equal( 8, element.val(), "script - stepUp 6 steps changes value"); + equal( 8, element.val(), "script - stepUp 6 steps changes value" ); element.spinner( "stepDown" ); equal( 7, element.val(), "script - stepDown 1 step changes value" ); @@ -57,11 +57,11 @@ test( "disable", function( assert ) { element.spinner( "pageDown" ); equal( 7, element.val(), "script - pageDown 1 page changes value" ); -}); +} ); test( "enable", function( assert ) { expect( 5 ); - var element = $( "#spin" ).val( 1 ).spinner({ disabled: true }), + var element = $( "#spin" ).val( 1 ).spinner( { disabled: true } ), wrapper = element.spinner( "widget" ); assert.hasClasses( wrapper, "ui-spinner-disabled" ); @@ -74,15 +74,15 @@ test( "enable", function( assert ) { simulateKeyDownUp( element, $.ui.keyCode.UP ); equal( 2, element.val(), "keyboard - value changes on key UP" ); -}); +} ); test( "isValid", function() { expect( 8 ); - var element = $( "#spin" ).spinner({ + var element = $( "#spin" ).spinner( { min: 0, max: 10, step: 2 - }), + } ), spinner = element.spinner( "instance" ); ok( !spinner.isValid(), "initial state is invalid" ); @@ -106,14 +106,14 @@ test( "isValid", function() { element.val( "1" ); ok( !spinner.isValid(), "step mismatch is invalid" ); -}); +} ); test( "pageDown", function() { expect( 4 ); - var element = $( "#spin" ).val( -12 ).spinner({ + var element = $( "#spin" ).val( -12 ).spinner( { page: 20, min: -100 - }); + } ); element.spinner( "pageDown" ); equal( element.val(), -32, "pageDown 1 page" ); @@ -126,14 +126,14 @@ test( "pageDown", function() { element.spinner( "pageDown", 10 ); equal( element.val(), -100, "value at min and pageDown 10 pages" ); -}); +} ); test( "pageUp", function() { expect( 4 ); - var element = $( "#spin" ).val( 12 ).spinner({ + var element = $( "#spin" ).val( 12 ).spinner( { page: 20, max: 100 - }); + } ); element.spinner( "pageUp" ); equal( element.val(), 32, "pageUp 1 page" ); @@ -146,14 +146,14 @@ test( "pageUp", function() { element.spinner( "pageUp", 10 ); equal( element.val(), 100, "value at max and pageUp 10 pages" ); -}); +} ); test( "stepDown", function() { expect( 4 ); - var element = $( "#spin" ).val( 0 ).spinner({ + var element = $( "#spin" ).val( 0 ).spinner( { step: 2, min: -15 - }); + } ); element.spinner( "stepDown" ); equal( element.val(), "-1", "stepDown 1 step" ); @@ -166,14 +166,14 @@ test( "stepDown", function() { element.spinner( "stepDown" ); equal( element.val(), "-15", "at min and stepDown 1 step" ); -}); +} ); test( "stepUp", function() { expect( 4 ); - var element = $( "#spin" ).val( 0 ).spinner({ + var element = $( "#spin" ).val( 0 ).spinner( { step: 2, max: 16 - }); + } ); element.spinner( "stepUp" ); equal( element.val(), 2, "stepUp 1 step" ); @@ -186,19 +186,19 @@ test( "stepUp", function() { element.spinner( "stepUp" ); equal( element.val(), 16, "at max and stepUp 1 step" ); -}); +} ); test( "value", function() { expect( 2 ); - var element = $( "#spin" ).val( 0 ).spinner({ + var element = $( "#spin" ).val( 0 ).spinner( { step: 3 - }); + } ); element.spinner( "value", 10 ); equal( element.val(), 9, "change value via value method" ); equal( element.spinner( "value" ), 9, "get value via value method" ); -}); +} ); test( "widget", function() { expect( 2 ); @@ -206,6 +206,6 @@ test( "widget", function() { widgetElement = element.spinner( "widget" ); equal( widgetElement.length, 1, "one element" ); strictEqual( widgetElement[ 0 ], element.parent()[ 0 ], "parent element" ); -}); +} ); } ); diff --git a/tests/unit/spinner/options.js b/tests/unit/spinner/options.js index c3a9f74a2..8ad5caeaa 100644 --- a/tests/unit/spinner/options.js +++ b/tests/unit/spinner/options.js @@ -20,43 +20,43 @@ test( "icons: default ", function( assert ) { element.spinner( "option", "icons", { up: "ui-icon-caret-1-n", down: "ui-icon-caret-1-s" - }); + } ); assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:first" ), "ui-icon ui-icon-caret-1-n" ); assert.hasClasses( element.spinner( "widget" ).find( ".ui-icon:last" ), "ui-icon ui-icon-caret-1-s" ); -}); +} ); test( "icons: custom ", function( assert ) { expect( 2 ); - var element = $( "#spin" ).val( 0 ).spinner({ + var element = $( "#spin" ).val( 0 ).spinner( { icons: { down: "custom-down", up: "custom-up" } - }).spinner( "widget" ); + } ).spinner( "widget" ); assert.hasClasses( element.find( ".ui-icon:first" ), "ui-icon custom-up" ); assert.hasClasses( element.find( ".ui-icon:last" ), "ui-icon custom-down" ); -}); +} ); test( "incremental, false", function() { expect( 100 ); var i, prev = 0, - element = $( "#spin" ).val( prev ).spinner({ + element = $( "#spin" ).val( prev ).spinner( { incremental: false, spin: function( event, ui ) { equal( ui.value - prev, 1 ); prev = ui.value; } - }); + } ); for ( i = 0; i < 100; i++ ) { element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); } element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); -}); +} ); test( "incremental, true", function() { expect( 100 ); @@ -64,7 +64,7 @@ test( "incremental, true", function() { function fill( num, val ) { return $.map( new Array( num ), function() { return val; - }); + } ); } var i, @@ -72,26 +72,26 @@ test( "incremental, true", function() { expected = [].concat( fill( 18, 1 ), fill( 37, 2 ), fill( 14, 3 ), fill( 9, 4 ), fill( 6, 5 ), fill( 5, 6 ), fill ( 5, 7 ), fill( 4, 8 ), fill( 2, 9 ) ), - element = $( "#spin" ).val( prev ).spinner({ + element = $( "#spin" ).val( prev ).spinner( { incremental: true, spin: function( event, ui ) { equal( ui.value - prev, expected[ i ] ); prev = ui.value; } - }); + } ); for ( i = 0; i < 100; i++ ) { element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); } element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); -}); +} ); test( "incremental, function", function() { expect( 100 ); var i, prev = 0, - element = $( "#spin" ).val( prev ).spinner({ + element = $( "#spin" ).val( prev ).spinner( { incremental: function( i ) { return i; }, @@ -99,83 +99,83 @@ test( "incremental, function", function() { equal( ui.value - prev, i + 1 ); prev = ui.value; } - }); + } ); for ( i = 0; i < 100; i++ ) { element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); } element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); -}); +} ); test( "numberFormat, number", function() { expect( 2 ); - var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "n" }); + var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "n" } ); equal( element.val(), "0.00", "formatted on init" ); element.spinner( "stepUp" ); equal( element.val(), "1.00", "formatted after step" ); -}); +} ); test( "numberFormat, number, simple", function() { expect( 2 ); - var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "n0" }); + var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "n0" } ); equal( element.val(), "0", "formatted on init" ); element.spinner( "stepUp" ); equal( element.val(), "1", "formatted after step" ); -}); +} ); test( "numberFormat, currency", function() { expect( 2 ); - var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "C" }); + var element = $( "#spin" ).val( 0 ).spinner( { numberFormat: "C" } ); equal( element.val(), "$0.00", "formatted on init" ); element.spinner( "stepUp" ); equal( element.val(), "$1.00", "formatted after step" ); -}); +} ); test( "numberFormat, change", function() { expect( 2 ); - var element = $( "#spin" ).val( 5 ).spinner({ numberFormat: "n1" }); + var element = $( "#spin" ).val( 5 ).spinner( { numberFormat: "n1" } ); equal( element.val(), "5.0", "formatted on init" ); element.spinner( "option", "numberFormat", "c" ); equal( element.val(), "$5.00", "formatted after change" ); -}); +} ); test( "culture, null", function() { expect( 2 ); Globalize.culture( "ja-JP" ); - var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "C" }); + 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({ + 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( "currency, change", function() { expect( 2 ); - var element = $( "#spin" ).val( 5 ).spinner({ + var element = $( "#spin" ).val( 5 ).spinner( { numberFormat: "C", culture: "ja-JP" - }); + } ); equal( element.val(), "¥5", "formatted on init" ); element.spinner( "option", "culture", "en" ); equal( element.val(), "$5.00", "formatted after change" ); -}); +} ); test( "max", function() { expect( 3 ); - var element = $( "#spin" ).val( 1000 ).spinner({ max: 100 }); + var element = $( "#spin" ).val( 1000 ).spinner( { max: 100 } ); equal( element.val(), 1000, "value not constrained on init" ); element.spinner( "value", 1000 ); @@ -183,27 +183,27 @@ test( "max", function() { element.val( 1000 ).trigger( "blur" ); equal( element.val(), 1000, "max not constrained if manual entry" ); -}); +} ); test( "max, string", function() { expect( 3 ); var element = $( "#spin" ) .val( 1000 ) - .spinner({ + .spinner( { max: "$100.00", numberFormat: "C", culture: "en" - }); + } ); equal( element.val(), "$1,000.00", "value not constrained on init" ); equal( element.spinner( "option", "max" ), 100, "option converted to number" ); element.spinner( "value", 1000 ); equal( element.val(), "$100.00", "max constrained in value method" ); -}); +} ); test( "min", function() { expect( 3 ); - var element = $( "#spin" ).val( -1000 ).spinner({ min: -100 }); + var element = $( "#spin" ).val( -1000 ).spinner( { min: -100 } ); equal( element.val(), -1000, "value not constrained on init" ); element.spinner( "value", -1000 ); @@ -211,27 +211,27 @@ test( "min", function() { element.val( -1000 ).trigger( "blur" ); equal( element.val(), -1000, "min not constrained if manual entry" ); -}); +} ); test( "min, string", function() { expect( 3 ); var element = $( "#spin" ) .val( -1000 ) - .spinner({ + .spinner( { min: "-$100.00", numberFormat: "C", culture: "en" - }); + } ); equal( element.val(), "($1,000.00)", "value not constrained on init" ); equal( element.spinner( "option", "min" ), -100, "option converted to number" ); element.spinner( "value", -1000 ); equal( element.val(), "($100.00)", "min constrained in value method" ); -}); +} ); test( "step, 2", function() { expect( 3 ); - var element = $( "#spin" ).val( 0 ).spinner({ step: 2 }); + var element = $( "#spin" ).val( 0 ).spinner( { step: 2 } ); element.spinner( "stepUp" ); equal( element.val(), "2", "stepUp" ); @@ -242,30 +242,30 @@ test( "step, 2", function() { element.val( "4.5" ); element.spinner( "stepUp" ); equal( element.val(), "6", "stepUp" ); -}); +} ); test( "step, 0.7", function() { expect( 1 ); - var element = $("#spin").val( 0 ).spinner({ + var element = $( "#spin" ).val( 0 ).spinner( { step: 0.7 - }); + } ); element.spinner( "stepUp" ); equal( element.val(), "0.7", "stepUp" ); -}); +} ); test( "step, string", function() { expect( 2 ); - var element = $("#spin").val( 0 ).spinner({ + var element = $( "#spin" ).val( 0 ).spinner( { step: "$0.70", numberFormat: "C", culture: "en" - }); + } ); equal( element.spinner( "option", "step" ), 0.7, "option converted to number" ); element.spinner( "stepUp" ); equal( element.val(), "$0.70", "stepUp" ); -}); +} ); } ); diff --git a/ui/widgets/spinner.js b/ui/widgets/spinner.js index 712d99bad..a64d46c76 100644 --- a/ui/widgets/spinner.js +++ b/ui/widgets/spinner.js @@ -75,6 +75,7 @@ $.widget( "ui.spinner", { }, _create: function() { + // handle string values that need to be parsed this._setOption( "max", this.options.max ); this._setOption( "min", this.options.min ); @@ -83,6 +84,7 @@ $.widget( "ui.spinner", { // Only format if there is a value, prevents the field from being marked // as invalid in Firefox, see #9573. if ( this.value() !== "" ) { + // Format the value, but don't constrain. this._value( this.element.val(), true ); } @@ -169,6 +171,7 @@ $.widget( "ui.spinner", { if ( !isActive ) { this.element.trigger( "focus" ); this.previous = previous; + // support: IE // IE sets focus asynchronously, so we need to check if focus // moved off of the input because the user clicked on the button. @@ -200,6 +203,7 @@ $.widget( "ui.spinner", { }, "mouseup .ui-spinner-button": "_stop", "mouseenter .ui-spinner-button": function( event ) { + // button will add ui-state-active if mouse was down while mouseleave and kept down if ( !$( event.currentTarget ).hasClass( "ui-state-active" ) ) { return; @@ -210,6 +214,7 @@ $.widget( "ui.spinner", { } this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event ); }, + // TODO: do we really want to consider this a stop? // shouldn't we just stop the repeater and wait until mouseup before // we trigger the stop event? @@ -364,8 +369,10 @@ $.widget( "ui.spinner", { // - find out where we are relative to the base (min or 0) base = options.min !== null ? options.min : 0; aboveMin = value - base; + // - round to the nearest step aboveMin = Math.round( aboveMin / options.step ) * options.step; + // - rounding is based on 0, so adjust back to our base value = base + aboveMin; @@ -453,6 +460,7 @@ $.widget( "ui.spinner", { this.element.attr( { "aria-valuemin": this.options.min, "aria-valuemax": this.options.max, + // TODO: what should we do with values that can't be parsed? "aria-valuenow": this._parse( this.element.val() ) } ); |