I was trying to extract event handlers for forms submission. For one website I got this handler which is very weird: My question is what does this handler do and more importantly is it part of some JSLibrary.
It is the handler run when you try the email form on the top right which appears when you click Email button.
function q(a) {
a = a || window.event;
var b = a.target || a.srcElement, c, d;
while (b && b.nodeName.toLowerCase() !== "a") {
b = b.parentNode;
}
if (b && b.nodeName.toLowerCase() === "a" && b.href) {
c = b.href.match(f);
if (c) {
var e = o(b.href);
twttr.events.hub ? (d = new p(l.generateId(), b), l.add(d), n(e, b), twttr.events.trigger("click", {target:b, region:"intent", type:"click", data:{}})) : m(e), a.returnValue = !1, a.preventDefault && a.preventDefault();
}
}
}
No, the only library it uses is Twitter's. The rest is fairly straightforward JavaScript, although the variable and function names are minified so it's hard to read.
function q(a) {
// Get the event from the passed argument if it exists,
// otherwise use the current event in the window
a = a || window.event;
// Get the target or source of the event, initialize variables c and d
var b = a.target || a.srcElement, c, d;
// Keep moving to the parent node of the target until you reach an <a> node
while (b && b.nodeName.toLowerCase() !== "a") {
b = b.parentNode;
}
// Double-check that b is an <a> node, then that
// it has an href attribute, making it a link
if (b && b.nodeName.toLowerCase() === "a" && b.href) {
// f is unknown, but I assume here it matches the URL in the <a> tag
// against some regular expression to make sure it's valid
c = b.href.match(f);
if (c) {
// Extract the URL
var e = o(b.href);
// Send it on to Twitter if possible, otherwise just cancel
// the click event
twttr.events.hub ? (d = new p(l.generateId(), b), l.add(d), n(e, b),
twttr.events.trigger("click", {target:b, region:"intent",
type:"click", data:{}})) :
m(e), a.returnValue = !1,
a.preventDefault && a.preventDefault();
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.