PageSourceSearch

http://www.lluisribas.net/sites/all/modules/extlink/extlink.js

js lluisribas.net collected 2026-10-02 13:42:25 UTC 2,779 bytes, 72 lines download raw bytes

1if (Drupal.jsEnabled) {
2  $(document).ready(function() {
3    // Strip the host name down, removing subdomains or www.
4    var host = window.location.host.replace(/^(([^\/]+?\.)*)([^\.]{4,})((\.[a-z]{1,4})*)$/, '$3$4');
5    var subdomain = window.location.host.replace(/^(([^\/]+?\.)*)([^\.]{4,})((\.[a-z]{1,4})*)$/, '$1');
6
7    // Determine what subdomains are considered internal.
8    if (Drupal.settings.extlink.extSubdomains) {
9      var subdomains = "([^/]*)?";
10    }
11    else if (subdomain == 'www.' || subdomain == '') {
12      var subdomains = "(www\.)?";
13    }
14    else {
15      var subdomains = subdomain.replace(".", "\.");
16    }
17
18    // Build regular expressions that define an internal link.
19    var internal_link = new RegExp("^https?://" + subdomains + host, "i");
20
21    // Find all links which are NOT internal and begin with http (as opposed
22    // to ftp://, javascript:, etc. other kinds of links.
23    // When operating on the 'this' variable, the host has been appended to
24    // all links by the browser, even local ones.
25    // In jQuery 1.1 and higher, we'd us a filter method here, but it is not
26    // available in jQuery 1.0 (Drupal 5 default).
27    var external_links = new Array();
28    var mailto_links = new Array();
29    $("a").each(function(el) {
30      try {
31        var url = this.href.toLowerCase();
32        if (url.indexOf('http') == 0 && !url.match(internal_link)) {
33          external_links.push(this);
34        }
35        else if (url.indexOf('mailto:') == 0) {
36          mailto_links.push(this);
37        }
38      }
39      // IE7 throws errors often when dealing with irregular links, such as:
40      // <a href="node/10"></a> Empty tags.
41      // <a href="http://user:[email protected]">example</a> User:pass syntax.
42      catch(error) {
43        return false;
44      }
45    });
46
47    if (Drupal.settings.extlink.extClass) {
48      // Apply the "ext" class to all links not containing images.
49      if (parseFloat($().jquery) < 1.2) {
50        $(external_links).not('[img]').addClass(Drupal.settings.extlink.extClass);
51      }
52      else {
53        $(external_links).not($(external_links).find('img').parents('a')).addClass(Drupal.settings.extlink.extClass);
54      }
55    }
56
57    if (Drupal.settings.extlink.mailtoClass) {
58      // Apply the "mailto" class to all mailto links not containing images.
59      if (parseFloat($().jquery) < 1.2) {
60        $(mailto_links).not('[img]').addClass(Drupal.settings.extlink.mailtoClass);
61      }
62      else {
63        $(mailto_links).not($(mailto_links).find('img').parents('a')).addClass(Drupal.settings.extlink.mailtoClass);
64      }
65    }
66
67    if (Drupal.settings.extlink.extTarget) {
68      // Apply the target attribute to all links.
69      $(external_links).attr('target', Drupal.settings.extlink.extTarget);
70    }
71  });
72}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.