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

Commit 24b85fc

Browse files
author
Gabriel Schulhof
committed
Navigation: vclick handler: be more paranoid about the possibility that target.parentNode is null, and improve buttonMarkup data retrieval heuristics
1 parent ee0f113 commit 24b85fc

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

js/jquery.mobile.navigation.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,12 +1339,15 @@ define( [
13391339

13401340
// Try to find a target element to which the active class will be applied
13411341
if ( $.data( target, "mobile-button" ) ) {
1342+
// If the form will not be submitted via AJAX, do not add active class
13421343
if ( !getAjaxFormData( $( target ).closest( "form" ), true ) ) {
13431344
return;
13441345
}
13451346
// We will apply the active state to this button widget - the parent
13461347
// of the input that was clicked will have the associated data
1347-
target = target.parentNode;
1348+
if ( target.parentNode ) {
1349+
target = target.parentNode;
1350+
}
13481351
} else {
13491352
target = findClosestLink( target );
13501353
if ( !( target && path.parseUrl( target.getAttribute( "href" ) || "#" ).hash !== "#" ) ) {
@@ -1359,19 +1362,29 @@ define( [
13591362
}
13601363

13611364
// Avoid calling .closest by using the data set during .buttonMarkup()
1362-
btnEls = $.data( target, "buttonElements" );
1365+
// List items have the button data in the parent of the element clicked
1366+
if ( !!~target.className.indexOf( "ui-link-inherit" ) ) {
1367+
if ( target.parentNode ) {
1368+
btnEls = $.data( target.parentNode, "buttonElements" );
1369+
}
1370+
// Otherwise, look for the data on the target itself
1371+
} else {
1372+
btnEls = $.data( target, "buttonElements" );
1373+
}
1374+
// If found, grab the button's outer element
13631375
if ( btnEls ) {
13641376
target = btnEls.outer;
13651377
} else {
13661378
needClosest = true;
13671379
}
13681380

13691381
$btn = $( target );
1382+
// If the outer element wasn't found by the our heuristics, use .closest()
13701383
if ( needClosest ) {
13711384
$btn = $btn.closest( ".ui-btn" );
13721385
}
1373-
$btn = $btn.not( ".ui-disabled" );
1374-
if ( $btn.length > 0 && !$btn.hasClass( $.mobile.activeBtnClass ) ) {
1386+
1387+
if ( $btn.length > 0 && !( $btn.hasClass( $.mobile.activeBtnClass ) || $btn.hasClass( "ui-disabled" ) ) ) {
13751388
removeActiveLinkClass( true );
13761389
$activeClickedLink = $btn;
13771390
$activeClickedLink.addClass( $.mobile.activeBtnClass );

0 commit comments

Comments
 (0)