Fix: eventcatcher widget - variables can be undefined (#6668)

* Fix: eventcatcher widget - variables can be undefined

* Fix: selectedNode can be an svg where offsetLeft ... are undefined

* Make check for offsetLeft short

* remove second collectDOMNodeVariables
This commit is contained in:
Simon Huber 2022-05-06 18:11:13 +02:00 committed by GitHub
parent 9b9e443c73
commit 4b8594c4a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View File

@ -292,14 +292,17 @@ exports.collectDOMVariables = function(selectedNode,domNode,event) {
$tw.utils.each(selectedNode.attributes,function(attribute) {
variables["dom-" + attribute.name] = attribute.value.toString();
});
// Add a variable with a popup coordinate string for the selected node
variables["tv-popup-coords"] = "(" + selectedNode.offsetLeft + "," + selectedNode.offsetTop +"," + selectedNode.offsetWidth + "," + selectedNode.offsetHeight + ")";
if(selectedNode.offsetLeft) {
// Add a variable with a popup coordinate string for the selected node
variables["tv-popup-coords"] = "(" + selectedNode.offsetLeft + "," + selectedNode.offsetTop +"," + selectedNode.offsetWidth + "," + selectedNode.offsetHeight + ")";
// Add variables for offset of selected node
variables["tv-selectednode-posx"] = selectedNode.offsetLeft.toString();
variables["tv-selectednode-posy"] = selectedNode.offsetTop.toString();
variables["tv-selectednode-width"] = selectedNode.offsetWidth.toString();
variables["tv-selectednode-height"] = selectedNode.offsetHeight.toString();
// Add variables for offset of selected node
variables["tv-selectednode-posx"] = selectedNode.offsetLeft.toString();
variables["tv-selectednode-posy"] = selectedNode.offsetTop.toString();
variables["tv-selectednode-width"] = selectedNode.offsetWidth.toString();
variables["tv-selectednode-height"] = selectedNode.offsetHeight.toString();
}
}
if(event && event.clientX && event.clientY) {

View File

@ -52,7 +52,7 @@ EventWidget.prototype.render = function(parent,nextSibling) {
selectedNode = event.target,
selectedNodeRect,
catcherNodeRect,
variables;
variables = {};
// Firefox can fire dragover and dragenter events on text nodes instead of their parents
if(selectedNode.nodeType === 3) {
selectedNode = selectedNode.parentNode;