BeamerReveal

 view release on metacpan or  search on metacpan

share/libs/revealjs/plugin/notes/jojo.html  view on Meta::CPAN

	      if( window.location.origin !== event.origin && window.location.origin !== 'file://' ) {
		  return
	      }

	      clearTimeout( connectionTimeout );
	      connectionStatus.style.display = 'none';

	      var data = JSON.parse( event.data );

	      // The overview mode is only useful to the reveal.js instance
	      // where navigation occurs so we don't sync it
	      if( data.state ) delete data.state.overview;

	      // Messages sent by the notes plugin inside of the main window
	      if( data && data.namespace === 'reveal-notes' ) {
		  if( data.type === 'connect' ) {
		      handleConnectMessage( data );
		  }
		  else if( data.type === 'state' ) {
		      handleStateMessage( data );
		  }
		  else if( data.type === 'return' ) {
		      pendingCalls[data.callId](data.result);
		      delete pendingCalls[data.callId];
		  }
	      }
	      // Messages sent by the reveal.js inside of the current slide preview
	      else if( data && data.namespace === 'reveal' ) {
		  const supportedEvents = [
		      'slidechanged',
		      'fragmentshown',
		      'fragmenthidden',
		      'paused',
		      'resumed',
		      'previewiframe',
		      'previewimage',
		      'previewvideo',
		      'closeoverlay'
		  ];

		  if( /ready/.test( data.eventName ) ) {
		      // Send a message back to notify that the handshake is complete
		      window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'connected'} ), '*' );
		  }
		  else if( supportedEvents.includes( data.eventName ) && currentState !== JSON.stringify( data.state ) ) {
		      dispatchStateToMainWindow( data.state );
		  }
	      }

	  } );

	  /**
	   * Updates the presentation in the main window to match the state
	   * of the presentation in the notes window.
	   */
	  const dispatchStateToMainWindow = debounce(( state ) => {
	      window.opener.postMessage( JSON.stringify({ method: 'setState', args: [ state ]} ), '*' );
	  }, 500);

	  /**
	   * Asynchronously calls the Reveal.js API of the main frame.
	   */
	  function callRevealApi( methodName, methodArguments, callback ) {

	      var callId = ++lastRevealApiCallId;
	      pendingCalls[callId] = callback;
	      window.opener.postMessage( JSON.stringify( {
		  namespace: 'reveal-notes',
		  type: 'call',
		  callId: callId,
		  methodName: methodName,
		  arguments: methodArguments
	      } ), '*' );

	  }

	  /**
	   * Called when the main window is trying to establish a
	   * connection.
	   */
	  function handleConnectMessage( data ) {

	      if( connected === false ) {
		  connected = true;

		  setupIframes( data );
		  setupKeyboard();
		  setupNotes();
		  setupTimer();
		  setupHeartbeat();
	      }

	  }

	  /**
	   * Called when the main window sends an updated state.
	   */
	  function handleStateMessage( data ) {

	      // Store the most recently set state to avoid circular loops
	      // applying the same state
	      currentState = JSON.stringify( data.state );

	      // No need for updating the notes in case of fragment changes
	      if ( data.notes ) {
		  notes.classList.remove( 'hidden' );
		  notesValue.style.whiteSpace = data.whitespace;
		  if( data.markdown ) {
		      notesValue.innerHTML = marked( data.notes );
		  }
		  else {
		      notesValue.innerHTML = data.notes;
		  }
	      }
	      else {
		  notes.classList.add( 'hidden' );
	      }

	      // Don't show lightboxes in the upcoming slide
	      const { previewVideo, previewImage, previewIframe, ...upcomingState } = data.state;



( run in 0.872 second using v1.01-cache-2.11-cpan-9581c071862 )