A JavaScript library to help you extend
Reveal.js - the HTML Presentation Framework.
What does an add-on look like?
rad-example.js
(function() {
var RadReveal = require('rad-reveal');
function exampleInit(radConfig, slides) {
for(var s = 0, len = slides.length; s < len; s++) {
slides[s].className += ' ' + radConfig.addClass;
}
}
RadReveal.register('example', exampleInit);
}());
How is it loaded?
Reveal.initialize({
... normal Reveal configuration here
dependencies: [
{
//include it just like a normal dependency,
// but with radName and radConfig properties
src: 'somepath/rad-example.js',
radName: 'example',
radConfig: { addClass: 'example' }
}
... other dependencies go here
]
});
var RadReveal = require('rad-reveal');
RadReveal.initialize();
How does that work?
Reveal.initialize loads dependencies, including rad-example.jsRadReveal.register(nameString, initFunction)RadReveal.initialize();initialize calls example add-on's initialize,
passing radConfig, allSlidesinitializeImagine you want to run some code against specific slides at certain points in the slideshow.
How could you do that?
initializeReveal.js provides some data attributes you can attach to slides to cause certain behaviors (different transitions, backgrounds, etc).
RadReveal allows you to use a similar approach.
initializeYou can provide RadReveal attribute event listeners to define an attribute listener function for your add-on.
RadReveal.on(attribute, eventName, function)initializeFor example, in our example add-on we could have:
RadReveal.on('data-rad-example', 'load', someFunction);
For any slide with the data-rad-example attribute, someFunction
will be called when the add-on loads.
initializeThese events are available for listeners:
load is fired when the add-on is loaded.init is fired when RadReveal.initialize is called.show is fired when the matching slide or fragment is displayed.hide is fired when the matching slide or fragment is hidden.initializeThe listener function is called with four arguments:
attrVal, the value of the attribute for this slide or fragment.slideObj, an object representing the slide or fragment.event, the event object.radEventName, the name of the event.initializeYou can use this to do something to the slide element. For example, we could add a class based on the attribute value.
(function() {
var RadReveal = require('rad-reveal');
function addTheClass(attrVal, slideObj, event, radEventName) {
slideObj.element.className += ' ' + attrVal;
}
RadReveal.on('data-rad-example', 'load', addTheClass);
}());
initialize...which would mean that this slide:
<section data-rad-example="totallyRad">
would end up having an additional class
of totallyRad
added to it:
<section data-rad-example="totallyRad" class="totallyRad">
which is a silly example but illustrates the point.
If you wanted to run a function upon showing or hiding a slide with a specific attribute, you could do this:
RadReveal.on('data-rad-example', 'show, hide', doSomething);
functionRunner
functionRunner is a simple add-on that triggers a function to run for
any slide whose section tag has a
data-rad-functionrunner-{eventName} attribute.
loadThis slide has a data-rad-functionrunner-load attr:
<section data-rad-functionrunner-load='{"root":"bar","func":"baz"}'>
and the page has a (global) bar object defined:
var bar = {
value: 'Hello world!',
baz: function(slideObj, event, radEventName) {
var span = document.createElement('span');
span.innerHTML = radEventName + ': ' + this.value;
slideObj.element.appendChild(span);
}
}
which together results in the text being added to the slide:
This slide has a data-rad-functionrunner-show attr:
<section
data-rad-functionrunner-show='{"func":"foo","args":["show","1"]}'>
and the page has a (global) function foo defined:
function foo(arg0, slideObj, event, radEventName) {
var span = document.createElement('span');
span.innerHTML = radEventName + ' with ' + arg0;
slideObj.element.appendChild(span);
}
which results in appending some HTML to the slide every time it is displayed:
This slide has a data-rad-functionrunner-hide attr:
<section
data-rad-functionrunner-hide='{"func":"foo","args":["2"]}'>
and we're still using the foo function.
If you go to the next slide and then come back, you should see something appended to the page here:
Unless you already did that, then please go forward.
You can use the same attributes on inner/vertical slides (hit the down arrow this time):
(down again)
(now go forward/right)
The first fragment on this slide has these attributes:
<li class="fragment"
data-rad-functionrunner-load='{ "func" : "foo", "args": ["3"] }'
data-rad-functionrunner-show='{ "func" : "foo", "args": ["3"] }'
data-rad-functionrunner-hide='{ "func" : "foo", "args": ["3"] }'>
You will see the results as you proceed:
The dream would be a tiny ecosystem of well written addons that folks can use to make rad presentations.