take closestParentPage off of $.fn

This commit is contained in:
John Bender 2011-12-09 14:28:51 -08:00
parent 851f6d4c67
commit c716ab707a
4 changed files with 17 additions and 17 deletions

View file

@ -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 ) {

View file

@ -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;

View file

@ -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 ]();

View file

@ -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);