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

Commit 978762d

Browse files
committed
centralized method for finding closest page data
1 parent 2b49d38 commit 978762d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

js/jquery.mobile.core.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@
160160
}
161161
});
162162

163+
// TODO the following $ and $.fn extensions can/probably should be moved into
164+
// jquery.mobile.core.helpers
165+
166+
// Find the closest javascript page element to gather settings data
167+
// TODO complex selector parsing will slow down page load times
168+
$.fn.closestPageData = function() {
169+
return $(this)
170+
.closest(':jqmData(role="page"), :jqmData(role="dialog")')
171+
.data("page");
172+
};
173+
163174
// Mobile version of data and removeData and hasData methods
164175
// ensures all data is set and retrieved using jQuery Mobile's data namespace
165176
$.fn.jqmData = function( prop, value ) {

js/jquery.mobile.degradeInputs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $.mobile.page.prototype.options.degradeInputs = {
2424
//auto self-init widgets
2525
$( document ).bind( "pagecreate create", function( e ){
2626

27-
var page = $(e.target).closest(':jqmData(role="page"),:jqmData(role="dialog")').data("page"), options;
27+
var page = $(e.target).closestPageData();
2828

2929
if( !page ) {
3030
return;

js/jquery.mobile.widget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $.widget( "mobile.widget", {
3939
// TODO remove dependency on the page widget for the keepNative.
4040
// Currently the keepNative value is defined on the page prototype so
4141
// the method is as well
42-
var page = $(target).closest(":jqmData(role='page')").data( "page" ),
42+
var page = $(target).closestPageData(),
4343
keepNative = (page && page.keepNativeSelector()) || "";
4444

4545
$( this.options.initSelector, target ).not( keepNative )[ this.widgetName ]();

0 commit comments

Comments
 (0)