Browse Source

refactoring

Hakim El Hattab 5 years ago
parent
commit
ac15678dea
5 changed files with 68 additions and 52 deletions
  1. 3 3
      README.md
  2. 0 0
      dist/reveal.min.js
  3. 34 26
      js/controllers/keyboard.js
  4. 5 23
      js/reveal.js
  5. 26 0
      js/utils/util.js

+ 3 - 3
README.md

@@ -133,8 +133,8 @@ Here's a barebones example of a fully working reveal.js presentation:
 ```html
 <html>
 	<head>
-		<link rel="stylesheet" href="css/reveal.css">
-		<link rel="stylesheet" href="css/theme/white.css">
+		<link rel="stylesheet" href="dist/reveal.css">
+		<link rel="stylesheet" href="dist/theme/white.css">
 	</head>
 	<body>
 		<div class="reveal">
@@ -143,7 +143,7 @@ Here's a barebones example of a fully working reveal.js presentation:
 				<section>Slide 2</section>
 			</div>
 		</div>
-		<script src="js/reveal.js"></script>
+		<script src="dist/reveal.min.js"></script>
 		<script>
 			Reveal.initialize();
 		</script>

File diff suppressed because it is too large
+ 0 - 0
dist/reveal.min.js


+ 34 - 26
js/controllers/keyboard.js

@@ -1,7 +1,7 @@
-import { extend, toArray, enterFullscreen } from '../utils/util.js'
+import { enterFullscreen } from '../utils/util.js'
 
 /**
- *
+ * Handles all reveal.js keyboard interactions.
  */
 export default class Keyboard {
 
@@ -21,30 +21,9 @@ export default class Keyboard {
 
 	}
 
-	refreshSortcuts() {
-
-		// Define our contextual list of keyboard shortcuts
-		if( this.Reveal.getConfig().navigationMode === 'linear' ) {
-			this.shortcuts['&#8594;  ,  &#8595;  ,  SPACE  ,  N  ,  L  ,  J'] = 'Next slide';
-			this.shortcuts['&#8592;  ,  &#8593;  ,  P  ,  H  ,  K']           = 'Previous slide';
-		}
-		else {
-			this.shortcuts['N  ,  SPACE']   = 'Next slide';
-			this.shortcuts['P']             = 'Previous slide';
-			this.shortcuts['&#8592;  ,  H'] = 'Navigate left';
-			this.shortcuts['&#8594;  ,  L'] = 'Navigate right';
-			this.shortcuts['&#8593;  ,  K'] = 'Navigate up';
-			this.shortcuts['&#8595;  ,  J'] = 'Navigate down';
-		}
-
-		this.shortcuts['Home  ,  Shift &#8592;']        = 'First slide';
-		this.shortcuts['End  ,  Shift &#8594;']         = 'Last slide';
-		this.shortcuts['B  ,  .']                       = 'Pause';
-		this.shortcuts['F']                             = 'Fullscreen';
-		this.shortcuts['ESC, O']                        = 'Slide overview';
-
-	}
-
+	/**
+	 * Starts listening for keyboard events.
+	 */
 	bind() {
 
 		document.addEventListener( 'keydown', this.onDocumentKeyDown, false );
@@ -52,6 +31,9 @@ export default class Keyboard {
 
 	}
 
+	/**
+	 * Stops listening for keyboard events.
+	 */
 	unbind() {
 
 		document.removeEventListener( 'keydown', this.onDocumentKeyDown, false );
@@ -91,6 +73,32 @@ export default class Keyboard {
 
 	}
 
+	/**
+	 * Updates our keyboard shortcuts based on current settings.
+	 */
+	refreshSortcuts() {
+
+		if( this.Reveal.getConfig().navigationMode === 'linear' ) {
+			this.shortcuts['&#8594;  ,  &#8595;  ,  SPACE  ,  N  ,  L  ,  J'] = 'Next slide';
+			this.shortcuts['&#8592;  ,  &#8593;  ,  P  ,  H  ,  K']           = 'Previous slide';
+		}
+		else {
+			this.shortcuts['N  ,  SPACE']   = 'Next slide';
+			this.shortcuts['P']             = 'Previous slide';
+			this.shortcuts['&#8592;  ,  H'] = 'Navigate left';
+			this.shortcuts['&#8594;  ,  L'] = 'Navigate right';
+			this.shortcuts['&#8593;  ,  K'] = 'Navigate up';
+			this.shortcuts['&#8595;  ,  J'] = 'Navigate down';
+		}
+
+		this.shortcuts['Home  ,  Shift &#8592;']        = 'First slide';
+		this.shortcuts['End  ,  Shift &#8594;']         = 'Last slide';
+		this.shortcuts['B  ,  .']                       = 'Pause';
+		this.shortcuts['F']                             = 'Fullscreen';
+		this.shortcuts['ESC, O']                        = 'Slide overview';
+
+	}
+
 	/**
 	 * Programmatically triggers a keyboard event
 	 *

+ 5 - 23
js/reveal.js

@@ -20,7 +20,8 @@ import {
 	transformElement,
 	createStyleSheet,
 	closestParent,
-	enterFullscreen
+	enterFullscreen,
+	getQueryHash
 } from './utils/util.js'
 import { isMobile, isChrome, isAndroid, supportsZoom } from './utils/device.js'
 import { colorToRgb, colorBrightness } from './utils/color.js'
@@ -146,7 +147,7 @@ export default function( revealElement, options ) {
 		window.addEventListener( 'load', layout, false );
 
 		// Copy options over to our config object
-		config = { ...defaultConfig, ...options, ...Reveal.getQueryHash() };
+		config = { ...defaultConfig, ...options, ...getQueryHash() };
 
 		// Load plugins then move on to #start()
 		plugins.load( config.dependencies ).then( start )
@@ -3896,27 +3897,8 @@ export default function( revealElement, options ) {
 		// Returns the current configuration object
 		getConfig: () => config,
 
-		// Helper method, retrieves query string as a key/value hash
-		getQueryHash: () => {
-			let query = {};
-
-			location.search.replace( /[A-Z0-9]+?=([\w\.%-]*)/gi, a => {
-				query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
-			} );
-
-			// Basic deserialization
-			for( let i in query ) {
-				let value = query[ i ];
-
-				query[ i ] = deserialize( unescape( value ) );
-			}
-
-			// Do not accept new dependencies via query config to avoid
-			// the potential of malicious script injection
-			if( typeof query['dependencies'] !== 'undefined' ) delete query['dependencies'];
-
-			return query;
-		},
+		// Helper method, retrieves query string as a key:value map
+		getQueryHash,
 
 		// Returns the top-level DOM element
 		getRevealElement: () => dom.wrapper || document.querySelector( '.reveal' ),

+ 26 - 0
js/utils/util.js

@@ -158,4 +158,30 @@ export const createStyleSheet = ( value ) => {
 
 	return tag;
 
+}
+
+/**
+ * Returns a key:value hash of all query params.
+ */
+export const getQueryHash = () => {
+
+	let query = {};
+
+	location.search.replace( /[A-Z0-9]+?=([\w\.%-]*)/gi, a => {
+		query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
+	} );
+
+	// Basic deserialization
+	for( let i in query ) {
+		let value = query[ i ];
+
+		query[ i ] = deserialize( unescape( value ) );
+	}
+
+	// Do not accept new dependencies via query config to avoid
+	// the potential of malicious script injection
+	if( typeof query['dependencies'] !== 'undefined' ) delete query['dependencies'];
+
+	return query;
+
 }

Some files were not shown because too many files changed in this diff