RadReveal

Reveal.js add-ons

A JavaScript library to help you extend
Reveal.js - the HTML Presentation Framework.

Reveal.js rocks!

  • Web Developers love Reveal.js.
  • I love Reveal.js because it is hackable.

...but

  • But not a lot of people customize or extend it.
  • Or if they are, they aren't sharing!

The solution? RadReveal

  • Makes customizing Reveal.js easy.
  • Attach behaviors to slides using attributes.
  • Encourages small, shareable packages.

Simple example

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);
}());

Simple example

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();

Simple example

How does that work?

  1. Reveal.initialize loads dependencies, including rad-example.js
  2. Example add-on registers self with RadReveal.register(nameString, initFunction)
  3. After Reveal is initialized, we call RadReveal.initialize();
  4. RadReveal's initialize calls example add-on's initialize, passing radConfig, allSlides
  5. Example add-on does whatever it wants.
  6. In this example, the add-on appends a class to every slide.

Beyond initialize

Imagine you want to run some code against specific slides at certain points in the slideshow.

How could you do that?

Beyond initialize

Reveal.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.

Beyond initialize

You can provide RadReveal attribute event listeners to define an attribute listener function for your add-on.

  • Listener functions are only called for slides or fragments that have specific attributes.
  • and only when specific events occur
  • You register them with RadReveal.on(attribute, eventName, function)

Beyond initialize

For 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.

Beyond initialize

These 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.

Beyond initialize

The 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.

Beyond initialize

You 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);
}());

Beyond 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.

When arriving at a slide

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);
    

a demo

The functionRunner
add-on.

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.

Run something on load

This 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:

Run when slide is shown

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:

Run when slide is hidden

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:

Now go back...

Unless you already did that, then please go forward.

Inner slide

You can use the same attributes on inner/vertical slides (hit the down arrow this time):

Second inner slide

(down again)

Third inner slide

(now go forward/right)

Fragment support

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:

  • First item
  • Second item - now go back twice and then forward.
  • Last item

In </closing>

More add-ons coming

  • I have released a few add-ons already and more on the way.
  • These are listed on the RadReveal README.

Please write your own!

The dream would be a tiny ecosystem of well written addons that folks can use to make rad presentations.

Thank you!

RadReveal