~dricottone/noticable

ref: 4d60328797c769865abfe3bc739d0e82c1f233f7 noticable/index.html -rw-r--r-- 3.2 KiB
4d603287Dominic Ricottone functional file reading 3 years ago
                                                                                
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>A noticable note editor</title>
    <meta name="description" content="" />
    <link rel="stylesheet" href="node_modules/github-markdown-css/github-markdown.css" />
    <style>
body {
  height: 95vh;
  padding: 0;
}
.sidebar {
  width: 200px;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background-color: #000;
  overflow-x: hidden;
}
.sidebar li {
  color: #fff;
}
.sidebar a {
  color: #fff;
  text-decoration: none;
  display: block;
}
.container {
  max-width: 1000px;
  height: 100%;
  margin-left: 200px;
  transition: all 0.4s ease-out;
  display: none;
}
.container.focused {
  display: block;
}
#container-editor {
  border: 1px solid #ccc;
}
    </style>
  </head>
  <body>
    <div class="sidebar">
      <ul id="list-filenames"></ul>
    </div>
    <div class="container focused" id="container-editor"></div>
    <div class="container markdown-body" id="container-results"></div>
    <script src="node_modules/jquery/dist/jquery.min.js"></script>
    <script src="node_modules/monaco-editor/min/vs/loader.js"></script>
    <script>
// initialize monaco editor
require.config({ paths: { vs: 'node_modules/monaco-editor/min/vs' } });
require(['vs/editor/editor.main'], function () {
  window.editor = monaco.editor.create(document.getElementById('container-editor'), {
    language: 'markdown',
    minimap: {
      enabled: false
    },
    value: ''
  });
});

function requestPostFile(filename) {
  console.log("[renderer] triggering 'request-post-file' on '" + filename + "'...");
  window.postMessage({ type: "request-post-file", text: filename }, "*");
}
function sortFileNames(a, b) {
  return ($(b).text()) < ($(a).text());
}
function buildFileName(filename) {
  var el = document.createElement("li");
  el.innerHTML = filename;
  el.addEventListener("click", () => { requestPostFile(filename); });
  return el
}

// listen to preload
window.addEventListener("message", (event) => {
  if (event.source != window) return;
  if (event.data.type && (event.data.type == "request-post-markdown")) {
    console.log("[renderer] caught 'request-post-markdown'!");
    console.log("[renderer] sending 'post-markdown'...");
    window.postMessage({ type: "post-markdown", text: window.editor.getValue() }, "*");
  };
  if (event.data.type && (event.data.type == "request-insert-filename")) {
    console.log("[renderer] caught 'request-insert-filename'!");
    $("#list-filenames").append(buildFileName(event.data.text));
    $("#list-filenames li").sort(sortFileNames).appendTo("#list-filenames");
  };
  if (event.data.type && (event.data.type == "request-insert-html")) {
    console.log("[renderer] caught 'request-insert-html'!");
    $("#container-results").html(event.data.text);
    $(".container").toggleClass("focused");
  };
  if (event.data.type && (event.data.type == "request-toggle-editor")) {
    console.log("[renderer] caught 'request-toggle-editor'!");
    $(".container").toggleClass("focused");
  };
  if (event.data.type && (event.data.type == "post-file")) {
    console.log("[renderer] caught 'post-file'!");
    console.log(event.data.text)
    window.editor.setValue(event.data.text);
  };
}, false);

    </script>
  </body>
</html>