Merge pull request #398 from jmdobry/multiplex-docs
[reveal.js.git] / README.md
1 # reveal.js [![Build Status](https://travis-ci.org/hakimel/reveal.js.png?branch=master)](https://travis-ci.org/hakimel/reveal.js)
2
3 A framework for easily creating beautiful presentations using HTML. [Check out the live demo](http://lab.hakim.se/reveal-js/).
4
5 reveal.js comes with a broad range of features including [nested slides](https://github.com/hakimel/reveal.js#markup), [markdown contents](https://github.com/hakimel/reveal.js#markdown), [PDF export](https://github.com/hakimel/reveal.js#pdf-export), [speaker notes](https://github.com/hakimel/reveal.js#speaker-notes) and a [JavaScript API](https://github.com/hakimel/reveal.js#api). It's best viewed in a browser with support for CSS 3D transforms but [fallbacks](https://github.com/hakimel/reveal.js/wiki/Browser-Support) are available to make sure your presentation can still be viewed elsewhere.
6
7
8 #### More reading in the Wiki:
9 - [Changelog](https://github.com/hakimel/reveal.js/wiki/Changelog): Up-to-date version history.
10 - [Examples](https://github.com/hakimel/reveal.js/wiki/Example-Presentations): Presentations created with reveal.js, add your own!
11 - [Browser Support](https://github.com/hakimel/reveal.js/wiki/Browser-Support): Explanation of browser support and fallbacks.
12
13 ## rvl.io
14
15 Slides are written using HTML or markdown but there's also an online editor for those of you who prefer a more traditional user interface. Give it a try at [www.rvl.io](http://www.rvl.io).
16
17
18 ## Instructions
19
20 ### Markup
21
22 Markup heirarchy needs to be ``<div class="reveal"> <div class="slides"> <section>`` where the ``<section>`` represents one slide and can be repeated indefinitely. If you place multiple ``<section>``'s inside of another ``<section>`` they will be shown as vertical slides. The first of the vertical slides is the "root" of the others (at the top), and it will be included in the horizontal sequence. For example:
23
24 ```html
25 <div class="reveal">
26         <div class="slides">
27                 <section>Single Horizontal Slide</section>
28                 <section>
29                         <section>Vertical Slide 1</section>
30                         <section>Vertical Slide 2</section>
31                 </section>
32         </div>
33 </div>
34 ```
35
36 ### Markdown
37
38 It's possible to write your slides using Markdown. To enable Markdown, add the ```data-markdown``` attribute to your ```<section>``` elements and wrap the contents in a ```<script type="text/template">``` like the example below.
39
40 This is based on [data-markdown](https://gist.github.com/1343518) from [Paul Irish](https://github.com/paulirish) which in turn uses [showdown](https://github.com/coreyti/showdown/). Sensitive to indentation (avoid mixing tabs and spaces) and line breaks (avoid consecutive breaks).
41
42 ```html
43 <section data-markdown>
44         <script type="text/template">
45                 ## Page title
46
47                 A paragraph with some text and a [link](http://hakim.se).
48         </script>
49 </section>
50 ```
51
52 #### External Markdown
53
54 You can write your content as a separate file and have reveal.js load it at runtime. Note the separator arguments which determine how slides are delimited in the external file.
55
56 ```html
57 <section data-markdown="example.md" data-separator="^\n\n\n" data-vertical="^\n\n"></section>
58 ```
59
60 ### Configuration
61
62 At the end of your page you need to initialize reveal by running the following code. Note that all config values are optional and will default as specified below.
63
64 ```javascript
65 Reveal.initialize({
66
67         // Display controls in the bottom right corner
68         controls: true,
69
70         // Display a presentation progress bar
71         progress: true,
72
73         // Push each slide change to the browser history
74         history: false,
75
76         // Enable keyboard shortcuts for navigation
77         keyboard: true,
78
79         // Enable the slide overview mode
80         overview: true,
81
82         // Vertical centering of slides
83         center: true,
84
85         // Loop the presentation
86         loop: false,
87
88         // Change the presentation direction to be RTL
89         rtl: false,
90
91         // Number of milliseconds between automatically proceeding to the
92         // next slide, disabled when set to 0, this value can be overwritten
93         // by using a data-autoslide attribute on your slides
94         autoSlide: 0,
95
96         // Enable slide navigation via mouse wheel
97         mouseWheel: false,
98
99         // Apply a 3D roll to links on hover
100         rollingLinks: true,
101
102         // Transition style
103         transition: 'default', // default/cube/page/concave/zoom/linear/fade/none
104
105         // Transition speed
106         transitionSpeed: 'default', // default/fast/slow
107
108 });
109 ```
110
111 Note that the new default vertical centering option will break compatibility with slides that were using transitions with backgrounds (`cube` and `page`). To restore the previous behavior, set `center` to `false`.
112
113
114 The configuration can be updated after initialization using the ```configure``` method:
115
116 ```javascript
117 // Turn autoSlide off
118 Reveal.configure({ autoSlide: 0 });
119
120 // Start auto-sliding every 5s
121 Reveal.configure({ autoSlide: 5000 });
122 ```
123
124
125 ### Presentation Size
126
127 All presentations have a normal size, that is the resolution at which they are authored. The framework will automatically scale presentations uniformly based on this size to ensure that everything fits on any given display or viewport.
128
129 See below for a list of configuration options related to sizing, including default values:
130
131 ```javascript
132 Reveal.initialize({
133
134         ...
135
136         // The "normal" size of the presentation, aspect ratio will be preserved
137         // when the presentation is scaled to fit different resolutions. Can be
138         // specified using percentage units.
139         width: 960,
140         height: 700,
141
142         // Factor of the display size that should remain empty around the content
143         margin: 0.1,
144
145         // Bounds for smallest/largest possible scale to apply to content
146         minScale: 0.2,
147         maxScale: 1.0
148
149 });
150 ```
151
152
153 ### Dependencies
154
155 Reveal.js doesn't _rely_ on any third party scripts to work but a few optional libraries are included by default. These libraries are loaded as dependencies in the order they appear, for example:
156
157 ```javascript
158 Reveal.initialize({
159         dependencies: [
160                 // Cross-browser shim that fully implements classList - https://github.com/eligrey/classList.js/
161                 { src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
162
163                 // Interpret Markdown in <section> elements
164                 { src: 'plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
165                 { src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
166
167                 // Syntax highlight for <code> elements
168                 { src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
169
170                 // Zoom in and out with Alt+click
171                 { src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
172
173                 // Speaker notes
174                 { src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } },
175
176                 // Remote control your reveal.js presentation using a touch device
177                 { src: 'plugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } }
178         ]
179 });
180 ```
181
182 You can add your own extensions using the same syntax. The following properties are available for each dependency object:
183 - **src**: Path to the script to load
184 - **async**: [optional] Flags if the script should load after reveal.js has started, defaults to false
185 - **callback**: [optional] Function to execute when the script has loaded
186 - **condition**: [optional] Function which must return true for the script to be loaded
187
188
189 ### API
190
191 The ``Reveal`` class provides a minimal JavaScript API for controlling navigation and reading state:
192
193 ```javascript
194 // Navigation
195 Reveal.slide( indexh, indexv, indexf );
196 Reveal.left();
197 Reveal.right();
198 Reveal.up();
199 Reveal.down();
200 Reveal.prev();
201 Reveal.next();
202 Reveal.prevFragment();
203 Reveal.nextFragment();
204 Reveal.toggleOverview();
205
206 // Retrieves the previous and current slide elements
207 Reveal.getPreviousSlide();
208 Reveal.getCurrentSlide();
209
210 Reveal.getIndices(); // { h: 0, v: 0 } }
211 ```
212
213 ### States
214
215 If you set ``data-state="somestate"`` on a slide ``<section>``, "somestate" will be applied as a class on the document element when that slide is opened. This allows you to apply broad style changes to the page based on the active slide.
216
217 Furthermore you can also listen to these changes in state via JavaScript:
218
219 ```javascript
220 Reveal.addEventListener( 'somestate', function() {
221         // TODO: Sprinkle magic
222 }, false );
223 ```
224
225 ### Ready event
226
227 The 'ready' event is fired when reveal.js has loaded all (synchronous) dependencies and is ready to start navigating.
228
229 ```javascript
230 Reveal.addEventListener( 'ready', function( event ) {
231         // event.currentSlide, event.indexh, event.indexv
232 } );
233 ```
234
235 ### Slide change event
236
237 An 'slidechanged' event is fired each time the slide is changed (regardless of state). The event object holds the index values of the current slide as well as a reference to the previous and current slide HTML nodes.
238
239 Some libraries, like MathJax (see [#226](https://github.com/hakimel/reveal.js/issues/226#issuecomment-10261609)), get confused by the transforms and display states of slides. Often times, this can be fixed by calling their update or render function from this callback.
240
241 ```javascript
242 Reveal.addEventListener( 'slidechanged', function( event ) {
243         // event.previousSlide, event.currentSlide, event.indexh, event.indexv
244 } );
245 ```
246
247 ### Internal links
248
249 It's easy to link between slides. The first example below targets the index of another slide whereas the second targets a slide with an ID attribute (```<section id="some-slide">```):
250
251 ```html
252 <a href="#/2/2">Link</a>
253 <a href="#/some-slide">Link</a>
254 ```
255
256 You can also add relative navigation links, similar to the built in reveal.js controls, by appending one of the following classes on any element. Note that each element is automatically given an ```enabled``` class when it's a valid navigation route based on the current slide.
257
258 ```html
259 <a href="#" class="navigate-left">
260 <a href="#" class="navigate-right">
261 <a href="#" class="navigate-up">
262 <a href="#" class="navigate-down">
263 <a href="#" class="navigate-prev"> <!-- Previous vertical or horizontal slide -->
264 <a href="#" class="navigate-next"> <!-- Next vertical or horizontal slide -->
265 ```
266
267 ### Alternating transitions
268 The global presentation transition is set using the ```transition``` config value. You can override the global transition for a specific slide by using the ```data-transition``` attribute:
269
270 ```html
271 <section data-transition="zoom">
272         <h2>This slide will override the presentation transition and zoom!</h2>
273 </section>
274
275 <section data-transition-speed="fast">
276         <h2>Choose from three transition speeds: default, fast or slow!</h2>
277 </section>
278 ```
279
280 Note that this does not work with the page and cube transitions.
281
282
283 ### Fragments
284 Fragments are used to highlight individual elements on a slide. Every elmement with the class ```fragment``` will be stepped through before moving on to the next slide. Here's an example: http://lab.hakim.se/reveal-js/#/16
285
286 The default fragment style is to start out invisible and fade in. This style can be changed by appending a different class to the fragment:
287
288 ```html
289 <section>
290         <p class="fragment grow">grow</p>
291         <p class="fragment shrink">shrink</p>
292         <p class="fragment roll-in">roll-in</p>
293         <p class="fragment fade-out">fade-out</p>
294         <p class="fragment highlight-red">highlight-red</p>
295         <p class="fragment highlight-green">highlight-green</p>
296         <p class="fragment highlight-blue">highlight-blue</p>
297 </section>
298 ```
299
300 Multiple fragments can be applied to the same element sequentially by wrapping it, this will fade in the text on the first step and fade it back out on the second.
301
302 ```html
303 <section>
304         <span class="fragment fade-in">
305                 <span class="fragment fade-out">I'll fade in, then out</span>
306         </span>
307 </section>
308 ```
309
310 The display order of fragments can be controlled using the ```data-fragment-index``` attribute.
311
312 ```html
313 <section>
314         <p class="fragment" data-fragment-index="3">Appears last</p>
315         <p class="fragment" data-fragment-index="1">Appears first</p>
316         <p class="fragment" data-fragment-index="2">Appears second</p>
317 </section>
318 ```
319
320 ### Fragment events
321
322 When a slide fragment is either shown or hidden reveal.js will dispatch an event.
323
324 ```javascript
325 Reveal.addEventListener( 'fragmentshown', function( event ) {
326         // event.fragment = the fragment DOM element
327 } );
328 Reveal.addEventListener( 'fragmenthidden', function( event ) {
329         // event.fragment = the fragment DOM element
330 } );
331 ```
332
333 ### Code syntax highlighting
334
335 By default, Reveal is configured with [highlight.js](http://softwaremaniacs.org/soft/highlight/en/) for code syntax highlighting. Below is an example with clojure code that will be syntax highlighted:
336
337 ```html
338 <section>
339         <pre><code>
340 (def lazy-fib
341   (concat
342    [0 1]
343    ((fn rfib [a b]
344         (lazy-cons (+ a b) (rfib b (+ a b)))) 0 1)))
345         </code></pre>
346 </section>
347 ```
348
349
350 ### Overview mode
351
352 Press "Esc" key to toggle the overview mode on and off. While you're in this mode, you can still navigate between slides,
353 as if you were at 1,000 feet above your presentation. The overview mode comes with a few API hooks:
354
355 ```javascript
356 Reveal.addEventListener( 'overviewshown', function( event ) { /* ... */ } );
357 Reveal.addEventListener( 'overviewhidden', function( event ) { /* ... */ } );
358
359 // Toggle the overview mode programmatically
360 Reveal.toggleOverview();
361 ```
362
363 ### Fullscreen mode
364 Just press Â»F« on your keyboard to show your presentation in fullscreen mode. Press the Â»ESC« key to exit fullscreen mode.
365
366
367 ## PDF Export
368
369 Presentations can be exported to PDF via a special print stylesheet. This feature requires that you use [Google Chrome](http://google.com/chrome).
370 Here's an example of an exported presentation that's been uploaded to SlideShare: http://www.slideshare.net/hakimel/revealjs-13872948.
371
372 1. Open your presentation with [css/print/pdf.css](https://github.com/hakimel/reveal.js/blob/master/css/print/pdf.css) included on the page. The default index HTML lets you add *print-pdf* anywhere in the query to include the stylesheet, for example: [lab.hakim.se/reveal-js?print-pdf](http://lab.hakim.se/reveal-js?print-pdf).
373 2. Open the in-browser print dialog (CMD+P).
374 3. Change the **Destination** setting to **Save as PDF**.
375 4. Change the **Layout** to **Landscape**.
376 5. Change the **Margins** to **None**.
377 6. Click **Save**.
378
379 ![Chrome Print Settings](https://s3.amazonaws.com/hakim-static/reveal-js/pdf-print-settings.png)
380
381
382 ## Speaker Notes
383
384 reveal.js comes with a speaker notes plugin which can be used to present per-slide notes in a separate browser window. The notes window also gives you a preview of the next upcoming slide so it may be helpful even if you haven't written any notes. Append ```?notes``` to the presentation URL or press the 's' key on your keyboard to open the notes window.
385
386 By default notes are written using standard HTML, see below, but you can add a ```data-markdown``` attribute to the ```<aside>``` to write them using Markdown.
387
388 ```html
389 <section>
390         <h2>Some Slide</h2>
391
392         <aside class="notes">
393                 Oh hey, these are some notes. They'll be hidden in your presentation, but you can see them if you open the speaker notes window (hit 's' on your keyboard).
394         </aside>
395 </section>
396 ```
397
398 ## Server Side Speaker Notes
399
400 In some cases it can be desirable to run notes on a separate device from the one you're presenting on. The Node.js-based notes plugin lets you do this using the same note definitions as its client side counterpart. Include the required scripts by adding the following dependencies:
401
402 ```javascript
403 Reveal.initialize({
404         ...
405
406         dependencies: [
407                 { src: 'socket.io/socket.io.js', async: true },
408                 { src: 'plugin/notes-server/client.js', async: true }
409         ]
410 });
411 ```
412
413 Then:
414
415 1. Install [Node.js](http://nodejs.org/)
416 2. Run ```npm install```
417 3. Run ```node plugin/notes-server```
418
419
420 ## Multiplexing
421
422 The multiplex plugin allows your audience to view the slides of the presentation you are controlling on their own phone, tablet or laptop. As the master presentation navigates the slides, all client presentations will update in real time. See a demo at [http://revealjs.jit.su/](http://revealjs.jit.su).
423
424 The multiplex plugin needs the following 3 things to operate:
425
426 1. Master presentation that has control
427 2. Client presentations that follow the master
428 3. Socket.io server to broadcast events from the master to the clients
429
430 More details:
431
432 #### Master presentation
433 Served from a static file server accessible (preferably) only to the presenter. This need only be on your (the presenter's) computer. (It's safer to run the master presentation from your own computer, so if the venue's Internet goes down it doesn't stop the show.) An example would be to execute the following commands in the directory of your master presentation: 
434
435 1. ```npm install node-static```
436 2. ```static```
437
438 If you want to use the speaker notes plugin with you master presentation then make sure you have the speaker notes plugin configured correctly along with the configuration shown below, then execute ```node plugin/notes-server``` in the directory of your master presentation. The configuration below will cause it to connect to the socket.io server as a master, as well as launch your speaker-notes/static-file server.
439
440 You can then access your master presentation at ```http://localhost:1947```
441
442 Example configuration:
443 ```javascript
444 Reveal.initialize({
445         // other options
446
447         multiplex: {
448                 // Example values. Generate your own.
449                 secret: '13652805320794272084', // Obtained from the socket.io server. Gives this (the master) control of the presentation
450                 id: '1ea875674b17ca76', // Obtained from socket.io server
451                 url: 'revealjs.jit.su:80' // Location of socket.io server
452         },
453
454         // Optional libraries used to extend on reveal.js
455         dependencies: [
456                 // other deps
457                 { src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.10/socket.io.min.js', async: true },
458                 { src: 'plugin/multiplex/master.js', async: true },
459
460                 // and if you want speaker notes
461                 { src: 'plugin/notes-server/client.js', async: true }
462         ]
463 });
464 ```
465
466 #### Client presentation
467 Served from a publicly accessible static file server. Examples include: GitHub Pages, Amazon S3, Dreamhost, Akamai, etc. The more reliable, the better. Your audience can then access the client presentation via ```http://example.com/path/to/presentation/client/index.html```, with the configuration below causing them to connect to the socket.io server as clients.
468
469 Example configuration:
470 ```javascript
471 Reveal.initialize({
472         // other options
473
474         multiplex: {
475                 // Example values. Generate your own.
476                 secret: null, // null so the clients do not have control of the master presentation
477                 id: '1ea875674b17ca76', // id, obtained from socket.io server
478                 url: 'revealjs.jit.su:80' // Location of socket.io server
479         },
480
481         // Optional libraries used to extend on reveal.js
482         dependencies: [
483                 // other deps
484                 { src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.10/socket.io.min.js', async: true },
485                 { src: 'plugin/multiplex/client.js', async: true }
486         ]
487 });
488 ```
489
490 #### Socket.io server
491 Server that receives the slideChanged events from the master presentation and broadcasts them out to the connected client presentations. This needs to be publicly accessible. You can run your own socket.io server with the commands:
492
493 1. ```npm install```
494 2. ```node plugin/multiplex```
495
496 Or you use the socket.io server at [http://revealjs.jit.su](http://revealjs.jit.su).
497
498 You'll need to generate a unique secret and token pair for your master and client presentations. To do so, visit ```http://example.com/token```, where ```http://example.com``` is the location of your socket.io server. Or if you're going to use the socket.io server at [http://revealjs.jit.su](http://revealjs.jit.su), visit [http://revealjs.jit.su/token](http://revealjs.jit.su/token).
499
500 You are very welcome to point your presentations at the Socket.io server running at [http://revealjs.jit.su](http://revealjs.jit.su), but availability and stability are not guaranteed. For anything mission critical I recommend you run your own server. It is simple to deploy to nodejitsu, heroku, your own environment, etc.
501
502 ##### socket.io server as file static server
503
504 The socket.io server can play the role of static file server for your client presentation, as in the example at [http://revealjs.jit.su](http://revealjs.jit.su). (Open [http://revealjs.jit.su](http://revealjs.jit.su) in two browsers. Navigate through the slides on one, and the other will update to match.) 
505
506 Example configuration:
507 ```javascript
508 Reveal.initialize({
509         // other options
510
511         multiplex: {
512                 // Example values. Generate your own.
513                 secret: null, // null so the clients do not have control of the master presentation
514                 id: '1ea875674b17ca76', // id, obtained from socket.io server
515                 url: 'example.com:80' // Location of your socket.io server
516         },
517
518         // Optional libraries used to extend on reveal.js
519         dependencies: [
520                 // other deps
521                 { src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.10/socket.io.min.js', async: true },
522                 { src: 'plugin/multiplex/client.js', async: true }
523         ]
524 ```
525
526 It can also play the role of static file server for your master presentation and client presentations at the same time (as long as you don't want to use speaker notes). (Open [http://revealjs.jit.su](http://revealjs.jit.su) in two browsers. Navigate through the slides on one, and the other will update to match. Navigate through the slides on the second, and the first will update to match.) This is probably not desirable, because you don't want your audience to mess with your slides while you're presenting. ;)
527
528 Example configuration:
529 ```javascript
530 Reveal.initialize({
531         // other options
532
533         multiplex: {
534                 // Example values. Generate your own.
535                 secret: '13652805320794272084', // Obtained from the socket.io server. Gives this (the master) control of the presentation
536                 id: '1ea875674b17ca76', // Obtained from socket.io server
537                 url: 'example.com:80' // Location of your socket.io server
538         },
539
540         // Optional libraries used to extend on reveal.js
541         dependencies: [
542                 // other deps
543                 { src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.10/socket.io.min.js', async: true },
544                 { src: 'plugin/multiplex/master.js', async: true },
545                 { src: 'plugin/multiplex/client.js', async: true }
546         ]
547 });
548 ```
549
550 ## Theming
551
552 The framework comes with a few different themes included:
553
554 - default: Gray background, white text, blue links
555 - beige: Beige background, dark text, brown links
556 - sky: Blue background, thin white text, blue links
557 - night: Black background, thick white text, orange links
558 - serif: Cappuccino background, gray text, brown links
559 - simple: White background, black text, blue links
560
561 Each theme is available as a separate stylesheet. To change theme you will need to replace **default** below with your desired theme name in index.html:
562
563 ```html
564 <link rel="stylesheet" href="css/theme/default.css" id="theme">
565 ```
566
567 If you want to add a theme of your own see the instructions here: [/css/theme/README.md](https://github.com/hakimel/reveal.js/blob/master/css/theme/README.md).
568
569
570 ## Development Environment
571
572 reveal.js is built using the task-based command line build tool [grunt.js](http://gruntjs.com) ([installation instructions](http://gruntjs.com/getting-started#installing-the-cli)). With Node.js and grunt.js installed, you need to start by running ```npm install``` in the reveal.js root. When the dependencies have been installed you should run ```grunt watch``` to start monitoring files for changes.
573
574 If you want to customise reveal.js without running grunt.js you can alter the HTML to point to the uncompressed source files (css/reveal.css & js/reveal.js).
575
576 ### Folder Structure
577 - **css/** Core styles without which the project does not function
578 - **js/** Like above but for JavaScript
579 - **plugin/** Components that have been developed as extensions to reveal.js
580 - **lib/** All other third party assets (JavaScript, CSS, fonts)
581
582
583 ## License
584
585 MIT licensed
586
587 Copyright (C) 2013 Hakim El Hattab, http://hakim.se
588