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:
parent
a0f317d1d6
commit
d5ba548902
|
@ -3,6 +3,13 @@
|
||||||
https://github.com/josdejong/jsoneditor
|
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
|
## 2017-08-20, version 5.9.4
|
||||||
|
|
||||||
- Fixed #447: context menus not working in Shadow DOM. Thanks @tomalec.
|
- Fixed #447: context menus not working in Shadow DOM. Thanks @tomalec.
|
||||||
|
|
|
@ -10,6 +10,7 @@ var util = require('./util');
|
||||||
function getRootNode(node){
|
function getRootNode(node){
|
||||||
return node.getRootNode && node.getRootNode() || window;
|
return node.getRootNode && node.getRootNode() || window;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A context menu
|
* A context menu
|
||||||
* @param {Object[]} items Array containing the menu structure
|
* @param {Object[]} items Array containing the menu structure
|
||||||
|
@ -241,6 +242,9 @@ ContextMenu.prototype.show = function (anchor, contentWindow) {
|
||||||
this.dom.menu.style.bottom = '0px';
|
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
|
// attach the menu to the parent of the anchor
|
||||||
var parent = anchor.parentNode;
|
var parent = anchor.parentNode;
|
||||||
parent.insertBefore(this.dom.root, parent.firstChild);
|
parent.insertBefore(this.dom.root, parent.firstChild);
|
||||||
|
@ -248,8 +252,7 @@ ContextMenu.prototype.show = function (anchor, contentWindow) {
|
||||||
// create and attach event listeners
|
// create and attach event listeners
|
||||||
var me = this;
|
var me = this;
|
||||||
var list = this.dom.list;
|
var list = this.dom.list;
|
||||||
var rootNode = getRootNode(list);
|
this.eventListeners.mousedown = util.addEventListener(this.rootNode, 'mousedown', function (event) {
|
||||||
this.eventListeners.mousedown = util.addEventListener(rootNode, 'mousedown', function (event) {
|
|
||||||
// hide menu on click outside of the menu
|
// hide menu on click outside of the menu
|
||||||
var target = event.target;
|
var target = event.target;
|
||||||
if ((target != list) && !me._isChildOf(target, list)) {
|
if ((target != list) && !me._isChildOf(target, list)) {
|
||||||
|
@ -258,7 +261,7 @@ ContextMenu.prototype.show = function (anchor, contentWindow) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.eventListeners.keydown = util.addEventListener(rootNode, 'keydown', function (event) {
|
this.eventListeners.keydown = util.addEventListener(this.rootNode, 'keydown', function (event) {
|
||||||
me._onKeyDown(event);
|
me._onKeyDown(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -289,12 +292,11 @@ ContextMenu.prototype.hide = function () {
|
||||||
|
|
||||||
// remove all event listeners
|
// remove all event listeners
|
||||||
// all event listeners are supposed to be attached to document.
|
// all event listeners are supposed to be attached to document.
|
||||||
var rootNode = getRootNode(this.dom.list);
|
|
||||||
for (var name in this.eventListeners) {
|
for (var name in this.eventListeners) {
|
||||||
if (this.eventListeners.hasOwnProperty(name)) {
|
if (this.eventListeners.hasOwnProperty(name)) {
|
||||||
var fn = this.eventListeners[name];
|
var fn = this.eventListeners[name];
|
||||||
if (fn) {
|
if (fn) {
|
||||||
util.removeEventListener(rootNode, name, fn);
|
util.removeEventListener(this.rootNode, name, fn);
|
||||||
}
|
}
|
||||||
delete this.eventListeners[name];
|
delete this.eventListeners[name];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue