This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
controlgroup.js
114 lines (96 loc) · 3.61 KB
/
controlgroup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Visually groups sets of buttons, checks, radios, etc.
//>>label: Controlgroups
//>>group: Forms
//>>css.structure: ../../css/structure/jquery.mobile.controlgroup.css
//>>css.theme: ../../css/themes/default/jquery.mobile.theme.css
define( [ "jquery",
"../jquery.mobile.buttonMarkup",
"./addFirstLastClasses",
"../jquery.mobile.widget" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {
$.widget( "mobile.controlgroup", $.mobile.widget, {
options: {
shadow: false,
corners: true,
excludeInvisible: true,
type: "vertical",
mini: false,
initSelector: ":jqmData(role='controlgroup')"
},
_create: function() {
var $el = this.element,
ui = {
inner: $( "<div class='ui-controlgroup-controls'></div>" ),
legend: $( "<div role='heading' class='ui-controlgroup-label'></div>" )
},
grouplegend = $el.children( "legend" ),
self = this;
// Apply the proto
$el.wrapInner( ui.inner );
if ( grouplegend.length ) {
ui.legend.append( grouplegend ).insertBefore( $el.children( 0 ) );
}
$el.addClass( "ui-corner-all ui-controlgroup" );
$.each( this.options, function( key, value ) {
// Cause initial options to be applied by their handler by temporarily setting the option to undefined
// - the handler then sets it to the initial value
self.options[ key ] = undefined;
self._setOption( key, value, true );
});
this._refresh( true );
},
_setOption: function( key, value ) {
var setter = "_set" + key.charAt( 0 ).toUpperCase() + key.slice( 1 );
if ( this[ setter ] !== undefined ) {
this[ setter ]( value );
}
this._super( key, value );
this.element.attr( "data-" + ( $.mobile.ns || "" ) + ( key.replace( /([A-Z])/, "-$1" ).toLowerCase() ), value );
},
_setType: function( value ) {
this.element
.removeClass( "ui-controlgroup-horizontal ui-controlgroup-vertical" )
.addClass( "ui-controlgroup-" + value );
this._refresh( false );
},
_setCorners: function( value ) {
this.element.toggleClass( "ui-corner-all", value );
},
_setShadow: function( value ) {
this.element.toggleClass( "ui-shadow", value );
},
_setMini: function( value ) {
this.element.toggleClass( "ui-mini", value );
},
container: function() {
return this.element.children( ".ui-controlgroup-controls" );
},
_refresh: function( create ) {
var els = this.element.find( ".ui-btn" ).not( ".ui-slider-handle" );
this.element.find( ":mobile-checkboxradio" ).checkboxradio( "refresh" );
this._addFirstLastClasses( els, this.options.excludeInvisible ? this._getVisibles( els, create ) : els, create );
},
refresh: function() {
this._refresh( false );
}
});
$.widget( "mobile.controlgroup", $.mobile.controlgroup, $.mobile.behaviors.addFirstLastClasses );
// TODO: Implement a mechanism to allow widgets to become enhanced in the
// correct order when their correct enhancement depends on other widgets in
// the page being correctly enhanced already.
//
// For now, we wait until dom-ready to attach the controlgroup's enhancement
// hook, because by that time, all the other widgets' enhancement hooks should
// already be in place, ensuring that all widgets that need to be grouped will
// already have been enhanced by the time the controlgroup is created.
$( function() {
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.controlgroup.prototype.enhanceWithin( e.target, true );
});
});
})(jQuery);
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");