2019-03-14 16:03:55 +01:00
|
|
|
<!doctype html>
|
|
|
|
<html lang="en">
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
|
|
|
<title>reveal.js - Test Plugins</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>
|
2019-03-14 16:03:55 +01: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>Slide content</section>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2020-05-04 10:39:37 +02:00
|
|
|
<script src="../dist/reveal.js"></script>
|
2019-03-14 16:03:55 +01:00
|
|
|
<script>
|
|
|
|
|
2023-01-10 10:24:41 +01:00
|
|
|
QUnit.config.testTimeout = 30000;
|
2019-03-14 16:03:55 +01:00
|
|
|
QUnit.module( 'Plugins' );
|
|
|
|
|
|
|
|
var initCounter = { PluginB: 0, PluginC: 0, PluginD: 0 };
|
|
|
|
|
|
|
|
// Plugin with no init method
|
2020-04-08 13:05:28 +02:00
|
|
|
var PluginA = { id: 'PluginA' };
|
2019-03-14 16:03:55 +01:00
|
|
|
|
|
|
|
// Plugin with init method
|
2020-04-08 13:05:28 +02:00
|
|
|
var PluginB = { id: 'PluginB', init: function() {
|
2019-03-14 16:03:55 +01:00
|
|
|
initCounter['PluginB'] += 1;
|
|
|
|
} };
|
|
|
|
|
|
|
|
// Async plugin with init method
|
2020-04-08 13:05:28 +02:00
|
|
|
var PluginC = { id: 'PluginC', init: function() {
|
2019-03-14 16:03:55 +01:00
|
|
|
return new Promise(function( resolve ) {
|
|
|
|
setTimeout( () => {
|
|
|
|
initCounter['PluginC'] += 1;
|
|
|
|
resolve();
|
|
|
|
}, 1000 );
|
|
|
|
});
|
|
|
|
} };
|
|
|
|
|
|
|
|
// Plugin initialized after reveal.js is ready
|
2020-04-08 13:05:28 +02:00
|
|
|
var PluginD = { id: 'PluginD', init: function() {
|
2019-03-14 16:03:55 +01:00
|
|
|
initCounter['PluginD'] += 1;
|
|
|
|
} };
|
|
|
|
|
2020-04-08 13:05:28 +02:00
|
|
|
var PluginE = { id: 'PluginE' };
|
2019-04-01 11:07:11 +02:00
|
|
|
|
2020-04-17 14:21:20 +02:00
|
|
|
var reveal = new Reveal( document.querySelector( '.reveal' ), {
|
|
|
|
plugins: [ PluginA ]
|
|
|
|
} );
|
2020-03-07 18:19:08 +01:00
|
|
|
|
2020-04-08 13:05:28 +02:00
|
|
|
reveal.registerPlugin( PluginB );
|
|
|
|
reveal.registerPlugin( PluginC );
|
2019-03-14 16:03:55 +01:00
|
|
|
|
2020-03-07 18:19:08 +01:00
|
|
|
reveal.initialize();
|
2019-03-14 16:03:55 +01:00
|
|
|
|
|
|
|
QUnit.test( 'Can initialize synchronously', function( assert ) {
|
|
|
|
assert.strictEqual( initCounter['PluginB'], 1 );
|
|
|
|
|
2020-04-08 13:05:28 +02:00
|
|
|
reveal.registerPlugin( PluginB );
|
2019-03-14 16:03:55 +01:00
|
|
|
|
|
|
|
assert.strictEqual( initCounter['PluginB'], 1, 'prevents duplicate registration' );
|
|
|
|
});
|
|
|
|
|
2019-04-01 11:07:11 +02:00
|
|
|
QUnit.test( 'Can initialize asynchronously', function( assert ) {
|
2019-03-14 16:03:55 +01:00
|
|
|
assert.expect( 3 );
|
|
|
|
var done = assert.async( 2 );
|
|
|
|
|
|
|
|
assert.strictEqual( initCounter['PluginC'], 0, 'async plugin not immediately initialized' );
|
|
|
|
|
2020-04-07 09:05:56 +02:00
|
|
|
reveal.on( 'ready', function() {
|
2019-03-14 16:03:55 +01:00
|
|
|
assert.strictEqual( initCounter['PluginC'], 1, 'finsihed initializing when reveal.js dispatches "ready"' );
|
|
|
|
done();
|
|
|
|
|
2020-04-08 13:05:28 +02:00
|
|
|
reveal.registerPlugin( PluginD );
|
2019-03-14 16:03:55 +01:00
|
|
|
assert.strictEqual( initCounter['PluginD'], 1, 'plugin registered after reveal.js is ready still initiailizes' );
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
} );
|
2019-04-01 11:07:11 +02:00
|
|
|
|
|
|
|
QUnit.test( 'Can check if plugin is registered', function( assert ) {
|
2020-03-07 18:19:08 +01:00
|
|
|
assert.strictEqual( reveal.hasPlugin( 'PluginA' ), true );
|
|
|
|
assert.strictEqual( reveal.hasPlugin( 'PluginE' ), false );
|
2020-04-08 13:05:28 +02:00
|
|
|
reveal.registerPlugin( PluginE );
|
2020-03-07 18:19:08 +01:00
|
|
|
assert.strictEqual( reveal.hasPlugin( 'PluginE' ), true );
|
2019-04-01 11:07:11 +02:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'Can retrieve plugin instance', function( assert ) {
|
2020-03-07 18:19:08 +01:00
|
|
|
assert.strictEqual( reveal.getPlugin( 'PluginB' ), PluginB );
|
2019-04-01 11:07:11 +02:00
|
|
|
} );
|
2019-03-14 16:03:55 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|