From 263193f4909df7516cd3969122502c0c779dc079 Mon Sep 17 00:00:00 2001 From: scottjehl Date: Wed, 27 Jul 2011 18:42:16 -0400 Subject: [PATCH] Moved autoinit calls to after widgets. Made it so auto init selectors use the initSelector option, so that it can be configurable. --- js/jquery.mobile.collapsible.js | 15 +++---- js/jquery.mobile.controlGroup.js | 13 +++--- js/jquery.mobile.dialog.js | 15 +++---- js/jquery.mobile.fieldContain.js | 12 +++-- js/jquery.mobile.fixHeaderFooter.js | 58 ++++++++++++------------- js/jquery.mobile.forms.button.js | 19 ++++---- js/jquery.mobile.forms.checkboxradio.js | 19 ++++---- js/jquery.mobile.forms.select.js | 19 ++++---- js/jquery.mobile.forms.slider.js | 25 +++++------ js/jquery.mobile.forms.textinput.js | 21 ++++----- js/jquery.mobile.listview.js | 16 +++---- js/jquery.mobile.navbar.js | 14 +++--- 12 files changed, 114 insertions(+), 132 deletions(-) diff --git a/js/jquery.mobile.collapsible.js b/js/jquery.mobile.collapsible.js index 66cf7375..5763ea12 100644 --- a/js/jquery.mobile.collapsible.js +++ b/js/jquery.mobile.collapsible.js @@ -6,13 +6,6 @@ */ (function( $, undefined ) { -//auto self-init widgets -var initSelector = ":jqmData(role='collapsible')"; - -$( document ).bind( "pagecreate create", function( e ){ - $( initSelector, e.target ).collapsible(); -}); - $.widget( "mobile.collapsible", $.mobile.widget, { options: { expandCueText: " click to expand contents", @@ -21,7 +14,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, { heading: ">:header,>legend", theme: null, iconTheme: "d", - initSelector: initSelector + initSelector: ":jqmData(role='collapsible')" }, _create: function() { @@ -163,4 +156,10 @@ $.widget( "mobile.collapsible", $.mobile.widget, { }); } }); + +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + $( $.mobile.collapsible.prototype.options.initSelector, e.target ).collapsible(); +}); + })( jQuery ); diff --git a/js/jquery.mobile.controlGroup.js b/js/jquery.mobile.controlGroup.js index ea60176f..d2e47327 100644 --- a/js/jquery.mobile.controlGroup.js +++ b/js/jquery.mobile.controlGroup.js @@ -6,13 +6,6 @@ */ (function( $, undefined ) { -//auto self-init widgets -var initSelector = ":jqmData(role='controlgroup')"; - -$( document ).bind( "pagecreate create", function( e ){ - $( initSelector, e.target ).controlgroup({ excludeInvisible: false }); -}); - $.fn.controlgroup = function( options ) { return this.each(function() { @@ -53,4 +46,10 @@ $.fn.controlgroup = function( options ) { } }); }; + +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + $( ":jqmData(role='controlgroup')", e.target ).controlgroup({ excludeInvisible: false }); +}); + })(jQuery); \ No newline at end of file diff --git a/js/jquery.mobile.dialog.js b/js/jquery.mobile.dialog.js index 4747a6db..24d974f5 100644 --- a/js/jquery.mobile.dialog.js +++ b/js/jquery.mobile.dialog.js @@ -6,18 +6,11 @@ (function( $, window, undefined ) { -//auto self-init widgets -var initSelector = ":jqmData(role='dialog')"; - -$( initSelector ).live( "pagecreate", function(){ - $( this ).dialog(); -}); - $.widget( "mobile.dialog", $.mobile.widget, { options: { closeBtnText : "Close", theme : "a", - initSelector : initSelector + initSelector : ":jqmData(role='dialog')" }, _create: function() { var $el = this.element, @@ -68,4 +61,10 @@ $.widget( "mobile.dialog", $.mobile.widget, { window.history.back(); } }); + +//auto self-init widgets +$( $.mobile.dialog.prototype.options.initSelector ).live( "pagecreate", function(){ + $( this ).dialog(); +}); + })( jQuery, this ); diff --git a/js/jquery.mobile.fieldContain.js b/js/jquery.mobile.fieldContain.js index 4471cb4c..1d9c7f75 100644 --- a/js/jquery.mobile.fieldContain.js +++ b/js/jquery.mobile.fieldContain.js @@ -7,15 +7,13 @@ (function( $, undefined ) { -//auto self-init widgets -var initSelector = ":jqmData(role='fieldcontain')"; - -$( document ).bind( "pagecreate create", function( e ){ - $( initSelector, e.target ).fieldcontain(); -}); - $.fn.fieldcontain = function( options ) { return this.addClass( "ui-field-contain ui-body ui-br" ); }; +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + $( ":jqmData(role='fieldcontain')", e.target ).fieldcontain(); +}); + })( jQuery ); \ No newline at end of file diff --git a/js/jquery.mobile.fixHeaderFooter.js b/js/jquery.mobile.fixHeaderFooter.js index e70648b8..7fca9958 100644 --- a/js/jquery.mobile.fixHeaderFooter.js +++ b/js/jquery.mobile.fixHeaderFooter.js @@ -6,37 +6,6 @@ */ (function( $, undefined ) { - -//auto self-init widgets -var initSelector = ":jqmData(position='fixed')"; - -$( document ).bind( "pagecreate create", function( e ){ - - if( $( initSelector, e.target ).length ){ - $( e.target ).each(function(){ - - if ( !$.support.scrollTop ) { - return this; - } - - var $this = $( this ); - - if ( $this.jqmData( "fullscreen" ) ) { - $this.addClass( "ui-page-fullscreen" ); - } - - // Should be slidedown - $this.find( ".ui-header:jqmData(position='fixed')" ).addClass( "ui-header-fixed ui-fixed-inline fade" ); - - // Should be slideup - $this.find( ".ui-footer:jqmData(position='fixed')" ).addClass( "ui-footer-fixed ui-fixed-inline fade" ); - - }) - - } -}); - - $.fn.fixHeaderFooter = function( options ) { @@ -376,4 +345,31 @@ $.fixedToolbars = (function() { }; })(); +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + + if( $( ":jqmData(position='fixed')", e.target ).length ){ + $( e.target ).each(function(){ + + if ( !$.support.scrollTop ) { + return this; + } + + var $this = $( this ); + + if ( $this.jqmData( "fullscreen" ) ) { + $this.addClass( "ui-page-fullscreen" ); + } + + // Should be slidedown + $this.find( ".ui-header:jqmData(position='fixed')" ).addClass( "ui-header-fixed ui-fixed-inline fade" ); + + // Should be slideup + $this.find( ".ui-footer:jqmData(position='fixed')" ).addClass( "ui-footer-fixed ui-fixed-inline fade" ); + + }) + + } +}); + })(jQuery); diff --git a/js/jquery.mobile.forms.button.js b/js/jquery.mobile.forms.button.js index 781e60ab..21894d27 100644 --- a/js/jquery.mobile.forms.button.js +++ b/js/jquery.mobile.forms.button.js @@ -7,15 +7,6 @@ (function( $, undefined ) { -//auto self-init widgets -var initSelector = "button, [type='button'], [type='submit'], [type='reset'], [type='image']"; - -$( document ).bind( "pagecreate create", function( e ){ - $( initSelector, e.target ) - .not( ":jqmData(role='none'), :jqmData(role='nojs')" ) - .button(); -}); - $.widget( "mobile.button", $.mobile.widget, { options: { theme: null, @@ -25,7 +16,7 @@ $.widget( "mobile.button", $.mobile.widget, { corners: true, shadow: true, iconshadow: true, - initSelector: initSelector + initSelector: "button, [type='button'], [type='submit'], [type='reset'], [type='image']" }, _create: function() { var $el = this.element, @@ -91,4 +82,12 @@ $.widget( "mobile.button", $.mobile.widget, { } } }); + +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + $( $.mobile.button.prototype.options.initSelector, e.target ) + .not( ":jqmData(role='none'), :jqmData(role='nojs')" ) + .button(); +}); + })( jQuery ); \ No newline at end of file diff --git a/js/jquery.mobile.forms.checkboxradio.js b/js/jquery.mobile.forms.checkboxradio.js index 2f08a8a1..7196b70e 100644 --- a/js/jquery.mobile.forms.checkboxradio.js +++ b/js/jquery.mobile.forms.checkboxradio.js @@ -7,19 +7,10 @@ (function( $, undefined ) { -//auto self-init widgets -var initSelector = "input[type='checkbox'],input[type='radio']"; - -$( document ).bind( "pagecreate create", function( e ){ - $( initSelector, e.target ) - .not( ":jqmData(role='none'), :jqmData(role='nojs')" ) - .checkboxradio(); -}); - $.widget( "mobile.checkboxradio", $.mobile.widget, { options: { theme: null, - initSelector: initSelector + initSelector: "input[type='checkbox'],input[type='radio']" }, _create: function() { var self = this, @@ -192,4 +183,12 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, { this.element.prop( "disabled", false ).parent().removeClass( "ui-disabled" ); } }); + +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + $( $.mobile.checkboxradio.prototype.options.initSelector, e.target ) + .not( ":jqmData(role='none'), :jqmData(role='nojs')" ) + .checkboxradio(); +}); + })( jQuery ); diff --git a/js/jquery.mobile.forms.select.js b/js/jquery.mobile.forms.select.js index cb24f51a..9bfc3ddd 100644 --- a/js/jquery.mobile.forms.select.js +++ b/js/jquery.mobile.forms.select.js @@ -7,15 +7,6 @@ (function( $, undefined ) { -//auto self-init widgets -var initSelector = "select:not(:jqmData(role='slider'))"; - -$( document ).bind( "pagecreate create", function( e ){ - $( initSelector, e.target ) - .not( ":jqmData(role='none'), :jqmData(role='nojs')" ) - .selectmenu(); -}); - $.widget( "mobile.selectmenu", $.mobile.widget, { options: { theme: null, @@ -31,7 +22,7 @@ $.widget( "mobile.selectmenu", $.mobile.widget, { hidePlaceholderMenuItems: true, closeText: "Close", nativeMenu: true, - initSelector: initSelector + initSelector: "select:not(:jqmData(role='slider'))" }, _create: function() { @@ -611,5 +602,13 @@ $.widget( "mobile.selectmenu", $.mobile.widget, { return this._setOption( "disabled", false ); } }); + +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + $( $.mobile.selectmenu.prototype.options.initSelector, e.target ) + .not( ":jqmData(role='none'), :jqmData(role='nojs')" ) + .selectmenu(); +}); + })( jQuery ); diff --git a/js/jquery.mobile.forms.slider.js b/js/jquery.mobile.forms.slider.js index 2d13db3a..e3d9fc82 100644 --- a/js/jquery.mobile.forms.slider.js +++ b/js/jquery.mobile.forms.slider.js @@ -7,24 +7,12 @@ ( function( $, undefined ) { -//auto self-init widgets -var initSelector = "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')"; - -$( document ).bind( "pagecreate create", function( e ){ - - //now self-init - $( initSelector, e.target ) - .not( ":jqmData(role='none'), :jqmData(role='nojs')" ) - .slider(); - -}); - $.widget( "mobile.slider", $.mobile.widget, { options: { theme: null, trackTheme: null, disabled: false, - initSelector: initSelector + initSelector: "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')" }, _create: function() { @@ -325,5 +313,14 @@ $.widget( "mobile.slider", $.mobile.widget, { } }); -})( jQuery ); +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + + $( $.mobile.slider.prototype.options.initSelector, e.target ) + .not( ":jqmData(role='none'), :jqmData(role='nojs')" ) + .slider(); + +}); + +})( jQuery ); \ No newline at end of file diff --git a/js/jquery.mobile.forms.textinput.js b/js/jquery.mobile.forms.textinput.js index a121822b..1d8ab441 100644 --- a/js/jquery.mobile.forms.textinput.js +++ b/js/jquery.mobile.forms.textinput.js @@ -7,19 +7,10 @@ (function( $, undefined ) { -//auto self-init widgets -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"; - -$( document ).bind( "pagecreate create", function( e ){ - $( initSelector, e.target ) - .not( ":jqmData(role='none'), :jqmData(role='nojs')" ) - .textinput(); -}); - $.widget( "mobile.textinput", $.mobile.widget, { options: { theme: null, - initSelector: initSelector + 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" }, _create: function() { @@ -131,4 +122,14 @@ $.widget( "mobile.textinput", $.mobile.widget, { this.element.parent() : this.element ).removeClass( "ui-disabled" ); } }); + +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + + $( $.mobile.textinput.prototype.options.initSelector, e.target ) + .not( ":jqmData(role='none'), :jqmData(role='nojs')" ) + .textinput(); + +}); + })( jQuery ); diff --git a/js/jquery.mobile.listview.js b/js/jquery.mobile.listview.js index 28047923..7fee8211 100644 --- a/js/jquery.mobile.listview.js +++ b/js/jquery.mobile.listview.js @@ -7,13 +7,6 @@ (function( $, undefined ) { -//auto self-init widgets -var initSelector = ":jqmData(role='listview')"; - -$( document ).bind( "pagecreate create", function( e ){ - $( initSelector, e.target ).listview(); -}); - //Keeps track of the number of lists per page UID //This allows support for multiple nested list in the same page //https://github.com/jquery/jquery-mobile/issues/1617 @@ -28,7 +21,7 @@ $.widget( "mobile.listview", $.mobile.widget, { splitIcon: "arrow-r", splitTheme: "b", inset: false, - initSelector: initSelector + initSelector: ":jqmData(role='listview')" }, _create: function() { @@ -264,4 +257,9 @@ $.widget( "mobile.listview", $.mobile.widget, { } }); -})( jQuery ); +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + $( $.mobile.listview.prototype.options.initSelector, e.target ).listview(); +}); + +})( jQuery ); \ No newline at end of file diff --git a/js/jquery.mobile.navbar.js b/js/jquery.mobile.navbar.js index 61b51e9f..4da6d903 100755 --- a/js/jquery.mobile.navbar.js +++ b/js/jquery.mobile.navbar.js @@ -7,18 +7,11 @@ (function( $, undefined ) { -//auto self-init widgets -var initSelector = ":jqmData(role='navbar')"; - -$( document ).bind( "pagecreate create", function( e ){ - $( initSelector, e.target ).navbar(); -}); - $.widget( "mobile.navbar", $.mobile.widget, { options: { iconpos: "top", grid: null, - initSelector: initSelector + initSelector: ":jqmData(role='navbar')" }, _create: function(){ @@ -50,4 +43,9 @@ $.widget( "mobile.navbar", $.mobile.widget, { } }); +//auto self-init widgets +$( document ).bind( "pagecreate create", function( e ){ + $( $.mobile.navbar.prototype.options.initSelector, e.target ).navbar(); +}); + })( jQuery );