87 |
88 |
--------------------------------------------------------------------------------
/ui.spinner.css:
--------------------------------------------------------------------------------
1 | .ui-spinner {position: relative; border: 0px solid white; }
2 | .ui-spinner-buttons {position: absolute}
3 | .ui-spinner-button {overflow: hidden}
4 |
--------------------------------------------------------------------------------
/ui.spinner.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @license jQuery UI Spinner 1.20
3 | *
4 | * Copyright (c) 2009-2010 Brant Burnett
5 | * Dual licensed under the MIT or GPL Version 2 licenses.
6 | */
7 | (function($, undefined) {
8 |
9 | var
10 | // constants
11 | active = 'ui-state-active',
12 | hover = 'ui-state-hover',
13 | disabled = 'ui-state-disabled',
14 |
15 | keyCode = $.ui.keyCode,
16 | up = keyCode.UP,
17 | down = keyCode.DOWN,
18 | right = keyCode.RIGHT,
19 | left = keyCode.LEFT,
20 | pageUp = keyCode.PAGE_UP,
21 | pageDown = keyCode.PAGE_DOWN,
22 | home = keyCode.HOME,
23 | end = keyCode.END,
24 |
25 | msie = $.browser.msie,
26 | mouseWheelEventName = $.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel',
27 |
28 | // namespace for events on input
29 | eventNamespace = '.uispinner',
30 |
31 | // only these special keys will be accepted, all others will be ignored unless CTRL or ALT are pressed
32 | validKeys = [up, down, right, left, pageUp, pageDown, home, end, keyCode.BACKSPACE, keyCode.DELETE, keyCode.TAB],
33 |
34 | // stores the currently focused spinner
35 | // Note: due to oddities in the focus/blur events, this is part of a two-part system for confirming focus
36 | // this must set to the control, and the focus variable must be true
37 | // this is because hitting up/down arrows with mouse causes focus to change, but blur event for previous control doesn't fire
38 | focusCtrl;
39 |
40 | $.widget('ui.spinner', {
41 | options: {
42 | min: null,
43 | max: null,
44 | allowNull: false,
45 |
46 | group: '',
47 | point: '.',
48 | prefix: '',
49 | suffix: '',
50 | places: null, // null causes it to detect the number of places in step
51 |
52 | defaultStep: 1, // real value is 'step', and should be passed as such. This value is used to detect if passed value should override HTML5 attribute
53 | largeStep: 10,
54 | mouseWheel: true,
55 | increment: 'slow',
56 | className: null,
57 | showOn: 'always',
58 | width: 16,
59 | upIconClass: "ui-icon-triangle-1-n",
60 | downIconClass: "ui-icon-triangle-1-s",
61 |
62 | format: function(num, places) {
63 | var options = this,
64 | regex = /(\d+)(\d{3})/,
65 | result = ((isNaN(num) ? 0 : Math.abs(num)).toFixed(places)) + '';
66 |
67 | for (result = result.replace('.', options.point); regex.test(result) && options.group; result=result.replace(regex, '$1'+options.group+'$2')) {};
68 | return (num < 0 ? '-' : '') + options.prefix + result + options.suffix;
69 | },
70 |
71 | parse: function(val) {
72 | var options = this;
73 |
74 | if (options.group == '.')
75 | val = val.replace('.', '');
76 | if (options.point != '.')
77 | val = val.replace(options.point, '.');
78 | return parseFloat(val.replace(/[^0-9\-\.]/g, ''));
79 | }
80 | },
81 |
82 | // * Widget fields *
83 | // curvalue - current value
84 | // places - currently effective number of decimal places
85 | // oWidth - original input width (used for destroy)
86 | // oMargin - original input right margin (used for destroy)
87 | // counter - number of spins at the current spin speed
88 | // incCounter - index within options.increment of the current spin speed
89 | // selfChange - indicates that change event is being fired by the widget, so don't reprocess input value
90 | // inputMaxLength - initial maxLength value on the input
91 | // focused - this spinner currently has the focus
92 |
93 | _create: function() {
94 | // shortcuts
95 | var self = this,
96 | input = self.element,
97 | type = input.attr('type');
98 |
99 | if (!input.is('input') || ((type != 'text') && (type != 'number'))) {
100 | console.error('Invalid target for ui.spinner');
101 | return;
102 | }
103 |
104 | self._procOptions(true);
105 | self._createButtons(input);
106 |
107 | if (!input.is(':enabled'))
108 | self.disable();
109 | },
110 |
111 | _createButtons: function(input) {
112 | function getMargin(margin) {
113 | // IE8 returns auto if no margin specified
114 | return margin == 'auto' ? 0 : parseInt(margin);
115 | }
116 |
117 | var self = this,
118 | options = self.options,
119 | className = options.className,
120 | buttonWidth = options.width,
121 | showOn = options.showOn,
122 | box = $.support.boxModel,
123 | height = input.outerHeight(),
124 | rightMargin = self.oMargin = getMargin(input.css('margin-right')), // store original width and right margin for later destroy
125 | wrapper = self.wrapper = input.css({ width: (self.oWidth = (box ? input.width() : input.outerWidth())) - buttonWidth,
126 | marginRight: rightMargin + buttonWidth, textAlign: 'right' })
127 | .after('