Fixed a regression introduced in #448: after using the context menu once, it was not possible to set focus to an other input field anymore

This commit is contained in:
jos 2017-08-26 13:15:19 +02:00
parent a0f317d1d6
commit d5ba548902
2 changed files with 14 additions and 5 deletions

View File

@ -3,6 +3,13 @@
https://github.com/josdejong/jsoneditor
## 2017-08-26, version 5.9.5
- Fixed a regression introduced in `v5.9.4`: after using the context
menu once, it was not possible to set focus to an other input field
anymore.
## 2017-08-20, version 5.9.4
- Fixed #447: context menus not working in Shadow DOM. Thanks @tomalec.

View File

@ -10,6 +10,7 @@ var util = require('./util');
function getRootNode(node){
return node.getRootNode && node.getRootNode() || window;
}
/**
* A context menu
* @param {Object[]} items Array containing the menu structure
@ -241,6 +242,9 @@ ContextMenu.prototype.show = function (anchor, contentWindow) {
this.dom.menu.style.bottom = '0px';
}
// find the root node of the page (window, or a shadow dom root element)
this.rootNode = getRootNode(anchor);
// attach the menu to the parent of the anchor
var parent = anchor.parentNode;
parent.insertBefore(this.dom.root, parent.firstChild);
@ -248,8 +252,7 @@ ContextMenu.prototype.show = function (anchor, contentWindow) {
// create and attach event listeners
var me = this;
var list = this.dom.list;
var rootNode = getRootNode(list);
this.eventListeners.mousedown = util.addEventListener(rootNode, 'mousedown', function (event) {
this.eventListeners.mousedown = util.addEventListener(this.rootNode, 'mousedown', function (event) {
// hide menu on click outside of the menu
var target = event.target;
if ((target != list) && !me._isChildOf(target, list)) {
@ -258,7 +261,7 @@ ContextMenu.prototype.show = function (anchor, contentWindow) {
event.preventDefault();
}
});
this.eventListeners.keydown = util.addEventListener(rootNode, 'keydown', function (event) {
this.eventListeners.keydown = util.addEventListener(this.rootNode, 'keydown', function (event) {
me._onKeyDown(event);
});
@ -289,12 +292,11 @@ ContextMenu.prototype.hide = function () {
// remove all event listeners
// all event listeners are supposed to be attached to document.
var rootNode = getRootNode(this.dom.list);
for (var name in this.eventListeners) {
if (this.eventListeners.hasOwnProperty(name)) {
var fn = this.eventListeners[name];
if (fn) {
util.removeEventListener(rootNode, name, fn);
util.removeEventListener(this.rootNode, name, fn);
}
delete this.eventListeners[name];
}