diff options
author | Guillaume Turri <guillaume.turri@gmail.com> | 2013-07-28 22:41:55 +0200 |
---|---|---|
committer | Guillaume Turri <guillaume.turri@gmail.com> | 2013-07-29 14:46:02 +0200 |
commit | 04b9e444d97b31c1c5b867c02fe58b59a80386f4 (patch) | |
tree | 6952787e943bc4fdc3f9a4612055fe2d853003d2 /js/reveal.js | |
parent | 7d19b4f7ce2ab3fd7880d0f60b1c147d44808f0c (diff) | |
download | fosdem-2018-presentation-04b9e444d97b31c1c5b867c02fe58b59a80386f4.tar fosdem-2018-presentation-04b9e444d97b31c1c5b867c02fe58b59a80386f4.tar.gz |
Minor refactoring
Removed some code duplication
Diffstat (limited to 'js/reveal.js')
-rw-r--r-- | js/reveal.js | 61 |
1 files changed, 28 insertions, 33 deletions
diff --git a/js/reveal.js b/js/reveal.js index 033fe31..4666642 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -193,49 +193,26 @@ var Reveal = (function(){ dom.slides = document.querySelector( '.reveal .slides' ); // Background element - if( !document.querySelector( '.reveal .backgrounds' ) ) { - dom.background = document.createElement( 'div' ); - dom.background.classList.add( 'backgrounds' ); - dom.wrapper.appendChild( dom.background ); - } + dom.background = initializeNode(dom.wrapper, 'div', 'backgrounds', null); // Progress bar - if( !dom.wrapper.querySelector( '.progress' ) ) { - var progressElement = document.createElement( 'div' ); - progressElement.classList.add( 'progress' ); - progressElement.innerHTML = '<span></span>'; - dom.wrapper.appendChild( progressElement ); - } + dom.progress = initializeNode(dom.wrapper, 'div', 'progress', '<span></span>'); + dom.progressbar = dom.progress.querySelector('span'); // Arrow controls - if( !dom.wrapper.querySelector( '.controls' ) ) { - var controlsElement = document.createElement( 'aside' ); - controlsElement.classList.add( 'controls' ); - controlsElement.innerHTML = '<div class="navigate-left"></div>' + - '<div class="navigate-right"></div>' + - '<div class="navigate-up"></div>' + - '<div class="navigate-down"></div>'; - dom.wrapper.appendChild( controlsElement ); - } + initializeNode(dom.wrapper, 'aside', 'controls', + '<div class="navigate-left"></div>' + + '<div class="navigate-right"></div>' + + '<div class="navigate-up"></div>' + + '<div class="navigate-down"></div>'); // State background element [DEPRECATED] - if( !dom.wrapper.querySelector( '.state-background' ) ) { - var stateBackgroundElement = document.createElement( 'div' ); - stateBackgroundElement.classList.add( 'state-background' ); - dom.wrapper.appendChild( stateBackgroundElement ); - } + initializeNode(dom.wrapper, 'div', 'state-background', null); // Overlay graphic which is displayed during the paused mode - if( !dom.wrapper.querySelector( '.pause-overlay' ) ) { - var pausedElement = document.createElement( 'div' ); - pausedElement.classList.add( 'pause-overlay' ); - dom.wrapper.appendChild( pausedElement ); - } + initializeNode(dom.wrapper, 'div', 'pause-overlay', null); // Cache references to elements - dom.progress = document.querySelector( '.reveal .progress' ); - dom.progressbar = document.querySelector( '.reveal .progress span' ); - if ( config.controls ) { dom.controls = document.querySelector( '.reveal .controls' ); @@ -250,6 +227,24 @@ var Reveal = (function(){ } + function initializeNode(container, tagname, classname, innerHTML){ + var node = container.querySelector('.' + classname); + if( !node ){ + node = buildNode(tagname, classname, innerHTML); + container.appendChild(node); + } + return node; + } + + function buildNode(tagname, classname, innerHTML){ + var node = document.createElement(tagname); + node.classList.add(classname); + if(innerHTML !== null){ + node.innerHTML = innerHTML; + } + return node; + } + /** * Creates the slide background elements and appends them * to the background container. One element is created per |