简体   繁体   中英

What does this javascript event handler do?

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.

Here is a link to the web page: 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=

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM