custom composedPath (ISSUE #24)
This commit is contained in:
parent
9f0138292e
commit
514671d82b
27
dist/mailgo.js
vendored
27
dist/mailgo.js
vendored
@ -279,8 +279,12 @@ var isMailgo = function isMailgo(element) {
|
||||
|
||||
var mailgoCheckRender = function mailgoCheckRender(event) {
|
||||
// check if the id=mailgo exists in the body
|
||||
if (!document.contains(getE("mailgo"))) return;
|
||||
event.path.forEach(function (element) {
|
||||
if (!document.contains(getE("mailgo"))) return; // the path of the event
|
||||
|
||||
var path = event.path || event.composedPath && event.composedPath() || composedPath(event.target);
|
||||
|
||||
if (path) {
|
||||
path.forEach(function (element) {
|
||||
// go in the event.path to find if the user has clicked on a mailgo element
|
||||
if (isMailgo(element)) {
|
||||
// stop the normal execution of the element click
|
||||
@ -290,6 +294,8 @@ var mailgoCheckRender = function mailgoCheckRender(event) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
/**
|
||||
@ -393,4 +399,21 @@ var encodeEmail = function encodeEmail(email) {
|
||||
|
||||
var getE = function getE(id) {
|
||||
return document.getElementById(id);
|
||||
}; // custom composedPath
|
||||
|
||||
|
||||
var composedPath = function composedPath(el) {
|
||||
var path = [];
|
||||
|
||||
while (el) {
|
||||
path.push(el);
|
||||
|
||||
if (el.tagName === "HTML") {
|
||||
path.push(document);
|
||||
path.push(window);
|
||||
return path;
|
||||
}
|
||||
|
||||
el = el.parentElement;
|
||||
}
|
||||
};
|
2
dist/mailgo.min.js
vendored
2
dist/mailgo.min.js
vendored
File diff suppressed because one or more lines are too long
@ -360,7 +360,14 @@ const mailgoCheckRender = event => {
|
||||
// check if the id=mailgo exists in the body
|
||||
if (!document.contains(getE("mailgo"))) return;
|
||||
|
||||
event.composedPath().forEach(element => {
|
||||
// the path of the event
|
||||
let path =
|
||||
event.path ||
|
||||
(event.composedPath && event.composedPath()) ||
|
||||
composedPath(event.target);
|
||||
|
||||
if (path) {
|
||||
path.forEach(element => {
|
||||
// go in the event.path to find if the user has clicked on a mailgo element
|
||||
if (isMailgo(element)) {
|
||||
// stop the normal execution of the element click
|
||||
@ -372,6 +379,7 @@ const mailgoCheckRender = event => {
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
@ -472,3 +480,21 @@ const encodeEmail = email => btoa(email);
|
||||
|
||||
// getE shorthand
|
||||
const getE = id => document.getElementById(id);
|
||||
|
||||
// custom composedPath
|
||||
const composedPath = el => {
|
||||
let path = [];
|
||||
|
||||
while (el) {
|
||||
path.push(el);
|
||||
|
||||
if (el.tagName === "HTML") {
|
||||
path.push(document);
|
||||
path.push(window);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
el = el.parentElement;
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user