Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

take closestParentPage off of $.fn

  • Loading branch information...
commit c716ab707a74b263a6741114bb4d1934cba2a3ac 1 parent 851f6d4
@johnbender johnbender authored
View
26 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 ) {
View
2  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;
View
2  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 ]();
View
4 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);
Please sign in to comment.
Something went wrong with that request. Please try again.