Skip to content
This repository was archived by the owner on Sep 23, 2021. It is now read-only.

Commit 3e99709

Browse files
authored
Merge pull request #11 from msoedov/theme-chage
Theme select button
2 parents 33b85d8 + 7de98ee commit 3e99709

File tree

3 files changed

+88
-45
lines changed

3 files changed

+88
-45
lines changed

static/js/index.js

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,51 @@
11
$(function() {
22

3-
function slideSeparatorLines(text) {
4-
var lines = text.split('\n');
3+
function slideSeparatorLines(text) {
4+
var lines = text.split('\n');
55

6-
var separatorLineNumbers = [];
6+
var separatorLineNumbers = [];
77

8-
for (i = 0; i < lines.length; i++) {
9-
var line = lines[i];
10-
if (line === '---') {
11-
separatorLineNumbers.push(i);
12-
}
8+
for (i = 0; i < lines.length; i++) {
9+
var line = lines[i];
10+
if (line === '---') {
11+
separatorLineNumbers.push(i);
12+
}
13+
}
14+
15+
return separatorLineNumbers;
1316
}
1417

15-
return separatorLineNumbers;
16-
}
17-
18-
function currentCursorSlide(cursorLine) {
19-
var text = ace.edit("editor").getValue();
20-
var separatorPositions = slideSeparatorLines(text);
21-
var slideNumber = separatorPositions.length;
22-
separatorPositions.every(function(pos, num) {
23-
if (pos >= cursorLine) {
24-
slideNumber = num;
25-
return false;
26-
}
27-
return true;
28-
});
29-
return slideNumber;
30-
}
31-
32-
33-
var editor = ace.edit("editor");
34-
editor.setTheme("ace/theme/chrome");
35-
editor.getSession().setMode("ace/mode/markdown");
36-
editor.getSession().setUseWrapMode(true);
37-
editor.setShowPrintMargin(true);
38-
39-
$.get('/slides.md', function(data) {
40-
editor.setValue(data, -1);
41-
});
42-
43-
ace.edit('editor').getSession().selection.on('changeCursor', function(e) {
44-
var cursorRow = ace.edit('editor').getCursorPosition().row;
45-
var currentSlide = currentCursorSlide(cursorRow);
46-
$('#slides-frame')[0].contentWindow.postMessage(JSON.stringify({
47-
method: 'slide',
48-
args: [currentSlide]
49-
}), window.location.origin);
50-
});
51-
});
18+
function currentCursorSlide(cursorLine) {
19+
var text = ace.edit("editor").getValue();
20+
var separatorPositions = slideSeparatorLines(text);
21+
var slideNumber = separatorPositions.length;
22+
separatorPositions.every(function(pos, num) {
23+
if (pos >= cursorLine) {
24+
slideNumber = num;
25+
return false;
26+
}
27+
return true;
28+
});
29+
return slideNumber;
30+
}
5231

5332

33+
var editor = ace.edit("editor");
34+
editor.setTheme("ace/theme/chrome");
35+
editor.getSession().setMode("ace/mode/markdown");
36+
editor.getSession().setUseWrapMode(true);
37+
editor.setShowPrintMargin(true);
5438

39+
$.get('/slides.md', function(data) {
40+
editor.setValue(data, -1);
41+
});
42+
43+
ace.edit('editor').getSession().selection.on('changeCursor', function(e) {
44+
var cursorRow = ace.edit('editor').getCursorPosition().row;
45+
var currentSlide = currentCursorSlide(cursorRow);
46+
$('#slides-frame')[0].contentWindow.postMessage(JSON.stringify({
47+
method: 'slide',
48+
args: [currentSlide]
49+
}), window.location.origin);
50+
});
51+
});

static/js/slides.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function isPreview() {
55
function initializeReveal() {
66
// Full list of configuration options available at:
77
// https://github.com/hakimel/reveal.js#configuration
8+
89
Reveal.initialize({
910
controls: true,
1011
progress: true,
@@ -70,6 +71,8 @@ function initializeReveal() {
7071
}
7172
]
7273
});
74+
75+
themesCtrl();
7376
}
7477

7578
function highlightAnyCodeBlocks() {
@@ -112,6 +115,47 @@ function externalLinksInNewWindow() {
112115
insertMarkdownReference();
113116
initializeReveal();
114117

118+
function themesCtrl() {
119+
var defaultTheme = "black.css",
120+
currentTheme = localStorage.getItem('theme?') ||
121+
defaultTheme;
122+
123+
function setTheme(theme) {
124+
cssEl = $("#theme");
125+
cssEl.attr("href", "/static/reveal.js/css/theme/" + theme);
126+
localStorage.setItem('theme?', theme);
127+
}
128+
setTheme(currentTheme);
129+
130+
if (!isPreview()) {
131+
return
132+
}
133+
var availableThemes = [
134+
"black.css",
135+
"beige.css",
136+
"blood.css",
137+
"league.css",
138+
"moon.css",
139+
"night.css",
140+
"serif.css",
141+
"simple.css",
142+
"sky.css",
143+
"solarized.css",
144+
"white.css",
145+
];
146+
themeEl = $("#themes");
147+
availableThemes.forEach(function(theme) {
148+
elem = $("<option value=" + theme + ">" + theme + "</option>");
149+
themeEl.append(elem);
150+
})
151+
themeEl.val(currentTheme);
152+
themeEl.change(function() {
153+
val = themeEl.val()
154+
setTheme(val);
155+
});
156+
themeEl.attr("hidden", false);
157+
}
158+
115159
// Monkey patch Reveal so we can reload markdown through an
116160
// inter window message (using the reveal rpc api)
117161
// (yes, reveal has an rpc api!)

templates/slides.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
</head>
3737

3838
<body>
39+
<select id="themes" hidden="true" style="float:right;">
40+
</select>
3941
<div class="reveal">
4042
<div class="slides"></div>
4143
</div>

0 commit comments

Comments
 (0)