Skip to content
This repository
Browse code

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 authored August 08, 2012
28  js/widgets/navbar.js
@@ -37,10 +37,30 @@ $.widget( "mobile.navbar", $.mobile.widget, {
37 37
 			iconpos:	iconpos
38 38
 		});
39 39
 
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 );
44 64
 			}
45 65
 		});
46 66
 
11  tests/unit/navbar/navbar_core.js
@@ -28,4 +28,15 @@
28 28
 
29 29
 		$.mobile.ignoreContentEnabled = false;
30 30
 	});
  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
+	});
31 42
 })(jQuery);

0 notes on commit b668b60

Please sign in to comment.
Something went wrong with that request. Please try again.