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

Commit b837a49

Browse files
committed
add dependent tracking functions for jquery mobile objects
1 parent eb7c4d0 commit b837a49

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

js/jquery.mobile.core.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@
151151
return $.removeData( elem, $.mobile.nsNormalize( prop ) );
152152
};
153153

154+
$.fn.removeWithDependents = function() {
155+
$.removeWithDependents( this );
156+
};
157+
158+
$.removeWithDependents = function( elem ) {
159+
var $elem = $( elem );
160+
161+
( $elem.jqmData('dependents') || $() ).remove();
162+
$elem.remove();
163+
};
164+
165+
$.fn.addDependent = function( newDependents ) {
166+
$.addDependent( $(this), newDependents );
167+
};
168+
169+
$.addDependent = function( elem, newDependents ) {
170+
var dependents = $(elem).jqmData( 'dependents' ) || $();
171+
172+
$(elem).jqmData( 'dependents', $.merge(dependents, newDependents) );
173+
};
174+
154175
// Monkey-patching Sizzle to filter the :jqmData selector
155176
var oldFind = $.find;
156177

js/jquery.mobile.forms.select.custom.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@
200200
return false;
201201
}
202202
});
203+
204+
self.thisPage.addDependent( this.menuPage );
205+
206+
self.menuPage.find(":jqmData(role='header') :jqmData(rel='back')").click(function() {
207+
self.close();
208+
return false;
209+
});
203210
},
204211

205212
_isRebuildRequired: function() {
@@ -265,7 +272,7 @@
265272
// of a dialog sized custom select
266273
if( !self.thisPage.data("page").options.domCache ){
267274
self.thisPage.bind( "pagehide.remove", function() {
268-
$(self).remove();
275+
$(this).removeWithDependents();
269276
});
270277
}
271278

js/jquery.mobile.navigation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@
854854
// when dom caching is not enabled bind to remove the page on hide
855855
if( !page.data("page").options.domCache ){
856856
page.bind( "pagehide.remove", function(){
857-
$(this).remove();
857+
$(this).removeWithDependents();
858858
});
859859
}
860860
});

0 commit comments

Comments
 (0)