Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit d9bbfc4

Browse files
author
Gabriel Schulhof
committed
Controlgroup: Implement "enhanced" attribute.
1 parent 4aeb206 commit d9bbfc4

File tree

1 file changed

+54
-30
lines changed

1 file changed

+54
-30
lines changed

js/widgets/controlgroup.js

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ define( [ "jquery",
1414

1515
$.widget( "mobile.controlgroup", $.extend( {
1616
options: {
17+
enhanced: false,
1718
theme: null,
1819
shadow: false,
1920
corners: true,
@@ -24,63 +25,86 @@ $.widget( "mobile.controlgroup", $.extend( {
2425
},
2526

2627
_create: function() {
27-
var $el = this.element,
28-
inner = $( "<div class='ui-controlgroup-controls'></div>" ),
29-
grouplegend = $el.children( "legend" );
30-
31-
// Apply the proto
32-
$el.wrapInner( inner ).addClass( "ui-controlgroup" );
33-
if ( grouplegend.length ) {
34-
$( "<div role='heading' class='ui-controlgroup-label'></div>" ).append( grouplegend ).insertBefore( $el.children( 0 ) );
35-
}
28+
var elem = this.element,
29+
opts = this.options;
3630

3731
$.extend( this, {
32+
_ui: null,
33+
_classes: "",
3834
_initialRefresh: true
3935
});
4036

41-
this._setOptions( this.options );
42-
37+
if ( !opts.enhanced ) {
38+
this._ui = {
39+
groupLegend: elem.children( "legend" ),
40+
childWrapper: elem
41+
.wrapInner( "<div class='ui-controlgroup-controls'></div>" )
42+
.addClass( "ui-controlgroup" )
43+
.children()
44+
}
45+
if ( this._ui.groupLegend.length > 0 ) {
46+
$( "<div role='heading' class='ui-controlgroup-label'></div>" )
47+
.append( this._ui.groupLegend )
48+
.prependTo( elem );
49+
}
50+
this._setOptions( opts );
51+
} else {
52+
this._ui = {
53+
groupLegend: elem.children( ".ui-controlgroup-label" ).children(),
54+
childWrapper: elem.children( ".ui-controlgroup-controls" )
55+
};
56+
}
4357
},
4458

4559
_init: function() {
4660
this.refresh();
4761
},
4862

49-
_setOptions: function( o ) {
50-
var $el = this.element;
63+
_setOptions: function( options ) {
64+
var callRefresh, opts,
65+
classes = "";
5166

52-
if ( o.type !== undefined ) {
53-
$el
54-
.removeClass( "ui-controlgroup-horizontal ui-controlgroup-vertical" )
55-
.addClass( "ui-controlgroup-" + o.type );
56-
this.refresh();
67+
// Must not be able to unset the type of the controlgroup
68+
if ( options.type === null ) {
69+
options.type = undefined;
5770
}
71+
opts = $.extend( {}, this.options, options );
5872

59-
if ( o.theme !== undefined ) {
60-
$el.removeClass( "ui-group-theme-" + this.options.theme );
73+
if ( opts.type != null ) {
74+
classes += " ui-controlgroup-" + opts.type;
6175

62-
if ( o.theme ) {
63-
$el.addClass( "ui-group-theme-" + o.theme );
76+
// No need to call refresh if the type hasn't changed
77+
if ( this.options.type !== options.type ) {
78+
callRefresh = true;
6479
}
6580
}
6681

67-
if ( o.corners !== undefined ) {
68-
$el.toggleClass( "ui-corner-all", o.corners );
82+
if ( opts.theme != null && opts.theme !== "none" ) {
83+
classes += " ui-group-theme-" + opts.theme;
6984
}
7085

71-
if ( o.shadow !== undefined ) {
72-
$el.find( ".ui-controlgroup-controls" ).toggleClass( "ui-shadow", o.shadow );
86+
if ( opts.corners ) {
87+
classes += " ui-corner-all";
7388
}
7489

75-
if ( o.mini !== undefined ) {
76-
$el.toggleClass( "ui-mini", o.mini );
90+
if ( opts.shadow != undefined ) {
91+
this._ui.childWrapper.toggleClass( "ui-shadow", opts.shadow );
92+
}
93+
94+
if ( opts.mini ) {
95+
classes += " ui-mini";
96+
}
97+
98+
this._toggleClasses( this.element, "_classes", classes );
99+
if ( callRefresh ) {
100+
this.refresh();
77101
}
78102

79-
return this._super( o );
103+
return this._super( options );
80104
},
81105

82106
container: function() {
83-
return this.element.children( ".ui-controlgroup-controls" );
107+
return this._ui.childWrapper;
84108
},
85109

86110
refresh: function() {

0 commit comments

Comments
 (0)