2011-06-15 99 views
0

我試圖提取表單提交的事件處理程序。 對於一個網站,我得到這個非常奇怪的處理程序: 我的問題是這個處理程序做什麼,更重要的是它是一些 JSLibrary的一部分。這個javascript事件處理程序是做什麼的?

這裏是一個網頁的鏈接: http://www.nfl.com/fantasy/story/09000d5d817fb977/article/nfl.fantasy/story;s1=story;slot=top;url=story;nfl=ad;!category=;kw=;team=no;team=was;team=sd;team=nyg;team=ten;team=bal;conf=nfc;conf=afc;dvsn=ncs;dvsn=nce;dvsn=acw;dvsn=acs;dvsn=acn;plyr=matthew_ryan;plyr=anquan_boldin;plyr=derrick_mason;event=fantasy;tile=

這是處理程序運行時,你試穿,當您單擊電子郵件按鈕,在出現的右上角的電子郵件的形式。

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(); 
     } 
    } 

}

+0

谷歌搜索表明它與[Twitter的網絡意圖(http://dev.twitter.com/pages/intents-events) – 2011-06-15 02:50:47

回答

0

不,它使用的唯一庫是Twitter的。剩下的就是相當直接的JavaScript,儘管變量和函數的名字被縮小了,所以很難閱讀。

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(); 
     } 
    } 
} 
+0

感謝您的回答 我實際上意味着,如果你能識別某些庫代碼的模式。澄清更多:你認爲這段代碼是一些JavaScript庫中的一些代碼來處理點擊事件。我說這是因爲它似乎是處理任何點擊事件的通用代碼,因爲表單與這裏發生的事情沒有任何關係。 它也來自一個叫做widgets.js的文件 再次感謝 – Muath 2011-06-15 03:23:29

+0

是的,它來自Twitter API(與jQuery或YUI等框架相反)。如果找到有效的鏈接標籤,它的目的就是將點擊事件傳遞給Twitter,否則它不會執行任何操作,也不會干擾用戶。它是頁面的一部分,可以讓你發佈它,而不是其他任何內容。順便說一下,它也不是表單提交的一部分。從代碼的外觀來看,它似乎只是用一堆點擊事件亂丟頁面,然後再測試它們是否與Twitter按鈕相關。 – brymck 2011-06-15 03:39:50

相關問題