Skip to content

Commit

Permalink
remove popup example
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Apr 12, 2020
1 parent a7e8b19 commit b4d6485
Showing 1 changed file with 2 additions and 43 deletions.
45 changes: 2 additions & 43 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,63 +30,22 @@
font-family: "Source Code Pro", monospace;
font-size: 14px;
font-weight: 400;
min-height: 340px;
min-height: 240px;
letter-spacing: normal;
line-height: 20px;
padding: 10px;
tab-size: 4;
}

.popup {
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
display: none;
font-family: "Source Code Pro", monospace;
font-size: 14px;
font-weight: 400;
letter-spacing: normal;
line-height: 20px;
max-width: 500px;
overflow: hidden;
padding: 5px;
pointer-events: none;
position: absolute;
z-index: 2;
}
</style>
</head>
<body>
<main>
<div class="editor language-js"></div>
<div class="popup"></div>
</main>
<script type="module">
import {CodeJar} from './codejar.js'
import {withLineNumbers} from './linenumbers.js'
import {cursorPosition, selectedText, textBeforeCursor, textAfterCursor} from './cursor.js'

const editor = document.querySelector('.editor')
const popup = document.querySelector('.popup')

const updatePopup = () => {
const pos = cursorPosition()
popup.style.top = pos.top
popup.style.left = pos.left

const before = textBeforeCursor(editor).match(/\b\w+$/)
const after = textAfterCursor(editor).match(/^\w+\b/)
let word = (before && before[0]) || ''
word += selectedText()
word += (after && after[0]) || ''
if (word) {
popup.style.display = 'block'
popup.textContent = word
} else popup.style.display = 'none'
}

editor.addEventListener('click', updatePopup)
editor.addEventListener('keyup', updatePopup)

const highlight = editor => {
// highlight.js does not trim old tags,
Expand All @@ -95,7 +54,7 @@
hljs.highlightBlock(editor)
}

const jar = new CodeJar(editor, withLineNumbers(highlight), {tab: ' '})
const jar = new CodeJar(editor, highlight)

jar.updateCode(localStorage.getItem('code'))
jar.onUpdate(code => {
Expand Down

0 comments on commit b4d6485

Please sign in to comment.