-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
81 lines (74 loc) · 2.61 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<meta http-equiv="Content-Security-Policy"
content="script-src 'self' 'unsafe-inline' 'unsafe-eval';"/>
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src-elem -->
<!-- 'unsafe-eval' is needed for console.log of drop-Event -->
<link rel="stylesheet" href="./node_modules/simplemde/dist/simplemde.min.css">
<script src="./node_modules/simplemde/dist/simplemde.min.js"></script>
<style>
html, body {
height: 100%;
display: flex;
flex: 1;
flex-direction: column;
}
.CodeMirror {
flex: 1;
}
</style>
<title>MD-Editor</title>
</head>
<body id="main_ui">
<h1>Editor</h1>
<textarea id="editor"></textarea>
<script>
//https://github.com/sparksuite/simplemde-markdown-editor
var editor = new SimpleMDE({
element: document.getElementById('editor')
});
const { ipcRenderer } = require('electron');
ipcRenderer.on('editor-event', (event, arg) => {
console.log(arg);
// send message back to main process
event.sender.send('editor-reply', `Received ${arg}`);
if (arg === 'toggle-bold'){
editor.toggleBold();
}
if (arg === 'save') {
event.sender.send('save', editor.value());
}
});
//This message means that your first messaging channel
//works from the renderer process to the main one.
ipcRenderer.send('editor-reply', 'Page Loaded');
document.getElementById('main_ui').ondrop = (event) => {
console.log('File(s) dropped');
event.preventDefault();
let tmpItems = event.dataTransfer.items;
if (tmpItems){
console.log(tmpItems);
console.log(`kind: ${tmpItems[0].kind}`);
if (tmpItems[0].kind === 'file'){
let file = tmpItems[0].getAsFile();
console.log(`file: ${file.type}, ${file.size},
${file.path} ${file.name} ${file.sha1}`);
if (file.size > 0){
let reader = new FileReader();
reader.onload = e => {
//console.log(e.target.result);
editor.codemirror.setValue(e.target.result);
}
reader.readAsText(file);
}
}
}
//ipcRenderer.send('ondragstart', '/absolute/path/to/the/item')
}
</script>
</body>
</html>