mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-29 02:14:44 +00:00
centralized method for finding closest page data
This commit is contained in:
parent
2b49d382d8
commit
978762dc67
3 changed files with 13 additions and 2 deletions
|
|
@ -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 ) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 ]();
|
||||
|
|
|
|||
Loading…
Reference in a new issue