Skip to content

Commit

Permalink
Issue jquery-archive#2853: Added role plugin and use it in widgets an…
Browse files Browse the repository at this point in the history
…d controls.
  • Loading branch information
Ghislain Seguin committed Oct 27, 2011
1 parent d106e68 commit 3fd3339
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion js/jquery.mobile.collapsible.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, {


//auto self-init widgets //auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate create", function( e ){
$( $.mobile.collapsible.prototype.options.initSelector, e.target ).collapsible(); e.$jqmRoleElements.filter( $.mobile.collapsible.prototype.options.initSelector ).collapsible();
}); });


})( jQuery ); })( jQuery );
2 changes: 1 addition & 1 deletion js/jquery.mobile.controlGroup.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $.fn.controlgroup = function( options ) {


//auto self-init widgets //auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate create", function( e ){
$( ":jqmData(role='controlgroup')", e.target ).controlgroup({ excludeInvisible: false }); e.$jqmRoleElements.filter( ":jqmData(role='controlgroup')" ).controlgroup({ excludeInvisible: false });
}); });


})(jQuery); })(jQuery);
2 changes: 1 addition & 1 deletion js/jquery.mobile.degradeInputs.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $( document ).bind( "pagecreate create", function( e ){
options = page.options; options = page.options;


// degrade inputs to avoid poorly implemented native functionality // degrade inputs to avoid poorly implemented native functionality
$( e.target ).find( "input" ).not( page.keepNativeSelector() ).each(function() { e.$controlElements.filter( "input" ).not( page.keepNativeSelector() ).each(function() {
var $this = $( this ), var $this = $( this ),
type = this.getAttribute( "type" ), type = this.getAttribute( "type" ),
optType = options.degradeInputs[ type ] || "text"; optType = options.degradeInputs[ type ] || "text";
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.mobile.dialog.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ $.widget( "mobile.dialog", $.mobile.widget, {
}); });


//auto self-init widgets //auto self-init widgets
$( $.mobile.dialog.prototype.options.initSelector ).live( "pagecreate", function(){ $( document ).bind( "pagecreate create", function( e ){
$( this ).dialog(); e.$jqmRoleElements.filter( $.mobile.dialog.prototype.options.initSelector ).dialog();
}); });


})( jQuery, this ); })( jQuery, this );
2 changes: 1 addition & 1 deletion js/jquery.mobile.fieldContain.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $.fn.fieldcontain = function( options ) {


//auto self-init widgets //auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate create", function( e ){
$( ":jqmData(role='fieldcontain')", e.target ).fieldcontain(); e.$jqmRoleElements.filter( ":jqmData(role='fieldcontain')" ).fieldcontain();
}); });


})( jQuery ); })( jQuery );
2 changes: 1 addition & 1 deletion js/jquery.mobile.forms.button.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ $.widget( "mobile.button", $.mobile.widget, {


//auto self-init widgets //auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate create", function( e ){
$.mobile.button.prototype.enhanceWithin( e.target ); $.mobile.button.prototype.enhanceWithin( e.target, e.$controlElements );
}); });


})( jQuery ); })( jQuery );
2 changes: 1 addition & 1 deletion js/jquery.mobile.forms.checkboxradio.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ $.widget( "mobile.checkboxradio", $.mobile.widget, {


//auto self-init widgets //auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate create", function( e ){
$.mobile.checkboxradio.prototype.enhanceWithin( e.target ); $.mobile.checkboxradio.prototype.enhanceWithin( e.target, e.$controlElements );
}); });


})( jQuery ); })( jQuery );
2 changes: 1 addition & 1 deletion js/jquery.mobile.forms.select.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -203,6 +203,6 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {


//auto self-init widgets //auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate create", function( e ){
$.mobile.selectmenu.prototype.enhanceWithin( e.target ); $.mobile.selectmenu.prototype.enhanceWithin( e.target, e.$controlElements );
}); });
})( jQuery ); })( jQuery );
2 changes: 1 addition & 1 deletion js/jquery.mobile.forms.slider.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ $.widget( "mobile.slider", $.mobile.widget, {


//auto self-init widgets //auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate create", function( e ){
$.mobile.slider.prototype.enhanceWithin( e.target ); $.mobile.slider.prototype.enhanceWithin( e.target, e.$controlElements );
}); });


})( jQuery ); })( jQuery );
2 changes: 1 addition & 1 deletion js/jquery.mobile.forms.textinput.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ $.widget( "mobile.textinput", $.mobile.widget, {


//auto self-init widgets //auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate create", function( e ){
$.mobile.textinput.prototype.enhanceWithin( e.target ); $.mobile.textinput.prototype.enhanceWithin( e.target, e.$controlElements );
}); });


})( jQuery ); })( jQuery );
2 changes: 1 addition & 1 deletion js/jquery.mobile.listview.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ $.widget( "mobile.listview", $.mobile.widget, {


//auto self-init widgets //auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate create", function( e ){
$( $.mobile.listview.prototype.options.initSelector, e.target ).listview(); e.$jqmRoleElements.filter( $.mobile.listview.prototype.options.initSelector ).listview();
}); });


})( jQuery ); })( jQuery );
2 changes: 1 addition & 1 deletion js/jquery.mobile.navbar.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $.widget( "mobile.navbar", $.mobile.widget, {


//auto self-init widgets //auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate create", function( e ){
$( $.mobile.navbar.prototype.options.initSelector, e.target ).navbar(); e.$jqmRoleElements.filter( $.mobile.navbar.prototype.options.initSelector ).navbar();
}); });


})( jQuery ); })( jQuery );
3 changes: 2 additions & 1 deletion js/jquery.mobile.role.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/ */


(function( $, undefined ) { (function( $, undefined ) {
$( document ).bind( "pagecreate create", function( e ){ $( document ).bind( "pagecreate", function( e ){
e.$jqmRoleElements = $( ":jqmData(role)", e.target ); e.$jqmRoleElements = $( ":jqmData(role)", e.target );
e.$controlElements = $( "input, textarea, select, button", e.target );
}); });
}( jQuery )); }( jQuery ));
13 changes: 9 additions & 4 deletions js/jquery.mobile.widget.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ $.widget( "mobile.widget", {
return options; return options;
}, },


enhanceWithin: function( target ) { enhanceWithin: function( target, coll ) {
// TODO remove dependency on the page widget for the keepNative. // TODO remove dependency on the page widget for the keepNative.
// Currently the keepNative value is defined on the page prototype so // Currently the keepNative value is defined on the page prototype so
// the method is as well // the method is as well
var page = $(target).closest(":jqmData(role='page')").data( "page" ), var page = $(target).closest(":jqmData(role='page')").data( "page" ),
keepNative = (page && page.keepNativeSelector()) || ""; keepNative = (page && page.keepNativeSelector()) || "",
elements;





if ( !coll ) {
$( this.options.initSelector, target ).not( keepNative )[ this.widgetName ](); elements = $( this.options.initSelector, target );
} else {
elements = coll.filter( this.options.initSelector );
}
elements.not( keepNative )[ this.widgetName ]();
} }
}); });


Expand Down

0 comments on commit 3fd3339

Please sign in to comment.