From 7de98eeea6f75af1a3eb9a305589e0720c37339d Mon Sep 17 00:00:00 2001 From: Alex Myasoedov Date: Thu, 2 Mar 2017 22:16:49 -0500 Subject: [PATCH] Update templates --- static/js/index.js | 85 +++++++++++++++++++++---------------------- templates/slides.tmpl | 2 + 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/static/js/index.js b/static/js/index.js index 0518c2c..d9e0ef7 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -1,54 +1,51 @@ $(function() { - function slideSeparatorLines(text) { - var lines = text.split('\n'); + function slideSeparatorLines(text) { + var lines = text.split('\n'); - var separatorLineNumbers = []; + var separatorLineNumbers = []; - for (i = 0; i < lines.length; i++) { - var line = lines[i]; - if (line === '---') { - separatorLineNumbers.push(i); - } + for (i = 0; i < lines.length; i++) { + var line = lines[i]; + if (line === '---') { + separatorLineNumbers.push(i); + } + } + + return separatorLineNumbers; } - return separatorLineNumbers; - } + function currentCursorSlide(cursorLine) { + var text = ace.edit("editor").getValue(); + var separatorPositions = slideSeparatorLines(text); + var slideNumber = separatorPositions.length; + separatorPositions.every(function(pos, num) { + if (pos >= cursorLine) { + slideNumber = num; + return false; + } + return true; + }); + return slideNumber; + } - function currentCursorSlide(cursorLine) { - var text = ace.edit("editor").getValue(); - var separatorPositions = slideSeparatorLines(text); - var slideNumber = separatorPositions.length; - separatorPositions.every(function(pos, num) { - if (pos >= cursorLine) { - slideNumber = num; - return false; - } - return true; + + var editor = ace.edit("editor"); + editor.setTheme("ace/theme/chrome"); + editor.getSession().setMode("ace/mode/markdown"); + editor.getSession().setUseWrapMode(true); + editor.setShowPrintMargin(true); + + $.get('/slides.md', function(data) { + editor.setValue(data, -1); }); - return slideNumber; - } - - var editor = ace.edit("editor"); - editor.setTheme("ace/theme/chrome"); - editor.getSession().setMode("ace/mode/markdown"); - editor.getSession().setUseWrapMode(true); - editor.setShowPrintMargin(true); - - $.get('/slides.md', function(data) { - editor.setValue(data, -1); - }); - - ace.edit('editor').getSession().selection.on('changeCursor', function(e) { - var cursorRow = ace.edit('editor').getCursorPosition().row; - var currentSlide = currentCursorSlide(cursorRow); - $('#slides-frame')[0].contentWindow.postMessage(JSON.stringify({ - method: 'slide', - args: [currentSlide] - }), window.location.origin); - }); + ace.edit('editor').getSession().selection.on('changeCursor', function(e) { + var cursorRow = ace.edit('editor').getCursorPosition().row; + var currentSlide = currentCursorSlide(cursorRow); + $('#slides-frame')[0].contentWindow.postMessage(JSON.stringify({ + method: 'slide', + args: [currentSlide] + }), window.location.origin); + }); }); - - - diff --git a/templates/slides.tmpl b/templates/slides.tmpl index ac6b646..bf590c0 100644 --- a/templates/slides.tmpl +++ b/templates/slides.tmpl @@ -36,6 +36,8 @@ +