[英]What does this javascript event handler do?
我試圖為 forms 提交提取事件處理程序。 對於一個網站,我得到了這個非常奇怪的處理程序:我的問題是這個處理程序做什么,更重要的是它是一些 JSLibrary 的一部分。
它是當您嘗試單擊 Email 按鈕時出現的右上角的 email 表單時運行的處理程序。
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();
}
}
}
不,它使用的唯一庫是 Twitter 的。 rest 是相當簡單的 JavaScript,盡管變量和 function 名稱被縮小了,因此很難閱讀。
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();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.