|
| 1 | +<!doctype html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <style> |
| 6 | + html, body { |
| 7 | + margin: 0; |
| 8 | + padding: 0; |
| 9 | + height: 100%; |
| 10 | + font-size: 32px; |
| 11 | + font-family: consolas, "ubuntu mono", monospace; |
| 12 | + } |
| 13 | + body { |
| 14 | + padding: 0 1rem; |
| 15 | + position: relative; |
| 16 | + } |
| 17 | + .frame { |
| 18 | + border: .25rem solid #1e77d3; |
| 19 | + border-radius: 1rem; |
| 20 | + margin: 1rem 0; |
| 21 | + min-height: 5rem; |
| 22 | + position: relative; |
| 23 | + padding: .5rem 2.5rem .5rem .5rem; |
| 24 | + } |
| 25 | + .button { |
| 26 | + border: 2px solid #333; |
| 27 | + border-radius: .5rem; |
| 28 | + width: 1.5rem; |
| 29 | + height: 1.5rem; |
| 30 | + text-align: center; |
| 31 | + line-height: 1.5rem; |
| 32 | + cursor: pointer; |
| 33 | + background: #efefef; |
| 34 | + font-family: initial; |
| 35 | + user-select: none; |
| 36 | + } |
| 37 | + .add { |
| 38 | + display: inline-block; |
| 39 | + transform: rotate(45deg); |
| 40 | + } |
| 41 | + .close { |
| 42 | + position: absolute; |
| 43 | + top: .25rem; |
| 44 | + right: .25rem; |
| 45 | + } |
| 46 | + |
| 47 | + .locals { |
| 48 | + margin-bottom: .5rem; |
| 49 | + } |
| 50 | + |
| 51 | + .cell { |
| 52 | + border: .25rem solid; |
| 53 | + display: inline-block; |
| 54 | + padding: .25rem .75rem; |
| 55 | + } |
| 56 | + .add-cell { |
| 57 | + position: absolute; |
| 58 | + top: 2.25rem; |
| 59 | + right: .25rem; |
| 60 | + } |
| 61 | + </style> |
| 62 | +</head> |
| 63 | +<body> |
| 64 | +<div id="frames"> |
| 65 | + <div class="button add">✕</div> |
| 66 | +</div> |
| 67 | +<script> |
| 68 | + (() => { |
| 69 | + const frames = document.getElementById('frames'); |
| 70 | + const addFrame = frames.querySelector('.add'); |
| 71 | + |
| 72 | + function closeFrame(e) { |
| 73 | + frames.removeChild(e.currentTarget.parentNode); |
| 74 | + } |
| 75 | + |
| 76 | + function deleteCell(e) { |
| 77 | + e.currentTarget.parentNode.removeChild(e.currentTarget); |
| 78 | + } |
| 79 | + |
| 80 | + function cell() { |
| 81 | + const cell = document.createElement('div'); |
| 82 | + cell.classList.add('cell'); |
| 83 | + cell.contentEditable = 'plaintext-only'; |
| 84 | + // comment out this line for fun wiggle in firefox :) |
| 85 | + cell.innerText = '\u200b'; |
| 86 | + cell.addEventListener('dblclick', deleteCell); |
| 87 | + return cell; |
| 88 | + } |
| 89 | + |
| 90 | + function addCell(e) { |
| 91 | + e.currentTarget.parentNode.appendChild(cell()); |
| 92 | + } |
| 93 | + |
| 94 | + function newFrame() { |
| 95 | + const frame = document.createElement('div'); |
| 96 | + frame.classList.add('frame'); |
| 97 | + |
| 98 | + const close = document.createElement('div'); |
| 99 | + close.classList.add('close', 'button'); |
| 100 | + close.addEventListener('click', closeFrame); |
| 101 | + close.innerText = '✕'; |
| 102 | + frame.appendChild(close); |
| 103 | + |
| 104 | + const locals = document.createElement('div'); |
| 105 | + locals.classList.add('locals'); |
| 106 | + locals.contentEditable = 'plaintext-only'; |
| 107 | + locals.innerText = 'locals: {}'; |
| 108 | + frame.appendChild(locals); |
| 109 | + |
| 110 | + frame.appendChild(cell()); |
| 111 | + |
| 112 | + const add = document.createElement('add'); |
| 113 | + add.classList.add('button', 'add', 'add-cell'); |
| 114 | + add.innerText = '✕'; |
| 115 | + add.addEventListener('click', addCell); |
| 116 | + frame.appendChild(add); |
| 117 | + |
| 118 | + frames.insertBefore(frame, addFrame); |
| 119 | + } |
| 120 | + |
| 121 | + addFrame.addEventListener('click', newFrame); |
| 122 | + newFrame(); |
| 123 | + })(); |
| 124 | +</script> |
| 125 | +</body> |
| 126 | +</html> |
0 commit comments