Skip to content
This repository was archived by the owner on Apr 22, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/basicContext.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 13 additions & 28 deletions src/scripts/basicContext.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
let overflow = null

const ITEM = 'item',
SEPARATOR = 'separator'

Expand Down Expand Up @@ -80,19 +78,17 @@ const build = function(items) {
let html = ''

html += `
<div class='basicContextContainer'>
<div class='basicContext'>
<table>
<tbody>
<div class='basicContext'>
<table>
<tbody>
`

items.forEach((item, i) => html += buildItem(item, i))

html += `
</tbody>
</table>
</div>
</div>
</tbody>
</table>
</div>
`

return html
Expand Down Expand Up @@ -183,18 +179,15 @@ const bind = function(item = {}) {

const show = function(items, e, fnClose, fnCallback) {

// Close any other open context menus
close()

// Build context
let html = build(items)

// Add context to the body
document.body.insertAdjacentHTML('beforeend', html)

// Save current overflow and block scrolling of site
if (overflow==null) {
overflow = document.body.style.overflow
document.body.style.overflow = 'hidden'
}

// Cache the context
let context = dom()

Expand All @@ -210,7 +203,7 @@ const show = function(items, e, fnClose, fnCallback) {
// Close fn fallback
if (fnClose==null) fnClose = close

// Bind click on background
// Bind click on parent element
context.parentElement.onclick = fnClose
context.parentElement.oncontextmenu = fnClose

Expand Down Expand Up @@ -239,17 +232,9 @@ const visible = function() {

const close = function() {

if (visible()===false) return false
let container = document.querySelector('.basicContext')

let container = document.querySelector('.basicContextContainer')

container.parentElement.removeChild(container)

// Reset overflow to its original value
if (overflow!=null) {
document.body.style.overflow = overflow
overflow = null
}
if (container!==null) container.parentElement.removeChild(container)

return true

Expand All @@ -261,4 +246,4 @@ return {
show,
visible,
close
}
}