Merge remote branch 'origin/master'

This commit is contained in:
scottjehl 2011-06-21 11:34:10 -04:00
commit a94f62a6e7
3 changed files with 54 additions and 46 deletions

View file

@ -75,6 +75,8 @@
});
},
// TODO move to eventSequence and invoke pageSequence with default of
// changepage event
pageSequence: function(fns, event){
var fn = fns.shift(),
self = this;
@ -94,6 +96,7 @@
clearTimeout(warnTimer);
// Let the current stack unwind before we fire off the next item in the sequence.
// TODO setTimeout(self.pageSequence, 0, [fns, event]);
setTimeout(function(){ self.pageSequence(fns, event); }, 0);
});

View file

@ -28,6 +28,8 @@
Math.abs = absFn;
$.Event.prototype.originalEvent = originalEventFn;
$.Event.prototype.preventDefault = preventDefaultFn;
$(window).unbind( "throttledresize" );
}
});
@ -69,8 +71,6 @@
$('#qunit-fixture').touchstart();
stop();
});
test( "defining event functions sets the attrFn to true", function(){
$.each(events, function(i, name){
@ -380,68 +380,68 @@
returnValue: undefined //NOTE result of unbind function call
});
});
/* The following 4 tests are async so that the throttled event triggers don't interfere with subsequent tests */
asyncTest( "throttledresize event proxies resize events", function(){
var called = false;
$(window).bind( "throttledresize", function(){
called = true;
});
$(window).trigger("resize");
setTimeout(function(){
ok( called );
$(window).unbind( "throttledresize" );
setTimeout(start, 500);
}, 500);
$.testHelper.sequence([
function(){ $(window).trigger( "resize" ); },
function(){ ok( called ); },
function(){
start();
}
], 200);
});
asyncTest( "throttledresize event prevents resize events from firing more frequently than 250ms", function(){
var called = 0;
$(window).bind( "throttledresize", function(){
called ++;
called++;
});
$(window).trigger( "resize" ).trigger( "resize" );
setTimeout(function(){
ok( called == 1 );
$(window).unbind( "throttledresize" );
setTimeout(start, 500);
}, 100);
// NOTE 250 ms * 3 = 750ms which is plenty of time
// for the events to trigger before the next test, but
// not so much time that the second resize will be triggered
// before the call to same() is made
$.testHelper.sequence([
function(){
$(window).trigger( "resize" ).trigger( "resize" );
},
// verify that only one throttled resize was called after 250ms
function(){ same( called, 1 ); },
function(){
start();
}
], 250);
});
asyncTest( "throttledresize event promises that a held call will execute after trottled timeout", function(){
var called = 0;
asyncTest( "throttledresize event promises that a held call will execute only once after throttled timeout", function(){
var called = 0;
$(window).bind( "throttledresize", function(){
called ++;
called++;
});
$(window).trigger( "resize" ).trigger( "resize" );
setTimeout(function(){
ok( called == 2 );
$(window).unbind( "throttledresize" );
setTimeout(start, 500);
}, 500);
});
asyncTest( "throttledresize event promises that a held call will execute only once after trottled timeout", function(){
var called = 0;
$(window).bind( "throttledresize", function(){
called ++;
});
$.testHelper.sequence([
// trigger a ton of throttledresize events
function(){
$(window).trigger( "resize" ).trigger( "resize" ).trigger( "resize" );
},
$(window).trigger( "resize" ).trigger( "resize" ).trigger( "resize" );
setTimeout(function(){
ok( called == 2 );
$(window).unbind( "throttledresize" );
setTimeout(start, 500);
}, 500);
// verify that after enough time has gone by to accomodate all of them
// ie 750ms, only to calls to the bound function were made
function(){
same( called, 2 );
start();
}
], 750);
});
})(jQuery);

View file

@ -6,6 +6,7 @@
<title>jQuery Mobile Event Test Suite</title>
<script src="../../../js/jquery.js"></script>
<script src="../jquery.setNameSpace.js"></script>
<script src="../../../tests/jquery.testHelper.js"></script>
<script src="../../../js/jquery.mobile.event.js"></script>
<script src="../../../js"></script>
@ -26,5 +27,9 @@
<div id="qunit-fixture"></div>
<div id="foo" data-nstest-role="page">
<a href="#bar" data-nstest-transition="flip"></a>
</div>
</body>
</html>