blob: 5ff78650fc1acb6ae2606a700c8268ed2540b2a6 [file] [log] [blame]
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +02001/*****************************************************************
2** Author: Asvin Goel, goel@telematique.eu
3**
4** A plugin replacing the default controls by custom controls.
5**
6** Version: 2.0.0
7**
8** License: MIT license (see LICENSE.md)
9**
10******************************************************************/
11window.RevealCustomControls = window.RevealCustomControls || {
12 id: 'RevealCustomControls',
13 init: function(deck) {
14 initCustomControls(deck);
15 }
16};
17
18const initCustomControls = function(Reveal){
19 var config = Reveal.getConfig().customcontrols || {};
20
21 var collapseIcon = config.collapseIcon || '<i class="fa fa-chevron-down"></i>';
22 var expandIcon = config.expandIcon || '<i class="fa fa-chevron-up"></i>';
23 var tooltip = config.tooltip || 'Show/hide controls';
24
25 var div = document.createElement( 'div' );
26 div.id = 'customcontrols';
27
28 var toggleButton = document.createElement( 'button' );
29 toggleButton.title = tooltip;
30 toggleButton.innerHTML = '<span id="collapse-customcontrols">' + collapseIcon + '</span>' + '<span id="expand-customcontrols">' + expandIcon + '</span>';
31
32 toggleButton.addEventListener('click', function( event ) {
33 var div = document.querySelector("div#customcontrols");
34 if ( div.classList.contains('collapsed') ) {
35 div.classList.remove('collapsed');
36 }
37 else {
38 div.classList.add('collapsed');
39 }
40 });
41
42 div.appendChild(toggleButton);
43
44 var controls = document.createElement( 'ul' );
45 for (var i = 0; i < config.controls.length; i++ ) {
46 var control = document.createElement( 'li' );
47 if ( config.controls[i].id ) {
48 control.id = config.controls[i].id;
49 }
50 control.innerHTML = '<button ' + ( config.controls[i].title ? 'title="' + config.controls[i].title + '" ': '' ) + 'onclick="' + config.controls[i].action + '">' + config.controls[i].icon + '</button>';
51 controls.appendChild( control );
52 }
53 div.appendChild( controls );
54
55
56 document.querySelector(".reveal").appendChild( div );
57
58 document.addEventListener( 'resize', function( event ) {
59 // expand controls to make sure they are visible
60 var div = document.querySelector("div#customcontrols.collapsed");
61 if ( div ) {
62 div.classList.remove('collapsed');
63 }
64 } );
65
66 return this;
67
68};
69