]> BookStack Code Mirror - website/blob - themes/bookstack/static/js/script.js
Merge branch 'patch-2' of git://github.com/Zenahr/website into Zenahr-patch-2
[website] / themes / bookstack / static / js / script.js
1
2 // Mobile menu
3
4 var menuButton = document.getElementById('menu-button');
5 var menuDropDown = document.querySelector('header div.inner');
6
7 menuButton.onclick = function(event) {
8     var menuClass = menuDropDown.className;
9     var visible = menuClass.indexOf('showing') !== -1;
10     if (visible) {
11         menuDropDown.className = menuClass.replace('showing', '');
12     } else {
13         menuDropDown.className += ' showing';
14     }
15     event.stopPropagation();
16 };
17
18 document.body.onclick = function(event) {
19     menuDropDown.className = menuDropDown.className.replace('showing', '');
20     event.stopPropagation();
21 };
22
23
24 // Handle video click to play
25 var videos = document.querySelectorAll('video');
26 for (var i = 0; i < videos.length; i++) {
27     videos[i].addEventListener('click', videoClick)
28 }
29
30 function videoClick() {
31     if (typeof InstallTrigger !== 'undefined') return;
32     this.paused ? this.play() : this.pause();
33 }
34
35
36 // Codemirror Setup
37
38 var modeMap = {
39   'language-html': 'htmlmixed',
40   'language-bash': 'shell',
41   'language-js': 'javascript',
42   'language-shell': 'bash',
43   'language-nginx': 'nginx',
44   'language-apache': 'apache',
45   'language-php': 'php',
46   'language-sql': 'text/x-mysql',
47 };
48
49 var codeBlocks = document.querySelectorAll('pre');
50 for (var i = 0; i < codeBlocks.length; i++) {
51   var block = codeBlocks[i];
52   var codeElem = block.querySelector('code');
53   if (codeElem === null) continue;
54
55   var langClass = codeElem.className;
56   var mode = (typeof modeMap[langClass] !== 'undefined') ? modeMap[langClass] : 'htmlmixed';
57   var content = codeElem.textContent.trim();
58   CodeMirror(function(cmElem) {
59     block.parentNode.replaceChild(cmElem, block);
60   }, {
61     theme: 'base16-light',
62     lineNumbers: true,
63     mode: mode,
64     readOnly: true,
65     value: content
66   });
67 }