<script type="text/javascript">\r
$(function() {\r
$("#spinner").spinner({\r
- step: 0.01\r
+ step: 0.01,\r
+ numberformat: "n"\r
}); \r
\r
$("#culture").change(function() {\r
\r
<script type="text/javascript" src="../../../jquery-1.4.3.js"></script>\r
<script type="text/javascript" src="../../../external/jquery.mousewheel-3.0.4.js"></script>\r
+ <script type="text/javascript" src="../../../external/glob.js"></script>\r
<script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script>\r
<script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script>\r
<script type="text/javascript" src="../../../ui/jquery.ui.button.js"></script>\r
* spinner_core.js\r
*/\r
\r
-var el,\r
- options,\r
- simulateKeyDownUp = function(el, kCode, shift) {\r
- el.simulate("keydown",{keyCode:kCode, shiftKey: shift || false })\r
- .simulate("keyup",{keyCode:kCode, shiftKey: shift || false });\r
- },\r
- wrapper = function() {\r
- return el.closest('.ui-spinner');\r
- },\r
- upButton = function() {\r
- return wrapper().find('.ui-spinner-up');\r
- },\r
- downButton = function() {\r
- return wrapper().find('.ui-spinner-down');\r
- },\r
- box = function() {\r
- return $('.ui-spinner-input', wrapper());\r
- };\r
+var simulateKeyDownUp = function(el, kCode, shift) {\r
+ el.simulate("keydown",{keyCode:kCode, shiftKey: shift || false })\r
+ .simulate("keyup",{keyCode:kCode, shiftKey: shift || false });\r
+};\r
\r
(function($) {\r
\r
// Spinner Tests\r
module("spinner: core");\r
\r
-test("init", function() {\r
- expect(3);\r
-\r
- $("<input>").appendTo('body').spinner().remove();\r
- ok(true, '.spinner() called on element');\r
-\r
- $('<input id="spinner_dis">').spinner().remove();\r
- ok(true, '.spinner() called on disconnected element');\r
-\r
- el = $('<input>').spinner();\r
- ok(el.hasClass('ui-spinner-input'), 'input gets ui-spinner-input class on init');\r
-\r
-});\r
-\r
test("destroy", function() {\r
- expect(3);\r
-\r
- $("<input>").appendTo('body').spinner().spinner("destroy").remove();\r
- ok(true, '.spinner("destroy") called on element');\r
-\r
- $('<input id="spinner_dis">').spinner().spinner("destroy").remove();\r
- ok(true, '.spinner().spinner("destroy") called on disconnected element');\r
-\r
- el = $('<input>').spinner().spinner('destroy');\r
- ok(!el.hasClass('ui-spinner-input'), 'ui-spinner-input class removed on destroy');\r
-});\r
-\r
-test("re-attach", function() {\r
- expect(2);\r
-\r
- el = $("<input>").spinner().spinner("destroy").spinner();\r
- ok(true, '.spinner().spinner("destroy").spinner() called on element');\r
-\r
- el = $('<input id="spinner_dis">').spinner().spinner("destroy").spinner().remove();\r
- ok(true, '.spinner().spinner("destroy").spinner() called on disconnected element');\r
-\r
+ var beforeHtml = $("#spin").parent().html();\r
+ var afterHtml = $("#spin").spinner().spinner("destroy").parent().html();\r
+ // Opera 9 outputs role="" instead of removing the attribute like everyone else\r
+ /*\r
+ if ($.browser.opera) {\r
+ afterHtml = afterHtml.replace(/ role=""/g, "");\r
+ }\r
+ */\r
+ equal( afterHtml, beforeHtml, "before/after html should be the same" );\r
});\r
\r
test("keydown UP on input, increases value not greater than max", function() {\r
- expect(3);\r
- \r
- el = $("#spin");\r
- options = {\r
+ var el = $("#spin").spinner({\r
max:100,\r
value:50,\r
step:10\r
- }\r
- el.spinner(options);\r
+ });\r
\r
simulateKeyDownUp(el, $.ui.keyCode.UP);\r
- \r
equals(el.val(), 60);\r
\r
for (i = 0; i<11; i++) {\r
simulateKeyDownUp(el, $.ui.keyCode.UP); \r
}\r
- \r
equals(el.val(), 100);\r
\r
el.val(50);\r
- \r
simulateKeyDownUp(el, $.ui.keyCode.UP);\r
- \r
equals(el.val(), 60);\r
});\r
\r
test("keydown DOWN on input, decreases value not less than min", function() {\r
- expect(3);\r
- \r
- el = $("#spin");\r
- options = {\r
+ var el = $("#spin").spinner({\r
min:-100,\r
value:50,\r
step:10\r
- }\r
- el.spinner(options);\r
+ });\r
\r
simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
- \r
equals(el.val(), 40);\r
\r
for (i = 0; i<21; i++) {\r
simulateKeyDownUp(el, $.ui.keyCode.DOWN); \r
}\r
- \r
equals(el.val(), -100);\r
\r
el.val(50);\r
- \r
simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
- \r
equals(el.val(), 40);\r
-\r
});\r
\r
test("keydown PGUP on input, increases value not greater than max", function() {\r
- expect(3);\r
+ var el = $("#spin").spinner({\r
+ max: 500,\r
+ value: 0,\r
+ step: 10\r
+ });\r
\r
- el = $("#spin");\r
- options = {\r
- max:100,\r
- value:0,\r
- step:10\r
- }\r
- el.spinner(options);\r
- \r
simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
- \r
- equals(el.val(), 50);\r
+ equal(el.val(), 100);\r
\r
for (i = 0; i<5; i++) {\r
simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP); \r
}\r
+ equal(el.val(), 500);\r
\r
- equals(el.val(), 100);\r
-\r
el.val(0);\r
- \r
simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
- \r
- equals(el.val(), 50);\r
+ equals(el.val(), 100);\r
});\r
\r
test("keydown PGDN on input, decreases value not less than min", function() {\r
- expect(3);\r
- \r
- el = $("#spin");\r
- options = {\r
- min:-100,\r
+ var el = $("#spin").spinner({\r
+ min:-500,\r
value:0,\r
step:10\r
- }\r
- el.spinner(options);\r
+ });\r
\r
simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
- \r
- equals(el.val(), -50);\r
+ equals(el.val(), -100);\r
\r
for (i = 0; i<5; i++) {\r
simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN); \r
}\r
- \r
- equals(el.val(), -100);\r
+ equals(el.val(), -500);\r
\r
el.val(0);\r
- \r
simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
- \r
- equals(el.val(), -50);\r
-});\r
-\r
-test("hold SHIFT and keydown UP, increments value but no greater than max", function() {\r
- expect(2);\r
- \r
- el = $("#spin");\r
- options = {\r
- max:100,\r
- value:0,\r
- step:10\r
- }\r
- el.spinner(options);\r
- \r
- simulateKeyDownUp(el, $.ui.keyCode.UP, true);\r
- \r
- equals(el.val(), 50);\r
- \r
- for (i = 0; i<5; i++) {\r
- simulateKeyDownUp(el, $.ui.keyCode.UP, true);\r
- }\r
- \r
- equals(el.val(), 100);\r
-});\r
-\r
-test("hold SHIFT and keydown DOWN, decreases value but no less than min", function() {\r
- expect(2);\r
- \r
- el = $("#spin");\r
- options = {\r
- min:-100,\r
- value:0,\r
- step:10\r
- }\r
- el.spinner(options);\r
- \r
- simulateKeyDownUp(el, $.ui.keyCode.DOWN, true);\r
- \r
- equals(el.val(), -50);\r
- \r
- for (i = 0; i<5; i++) {\r
- simulateKeyDownUp(el, $.ui.keyCode.DOWN, true); \r
- }\r
- \r
- equals(el.val(), -100); \r
-});\r
-\r
-test("keydown HOME on input, sets value to minimum", function() {\r
- el = $("#spin");\r
- options = {\r
- min:-100,\r
- value:50,\r
- step:10\r
- }\r
- el.spinner(options);\r
-\r
- simulateKeyDownUp(el, $.ui.keyCode.HOME); \r
equals(el.val(), -100);\r
- \r
- el.spinner('option', 'min', -200);\r
- \r
- simulateKeyDownUp(el, $.ui.keyCode.HOME);\r
- \r
- equals(el.val(), -200);\r
-});\r
-\r
-test("keydown END on input, sets value to maximum", function() {\r
- el = $("#spin");\r
- options = {\r
- max:100,\r
- value:50,\r
- step:10\r
- }\r
- el.spinner(options);\r
-\r
- simulateKeyDownUp(el, $.ui.keyCode.END); \r
- equals(el.val(), 100);\r
- \r
- el.spinner('option', 'max', 200);\r
- \r
- simulateKeyDownUp(el, $.ui.keyCode.END);\r
- \r
- equals(el.val(), 200);\r
-});\r
-\r
-test("keydown LEFT on input has no effect", function() {\r
- el = $("#spin");\r
- el.spinner();\r
- var value = el.val();\r
- \r
- simulateKeyDownUp(el, $.ui.keyCode.LEFT); \r
- equals(el.val(), value);\r
- \r
- for (i = 0; i<5; i++) {\r
- simulateKeyDownUp(el, $.ui.keyCode.LEFT); \r
- }\r
- \r
- equals(el.val(), value);\r
-});\r
-\r
-test("keydown RIGHT on input has no effect", function() {\r
- expect(2);\r
- \r
- el = $("#spin");\r
- el.spinner();\r
- var value = el.val();\r
- \r
- simulateKeyDownUp(el, $.ui.keyCode.RIGHT); \r
- equals(el.val(), value);\r
- \r
- for (i = 0; i<5; i++) {\r
- simulateKeyDownUp(el, $.ui.keyCode.RIGHT); \r
- }\r
- \r
- equals(el.val(), value);\r
});\r
\r
test("mouse click on buttons", function() {\r
- expect(4);\r
- \r
- el = $("#spin").spinner();\r
- val = 0;\r
+ var el = $("#spin").spinner(),\r
+ val = 0;\r
\r
$(".ui-spinner-up").trigger("mousedown").trigger("mouseup");\r
-\r
equals(el.val(), ++val, "mouse click to up");\r
\r
$(".ui-spinner-down").trigger("mousedown").trigger("mouseup");\r
-\r
equals(el.val(), --val, "mouse click to down");\r
\r
el.val(50);\r
- \r
$(".ui-spinner-up").trigger("mousedown").trigger("mouseup");\r
- \r
equals(el.val(), 51);\r
\r
el.val(50);\r
- \r
$(".ui-spinner-down").trigger("mousedown").trigger("mouseup");\r
- \r
equals(el.val(), 49);\r
- \r
});\r
\r
test("mouse wheel on input", function() {\r
- ok(false, 'missing test - untested code is broken code');\r
+ expect(3);\r
+ \r
+ var el = $("#spin").spinner();\r
+ el.trigger("mousewheel", 1);\r
+ equal(el.val(), 1);\r
+ \r
+ // mousewheel handler uses a timeout, need to accomodate that\r
+ stop();\r
+ setTimeout(function() {\r
+ el.trigger("mousewheel", -1);\r
+ equal(el.val(), 0);\r
+ \r
+ setTimeout(function() {\r
+ el.trigger("mousewheel", -1);\r
+ equal(el.val(), -1);\r
+ start();\r
+ }, 100);\r
+ }, 100);\r
+ \r
});\r
\r
test("reading HTML5 attributes", function() {\r
- expect(4);\r
- \r
- el = $('<input id="spinner" type="number" min="-100" max="100" value="5" step="2">').spinner();\r
-\r
+ var el = $('<input id="spinner" type="number" min="-100" max="100" value="5" step="2">').spinner();\r
equals(el.spinner('option', 'value'), 5, 'value'); \r
equals(el.spinner('option', 'max'), 100, 'max');\r
equals(el.spinner('option', 'min'), -100, 'min');\r
});\r
\r
test("ARIA attributes", function() {\r
- expect(7);\r
- \r
- el = $('#spin').spinner({ min: -5, max: 5, value: 2 });\r
+ var el = $('#spin').spinner({ min: -5, max: 5, value: 2 }),\r
+ wrapper = el.spinner("widget");\r
\r
- equals(wrapper().attr('role'), 'spinbutton', 'role');\r
- equals(wrapper().attr('aria-valuemin'), -5, 'aria-valuemin');\r
- equals(wrapper().attr('aria-valuemax'), 5, 'aria-valuemax');\r
- equals(wrapper().attr('aria-valuenow'), 2, 'aria-valuenow');\r
+ equals(wrapper.attr('role'), 'spinbutton', 'role');\r
+ equals(wrapper.attr('aria-valuemin'), -5, 'aria-valuemin');\r
+ equals(wrapper.attr('aria-valuemax'), 5, 'aria-valuemax');\r
+ equals(wrapper.attr('aria-valuenow'), 2, 'aria-valuenow');\r
\r
el.spinner('stepUp');\r
\r
- equals(wrapper().attr('aria-valuenow'), 3, 'stepUp 1 step changes aria-valuenow');\r
+ equals(wrapper.attr('aria-valuenow'), 3, 'stepUp 1 step changes aria-valuenow');\r
\r
el.spinner('option', { min: -10, max: 10 });\r
\r
- equals(wrapper().attr('aria-valuemin'), -10, 'min option changed aria-valuemin changes');\r
- equals(wrapper().attr('aria-valuemax'), 10, 'max option changed aria-valuemax changes');\r
+ equals(wrapper.attr('aria-valuemin'), -10, 'min option changed aria-valuemin changes');\r
+ equals(wrapper.attr('aria-valuemax'), 10, 'max option changed aria-valuemax changes');\r
});\r
\r
})(jQuery);\r
*/\r
\r
var spinner_defaults = {\r
- dir: 'ltr',\r
disabled: false,\r
incremental: true,\r
- max: null,\r
- min: null,\r
- mouseWheel: true,\r
- numberformat: "n",\r
- page: 5,\r
- step: null,\r
+ max: Number.MAX_VALUE,\r
+ min: -Number.MAX_VALUE,\r
+ numberformat: null,\r
+ step: 1,\r
value: null\r
};\r
\r
module("spinner: events");\r
\r
test("start", function() {\r
- expect(1);\r
-\r
var start = 0;\r
\r
- el = $("#spin").spinner({\r
+ var el = $("#spin").spinner({\r
start: function(){\r
start++;\r
}\r
});\r
\r
test("spin", function() {\r
- expect(1);\r
-\r
var spin = 0;\r
\r
- el = $("#spin").spinner({\r
+ var el = $("#spin").spinner({\r
spin: function(){\r
spin++;\r
}\r
});\r
\r
test("stop", function() {\r
- expect(1);\r
-\r
var stop = 0;\r
\r
- el = $("#spin").spinner({\r
+ var el = $("#spin").spinner({\r
stop: function(){\r
stop++;\r
}\r
});\r
\r
test("change", function() {\r
- expect(1);\r
-\r
var start = spin = stop = change = 0;\r
\r
- el = $("#spin").spinner({\r
+ var el = $("#spin").spinner({\r
change: function(){\r
change++;\r
}\r
module("spinner: methods");\r
\r
test("disable", function() {\r
- expect(14);\r
-\r
- el = $("#spin").spinner({ disabled: false });\r
- var val = el.val();\r
+ var el = $("#spin").spinner({ disabled: false }),\r
+ val = el.val(),\r
+ wrapper = $("#spin").spinner("widget");\r
\r
- ok(!wrapper().hasClass(".ui-spinner-disabled"), "before: wrapper does not have ui-spinner-disabled class");\r
- ok(!box().is(':disabled'), "before: input does not have disabled attribute");\r
+ ok(!wrapper.hasClass("ui-spinner-disabled"), "before: wrapper does not have ui-spinner-disabled class");\r
+ ok(!el.is(':disabled'), "before: input does not have disabled attribute");\r
\r
el.spinner("disable");\r
- ok(wrapper().hasClass(".ui-spinner-disabled"), "after: wrapper has ui-spinner-disabled class");\r
- ok(box().is(':disabled'), "after: input has disabled attribute");\r
+ ok(wrapper.hasClass("ui-spinner-disabled"), "after: wrapper has ui-spinner-disabled class");\r
+ ok(el.is(':disabled'), "after: input has disabled attribute");\r
\r
simulateKeyDownUp(el, $.ui.keyCode.UP); \r
equals(val, el.val(), "keyboard - value does not change on key UP");\r
simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
equals(val, el.val(), "keyboard - value does not change on key PGDN");\r
\r
- upButton().trigger('mousedown').trigger('mouseup');\r
+ wrapper.find(":ui-button").first().trigger('mousedown').trigger('mouseup');\r
equals(val, el.val(), "mouse - value does not change on clicking up button");\r
\r
- downButton().trigger('mousedown').trigger('mouseup');\r
+ wrapper.find(":ui-button").last().trigger('mousedown').trigger('mouseup');\r
equals(val, el.val(), "mouse - value does not change on clicking down button");\r
\r
el.spinner('stepUp', 6);\r
equals(5, el.val(), "script - stepDown 1 step changes value");\r
\r
el.spinner('pageUp');\r
- equals(10, el.val(), "script - pageUp 1 page changes value");\r
+ equals(15, el.val(), "script - pageUp 1 page changes value");\r
\r
el.spinner('pageDown');\r
equals(5, el.val(), "script - pageDown 1 page changes value");\r
});\r
\r
test("enable", function() {\r
- expect(14);\r
+ var el = $("#spin").spinner({ disabled: true })\r
+ val = el.val(),\r
+ wrapper = el.spinner("widget");\r
\r
- el = $("#spin").spinner({ disabled: true });\r
- var val = el.val();\r
- \r
- ok(wrapper().hasClass(".ui-spinner-disabled"), "before: wrapper has ui-spinner-disabled class");\r
- ok(box().is(':disabled'), "before: input has disabled attribute");\r
+ ok(wrapper.hasClass("ui-spinner-disabled"), "before: wrapper has ui-spinner-disabled class");\r
+ ok(el.is(':disabled'), "before: input has disabled attribute");\r
\r
el.spinner("enable");\r
\r
- ok(!wrapper().hasClass(".ui-spinner-disabled"), "after: wrapper does not have ui-spinner-disabled class");\r
- ok(!box().is(':disabled'), "after: input does not have disabled attribute");\r
-\r
- simulateKeyDownUp(el, $.ui.keyCode.UP);\r
- equals(1, el.val(), "keyboard - value changes on key UP");\r
-\r
- simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
- equals(0, el.val(), "keyboard - value changes on key DOWN");\r
-\r
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
- equals(5, el.val(), "keyboard - value changes on key PGUP");\r
-\r
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
- equals(0, el.val(), "keyboard - value changes on key PGDN");\r
- \r
- upButton().trigger('mousedown').trigger('mouseup');\r
- equals(1, el.val(), "mouse - value changes on clicking up button");\r
-\r
- downButton().trigger('mousedown').trigger('mouseup');\r
- equals(0, el.val(), "mouse - value changes on clicking down button");\r
- \r
- el.spinner('stepUp', 6);\r
- equals(6, el.val(), "script - stepUp 6 steps changes value");\r
-\r
- el.spinner('stepDown');\r
- equals(5, el.val(), "script - stepDown 1 step changes value");\r
-\r
- el.spinner('pageUp');\r
- equals(10, el.val(), "script - pageUp 1 page changes value");\r
-\r
- el.spinner('pageDown');\r
- equals(5, el.val(), "script - pageDown 1 page changes value"); \r
-\r
+ ok(!wrapper.hasClass(".ui-spinner-disabled"), "after: wrapper does not have ui-spinner-disabled class");\r
+ ok(!el.is(':disabled'), "after: input does not have disabled attribute");\r
});\r
\r
test("pageDown", function() {\r
- expect(4);\r
- \r
- el = $('#spin').spinner({ step: 2, page: 5, value: 0, min: -100 });\r
+ var el = $('#spin').spinner({\r
+ step: 2,\r
+ value: 0,\r
+ min: -100\r
+ });\r
\r
el.spinner('pageDown');\r
- equals(el.val(), -10, "pageDown 1 page");\r
+ equals(el.val(), -20, "pageDown 1 page");\r
\r
el.spinner('pageDown', 3);\r
- equals(el.val(), -40, "pageDown 3 pages");\r
+ equals(el.val(), -80, "pageDown 3 pages");\r
\r
el.val(-91).spinner('pageDown');\r
equals(el.val(), -100, "value close to min and pageDown 1 page");\r
});\r
\r
test("pageUp", function() {\r
- expect(4);\r
-\r
- el = $('#spin').spinner({ step: 2, page: 5, value: 0, max: 100 });\r
+ var el = $('#spin').spinner({\r
+ step: 2,\r
+ value: 0,\r
+ max: 100\r
+ });\r
\r
el.spinner('pageUp');\r
- equals(el.val(), 10, "pageUp 1 page");\r
+ equals(el.val(), 20, "pageUp 1 page");\r
\r
el.spinner('pageUp', 3);\r
- equals(el.val(), 40, "pageUp 3 pages");\r
+ equals(el.val(), 80, "pageUp 3 pages");\r
\r
el.val(91).spinner('pageUp');\r
equals(el.val(), 100, "value close to max and pageUp 1 page");\r
\r
module("spinner: options");\r
\r
-test("numberformat", function() {\r
- ok( false, "tests for numberformat!");\r
+test("numberformat, number", function() {\r
+ var el = $("#spin").spinner({\r
+ value: "1",\r
+ numberformat: "n"\r
+ });\r
+ equal(el.val(), "1.00");\r
});\r
\r
-test("dir - left-to-right (default)", function() { \r
- expect(3);\r
- \r
- el = $("#spin"); \r
- el.spinner();\r
- \r
- ok(upButton().position().left > box().position().left, 'input on left up button on right');\r
- ok(downButton().position().left > box().position().left, 'input on left down button on right');\r
- ok(wrapper().hasClass('ui-spinner-ltr'), 'container has correct text direction class setting');\r
+test("numberformat, number, simple", function() {\r
+ var el = $("#spin").spinner({\r
+ value: "1",\r
+ numberformat: "n0"\r
+ });\r
+ equal(el.val(), "1");\r
});\r
\r
-test("dir - right-to-left", function() {\r
- expect(3);\r
- \r
- el = $("#spin");\r
- el.spinner({ dir: 'rtl' });\r
- \r
- ok(upButton().position().left < box().position().left, 'input on right up button on left');\r
- ok(downButton().position().left < box().position().left, 'input on right down button on left');\r
- ok(wrapper().hasClass('ui-spinner-rtl'), 'container has correct text direction class setting');\r
+test("numberformat, currency", function() {\r
+ var el = $("#spin").spinner({\r
+ value: "1",\r
+ numberformat: "C"\r
+ });\r
+ equal(el.val(), "$1.00");\r
});\r
\r
+/* TODO figure out how to test this properly\r
test("incremental - false (default)", function() {\r
- expect(2);\r
- \r
- el = $("#spin").spinner({ incremental:false });\r
+ var el = $("#spin").spinner({ incremental:false });\r
\r
for ( var i = 1 ; i<=120 ; i++ ) {\r
el.simulate("keydown",{keyCode:$.ui.keyCode.UP});\r
equals(el.val(), -90, "incremental false - keydown 210 times");\r
});\r
\r
-test("incremental - true", function() {\r
- expect(2);\r
- \r
- el.spinner('option', 'incremental', true );\r
+test("incremental - true (default)", function() {\r
+ var el = $("#spin").spinner();\r
\r
for ( var i = 1 ; i<=120 ; i++ ) {\r
el.simulate("keydown",{keyCode:$.ui.keyCode.UP});\r
\r
equals(el.val(), -1800, "incremental true - keydown 210 times (300-100-100*10-10*100)");\r
});\r
+*/\r
\r
test("max", function() {\r
- expect(3);\r
- \r
- el = $("#spin").spinner({ max: 100, value: 1000 });\r
+ var el = $("#spin").spinner({ max: 100, value: 1000 });\r
equals(el.val(), 100, "max constrained if value option is greater");\r
\r
el.spinner('value', 1000);\r
});\r
\r
test("min", function() {\r
- expect(3);\r
- \r
- el = $("#spin").spinner({ min: -100, value: -1000 });\r
+ var el = $("#spin").spinner({ min: -100, value: -1000 });\r
equals(el.val(), -100, "min constrained if value option is greater");\r
\r
el.spinner('value', -1000);\r
equals(el.val(), -100, "min constrained if manual entry");\r
});\r
\r
-test("mouseWheel", function() {\r
- ok(false, 'missing test - untested code is broken code');\r
-});\r
-\r
-test("page", function() {\r
- expect(3);\r
-\r
- el = $("#spin").spinner({ step: 2, page:2.5 });\r
-\r
- equals(el.val(), "0", "start number");\r
-\r
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_DOWN);\r
-\r
- equals(el.val(), "-5", "PAGE_DOWN on spinner once");\r
-\r
- for ( var i = 1 ; i<=11 ; i++ ) {\r
- simulateKeyDownUp(el, $.ui.keyCode.PAGE_UP);\r
- }\r
-\r
- equals(el.val(), "50", "PAGE_UP 11 times on spinner");\r
-});\r
-\r
-test("step", function() {\r
- expect(7);\r
-\r
- el = $("#spin").spinner({ step:0.7 });\r
- equals(el.val(), "0.0", "value initialized to");\r
-\r
- simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
- equals(el.val(), "-0.7", "DOWN 1 time with step: 0.7");\r
-\r
- for ( var i = 0 ; i < 11 ; i++ ) {\r
- simulateKeyDownUp(el, $.ui.keyCode.UP);\r
- }\r
- equals(el.val(), "7.0", "UP 11 times with step: 0.7");\r
-\r
- el.spinner('option', 'step', 1);\r
- for ( var i = 0 ; i < 3 ; i++ ) {\r
- simulateKeyDownUp(el, $.ui.keyCode.UP);\r
- }\r
- equals(el.val(), "10.0", "UP 3 times with step: 1");\r
+test("step, 2", function() {\r
+ var el = $("#spin").spinner({ step: 2 });\r
+ equals(el.val(), "0", "value initialized to");\r
\r
- el.spinner('option', 'step', 2);\r
for ( var i = 0 ; i < 5 ; i++ ) {\r
simulateKeyDownUp(el, $.ui.keyCode.UP);\r
}\r
- equals(el.val(), "20.0", "UP 5 times with step: 2");\r
+ equals(el.val(), "10", "UP 5 times with step: 2");\r
\r
el.spinner('value', '10.5');\r
equals(el.val(), "10.5", "value reset to");\r
simulateKeyDownUp(el, $.ui.keyCode.UP);\r
}\r
equals(el.val(), "20.5", "UP 5 times with step: 2");\r
+});\r
\r
+test("step, 0.7", function() {\r
+ var el = $("#spin").spinner({\r
+ step: 0.7,\r
+ numberformat: "n1"\r
+ });\r
+ equals(el.val(), "0.0", "value initialized to");\r
+\r
+ simulateKeyDownUp(el, $.ui.keyCode.DOWN);\r
+ equals(el.val(), "-0.7", "DOWN 1 time with step: 0.7");\r
\r
+ for ( var i = 0 ; i < 11 ; i++ ) {\r
+ simulateKeyDownUp(el, $.ui.keyCode.UP);\r
+ }\r
+ equals(el.val(), "7.0", "UP 11 times with step: 0.7");\r
});\r
\r
test("value, default, specified in markup", function() {\r
incremental: true,\r
max: Number.MAX_VALUE,\r
min: -Number.MAX_VALUE,\r
- numberformat: "n",\r
+ numberformat: null,\r
step: 1,\r
value: null\r
},\r
\r
- _create: function() { \r
- this.value(this.options.value !== null ? this.options.value : this.element.val());\r
+ _create: function() {\r
+ // html5 attributes initalization\r
+ // TODO refactor\r
+ var min = this.element.attr("min");\r
+ if (typeof min == "string" && min.length > 0) {\r
+ this.options.min = this._parse(min);\r
+ }\r
+ var max = this.element.attr("max");\r
+ if (typeof max == "string" && max.length > 0) {\r
+ this.options.max = this._parse(max);\r
+ }\r
+ var step = this.element.attr("step");\r
+ if (typeof step == "string" && step.length > 0) {\r
+ this.options.step = this._parse(step);\r
+ }\r
+ this.value(this.options.value !== null ? this.options.value : this.element.val() || 0);\r
this._draw();\r
this._mousewheel();\r
this._aria();\r
var self = this,\r
options = self.options;\r
\r
- var uiSpinner = self.element\r
+ var uiSpinner = this.uiSpinner = self.element\r
.addClass('ui-spinner-input')\r
.attr('autocomplete', 'off')\r
.wrap(self._uiSpinnerHtml())\r
\r
this.element\r
.bind('keydown'+namespace, function(event) {\r
+ if (self.options.disabled) {\r
+ return;\r
+ }\r
if (self._start(event)) {\r
return self._keydown(event);\r
}\r
return true;\r
})\r
.bind('keyup'+namespace, function(event) {\r
+ if (self.options.disabled) {\r
+ return;\r
+ }\r
if (self.spinning) {\r
self._stop(event);\r
self._change(event); \r
self.focused = false;\r
});\r
\r
- // disable spinner if element was already disabled\r
- if (options.disabled) {\r
- this.disable();\r
- }\r
- \r
// button bindings\r
this.buttons = uiSpinner.find('.ui-spinner-button')\r
.attr("tabIndex", -1)\r
.last()\r
.removeClass("ui-corner-all")\r
.end()\r
- .bind('mousedown', function(event) { \r
+ .bind('mousedown', function(event) {\r
+ if (self.options.disabled) {\r
+ return;\r
+ }\r
if (self._start(event) === false) {\r
return false;\r
}\r
self._repeat(null, $(this).hasClass('ui-spinner-up') ? 1 : -1, event);\r
})\r
.bind('mouseup', function(event) {\r
+ if (self.options.disabled) {\r
+ return;\r
+ }\r
if (self.counter == 1) {\r
self._spin(($(this).hasClass('ui-spinner-up') ? 1 : -1) * self.options.step, event);\r
}\r
}\r
})\r
.bind("mouseenter", function() {\r
+ if (self.options.disabled) {\r
+ return;\r
+ }\r
// button will add ui-state-active if mouse was down while mouseleave and kept down\r
if ($(this).hasClass("ui-state-active")) {\r
if (self._start(event) === false) {\r
self._stop(event);\r
self._change(event);\r
}\r
- })\r
+ });\r
\r
- self.uiSpinner = uiSpinner;\r
+ // disable spinner if element was already disabled\r
+ if (options.disabled) {\r
+ this.disable();\r
+ }\r
},\r
_uiSpinnerHtml: function() {\r
return '<div role="spinbutton" class="ui-spinner ui-state-default ui-widget ui-widget-content ui-corner-all"></div>';\r
return false;\r
},\r
_spin: function(step, event) {\r
- if (this.options.disabled) {\r
- return;\r
- }\r
if (!this.counter) {\r
this.counter = 1;\r
}\r
_stop: function(event) {\r
this.counter = 0;\r
if (this.timer) {\r
- window.clearInterval(this.timer);\r
+ window.clearTimeout(this.timer);\r
}\r
this.element[0].focus();\r
this.spinning = false;\r
_mousewheel: function() {\r
var self = this;\r
this.element.bind("mousewheel", function(event, delta) {\r
+ if (self.options.disabled) {\r
+ return;\r
+ }\r
if (!self._start(event)) {\r
return false;\r
}\r
if (self.timeout) {\r
window.clearTimeout(self.timeout);\r
}\r
+ // TODO can we implement that without a timeout?\r
self.timeout = window.setTimeout(function() {\r
if (self.spinning) {\r
self._stop(event);\r
self._change(event);\r
}\r
- }, 50);\r
+ }, 13);\r
event.preventDefault();\r
});\r
},\r
break;\r
case 'value':\r
this._format(this._parse(this.options.value));\r
+ this._aria();\r
break;\r
}\r
},\r
_aria: function() {\r
- this.uiSpinner\r
+ // TODO remove check, as soon as this method doesn't get called anymore before uiSpinner is initalized\r
+ this.uiSpinner && this.uiSpinner\r
.attr('aria-valuemin', this.options.min)\r
.attr('aria-valuemax', this.options.max)\r
.attr('aria-valuenow', this.value());\r
var culture = Globalization.culture || Globalization.cultures['default'];\r
val = val.replace(culture.numberFormat.currency.symbol, "");\r
}\r
- val = window.Globalization ? Globalization.parseFloat(val) : +val;\r
+ val = window.Globalization && this.options.numberformat ? Globalization.parseFloat(val) : +val;\r
}\r
console.log("input", input, "parsed", val)\r
return isNaN(val) ? null : val;\r
},\r
_format: function(num) {\r
- this.element.val( window.Globalization ? Globalization.format(num, this.options.numberformat) : num );\r
+ this.element.val( window.Globalization && this.options.numberformat ? Globalization.format(num, this.options.numberformat) : num );\r
},\r
\r
destroy: function() {\r
enable: function() {\r
this.element\r
.removeAttr('disabled')\r
- .siblings()\r
- .removeAttr('disabled')\r
.parent()\r
.removeClass('ui-spinner-disabled ui-state-disabled');\r
this.options.disabled = false;\r
+ this.buttons.button("enable");\r
},\r
disable: function() {\r
this.element\r
.attr('disabled', true)\r
- .siblings()\r
- .attr('disabled', true)\r
.parent()\r
.addClass('ui-spinner-disabled ui-state-disabled');\r
this.options.disabled = true;\r
+ this.buttons.button("disable");\r
},\r
stepUp: function(steps) {\r
this._spin((steps || 1) * this.options.step, null);\r
return this;\r
},\r
pageUp: function(pages) {\r
- return this.stepUp((pages || 1) * this.options.page); \r
+ return this.stepUp((pages || 1) * pageModifier); \r
},\r
pageDown: function(pages) {\r
- return this.stepDown((pages || 1) * this.options.page); \r
+ return this.stepDown((pages || 1) * pageModifier); \r
},\r
\r
widget: function() {\r