Skip to content

Commit 263193f

Browse files
author
scottjehl
committed
Moved autoinit calls to after widgets. Made it so auto init selectors use the initSelector option, so that it can be configurable.
1 parent d1e8083 commit 263193f

12 files changed

+114
-132
lines changed

js/jquery.mobile.collapsible.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
*/
77
(function( $, undefined ) {
88

9-
//auto self-init widgets
10-
var initSelector = ":jqmData(role='collapsible')";
11-
12-
$( document ).bind( "pagecreate create", function( e ){
13-
$( initSelector, e.target ).collapsible();
14-
});
15-
169
$.widget( "mobile.collapsible", $.mobile.widget, {
1710
options: {
1811
expandCueText: " click to expand contents",
@@ -21,7 +14,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
2114
heading: ">:header,>legend",
2215
theme: null,
2316
iconTheme: "d",
24-
initSelector: initSelector
17+
initSelector: ":jqmData(role='collapsible')"
2518
},
2619
_create: function() {
2720

@@ -163,4 +156,10 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
163156
});
164157
}
165158
});
159+
160+
//auto self-init widgets
161+
$( document ).bind( "pagecreate create", function( e ){
162+
$( $.mobile.collapsible.prototype.options.initSelector, e.target ).collapsible();
163+
});
164+
166165
})( jQuery );

js/jquery.mobile.controlGroup.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
*/
77
(function( $, undefined ) {
88

9-
//auto self-init widgets
10-
var initSelector = ":jqmData(role='controlgroup')";
11-
12-
$( document ).bind( "pagecreate create", function( e ){
13-
$( initSelector, e.target ).controlgroup({ excludeInvisible: false });
14-
});
15-
169
$.fn.controlgroup = function( options ) {
1710

1811
return this.each(function() {
@@ -53,4 +46,10 @@ $.fn.controlgroup = function( options ) {
5346
}
5447
});
5548
};
49+
50+
//auto self-init widgets
51+
$( document ).bind( "pagecreate create", function( e ){
52+
$( ":jqmData(role='controlgroup')", e.target ).controlgroup({ excludeInvisible: false });
53+
});
54+
5655
})(jQuery);

js/jquery.mobile.dialog.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@
66

77
(function( $, window, undefined ) {
88

9-
//auto self-init widgets
10-
var initSelector = ":jqmData(role='dialog')";
11-
12-
$( initSelector ).live( "pagecreate", function(){
13-
$( this ).dialog();
14-
});
15-
169
$.widget( "mobile.dialog", $.mobile.widget, {
1710
options: {
1811
closeBtnText : "Close",
1912
theme : "a",
20-
initSelector : initSelector
13+
initSelector : ":jqmData(role='dialog')"
2114
},
2215
_create: function() {
2316
var $el = this.element,
@@ -68,4 +61,10 @@ $.widget( "mobile.dialog", $.mobile.widget, {
6861
window.history.back();
6962
}
7063
});
64+
65+
//auto self-init widgets
66+
$( $.mobile.dialog.prototype.options.initSelector ).live( "pagecreate", function(){
67+
$( this ).dialog();
68+
});
69+
7170
})( jQuery, this );

js/jquery.mobile.fieldContain.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77

88
(function( $, undefined ) {
99

10-
//auto self-init widgets
11-
var initSelector = ":jqmData(role='fieldcontain')";
12-
13-
$( document ).bind( "pagecreate create", function( e ){
14-
$( initSelector, e.target ).fieldcontain();
15-
});
16-
1710
$.fn.fieldcontain = function( options ) {
1811
return this.addClass( "ui-field-contain ui-body ui-br" );
1912
};
2013

14+
//auto self-init widgets
15+
$( document ).bind( "pagecreate create", function( e ){
16+
$( ":jqmData(role='fieldcontain')", e.target ).fieldcontain();
17+
});
18+
2119
})( jQuery );

js/jquery.mobile.fixHeaderFooter.js

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,6 @@
66
*/
77

88
(function( $, undefined ) {
9-
10-
//auto self-init widgets
11-
var initSelector = ":jqmData(position='fixed')";
12-
13-
$( document ).bind( "pagecreate create", function( e ){
14-
15-
if( $( initSelector, e.target ).length ){
16-
$( e.target ).each(function(){
17-
18-
if ( !$.support.scrollTop ) {
19-
return this;
20-
}
21-
22-
var $this = $( this );
23-
24-
if ( $this.jqmData( "fullscreen" ) ) {
25-
$this.addClass( "ui-page-fullscreen" );
26-
}
27-
28-
// Should be slidedown
29-
$this.find( ".ui-header:jqmData(position='fixed')" ).addClass( "ui-header-fixed ui-fixed-inline fade" );
30-
31-
// Should be slideup
32-
$this.find( ".ui-footer:jqmData(position='fixed')" ).addClass( "ui-footer-fixed ui-fixed-inline fade" );
33-
34-
})
35-
36-
}
37-
});
38-
39-
409

4110
$.fn.fixHeaderFooter = function( options ) {
4211

@@ -376,4 +345,31 @@ $.fixedToolbars = (function() {
376345
};
377346
})();
378347

348+
//auto self-init widgets
349+
$( document ).bind( "pagecreate create", function( e ){
350+
351+
if( $( ":jqmData(position='fixed')", e.target ).length ){
352+
$( e.target ).each(function(){
353+
354+
if ( !$.support.scrollTop ) {
355+
return this;
356+
}
357+
358+
var $this = $( this );
359+
360+
if ( $this.jqmData( "fullscreen" ) ) {
361+
$this.addClass( "ui-page-fullscreen" );
362+
}
363+
364+
// Should be slidedown
365+
$this.find( ".ui-header:jqmData(position='fixed')" ).addClass( "ui-header-fixed ui-fixed-inline fade" );
366+
367+
// Should be slideup
368+
$this.find( ".ui-footer:jqmData(position='fixed')" ).addClass( "ui-footer-fixed ui-fixed-inline fade" );
369+
370+
})
371+
372+
}
373+
});
374+
379375
})(jQuery);

js/jquery.mobile.forms.button.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77

88
(function( $, undefined ) {
99

10-
//auto self-init widgets
11-
var initSelector = "button, [type='button'], [type='submit'], [type='reset'], [type='image']";
12-
13-
$( document ).bind( "pagecreate create", function( e ){
14-
$( initSelector, e.target )
15-
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
16-
.button();
17-
});
18-
1910
$.widget( "mobile.button", $.mobile.widget, {
2011
options: {
2112
theme: null,
@@ -25,7 +16,7 @@ $.widget( "mobile.button", $.mobile.widget, {
2516
corners: true,
2617
shadow: true,
2718
iconshadow: true,
28-
initSelector: initSelector
19+
initSelector: "button, [type='button'], [type='submit'], [type='reset'], [type='image']"
2920
},
3021
_create: function() {
3122
var $el = this.element,
@@ -91,4 +82,12 @@ $.widget( "mobile.button", $.mobile.widget, {
9182
}
9283
}
9384
});
85+
86+
//auto self-init widgets
87+
$( document ).bind( "pagecreate create", function( e ){
88+
$( $.mobile.button.prototype.options.initSelector, e.target )
89+
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
90+
.button();
91+
});
92+
9493
})( jQuery );

js/jquery.mobile.forms.checkboxradio.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,10 @@
77

88
(function( $, undefined ) {
99

10-
//auto self-init widgets
11-
var initSelector = "input[type='checkbox'],input[type='radio']";
12-
13-
$( document ).bind( "pagecreate create", function( e ){
14-
$( initSelector, e.target )
15-
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
16-
.checkboxradio();
17-
});
18-
1910
$.widget( "mobile.checkboxradio", $.mobile.widget, {
2011
options: {
2112
theme: null,
22-
initSelector: initSelector
13+
initSelector: "input[type='checkbox'],input[type='radio']"
2314
},
2415
_create: function() {
2516
var self = this,
@@ -192,4 +183,12 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {
192183
this.element.prop( "disabled", false ).parent().removeClass( "ui-disabled" );
193184
}
194185
});
186+
187+
//auto self-init widgets
188+
$( document ).bind( "pagecreate create", function( e ){
189+
$( $.mobile.checkboxradio.prototype.options.initSelector, e.target )
190+
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
191+
.checkboxradio();
192+
});
193+
195194
})( jQuery );

js/jquery.mobile.forms.select.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77

88
(function( $, undefined ) {
99

10-
//auto self-init widgets
11-
var initSelector = "select:not(:jqmData(role='slider'))";
12-
13-
$( document ).bind( "pagecreate create", function( e ){
14-
$( initSelector, e.target )
15-
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
16-
.selectmenu();
17-
});
18-
1910
$.widget( "mobile.selectmenu", $.mobile.widget, {
2011
options: {
2112
theme: null,
@@ -31,7 +22,7 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
3122
hidePlaceholderMenuItems: true,
3223
closeText: "Close",
3324
nativeMenu: true,
34-
initSelector: initSelector
25+
initSelector: "select:not(:jqmData(role='slider'))"
3526
},
3627
_create: function() {
3728

@@ -611,5 +602,13 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
611602
return this._setOption( "disabled", false );
612603
}
613604
});
605+
606+
//auto self-init widgets
607+
$( document ).bind( "pagecreate create", function( e ){
608+
$( $.mobile.selectmenu.prototype.options.initSelector, e.target )
609+
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
610+
.selectmenu();
611+
});
612+
614613
})( jQuery );
615614

js/jquery.mobile.forms.slider.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,12 @@
77

88
( function( $, undefined ) {
99

10-
//auto self-init widgets
11-
var initSelector = "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')";
12-
13-
$( document ).bind( "pagecreate create", function( e ){
14-
15-
//now self-init
16-
$( initSelector, e.target )
17-
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
18-
.slider();
19-
20-
});
21-
2210
$.widget( "mobile.slider", $.mobile.widget, {
2311
options: {
2412
theme: null,
2513
trackTheme: null,
2614
disabled: false,
27-
initSelector: initSelector
15+
initSelector: "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')"
2816
},
2917

3018
_create: function() {
@@ -325,5 +313,14 @@ $.widget( "mobile.slider", $.mobile.widget, {
325313
}
326314

327315
});
328-
})( jQuery );
329316

317+
//auto self-init widgets
318+
$( document ).bind( "pagecreate create", function( e ){
319+
320+
$( $.mobile.slider.prototype.options.initSelector, e.target )
321+
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
322+
.slider();
323+
324+
});
325+
326+
})( jQuery );

js/jquery.mobile.forms.textinput.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,10 @@
77

88
(function( $, undefined ) {
99

10-
//auto self-init widgets
11-
var initSelector = "input[type='text'], input[type='search'], :jqmData(type='search'), input[type='number'], :jqmData(type='number'), input[type='password'], input[type='email'], input[type='url'], input[type='tel'], textarea";
12-
13-
$( document ).bind( "pagecreate create", function( e ){
14-
$( initSelector, e.target )
15-
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
16-
.textinput();
17-
});
18-
1910
$.widget( "mobile.textinput", $.mobile.widget, {
2011
options: {
2112
theme: null,
22-
initSelector: initSelector
13+
initSelector: "input[type='text'], input[type='search'], :jqmData(type='search'), input[type='number'], :jqmData(type='number'), input[type='password'], input[type='email'], input[type='url'], input[type='tel'], textarea"
2314
},
2415

2516
_create: function() {
@@ -131,4 +122,14 @@ $.widget( "mobile.textinput", $.mobile.widget, {
131122
this.element.parent() : this.element ).removeClass( "ui-disabled" );
132123
}
133124
});
125+
126+
//auto self-init widgets
127+
$( document ).bind( "pagecreate create", function( e ){
128+
129+
$( $.mobile.textinput.prototype.options.initSelector, e.target )
130+
.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
131+
.textinput();
132+
133+
});
134+
134135
})( jQuery );

0 commit comments

Comments
 (0)