1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ElectronClient/app/note-content.html

60 lines
1.3 KiB
HTML
Raw Normal View History

2017-11-07 23:11:14 +02:00
<style>
body {
overflow: hidden;
}
#content {
overflow-y: scroll;
height: 100%;
}
</style>
2017-11-05 18:51:03 +02:00
<div id="content"></div>
<script>
2017-11-07 23:11:14 +02:00
const { ipcRenderer } = require('electron');
const contentElement = document.getElementById('content');
2017-11-05 18:51:03 +02:00
ipcRenderer.on('setHtml', (event, html) => {
2017-11-07 23:11:14 +02:00
contentElement.innerHTML = html;
2017-11-05 18:51:03 +02:00
});
2017-11-07 23:11:14 +02:00
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);
});
// document.addEventListener('click', function(e) {
// e = e || window.event;
// const target = e.target || e.srcElement;
// const coords = elementMapCoordinates(target);
// ipcRenderer.sendToHost('editNote', coords);
// }, false);
2017-11-05 18:51:03 +02:00
</script>