Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

capture and retrigger clicks on the parent list item element in navba…

…rs Fixes #4663
  • Loading branch information...
commit b668b6006967354111f62caf96db37d63052bb52 1 parent 9b18cef
John Bender johnbender authored
Showing with 35 additions and 4 deletions.
  1. +24 −4 js/widgets/navbar.js
  2. +11 −0 tests/unit/navbar/navbar_core.js
28 js/widgets/navbar.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 );
}
});
11 tests/unit/navbar/navbar_core.js
View
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.