Skip to content

Commit

Permalink
Compatiblity to reveal 4
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed May 11, 2020
1 parent 7d653ce commit e2b8c00
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions themeoverride.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
var ThemeOverride = ( function( Reveal ){
var ThemeOverride = ( function( _Reveal ){

var Reveal = _Reveal;
var isHighlightJsUsed = null;
var constants = [{
id: 'theme', // id attribute of link element
parameter: 'theme', // URL parameter name
option: 'theme', // reveal configuration option name
path: 'css/theme/', // standard path to css file
path: null, // standard path to css file - dependend on reveal version
},{
// deprecatved settings for compat, don't move this setting
// so our new settings will overwrite deprecated ones
Expand Down Expand Up @@ -40,24 +42,28 @@ var ThemeOverride = ( function( Reveal ){
return o;
}

function isHighlightJsUsed(){
function isHighlightJsUsed3(){
var regex = /\bhighlight.js$/i;
var script = Array.from( document.querySelectorAll( 'script' ) ).find( function( e ){
return e.attributes.src && e.attributes.src.value.search( regex ) >= 0;
});
return !!script;
}

function isHighlightJsUsed4(){
return Reveal.hasPlugin( 'highlight' );
}

function getRevealJsPath(){
var regex = /\bjs\/reveal.js$/i;
var script = Array.from( document.querySelectorAll( 'script' ) ).find( function( e ){
return e.attributes.src && e.attributes.src.value.search( regex ) >= 0;
var regex = /\b[^/]+\/reveal.css$/i;
var script = Array.from( document.querySelectorAll( 'link' ) ).find( function( e ){
return e.attributes.href && e.attributes.href.value.search( regex ) >= 0;
});
if( !script ){
console.error( 'reveal.js script could not be found in included <script> elements. Did you rename this file?' );
console.error( 'reveal.css could not be found in included <link> elements. Did you rename this file?' );
return '';
}
return script.attributes.src.value.replace( regex, '' );
return script.attributes.href.value.replace( regex, '' );
}

function applyTheme( c, theme ){
Expand Down Expand Up @@ -148,10 +154,26 @@ var ThemeOverride = ( function( Reveal ){
});
}

install();

return {
var Plugin = {
configure: configure
};
}

if( Reveal && Reveal.VERSION && Reveal.VERSION.length && Reveal.VERSION[ 0 ] == '3' ){
// reveal 3.x
isHighlightJsUsed = isHighlightJsUsed3;
constants[ 0 ].path = 'css/theme/';
install();
}else{
// must be reveal 4.x
isHighlightJsUsed = isHighlightJsUsed4;
constants[ 0 ].path = 'dist/theme/';
Plugin.id = 'theme-override';
Plugin.init = function( _Reveal ){
Reveal = _Reveal;
install();
};
}

return Plugin;

})( Reveal );

0 comments on commit e2b8c00

Please sign in to comment.