Permalink
Browse files

capture and retrigger clicks on the parent list item element in navbars

Fixes #4663
  • Loading branch information...
johnbender committed Aug 8, 2012
1 parent 9b18cef commit b668b6006967354111f62caf96db37d63052bb52
Showing with 35 additions and 4 deletions.
  1. +24 −4 js/widgets/navbar.js
  2. +11 −0 tests/unit/navbar/navbar_core.js
View
@@ -37,10 +37,30 @@ $.widget( "mobile.navbar", $.mobile.widget, {
iconpos: iconpos
});
$navbar.delegate( "a", "vclick", function( event ) {
if ( !$(event.target).hasClass( "ui-disabled" ) ) {
$navbtns.removeClass( $.mobile.activeBtnClass );
$( this ).addClass( $.mobile.activeBtnClass );
$navbar.delegate( "li", "vclick", function( event ) {
// if the vclick was triggered on an anchor or the child
// of an anchor (eg, ui-btn), grab the parent link
var $link = $(event.target).closest( "a" );
// if there isn't a parent link find the child link and trigger a click
// this addresses Issue #4663 where the events are being triggered
// on the parent element in fixed position navbars
if( !$link.length ){
$link = $( this ).children( "a" ).first();
setTimeout(function() {
$link.trigger( "click" );
});
return false;
}
// clear existing active button states
$navbtns.removeClass( $.mobile.activeBtnClass );
// if the target button isn't disabled
if ( !$link.hasClass( "ui-disabled" ) ) {
$link.addClass( $.mobile.activeBtnClass );
}
});
@@ -28,4 +28,15 @@
$.mobile.ignoreContentEnabled = false;
});
// Issue #4663
asyncTest( "clicks/taps triggered on anything above the link get retriggered on the link", function() {
expect( 1 );
$( document ).delegate( "li", "vclick", function( event ) {
ok($( event.target ).is("a"), "target should always be an anchor" );
start();
});
$.mobile.activePage.find( "div:jqmData(role=navbar) li" ).first().trigger( "click" );
});
})(jQuery);

0 comments on commit b668b60

Please sign in to comment.