diff --git a/js/jquery.mobile.core.js b/js/jquery.mobile.core.js index 7d0691f0..790cda6c 100644 --- a/js/jquery.mobile.core.js +++ b/js/jquery.mobile.core.js @@ -157,22 +157,22 @@ // specified default. return ltr || defaultTheme || "a"; + }, + + // TODO the following $ and $.fn extensions can/probably should be moved into jquery.mobile.core.helpers + // + // Find the closest javascript page element to gather settings data jsperf test + // http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit + // possibly naive, but it shows that the parsing overhead for *just* the page selector vs + // the page and dialog selector is negligable. This could probably be speed up by + // doing a similar parent node traversal to the one found in the inherited theme code above + closestPageData: function( $target ) { + return $target + .closest(':jqmData(role="page"), :jqmData(role="dialog")') + .data("page"); } }); - // TODO the following $ and $.fn extensions can/probably should be moved into jquery.mobile.core.helpers - // - // Find the closest javascript page element to gather settings data jsperf test - // http://jsperf.com/single-complex-selector-vs-many-complex-selectors/edit - // possibly naive, but it shows that the parsing overhead for *just* the page selector vs - // the page and dialog selector is negligable. This could probably be speed up by - // doing a similar parent node traversal to the one found in the inherited theme code above - $.fn.closestPageData = function() { - return $(this) - .closest(':jqmData(role="page"), :jqmData(role="dialog")') - .data("page"); - }; - // Mobile version of data and removeData and hasData methods // ensures all data is set and retrieved using jQuery Mobile's data namespace $.fn.jqmData = function( prop, value ) { diff --git a/js/jquery.mobile.degradeInputs.js b/js/jquery.mobile.degradeInputs.js index 9d747f47..b2a98bd8 100644 --- a/js/jquery.mobile.degradeInputs.js +++ b/js/jquery.mobile.degradeInputs.js @@ -24,7 +24,7 @@ $.mobile.page.prototype.options.degradeInputs = { //auto self-init widgets $( document ).bind( "pagecreate create", function( e ){ - var page = $(e.target).closestPageData(); + var page = $.mobile.closestPageData( $(e.target) ); if( !page ) { return; diff --git a/js/jquery.mobile.widget.js b/js/jquery.mobile.widget.js index 46331758..45a69ecf 100644 --- a/js/jquery.mobile.widget.js +++ b/js/jquery.mobile.widget.js @@ -39,7 +39,7 @@ $.widget( "mobile.widget", { // TODO remove dependency on the page widget for the keepNative. // Currently the keepNative value is defined on the page prototype so // the method is as well - var page = $(target).closestPageData(), + var page = $.mobile.closestPageData( $(target) ), keepNative = (page && page.keepNativeSelector()) || ""; $( this.options.initSelector, target ).not( keepNative )[ this.widgetName ](); diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js index 11ce68d5..defcad35 100644 --- a/tests/unit/core/core.js +++ b/tests/unit/core/core.js @@ -150,13 +150,13 @@ var pageChild = $( "#page-child" ); $( "#parent-page" ).data( "page", { foo: "bar" } ); - same( pageChild.closestPageData().foo, "bar" ); + same( $.mobile.closestPageData( pageChild ).foo, "bar" ); }); test( "closestPageData returns the parent dialog's page data", function() { var dialogChild = $( "#dialog-child" ); $( "#parent-dialog" ).data( "page", { foo: "bar" } ); - same( dialogChild.closestPageData().foo, "bar" ); + same( $.mobile.closestPageData(dialogChild).foo, "bar" ); }); })(jQuery); \ No newline at end of file