1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-20 18:48:28 +02:00
joplin/ElectronClient/app/note-content.html
2017-11-09 23:28:08 +00:00

60 lines
1.3 KiB
HTML

<style>
body {
overflow: hidden;
}
#content {
overflow-y: scroll;
height: 100%;
}
</style>
<link rel="stylesheet" href="highlight/styles/atom-one-light.css">
<script src="highlight/highlight.pack.js"></script>
<div id="content"></div>
<script>
const { ipcRenderer } = require('electron');
const contentElement = document.getElementById('content');
ipcRenderer.on('setHtml', (event, html) => {
contentElement.innerHTML = html;
var codeElements = document.getElementsByClassName('code');
for (var i = 0; i < codeElements.length; i++) {
hljs.highlightBlock(codeElements[i]);
}
});
let ignoreNextScroll = false;
ipcRenderer.on('setPercentScroll', (event, percent) => {
ignoreNextScroll = true;
contentElement.scrollTop = percent * maxScrollTop();
});
function elementMapCoordinates(element) {
while (true) {
if (!element) break;
const m = element.getAttribute('data-map');
if (m) return m.split(':');
element = element.parentElement;
}
return null;
}
function maxScrollTop() {
return Math.max(0, contentElement.scrollHeight - contentElement.clientHeight);
}
contentElement.addEventListener('scroll', function(e) {
if (ignoreNextScroll) {
ignoreNextScroll = false;
return;
}
const m = maxScrollTop();
ipcRenderer.sendToHost('percentScroll', m ? contentElement.scrollTop / m : 0);
});
</script>