repl.it
@pyelias/

bad-editor

HTML, CSS, JS

No description

fork
loading
Files
  • index.html
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
82
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>repl.it</title>
    <style>
      #page {
        display: flex;
      }

      #editor {
        width: 100%;
        margin-left: 10px;
      }

      #text {
        width: 100%;
        height: 500px;
      }

      #saved {
        opacity: 0;
      }

      @keyframes fade {
        from {opacity: 1;}
        to {opacity: 0;}
      }
    </style>
  </head>
  <body>
    <div id="page">
      <div id="files">
        <ul id="file-list"></ul>
      </div>

      <div id="editor">
        <input id="save-name"></input><br>
        <button id="save">save</button>
        <span id="saved">saved</span><br>

        <textarea id="text"></textarea>
      </div>
    </div>

    <script>
      function reflow(el) {
        void(el.offsetHeight);
      }

      function showSaved() {
        let saved = document.getElementById("saved");
        saved.style.animation = null;
        reflow(saved);
        saved.style.animation = "fade 1s";
      }

      document.getElementById("save").addEventListener("click", () => {
        let name = document.getElementById("save-name").value;
        let text = document.getElementById("text").value;
        localStorage[name] = text;
        showSaved();
      });

      function makeFileElem(name) {
        let elem = document.createElement("li");
        elem.innerText = name;
        return elem;
      }

      function getFiles() {
        let files = document.getElementById("file-list");
        let names = Object.keys(localStorage);
        for (name of names) {
          files.appendChild(makeFileElem(name));
        }
      }
      getFiles();
    </script>
  </body>
</html>
result
console