Skip to content

Commit 537003d

Browse files
committed
feat: function to add click event to all documents in order to apply clickedElement to document dom object. this provides a refrence to the element that was actively clicked
1 parent 9e63cda commit 537003d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/index.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
/*globals DOMParser*/
2+
function clickedElement() {
3+
document.addEventListener('click', e => {
4+
document.clickedElement = e.target;
5+
});
6+
let frameDocuments = window.top.frameDocuments;
7+
if (!frameDocuments){
8+
window.top.frameDocuments = new Map();
9+
frameDocuments = window.top.frameDocuments;
10+
}
11+
let frames = document.querySelectorAll('iframe');
12+
for (let frame of frames){
13+
let frameDocument = frame.contentDocument;
14+
if (!frameDocuments.has(frameDocument)){
15+
frameDocuments.set(frameDocument, '')
16+
frameDocument.addEventListener('click', e => {
17+
frameDocument.clickedElement = e.target;
18+
});
19+
}
20+
}
21+
}
22+
223
export function getAttributes(element) {
324
return element.getAttributeNames().reduce((attrMap, name) => {
425
attrMap[name] = element.getAttribute(name);
@@ -136,6 +157,8 @@ export function queryFrameSelectorAll(selector) {
136157
// } while (parentElement);
137158
// }
138159

160+
clickedElement();
161+
139162
export default {
140163
parseTextToHtml,
141164
getAttributes,

0 commit comments

Comments
 (0)