diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..0e125ab --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,14 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "typescript", + "tsconfig": "tsconfig.json", + "problemMatcher": [ + "$tsc" + ], + "group": "build", + "label": "tsc: build - tsconfig.json" + } + ] +} \ No newline at end of file diff --git a/src/impress.ts b/src/impress.ts index af17891..732703d 100644 --- a/src/impress.ts +++ b/src/impress.ts @@ -31,6 +31,15 @@ // All internal functions are (to be) prefixed with an underscore +class ImpressNotSupportedError extends Error {} +class ImpressInitError extends Error {} + +class ImpressConfig { + constructor( ) { + + } +} + // eslint-disable-next-line @typescript-eslint/no-explicit-any ( window as any ).impress = () => { // Somehow eslint didn't like the variable being reassigned inside of a function... @@ -53,7 +62,7 @@ document.body.classList.add( 'impress-supported' ); } - type PluginInitFunction = () => undefined; + type PluginInitFunction = () => void; /** * This function is used to initialize impress. It calls some prep functions and then loads @@ -62,11 +71,14 @@ * @param {Array|undefined} [pluginsToLoad] An array of plugins to load when initializing impress. Defaults to the built-in plugins that require explicit initialization. * @returns {undefined} */ - const init = ( pluginsToLoad?: Array ): undefined => { + const init = ( pluginsToLoad?: Array ): void => { // Check if impress is supported and refuse to init, if not supported. if ( !isImpressSupported ) { - return; + throw new ImpressNotSupportedError( 'Your browser does not support all required CSS attributes. Impress.js can therefore not be started. You will see a simplified version of the presentation.' ); } + + // Set default set of plugins to initialize on init or, if pluginsToLoad is defined, + // use the plugins array to load let toBeLoadedPlugins: Array = []; if ( typeof pluginsToLoad !== 'undefined' ) { toBeLoadedPlugins = pluginsToLoad; @@ -78,11 +90,19 @@ toBeLoadedPlugins[ plugin ](); } else { // Maybe somebody thinks they are funny to pass in an array of something but functions... - console.warn( 'impress().init() only accepts an array of functions! What you passed in was an array of ' + typeof ( toBeLoadedPlugins[ plugin ] ) ); - return; + console.warn( 'impress().init() only accepts an array of functions! What you passed in was an array of ' + typeof ( toBeLoadedPlugins[ plugin ] ) + '. Impress will load regardless, but the plugins you wanted to load will not be loaded!' ); } } + // Get the main #impress element and raise ImpressInitError if no #impress element was found + var impressMain = document.getElementById( 'impress' ); + if ( impressMain === null ) { + throw new ImpressInitError( 'Your presentation does not contain any element with id "impress"' ); + } + + console.log( impressMain.dataset ); + // create config for impress + // Finally, with init done, send out the 'impress:init' event. // All plugins which use this event to initialize will now be initialized document.dispatchEvent( new Event( 'impress:init' ) ); diff --git a/src/index.html b/src/index.html index 7f1faf8..6007937 100644 --- a/src/index.html +++ b/src/index.html @@ -13,7 +13,6 @@ -