Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
take closestParentPage off of $.fn
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbender committed Dec 9, 2011
1 parent 851f6d4 commit c716ab7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
26 changes: 13 additions & 13 deletions js/jquery.mobile.core.js
Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.degradeInputs.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.widget.js
Expand Up @@ -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 ]();
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/core/core.js
Expand Up @@ -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);

0 comments on commit c716ab7

Please sign in to comment.