Skip to content

Commit

Permalink
fix #22
Browse files Browse the repository at this point in the history
  • Loading branch information
nkappler committed Aug 19, 2021
1 parent 9c81ead commit e74354a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
8 changes: 5 additions & 3 deletions docs/ctxmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@
this.hdir = "r";
this.vdir = "d";
window.addEventListener("click", function (ev) {
var item = ev.target && ev.target.parentElement;
var item = ev.target instanceof Element && ev.target.parentElement;

if (item && item.className !== "interactive") {
_this.closeMenu();
if (item && item.className === "interactive") {
return;
}

_this.closeMenu();
});
window.addEventListener("resize", function () {
return _this.closeMenu();
Expand Down
2 changes: 1 addition & 1 deletion docs/ctxmenu.min.js

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

8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ var ContextMenu = /*#__PURE__*/function () {
this.hdir = "r";
this.vdir = "d";
window.addEventListener("click", function (ev) {
var item = ev.target && ev.target.parentElement;
var item = ev.target instanceof Element && ev.target.parentElement;

if (item && item.className !== "interactive") {
_this.closeMenu();
if (item && item.className === "interactive") {
return;
}

_this.closeMenu();
});
window.addEventListener("resize", function () {
return _this.closeMenu();
Expand Down
9 changes: 5 additions & 4 deletions src/ctxmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ class ContextMenu implements CTXMenuSingleton {
private vdir: "u" | "d" = "d";
private constructor() {
window.addEventListener("click", ev => {
const item = ev.target && (ev.target as Element).parentElement;
if (item && item.className !== "interactive") {
this.closeMenu();
const item = ev.target instanceof Element && ev.target.parentElement;
if (item && item.className === "interactive") {
return;
}
this.closeMenu();
});
window.addEventListener("resize", () => this.closeMenu());
window.addEventListener("scroll", () => this.closeMenu());
Expand Down Expand Up @@ -340,7 +341,7 @@ class ContextMenu implements CTXMenuSingleton {
ev.preventDefault();
});
container.addEventListener("click", ev => {
const item = ev.target && (ev.target as Element).parentElement;
const item = ev.target instanceof Element && ev.target.parentElement;
if (item && item.className !== "interactive") {
ev.stopPropagation();
}
Expand Down
Loading

0 comments on commit e74354a

Please sign in to comment.