This commit is contained in:
Saq Imtiaz 2026-01-20 19:28:39 +00:00 committed by GitHub
commit b6dded55e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -255,65 +255,67 @@ exports.copyToClipboard = function(text,options) {
/*
Collect DOM variables
*/
exports.collectDOMVariables = function(selectedNode,domNode,event) {
var variables = {},
selectedNodeRect,
domNodeRect;
exports.collectDOMVariables = function(selectedNode,domNode,event){
const vars={};
const addRectVars = (prefix,{left,top,width,height}) => {
vars[`${prefix}-posx`] = `${left}`;
vars[`${prefix}-posy`] = `${top}`;
vars[`${prefix}-width`] = `${width}`;
vars[`${prefix}-height`] = `${height}`;
};
if(selectedNode) {
$tw.utils.each(selectedNode.attributes,function(attribute) {
variables["dom-" + attribute.name] = attribute.value.toString();
});
if("offsetLeft" in selectedNode) {
// Add variables with a (relative and absolute) popup coordinate string for the selected node
var nodeRect = {
for(const{name,value} of selectedNode.attributes) {
vars[`dom-${name}`] = `${value}`;
}
if("offsetLeft"in selectedNode) {
// Relative and absolute popup coordinate string for the selected node
const rect={
left: selectedNode.offsetLeft,
top: selectedNode.offsetTop,
width: selectedNode.offsetWidth,
height: selectedNode.offsetHeight
};
variables["tv-popup-coords"] = Popup.buildCoordinates(Popup.coordinatePrefix.csOffsetParent,nodeRect);
vars["tv-popup-coords"] = Popup.buildCoordinates(Popup.coordinatePrefix.csOffsetParent,rect);
var absRect = $tw.utils.extend({}, nodeRect);
for(var currentNode = selectedNode.offsetParent; currentNode; currentNode = currentNode.offsetParent) {
absRect.left += currentNode.offsetLeft;
absRect.top += currentNode.offsetTop;
}
variables["tv-popup-abs-coords"] = Popup.buildCoordinates(Popup.coordinatePrefix.csAbsolute,absRect);
vars["tv-popup-abs-coords"] = Popup.buildCoordinates(Popup.coordinatePrefix.csAbsolute,$tw.utils.getBoundingPageRect(selectedNode));
// 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();
// Offset of selected node
addRectVars("tv-selectednode",rect);
}
}
if(domNode && ("offsetWidth" in domNode)) {
variables["tv-widgetnode-width"] = domNode.offsetWidth.toString();
variables["tv-widgetnode-height"] = domNode.offsetHeight.toString();
if(domNode && "offsetWidth" in domNode) {
// Widget node size
vars["tv-widgetnode-width"] = `${domNode.offsetWidth}`;
vars["tv-widgetnode-height"] = `${domNode.offsetHeight}`;
}
if(event && ("clientX" in event) && ("clientY" in event)) {
const addEventVars = (prefix,node) => {
const{left, top} = node.getBoundingClientRect();
vars[`${prefix}-posx`] = `${event.clientX-left}`;
vars[`${prefix}-posy`] = `${event.clientY-top}`;
};
if(selectedNode) {
// Add variables for event X and Y position relative to selected node
selectedNodeRect = selectedNode.getBoundingClientRect();
variables["event-fromselected-posx"] = (event.clientX - selectedNodeRect.left).toString();
variables["event-fromselected-posy"] = (event.clientY - selectedNodeRect.top).toString();
}
if(domNode) {
// Add variables for event X and Y position relative to event catcher node
domNodeRect = domNode.getBoundingClientRect();
variables["event-fromcatcher-posx"] = (event.clientX - domNodeRect.left).toString();
variables["event-fromcatcher-posy"] = (event.clientY - domNodeRect.top).toString();
// Event position relative to selected node
addEventVars("event-fromselected",selectedNode);
}
// Add variables for event X and Y position relative to the viewport
variables["event-fromviewport-posx"] = event.clientX.toString();
variables["event-fromviewport-posy"] = event.clientY.toString();
if(domNode) {
// Event position relative to event catcher node
addEventVars("event-fromcatcher",domNode);
}
// Event position relative to the viewport
vars["event-fromviewport-posx"] = `${event.clientX}`;
vars["event-fromviewport-posy"] = `${event.clientY}`;
}
return variables;
return vars;
};
/*