videoconf/static/js/index.js

55 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-03-06 02:23:12 +01:00
$(function () {
2016-02-29 19:31:32 +01:00
2017-03-03 04:16:49 +01:00
function slideSeparatorLines(text) {
var lines = text.split('\n');
2016-02-29 19:31:32 +01:00
2017-03-03 04:16:49 +01:00
var separatorLineNumbers = [];
2016-02-29 19:31:32 +01:00
2017-03-03 04:16:49 +01:00
for (i = 0; i < lines.length; i++) {
var line = lines[i];
if (line === '---') {
separatorLineNumbers.push(i);
}
}
return separatorLineNumbers;
2016-02-29 19:31:32 +01:00
}
2017-03-03 04:16:49 +01:00
function currentCursorSlide(cursorLine) {
var text = ace.edit("editor").getValue();
var separatorPositions = slideSeparatorLines(text);
var slideNumber = separatorPositions.length;
2018-03-06 02:23:12 +01:00
separatorPositions.every(function (pos, num) {
2017-03-03 04:16:49 +01:00
if (pos >= cursorLine) {
slideNumber = num;
return false;
}
return true;
});
return slideNumber;
}
2016-02-29 19:31:32 +01:00
2017-03-03 04:16:49 +01:00
var editor = ace.edit("editor");
editor.setTheme("ace/theme/chrome");
editor.getSession().setMode("ace/mode/markdown");
editor.getSession().setUseWrapMode(true);
editor.setShowPrintMargin(true);
2018-03-06 02:23:12 +01:00
$.get('/slides.md', function (data) {
2017-03-03 04:16:49 +01:00
editor.setValue(data, -1);
});
var lastSRow = -1;
2018-03-06 02:23:12 +01:00
ace.edit('editor').getSession().selection.on('changeCursor', function (e) {
2017-03-03 04:16:49 +01:00
var cursorRow = ace.edit('editor').getCursorPosition().row;
2018-03-06 02:23:12 +01:00
if (lastSRow === cursorRow) {
return; // no update
}
lastSRow = cursorRow;
2017-03-03 04:16:49 +01:00
var currentSlide = currentCursorSlide(cursorRow);
$('#slides-frame')[0].contentWindow.postMessage(JSON.stringify({
method: 'slide',
args: [currentSlide]
}), window.location.origin);
});
});