Skip to content
This repository
Browse code

exposed automatic initialization selectors on most widgets that expos…

…e options through the widget factory. Option name is "initSelector"
  • Loading branch information...
commit e07c40e3d0bbc2826133dc8dd3552e030687cd9a 1 parent 79d3aa6
authored July 26, 2011
7  js/jquery.mobile.collapsible.js
@@ -7,8 +7,10 @@
7 7
 (function( $, undefined ) {
8 8
 
9 9
 //auto self-init widgets
  10
+var initSelector = ":jqmData(role='collapsible')";
  11
+
10 12
 $( document ).bind( "pagecreate create", function( e ){
11  
-	$( ":jqmData(role='collapsible')", e.target ).collapsible();
  13
+	$( initSelector, e.target ).collapsible();
12 14
 });
13 15
 
14 16
 $.widget( "mobile.collapsible", $.mobile.widget, {
@@ -18,7 +20,8 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
18 20
 		collapsed: false,
19 21
 		heading: ">:header,>legend",
20 22
 		theme: null,
21  
-		iconTheme: "d"
  23
+		iconTheme: "d",
  24
+		initSelector: initSelector
22 25
 	},
23 26
 	_create: function() {
24 27
 
4  js/jquery.mobile.controlGroup.js
@@ -7,8 +7,10 @@
7 7
 (function( $, undefined ) {
8 8
 
9 9
 //auto self-init widgets
  10
+var initSelector = ":jqmData(role='controlgroup')";
  11
+
10 12
 $( document ).bind( "pagecreate create", function( e ){
11  
-	$( ":jqmData(role='controlgroup')", e.target ).controlgroup({ excludeInvisible: false });
  13
+	$( initSelector, e.target ).controlgroup({ excludeInvisible: false });
12 14
 });
13 15
 
14 16
 $.fn.controlgroup = function( options ) {
7  js/jquery.mobile.dialog.js
@@ -7,14 +7,17 @@
7 7
 (function( $, window, undefined ) {
8 8
 
9 9
 //auto self-init widgets
10  
-$( ":jqmData(role='dialog')" ).live( "pagecreate", function(){
  10
+var initSelector = ":jqmData(role='dialog')";
  11
+
  12
+$( initSelector ).live( "pagecreate", function(){
11 13
 	$( this ).dialog();
12 14
 });
13 15
 
14 16
 $.widget( "mobile.dialog", $.mobile.widget, {
15 17
 	options: {
16 18
 		closeBtnText 	: "Close",
17  
-		theme			: "a"
  19
+		theme			: "a",
  20
+		initSelector	: initSelector
18 21
 	},
19 22
 	_create: function() {
20 23
 		var $el = this.element,
4  js/jquery.mobile.fieldContain.js
@@ -8,8 +8,10 @@
8 8
 (function( $, undefined ) {
9 9
 
10 10
 //auto self-init widgets
  11
+var initSelector = ":jqmData(role='fieldcontain')";
  12
+
11 13
 $( document ).bind( "pagecreate create", function( e ){
12  
-	$( ":jqmData(role='fieldcontain')", e.target ).fieldcontain();
  14
+	$( initSelector, e.target ).fieldcontain();
13 15
 });
14 16
 
15 17
 $.fn.fieldcontain = function( options ) {
4  js/jquery.mobile.fixHeaderFooter.js
@@ -8,9 +8,11 @@
8 8
 (function( $, undefined ) {
9 9
 	
10 10
 //auto self-init widgets
  11
+var initSelector = ":jqmData(position='fixed')";
  12
+
11 13
 $( document ).bind( "pagecreate create", function( e ){
12 14
 	
13  
-	if( $( ":jqmData(position='fixed')", e.target ).length ){
  15
+	if( $( initSelector, e.target ).length ){
14 16
 		$( e.target ).each(function(){
15 17
 			
16 18
 			if ( !$.support.scrollTop ) {
7  js/jquery.mobile.forms.button.js
@@ -8,8 +8,10 @@
8 8
 (function( $, undefined ) {
9 9
 
10 10
 //auto self-init widgets
  11
+var initSelector = "button, [type='button'], [type='submit'], [type='reset'], [type='image']";
  12
+
11 13
 $( document ).bind( "pagecreate create", function( e ){
12  
-	$( "button, [type='button'], [type='submit'], [type='reset'], [type='image']", e.target )
  14
+	$( initSelector, e.target )
13 15
 		.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
14 16
 		.button();
15 17
 });
@@ -22,7 +24,8 @@ $.widget( "mobile.button", $.mobile.widget, {
22 24
 		inline: null,
23 25
 		corners: true,
24 26
 		shadow: true,
25  
-		iconshadow: true
  27
+		iconshadow: true,
  28
+		initSelector: initSelector
26 29
 	},
27 30
 	_create: function() {
28 31
 		var $el = this.element,
7  js/jquery.mobile.forms.checkboxradio.js
@@ -8,15 +8,18 @@
8 8
 (function( $, undefined ) {
9 9
 
10 10
 //auto self-init widgets
  11
+var initSelector = "input[type='checkbox'],input[type='radio']";
  12
+
11 13
 $( document ).bind( "pagecreate create", function( e ){
12  
-	$( "input[type='checkbox'],input[type='radio']", e.target )
  14
+	$( $.mobile.checkboxradio.prototype.options.initSelector, e.target )
13 15
 		.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
14 16
 		.checkboxradio();
15 17
 });
16 18
 
17 19
 $.widget( "mobile.checkboxradio", $.mobile.widget, {
18 20
 	options: {
19  
-		theme: null
  21
+		theme: null,
  22
+		initSelector: initSelector
20 23
 	},
21 24
 	_create: function() {
22 25
 		var self = this,
7  js/jquery.mobile.forms.select.js
@@ -8,8 +8,10 @@
8 8
 (function( $, undefined ) {
9 9
 
10 10
 //auto self-init widgets
  11
+var initSelector = "select:not(:jqmData(role='slider'))";
  12
+
11 13
 $( document ).bind( "pagecreate create", function( e ){
12  
-	$( "select:not(:jqmData(role='slider'))", e.target )
  14
+	$( initSelector, e.target )
13 15
 		.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
14 16
 		.selectmenu();
15 17
 });
@@ -28,7 +30,8 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
28 30
 		overlayTheme: "a",
29 31
 		hidePlaceholderMenuItems: true,
30 32
 		closeText: "Close",
31  
-		nativeMenu: true
  33
+		nativeMenu: true,
  34
+		initSelector: initSelector
32 35
 	},
33 36
 	_create: function() {
34 37
 
7  js/jquery.mobile.forms.slider.js
@@ -8,10 +8,12 @@
8 8
 ( function( $, undefined ) {
9 9
 
10 10
 //auto self-init widgets
  11
+var initSelector = "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')";
  12
+
11 13
 $( document ).bind( "pagecreate create", function( e ){
12 14
 
13 15
 	//now self-init
14  
-	$( "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')", e.target )
  16
+	$( initSelector, e.target )
15 17
 		.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
16 18
 		.slider();
17 19
 
@@ -21,7 +23,8 @@ $.widget( "mobile.slider", $.mobile.widget, {
21 23
 	options: {
22 24
 		theme: null,
23 25
 		trackTheme: null,
24  
-		disabled: false
  26
+		disabled: false,
  27
+		initSelector: initSelector
25 28
 	},
26 29
 
27 30
 	_create: function() {
7  js/jquery.mobile.forms.textinput.js
@@ -8,15 +8,18 @@
8 8
 (function( $, undefined ) {
9 9
 
10 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
+
11 13
 $( document ).bind( "pagecreate create", function( e ){
12  
-	$( "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", e.target )
  14
+	$( initSelector, e.target )
13 15
 		.not( ":jqmData(role='none'), :jqmData(role='nojs')" )
14 16
 		.textinput();
15 17
 });
16 18
 
17 19
 $.widget( "mobile.textinput", $.mobile.widget, {
18 20
 	options: {
19  
-		theme: null
  21
+		theme: null,
  22
+		initSelector: initSelector
20 23
 	},
21 24
 
22 25
 	_create: function() {
7  js/jquery.mobile.listview.js
@@ -8,8 +8,10 @@
8 8
 (function( $, undefined ) {
9 9
 
10 10
 //auto self-init widgets
  11
+var initSelector = ":jqmData(role='listview')";
  12
+
11 13
 $( document ).bind( "pagecreate create", function( e ){
12  
-	$( ":jqmData(role='listview')", e.target ).listview();
  14
+	$( initSelector, e.target ).listview();
13 15
 });
14 16
 
15 17
 //Keeps track of the number of lists per page UID
@@ -25,7 +27,8 @@ $.widget( "mobile.listview", $.mobile.widget, {
25 27
 		dividerTheme: "b",
26 28
 		splitIcon: "arrow-r",
27 29
 		splitTheme: "b",
28  
-		inset: false
  30
+		inset: false,
  31
+		initSelector: initSelector
29 32
 	},
30 33
 
31 34
 	_create: function() {
7  js/jquery.mobile.navbar.js
@@ -8,14 +8,17 @@
8 8
 (function( $, undefined ) {
9 9
 
10 10
 //auto self-init widgets
  11
+var initSelector = ":jqmData(role='navbar')";
  12
+
11 13
 $( document ).bind( "pagecreate create", function( e ){
12  
-	$( ":jqmData(role='navbar')", e.target ).navbar();
  14
+	$( initSelector, e.target ).navbar();
13 15
 });
14 16
 
15 17
 $.widget( "mobile.navbar", $.mobile.widget, {
16 18
 	options: {
17 19
 		iconpos: "top",
18  
-		grid: null
  20
+		grid: null,
  21
+		initSelector: initSelector
19 22
 	},
20 23
 
21 24
 	_create: function(){

0 notes on commit e07c40e

negue

This is the only initSelector which is from .prototype.options.

All other are just using the default var initSelector, maybe all inits should use .prototype.options.initSelector

Scott Jehl

Thanks - yep that should be initSelector.

Please sign in to comment.
Something went wrong with that request. Please try again.