Ignore rally_conf.json
[functest-xtesting.git] / docs / com / plugin / notes-server / client.js
1 (function() {
2
3         // don't emit events from inside the previews themselves
4         if( window.location.search.match( /receiver/gi ) ) { return; }
5
6         var socket = io.connect( window.location.origin ),
7                 socketId = Math.random().toString().slice( 2 );
8
9         console.log( 'View slide notes at ' + window.location.origin + '/notes/' + socketId );
10
11         window.open( window.location.origin + '/notes/' + socketId, 'notes-' + socketId );
12
13         /**
14          * Posts the current slide data to the notes window
15          */
16         function post() {
17
18                 var slideElement = Reveal.getCurrentSlide(),
19                         notesElement = slideElement.querySelector( 'aside.notes' );
20
21                 var messageData = {
22                         notes: '',
23                         markdown: false,
24                         socketId: socketId,
25                         state: Reveal.getState()
26                 };
27
28                 // Look for notes defined in a slide attribute
29                 if( slideElement.hasAttribute( 'data-notes' ) ) {
30                         messageData.notes = slideElement.getAttribute( 'data-notes' );
31                 }
32
33                 // Look for notes defined in an aside element
34                 if( notesElement ) {
35                         messageData.notes = notesElement.innerHTML;
36                         messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string';
37                 }
38
39                 socket.emit( 'statechanged', messageData );
40
41         }
42
43         // When a new notes window connects, post our current state
44         socket.on( 'new-subscriber', function( data ) {
45                 post();
46         } );
47
48         // Monitor events that trigger a change in state
49         Reveal.addEventListener( 'slidechanged', post );
50         Reveal.addEventListener( 'fragmentshown', post );
51         Reveal.addEventListener( 'fragmenthidden', post );
52         Reveal.addEventListener( 'overviewhidden', post );
53         Reveal.addEventListener( 'overviewshown', post );
54         Reveal.addEventListener( 'paused', post );
55         Reveal.addEventListener( 'resumed', post );
56
57         // Post the initial state
58         post();
59
60 }());