Skip to content

Commit 77be50d

Browse files
committed
Controlgroup: Add spinner to widgets controlgroup works with
1 parent f6879fc commit 77be50d

4 files changed

Lines changed: 37 additions & 14 deletions

File tree

demos/controlgroup/default.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
</style>
1616
<script src="../../external/requirejs/require.js"></script>
17-
<script src="../bootstrap.js" data-modules="button checkboxradio selectmenu">
17+
<script src="../bootstrap.js" data-modules="button checkboxradio selectmenu spinner">
1818
$( ".controlgroup" ).controlgroup()
1919
$( ".controlgroup-vertical" ).controlgroup({
2020
"direction": "vertical"
@@ -27,6 +27,7 @@ <h1>Controlgroup</h1>
2727
<fieldset>
2828
<legend>Rental Car</legend>
2929
<div class="controlgroup">
30+
<input class="ui-spinner-input">
3031
<select>
3132
<option>Compact car</option>
3233
<option>Midsize car</option>
@@ -36,13 +37,15 @@ <h1>Controlgroup</h1>
3637
<option>Truck</option>
3738
<option>Van</option>
3839
</select>
40+
<input class="ui-spinner-input">
3941
<label for="transmission-standard">Standard</label>
4042
<input type="radio" name="transmission" id="transmission-standard">
4143
<label for="transmission-automatic">Automatic</label>
4244
<input type="radio" name="transmission" id="transmission-automatic">
4345
<label for="insurance">Insurance</label>
4446
<input type="checkbox" name="insurance" id="insurance">
4547
<button>Book Now!</button>
48+
<input class="ui-spinner-input">
4649
</div>
4750
</fieldset>
4851
<br/>

themes/base/controlgroup.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@
2727
}
2828
.ui-controlgroup-vertical label.ui-button {
2929
box-sizing: border-box;
30-
}
30+
}
31+
.ui-controlgroup .ui-spinner {
32+
padding-top: .225em;
33+
padding-bottom: .225em;
34+
border-color: #ccc;
35+
float: left;
36+
}

themes/base/core.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
vertical-align: middle;
7474
margin-top: -.25em;
7575
position: relative;
76+
text-indent: -99999px;
77+
overflow: hidden;
78+
background-repeat: no-repeat;
7679
}
7780

7881
.ui-widget-icon-block {

ui/widgets/controlgroup.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ return $.widget( "ui.controlgroup", {
3838
items: {
3939
"button": "input[type=button], input[type=submit], input[type=reset], button, a",
4040
"checkboxradio": "input[type='checkbox'], input[type='radio']",
41-
"selectmenu": "select"
41+
"selectmenu": "select",
42+
"spinner": ".ui-spinner-input"
4243
},
4344
direction: "horizontal",
4445
excludeInvisible: true
@@ -83,14 +84,13 @@ return $.widget( "ui.controlgroup", {
8384

8485
// Don't set data or add to the collection if the method is destroy
8586
widgets.each( function() {
87+
var element = $( this );
8688

8789
// Set data on the widget element pointing to the this.element of the widget
8890
// and telling us what type of widget this is
8991
var widgetElement =
90-
$( this )[ widget ]( "widget" ).data( "ui-controlgroup-data", {
91-
"widgetType": widget,
92-
"element": $( this )
93-
} );
92+
element[ widget ]( "widget" ).data( "ui-controlgroup-data", element.data( "ui-" +
93+
widget.charAt(0).toUpperCase() + widget.slice(1) ) );
9494

9595
childWidgets.push( widgetElement[ 0 ] );
9696
} );
@@ -104,8 +104,9 @@ return $.widget( "ui.controlgroup", {
104104
this.childWidgets.each( function() {
105105
var element = $( this ),
106106
data = element.data( "ui-controlgroup-data" );
107-
108-
data.element[ data.widgetType ]( method );
107+
if( data[ method ] ) {
108+
data[ method ]();
109+
}
109110
} );
110111
},
111112

@@ -122,6 +123,15 @@ return $.widget( "ui.controlgroup", {
122123
return result;
123124
},
124125

126+
_spinner_options: function( position, direction ) {
127+
var options = this._buildSimpleOptions( position, direction, "ui-spinner" );
128+
129+
options.classes[ "ui-spinner-up" ] = "";
130+
options.classes[ "ui-spinner-down" ] = "";
131+
132+
return options;
133+
},
134+
125135
_button_options: function( position, direction ) {
126136
return this._buildSimpleOptions( position, direction, "ui-button" );
127137
},
@@ -191,11 +201,12 @@ return $.widget( "ui.controlgroup", {
191201

192202
// We do this last because we need to make sure all enhancment is done
193203
// before determining first and last
194-
[ "first", "last" ].forEach( function( value ) {
195-
var data = children[ value ]().data( "ui-controlgroup-data" );
196-
if ( that[ "_" + data.widgetType + "_options" ] ) {
197-
data.element[ data.widgetType ](
198-
that[ "_" + data.widgetType + "_options" ](
204+
$.each( [ "first", "last" ], function( index, value ) {
205+
var instance = children[ value ]().data( "ui-controlgroup-data" );
206+
console.log( instance )
207+
if ( that[ "_" + instance.widgetName + "_options" ] ) {
208+
instance.element[ instance.widgetName ](
209+
that[ "_" + instance.widgetName + "_options" ](
199210
value,
200211
that.options.direction === "vertical"
201212
)

0 commit comments

Comments
 (0)