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

Commit b668b60

Browse files
committed
capture and retrigger clicks on the parent list item element in navbars Fixes #4663
1 parent 9b18cef commit b668b60

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

js/widgets/navbar.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,30 @@ $.widget( "mobile.navbar", $.mobile.widget, {
3737
iconpos: iconpos
3838
});
3939

40-
$navbar.delegate( "a", "vclick", function( event ) {
41-
if ( !$(event.target).hasClass( "ui-disabled" ) ) {
42-
$navbtns.removeClass( $.mobile.activeBtnClass );
43-
$( this ).addClass( $.mobile.activeBtnClass );
40+
$navbar.delegate( "li", "vclick", function( event ) {
41+
42+
// if the vclick was triggered on an anchor or the child
43+
// of an anchor (eg, ui-btn), grab the parent link
44+
var $link = $(event.target).closest( "a" );
45+
46+
// if there isn't a parent link find the child link and trigger a click
47+
// this addresses Issue #4663 where the events are being triggered
48+
// on the parent element in fixed position navbars
49+
if( !$link.length ){
50+
$link = $( this ).children( "a" ).first();
51+
setTimeout(function() {
52+
$link.trigger( "click" );
53+
});
54+
55+
return false;
56+
}
57+
58+
// clear existing active button states
59+
$navbtns.removeClass( $.mobile.activeBtnClass );
60+
61+
// if the target button isn't disabled
62+
if ( !$link.hasClass( "ui-disabled" ) ) {
63+
$link.addClass( $.mobile.activeBtnClass );
4464
}
4565
});
4666

tests/unit/navbar/navbar_core.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,15 @@
2828

2929
$.mobile.ignoreContentEnabled = false;
3030
});
31+
32+
// Issue #4663
33+
asyncTest( "clicks/taps triggered on anything above the link get retriggered on the link", function() {
34+
expect( 1 );
35+
$( document ).delegate( "li", "vclick", function( event ) {
36+
ok($( event.target ).is("a"), "target should always be an anchor" );
37+
start();
38+
});
39+
40+
$.mobile.activePage.find( "div:jqmData(role=navbar) li" ).first().trigger( "click" );
41+
});
3142
})(jQuery);

0 commit comments

Comments
 (0)