aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2019-04-01 11:07:11 +0200
committerHakim El Hattab <hakim.elhattab@gmail.com>2019-04-01 11:07:11 +0200
commitdf25fbebba5fe37e8b94d0d8329a9513a2cb76f9 (patch)
tree1833968674c8d070b3c7357ba7623d4b72578304
parentd6f0f41f771a6e6b4b53a7653ea0cc3c864a4d19 (diff)
downloadperl-software-in-gnu-guix-df25fbebba5fe37e8b94d0d8329a9513a2cb76f9.tar
perl-software-in-gnu-guix-df25fbebba5fe37e8b94d0d8329a9513a2cb76f9.tar.gz
add hasPlugin and getPlugin API methods and tests
-rw-r--r--js/reveal.js27
-rw-r--r--test/test-plugins.html15
2 files changed, 40 insertions, 2 deletions
diff --git a/js/reveal.js b/js/reveal.js
index 0437d2d..09f3af7 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -1595,6 +1595,29 @@
}
/**
+ * Checks if a specific plugin has been registered.
+ *
+ * @param {String} id Unique plugin identifier
+ */
+ function hasPlugin( id ) {
+
+ return !!plugins[id];
+
+ }
+
+ /**
+ * Returns the specific plugin instance, if a plugin
+ * with the given ID has been registered.
+ *
+ * @param {String} id Unique plugin identifier
+ */
+ function getPlugin( id ) {
+
+ return plugins[id];
+
+ }
+
+ /**
* Add a custom key binding with optional description to
* be added to the help screen.
*/
@@ -5975,8 +5998,10 @@
addKeyBinding: addKeyBinding,
removeKeyBinding: removeKeyBinding,
- // Called by plugins to register themselves
+ // API for registering and retrieving plugins
registerPlugin: registerPlugin,
+ hasPlugin: hasPlugin,
+ getPlugin: getPlugin,
// Programatically triggers a keyboard event
triggerKey: function( keyCode ) {
diff --git a/test/test-plugins.html b/test/test-plugins.html
index 13e3692..dfd65b7 100644
--- a/test/test-plugins.html
+++ b/test/test-plugins.html
@@ -57,6 +57,8 @@
initCounter['PluginD'] += 1;
} };
+ var PluginE = {};
+
Reveal.registerPlugin( 'PluginA', PluginA );
Reveal.registerPlugin( 'PluginB', PluginB );
Reveal.registerPlugin( 'PluginC', PluginC );
@@ -71,7 +73,7 @@
assert.strictEqual( initCounter['PluginB'], 1, 'prevents duplicate registration' );
});
- QUnit.test( 'Can initialie asynchronously', function( assert ) {
+ QUnit.test( 'Can initialize asynchronously', function( assert ) {
assert.expect( 3 );
var done = assert.async( 2 );
@@ -86,6 +88,17 @@
done();
});
} );
+
+ QUnit.test( 'Can check if plugin is registered', function( assert ) {
+ assert.strictEqual( Reveal.hasPlugin( 'PluginA' ), true );
+ assert.strictEqual( Reveal.hasPlugin( 'PluginE' ), false );
+ Reveal.registerPlugin( 'PluginE', PluginE );
+ assert.strictEqual( Reveal.hasPlugin( 'PluginE' ), true );
+ } );
+
+ QUnit.test( 'Can retrieve plugin instance', function( assert ) {
+ assert.strictEqual( Reveal.getPlugin( 'PluginB' ), PluginB );
+ } );
</script>
</body>