Skip to content

Commit

Permalink
Merge remote branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gseguin committed Sep 15, 2011
2 parents a908c5a + f932c9b commit e4ff8fb
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 8 deletions.
11 changes: 10 additions & 1 deletion js/jquery.mobile.navigation.js
Expand Up @@ -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 !== "#" ) {
Expand All @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions js/jquery.mobile.navigation.pushstate.js
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions js/jquery.mobile.vmouse.js
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions js/jquery.mobile.widget.js
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/event/event_core.js
Expand Up @@ -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);
8 changes: 8 additions & 0 deletions tests/unit/navigation/index.html
Expand Up @@ -263,5 +263,13 @@ <h1>Dialog</h1>
<a href="#active-state-page1" data-nstest-rel="back" data-nstest-role="button">back button</a>
</div>
</div>



<div id="odd-clicks-page" data-nstest-role="page">
<a href="#odd-clicks-page-dest" id="right-or-middle-click">foo</a>
</div>

<div id="odd-clicks-page-dest" data-nstest-role="page"></div>
</body>
</html>
33 changes: 33 additions & 0 deletions tests/unit/navigation/navigation_core.js
Expand Up @@ -40,6 +40,7 @@

$.mobile.urlHistory.stack = [];
$.mobile.urlHistory.activeIndex = 0;
$.Event.prototype.which = undefined;
}
});

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/widget/index.html
Expand Up @@ -5,11 +5,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Widget Test Suite</title>

<script src="../../../external/qunit.js"></script>
<script src="../../../js/jquery.js"></script>
<script src="widget_init.js"></script>
<script src="../../../js/"></script>

<link rel="stylesheet" href="../../../external/qunit.css"/>
<script src="../../../external/qunit.js"></script>

<script src="widget_core.js"></script>
</head>
Expand All @@ -34,6 +35,5 @@ <h2 id="qunit-userAgent"></h2>
<div id="foo" data-role="page">
</div>


</body>
</html>
16 changes: 16 additions & 0 deletions 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 );

0 comments on commit e4ff8fb

Please sign in to comment.