centralized method for finding closest page data

This commit is contained in:
John Bender 2011-12-09 12:17:20 -08:00
parent 2b49d382d8
commit 978762dc67
3 changed files with 13 additions and 2 deletions

View file

@ -160,6 +160,17 @@
}
});
// 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
// TODO complex selector parsing will slow down page load times
$.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).closest(':jqmData(role="page"),:jqmData(role="dialog")').data("page"), options;
var page = $(e.target).closestPageData();
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).closest(":jqmData(role='page')").data( "page" ),
var page = $(target).closestPageData(),
keepNative = (page && page.keepNativeSelector()) || "";
$( this.options.initSelector, target ).not( keepNative )[ this.widgetName ]();