diff --git a/js/jquery.mobile.navigation.js b/js/jquery.mobile.navigation.js index 69068730f1b..590d0bd2794 100755 --- a/js/jquery.mobile.navigation.js +++ b/js/jquery.mobile.navigation.js @@ -1177,6 +1177,12 @@ //add active state on vclick $( document ).bind( "vclick", function( event ) { + // if this isn't a left click we don't care. Its important to note + // that when the virtual event is generated it will create + if ( event.which > 1 ){ + return; + } + var link = findClosestLink( event.target ); if ( link ) { if ( path.parseUrl( link.getAttribute( "href" ) || "#" ).hash !== "#" ) { @@ -1191,7 +1197,10 @@ // click routing - direct to HTTP or Ajax, accordingly $( document ).bind( "click", function( event ) { var link = findClosestLink( event.target ); - if ( !link ) { + + // If there is no link associated with the click or its not a left + // click we want to ignore the click + if ( !link || event.which > 1) { return; } diff --git a/js/jquery.mobile.navigation.pushstate.js b/js/jquery.mobile.navigation.pushstate.js index 8b5a126e0e7..da0bb9db176 100644 --- a/js/jquery.mobile.navigation.pushstate.js +++ b/js/jquery.mobile.navigation.pushstate.js @@ -58,15 +58,15 @@ // NOTE this takes place *after* the vanilla navigation hash change // handling has taken place and set the state of the DOM onHashChange: function( e ) { - var href, state, - hash = location.hash, - isPath = $.mobile.path.isPath( hash ); - hash = isPath ? hash.replace( "#", "" ) : hash; - // disable this hash change if( self.onHashChangeDisabled ){ return; } + + var href, state, + hash = location.hash, + isPath = $.mobile.path.isPath( hash ); + hash = isPath ? hash.replace( "#", "" ) : hash; // propulate the hash when its not available state = self.state(); diff --git a/js/jquery.mobile.vmouse.js b/js/jquery.mobile.vmouse.js index 47e9823afef..a4d381282db 100644 --- a/js/jquery.mobile.vmouse.js +++ b/js/jquery.mobile.vmouse.js @@ -74,6 +74,12 @@ function createVirtualEvent( event, eventType ) { } } + // make sure that if the mouse and click virtual events are generated + // without a .which one is defined + if ( t.search(/mouse(down|up)|click/) > -1 && !event.which ){ + event.which = 1; + } + if ( t.search(/^touch/) !== -1 ) { ne = getNativeEvent( oe ); t = ne.touches; diff --git a/js/jquery.mobile.widget.js b/js/jquery.mobile.widget.js index 091faa011d7..919b1e154ef 100644 --- a/js/jquery.mobile.widget.js +++ b/js/jquery.mobile.widget.js @@ -8,6 +8,16 @@ (function( $, undefined ) { $.widget( "mobile.widget", { + // decorate the parent _createWidget to trigger `widgetinit` for users + // who wish to do post post `widgetcreate` alterations/additions + // + // TODO create a pull request for jquery ui to trigger this event + // in the original _createWidget + _createWidget: function() { + $.Widget.prototype._createWidget.apply( this, arguments ); + this._trigger( 'init' ); + }, + _getCreateOptions: function() { var elem = this.element, diff --git a/tests/unit/event/event_core.js b/tests/unit/event/event_core.js index a42489d9d7b..453245d0635 100644 --- a/tests/unit/event/event_core.js +++ b/tests/unit/event/event_core.js @@ -528,4 +528,23 @@ .trigger( "resize" ) .trigger( "resize" ); }); + + asyncTest( "mousedown mouseup and click events should add a which when its not defined", function() { + var whichDefined = function( event ){ + same(event.which, 1); + }; + + $( document ).bind( "vclick", whichDefined); + $( document ).trigger( "click" ); + + $( document ).bind( "vmousedown", whichDefined); + $( document ).trigger( "mousedown" ); + + $( document ).bind( "vmouseup", function( event ){ + same(event.which, 1); + start(); + }); + + $( document ).trigger( "mouseup" ); + }); })(jQuery); diff --git a/tests/unit/navigation/index.html b/tests/unit/navigation/index.html index feb2f278113..583cf49448d 100644 --- a/tests/unit/navigation/index.html +++ b/tests/unit/navigation/index.html @@ -263,5 +263,13 @@

Dialog

back button + + + +
+ foo +
+ +
diff --git a/tests/unit/navigation/navigation_core.js b/tests/unit/navigation/navigation_core.js index 421816f8b97..d53e2df5ec8 100644 --- a/tests/unit/navigation/navigation_core.js +++ b/tests/unit/navigation/navigation_core.js @@ -40,6 +40,7 @@ $.mobile.urlHistory.stack = []; $.mobile.urlHistory.activeIndex = 0; + $.Event.prototype.which = undefined; } }); @@ -787,6 +788,38 @@ ]); }); + asyncTest( "clicks with middle mouse button are ignored", function() { + $.testHelper.pageSequence([ + function() { + $.testHelper.openPage( "#odd-clicks-page" ); + }, + + function() { + $( "#right-or-middle-click" ).click(); + }, + + // make sure the page is opening first without the mocked button click value + // only necessary to prevent issues with test specific fixtures + function() { + same($.mobile.activePage[0], $("#odd-clicks-page-dest")[0]); + $.testHelper.openPage( "#odd-clicks-page" ); + + // mock the which value to simulate a middle click + $.Event.prototype.which = 2; + }, + + function() { + $( "#right-or-middle-click" ).click(); + }, + + function( timeout ) { + ok( timeout, "page event handler timed out due to ignored click" ); + ok($.mobile.activePage[0] !== $("#odd-clicks-page-dest")[0], "pages are not the same"); + start(); + } + ]); + }); + asyncTest( "handling of button active state when navigating by clicking back button", 1, function(){ $.testHelper.pageSequence([ // open our test page diff --git a/tests/unit/widget/index.html b/tests/unit/widget/index.html index d33f51ad5fc..9dfa476b25f 100644 --- a/tests/unit/widget/index.html +++ b/tests/unit/widget/index.html @@ -5,11 +5,12 @@ jQuery Mobile Widget Test Suite + + - @@ -34,6 +35,5 @@

- diff --git a/tests/unit/widget/widget_init.js b/tests/unit/widget/widget_init.js new file mode 100644 index 00000000000..2cd47073ed6 --- /dev/null +++ b/tests/unit/widget/widget_init.js @@ -0,0 +1,16 @@ +/* + * mobile widget unit tests + */ +(function($){ + var initFired = false; + + module( 'jquery.mobile.widget.js' ); + + $( "#foo" ).live( 'pageinit', function(){ + initFired = true; + }); + + test( "widget init event is fired after markup enhancement has taken place", function() { + ok( initFired ); + }); +})( jQuery ); \ No newline at end of file