Merge remote branch 'upstream/master'

This commit is contained in:
gseguin 2011-09-15 16:11:04 -07:00
commit e4ff8fb539
9 changed files with 109 additions and 8 deletions

View file

@ -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;
}

View file

@ -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();

View file

@ -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;

View file

@ -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,

View file

@ -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);

View file

@ -263,5 +263,13 @@
<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>

View file

@ -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

View file

@ -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>
@ -34,6 +35,5 @@
<div id="foo" data-role="page">
</div>
</body>
</html>

View file

@ -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 );