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

Commit 6fa0c36

Browse files
author
Gabriel Schulhof
committed
[controlgroup] Convert to widget
1 parent 710dbae commit 6fa0c36

File tree

4 files changed

+107
-82
lines changed

4 files changed

+107
-82
lines changed

js/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
'widgets/forms/select.custom.js',
5151
'widgets/forms/select.js',
5252
'jquery.mobile.buttonMarkup.js',
53-
'jquery.mobile.controlGroup.js',
53+
'widgets/controlgroup.js',
5454
'jquery.mobile.links.js',
5555
'widgets/fixedToolbar.js',
5656
'widgets/popup.js',

js/jquery.mobile.controlGroup.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

js/jquery.mobile.init.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ define( [ "jquery", "./jquery.mobile.core", "./jquery.mobile.support", "./jquery
122122
// so if it's 1, use 0 from now on
123123
$.mobile.defaultHomeScroll = ( !$.support.scrollTop || $( window ).scrollTop() === 1 ) ? 0 : 1;
124124

125-
126-
// TODO: Implement a proper registration mechanism with dependency handling in order to not have exceptions like the one below
127-
//auto self-init widgets for those widgets that have a soft dependency on others
128-
if ( $.fn.controlgroup ) {
129-
$( document ).bind( "pagecreate create", function( e ) {
130-
$( ":jqmData(role='controlgroup')", e.target )
131-
.jqmEnhanceable()
132-
.controlgroup({ excludeInvisible: false });
133-
});
134-
}
135-
136125
//dom-ready inits
137126
if ( $.mobile.autoInitializePage ) {
138127
$.mobile.initializePage();

js/widgets/controlgroup.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2+
//>>description: Visually groups sets of buttons, checks, radios, etc.
3+
//>>label: Controlgroups
4+
//>>group: Forms
5+
//>>css.structure: ../../css/structure/jquery.mobile.controlgroup.css
6+
//>>css.theme: ../../css/themes/default/jquery.mobile.theme.css
7+
8+
define( [ "jquery",
9+
"../jquery.mobile.buttonMarkup",
10+
"forms/button",
11+
"../jquery.mobile.widget" ], function( $ ) {
12+
//>>excludeEnd("jqmBuildExclude");
13+
(function( $, undefined ) {
14+
15+
function flipClasses( els, flCorners ) {
16+
els.removeClass( "ui-controlgroup-last" )
17+
.buttonMarkup( { corners: false, shadow: false } )
18+
.eq( 0 ).buttonMarkup( { corners: flCorners[ 0 ] } )
19+
.end()
20+
.last().buttonMarkup( { corners: flCorners[ 1 ] } ).addClass( "ui-controlgroup-last" );
21+
}
22+
23+
$.widget( "mobile.controlgroup", $.mobile.widget, {
24+
options: {
25+
shadow: false,
26+
excludeInvisible: false,
27+
type: "vertical",
28+
mini: false,
29+
initSelector: ":jqmData(role='controlgroup')"
30+
},
31+
32+
_create: function() {
33+
var $el = this.element,
34+
ui = {
35+
inner: $( "<div class='ui-controlgroup-controls'></div>" ),
36+
legend: $( "<div role='heading' class='ui-controlgroup-label'></div>" )
37+
},
38+
grouplegend = $el.children( "legend" ),
39+
groupcontrols = $el.children( ".ui-controlgroup-controls" ),
40+
self = this;
41+
42+
// Apply the proto
43+
$el.wrapInner( ui.inner );
44+
if ( grouplegend.length ) {
45+
ui.legend.append( grouplegend ).insertBefore( $el.children( 0 ) );
46+
}
47+
$el.addClass( "ui-btn-corner-all ui-controlgroup" );
48+
49+
$.each( this.options, function( key, value ) {
50+
// Cause initial options to be applied by their handler by temporarily setting the option to undefined
51+
// - the handler then sets it to the initial value
52+
self.options[ key ] = undefined;
53+
self._setOption( key, value, true );
54+
});
55+
56+
this.refresh();
57+
},
58+
59+
_setOption: function( key, value ) {
60+
var setter = "_set" + key.charAt( 0 ).toUpperCase() + key.slice( 1 );
61+
62+
if ( this[ setter ] !== undefined ) {
63+
this[ setter ]( value );
64+
}
65+
66+
this._super( "_setOption", key, value );
67+
this.element.attr( "data-" + ( $.mobile.ns || "" ) + ( key.replace( /([A-Z])/, "-$1" ).toLowerCase() ), value );
68+
},
69+
70+
_setType: function( value ) {
71+
this.element
72+
.removeClass( "ui-controlgroup-horizontal ui-controlgroup-vertical" )
73+
.addClass( "ui-controlgroup-" + value );
74+
this.options.type = value;
75+
this.refresh();
76+
},
77+
78+
_setShadow: function( value ) {
79+
this.element.toggleClass( "ui-shadow", value );
80+
},
81+
82+
_setMini: function( value ) {
83+
this.element.toggleClass( "ui-mini", value );
84+
},
85+
86+
refresh: function() {
87+
var els = this.element
88+
.find( ".ui-btn" + ( this.options.excludeInvisible ? ":visible" : "" ) )
89+
.not( '.ui-slider-handle' ),
90+
corners = [ true, true ];
91+
92+
if ( els.length > 1 ) {
93+
corners = ( this.options.type === "horizontal" ? [ "left", "right" ] : [ "top", "bottom" ] );
94+
}
95+
96+
flipClasses( els, corners );
97+
}
98+
});
99+
100+
$( document ).bind( "pagecreate create", function( e ) {
101+
$.mobile.controlgroup.prototype.enhanceWithin( e.target, true );
102+
});
103+
})(jQuery);
104+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
105+
});
106+
//>>excludeEnd("jqmBuildExclude");

0 commit comments

Comments
 (0)