2018-10-26 11:29:08 +02:00
|
|
|
<!doctype html>
|
|
|
|
<html lang="en">
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
|
|
|
<title>reveal.js - Test State</title>
|
|
|
|
|
2020-03-06 20:12:20 +01:00
|
|
|
<link rel="stylesheet" href="../dist/reveal.css">
|
2020-04-22 11:37:04 +02:00
|
|
|
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
|
|
|
|
<script src="../node_modules/qunit/qunit/qunit.js"></script>
|
2018-10-26 11:29:08 +02:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body style="overflow: auto;">
|
|
|
|
|
|
|
|
<div id="qunit"></div>
|
|
|
|
<div id="qunit-fixture"></div>
|
|
|
|
|
|
|
|
<div class="reveal" style="display: none;">
|
|
|
|
|
|
|
|
<div class="slides">
|
|
|
|
|
|
|
|
<section>No state</section>
|
|
|
|
<section id="slide2" data-state="state1">State 1</section>
|
|
|
|
<section data-state="state1">State 1</section>
|
|
|
|
<section data-state="state2">State 2</section>
|
|
|
|
<section>
|
|
|
|
<section>No state</section>
|
|
|
|
<section data-state="state1">State 1</section>
|
|
|
|
<section data-state="state3">State 3</section>
|
|
|
|
<section>No state</section>
|
|
|
|
</section>
|
|
|
|
<section>No state</section>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2020-05-04 10:39:37 +02:00
|
|
|
<script src="../dist/reveal.js"></script>
|
2018-10-26 11:29:08 +02:00
|
|
|
<script>
|
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.initialize();
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
QUnit.module( 'State' );
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
QUnit.test( 'Fire events when changing slide', function( assert ) {
|
|
|
|
assert.expect( 2 );
|
|
|
|
var state1 = assert.async();
|
|
|
|
var state2 = assert.async();
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
var _onState1 = function( event ) {
|
|
|
|
assert.ok( true, 'state1 fired' );
|
|
|
|
state1();
|
|
|
|
}
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
var _onState2 = function( event ) {
|
|
|
|
assert.ok( true, 'state2 fired' );
|
|
|
|
state2();
|
|
|
|
}
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.on( 'state1', _onState1 );
|
|
|
|
Reveal.on( 'state2', _onState2 );
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.slide( 1 );
|
|
|
|
Reveal.slide( 3 );
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.off( 'state1', _onState1 );
|
|
|
|
Reveal.off( 'state2', _onState2 );
|
|
|
|
});
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
QUnit.test( 'Fire state events for vertical slides', function( assert ) {
|
|
|
|
assert.expect( 2 );
|
|
|
|
var done = assert.async( 2 );
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
var _onState1 = function( event ) {
|
|
|
|
assert.ok( true, 'state1 fired' );
|
|
|
|
done();
|
|
|
|
}
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
var _onState3 = function( event ) {
|
|
|
|
assert.ok( true, 'state3 fired' );
|
|
|
|
done();
|
|
|
|
}
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.on( 'state1', _onState1 );
|
|
|
|
Reveal.on( 'state3', _onState3 );
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.slide( 0 );
|
|
|
|
Reveal.slide( 4, 1 );
|
|
|
|
Reveal.slide( 4, 2 );
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.off( 'state1', _onState1 );
|
|
|
|
Reveal.off( 'state3', _onState3 );
|
|
|
|
});
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
QUnit.test( 'No events if state remains unchanged', function( assert ) {
|
|
|
|
var stateChanges = 0;
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
var _onEvent = function( event ) {
|
|
|
|
stateChanges += 1;
|
|
|
|
}
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.on( 'state1', _onEvent );
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.slide( 0 ); // no state
|
|
|
|
Reveal.slide( 1 ); // state1
|
|
|
|
Reveal.slide( 2 ); // state1
|
|
|
|
Reveal.prev(); // state1
|
|
|
|
Reveal.next(); // state1
|
|
|
|
Reveal.slide( 4, 1 ); // state1
|
|
|
|
Reveal.slide( 0 ); // no state
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.off( 'state1', _onEvent );
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
assert.strictEqual( stateChanges, 1, 'no event was fired when going to slide with same state' );
|
|
|
|
});
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
QUnit.test( 'Event order', function( assert ) {
|
|
|
|
var _onEvent = function( event ) {
|
|
|
|
assert.ok( Reveal.getCurrentSlide() == document.querySelector( '#slide2' ), 'correct current slide immediately after state event' );
|
|
|
|
}
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.on( 'state1', _onEvent );
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.slide( 0 );
|
|
|
|
Reveal.slide( 1 );
|
2018-10-26 11:29:08 +02:00
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
Reveal.off( 'state1', _onEvent );
|
|
|
|
});
|
2018-10-26 11:29:08 +02:00
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|