add dependent tracking functions for jquery mobile objects

This commit is contained in:
John Bender 2011-09-22 22:58:37 -07:00
parent eb7c4d08d8
commit b837a49b32
3 changed files with 30 additions and 2 deletions

View file

@ -151,6 +151,27 @@
return $.removeData( elem, $.mobile.nsNormalize( prop ) );
};
$.fn.removeWithDependents = function() {
$.removeWithDependents( this );
};
$.removeWithDependents = function( elem ) {
var $elem = $( elem );
( $elem.jqmData('dependents') || $() ).remove();
$elem.remove();
};
$.fn.addDependent = function( newDependents ) {
$.addDependent( $(this), newDependents );
};
$.addDependent = function( elem, newDependents ) {
var dependents = $(elem).jqmData( 'dependents' ) || $();
$(elem).jqmData( 'dependents', $.merge(dependents, newDependents) );
};
// Monkey-patching Sizzle to filter the :jqmData selector
var oldFind = $.find;

View file

@ -200,6 +200,13 @@
return false;
}
});
self.thisPage.addDependent( this.menuPage );
self.menuPage.find(":jqmData(role='header') :jqmData(rel='back')").click(function() {
self.close();
return false;
});
},
_isRebuildRequired: function() {
@ -265,7 +272,7 @@
// of a dialog sized custom select
if( !self.thisPage.data("page").options.domCache ){
self.thisPage.bind( "pagehide.remove", function() {
$(self).remove();
$(this).removeWithDependents();
});
}

View file

@ -854,7 +854,7 @@
// when dom caching is not enabled bind to remove the page on hide
if( !page.data("page").options.domCache ){
page.bind( "pagehide.remove", function(){
$(this).remove();
$(this).removeWithDependents();
});
}
});