PageSourceSearch

https://www.buildinggreen.com/sites/all/modules/extlink/js/extlink.js?tm9cyc

js buildinggreen.com collected 2026-10-02 03:10:33 UTC 8,209 bytes, 214 lines download raw bytes

1/**
2 * @file
3 */
4
5(function ($) {
6
7  'use strict';
8
9  Drupal.extlink = Drupal.extlink || {};
10
11  Drupal.extlink.attach = function (context, settings) {
12    if (!settings.hasOwnProperty('extlink')) {
13      return;
14    }
15
16    // Strip the host name down, removing ports, subdomains, or www.
17    var pattern = /^(([^\/:]+?\.)*)([^\.:]{1,})((\.[a-z0-9]{1,253})*)(:[0-9]{1,5})?$/;
18    var host = window.location.host.replace(pattern, '$2$3$6');
19    var subdomain = window.location.host.replace(host, '');
20
21    // Determine what subdomains are considered internal.
22    var subdomains;
23    if (settings.extlink.extSubdomains) {
24      subdomains = '([^/]*\\.)?';
25    }
26    else if (subdomain === 'www.' || subdomain === '') {
27      subdomains = '(www\\.)?';
28    }
29    else {
30      subdomains = subdomain.replace('.', '\\.');
31    }
32
33    // Build regular expressions that define an internal link.
34    var internal_link = new RegExp('^https?://([^@]*@)?' + subdomains + host, 'i');
35
36    // Extra internal link matching.
37    var extInclude = false;
38    if (settings.extlink.extInclude) {
39      extInclude = new RegExp(settings.extlink.extInclude.replace(/\\/, '\\'), 'i');
40    }
41
42    // Extra external link matching.
43    var extExclude = false;
44    if (settings.extlink.extExclude) {
45      extExclude = new RegExp(settings.extlink.extExclude.replace(/\\/, '\\'), 'i');
46    }
47
48    // Extra external link CSS selector exclusion.
49    var extCssExclude = false;
50    if (settings.extlink.extCssExclude) {
51      extCssExclude = settings.extlink.extCssExclude;
52    }
53
54    // Extra external link CSS selector explicit.
55    var extCssExplicit = false;
56    if (settings.extlink.extCssExplicit) {
57      extCssExplicit = settings.extlink.extCssExplicit;
58    }
59
60    // Define the jQuery method (either 'append' or 'prepend') of placing the icon, defaults to 'append'.
61    var extIconPlacement = settings.extlink.extIconPlacement || 'append';
62
63    // Find all links which are NOT internal and begin with http as opposed
64    // to ftp://, javascript:, etc. other kinds of links.
65    // When operating on the 'this' variable, the host has been appended to
66    // all links by the browser, even local ones.
67    // In jQuery 1.1 and higher, we'd use a filter method here, but it is not
68    // available in jQuery 1.0 (Drupal 5 default).
69    var external_links = [];
70    var mailto_links = [];
71    $('a:not([data-extlink]), area:not([data-extlink])', context).each(function (el) {
72      try {
73        var url = '';
74        if (typeof this.href == 'string') {
75          url = this.href.toLowerCase();
76        }
77        // Handle SVG links (xlink:href).
78        else if (typeof this.href == 'object') {
79          url = this.href.baseVal;
80        }
81        if (url.indexOf('http') === 0
82          && ((!url.match(internal_link) && !(extExclude && url.match(extExclude))) || (extInclude && url.match(extInclude)))
83          && !(extCssExclude && $(this).is(extCssExclude))
84          && !(extCssExclude && $(this).parents(extCssExclude).length > 0)
85          && !(extCssExplicit && $(this).parents(extCssExplicit).length < 1)) {
86          external_links.push(this);
87        }
88        // Do not include area tags with begin with mailto: (this prohibits
89        // icons from being added to image-maps).
90        else if (this.tagName !== 'AREA'
91          && url.indexOf('mailto:') === 0
92          && !(extCssExclude && $(this).parents(extCssExclude).length > 0)
93          && !(extCssExplicit && $(this).parents(extCssExplicit).length < 1)) {
94          mailto_links.push(this);
95        }
96      }
97      // IE7 throws errors often when dealing with irregular links, such as:
98      // <a href="node/10"></a> Empty tags.
99      catch (error) {
100        return false;
101      }
102    });
103
104    if (settings.extlink.extClass) {
105      Drupal.extlink.applyClassAndSpan(external_links, settings.extlink.extClass, extIconPlacement);
106    }
107
108    if (settings.extlink.mailtoClass) {
109      Drupal.extlink.applyClassAndSpan(mailto_links, settings.extlink.mailtoClass, extIconPlacement);
110    }
111
112    if (settings.extlink.extTarget) {
113      // Apply the target attribute to all links.
114      $(external_links).attr('target', settings.extlink.extTarget);
115      // Add rel attributes noopener and noreferrer.
116      $(external_links).attr('rel', function (i, val) {
117        // If no rel attribute is present, create one with the values noopener and noreferrer.
118        if (val == null) {
119          return 'noopener noreferrer';
120        }
121        // Check to see if rel contains noopener or noreferrer. Add what doesn't exist.
122        if (val.indexOf('noopener') > -1 || val.indexOf('noreferrer') > -1) {
123          if (val.indexOf('noopener') === -1) {
124            return val + ' noopener';
125          }
126          if (val.indexOf('noreferrer') === -1) {
127            return val + ' noreferrer';
128          }
129          // Both noopener and noreferrer exist. Nothing needs to be added.
130          else {
131            return val;
132          }
133        }
134        // Else, append noopener and noreferrer to val.
135        else {
136          return val + ' noopener noreferrer';
137        }
138      });
139    }
140
141    Drupal.extlink = Drupal.extlink || {};
142
143    // Set up default click function for the external links popup. This should be
144    // overridden by modules wanting to alter the popup.
145    Drupal.extlink.popupClickHandler = Drupal.extlink.popupClickHandler || function () {
146      if (settings.extlink.extAlert) {
147        return confirm(settings.extlink.extAlertText);
148      }
149    };
150
151    $(external_links).click(function (e) {
152      return Drupal.extlink.popupClickHandler(e, this);
153    });
154  };
155
156  /**
157   * Apply a class and a trailing <span> to all links not containing images.
158   *
159   * @param {object[]} links
160   *   An array of DOM elements representing the links.
161   * @param {string} class_name
162   *   The class to apply to the links.
163   * @param {string} icon_placement
164   *   'append' or 'prepend' the icon to the link.
165   */
166  Drupal.extlink.applyClassAndSpan = function (links, class_name, icon_placement) {
167    var $links_to_process;
168    if (Drupal.settings.extlink.extImgClass) {
169      $links_to_process = $(links);
170    }
171    else {
172      var links_with_images = $(links).find('img').parents('a');
173      $links_to_process = $(links).not(links_with_images);
174    }
175    // Add data-extlink attribute.
176    $links_to_process.attr('data-extlink', '');
177    var i;
178    var length = $links_to_process.length;
179    for (i = 0; i < length; i++) {
180      var $link = $($links_to_process[i]);
181      if ($link.css('display') === 'inline' || $link.css('display') === 'inline-block') {
182        if (Drupal.settings.extlink.extUseFontAwesome) {
183          if (class_name === Drupal.settings.extlink.mailtoClass) {
184            $link[icon_placement]('<span class="fa-' + class_name + ' extlink"><span class="fa fa-envelope-o" title="' + Drupal.settings.extlink.mailtoLabel + '"></span><span class="element-invisible">' + Drupal.settings.extlink.mailtoLabel + '</span></span>');
185          }
186          else {
187            $link[icon_placement]('<span class="fa-' + class_name + ' extlink"><span class="fa fa-external-link" title="' + Drupal.settings.extlink.extLabel + '"></span><span class="element-invisible">' + Drupal.settings.extlink.extLabel + '</span></span>');
188          }
189        }
190        else {
191          if (class_name === Drupal.settings.extlink.mailtoClass) {
192            $link[icon_placement]('<span class="' + class_name + '"><span class="element-invisible">' + Drupal.settings.extlink.mailtoLabel + '</span></span>');
193          }
194          else {
195            $link[icon_placement]('<span class="' + class_name + '"><span class="element-invisible">' + Drupal.settings.extlink.extLabel + '</span></span>');
196          }
197        }
198      }
199    }
200  };
201
202  Drupal.behaviors.extlink = Drupal.behaviors.extlink || {};
203  Drupal.behaviors.extlink.attach = function (context, settings) {
204    // Backwards compatibility, for the benefit of modules overriding extlink
205    // functionality by defining an "extlinkAttach" global function.
206    if (typeof extlinkAttach === 'function') {
207      extlinkAttach(context);
208    }
209    else {
210      Drupal.extlink.attach(context, settings);
211    }
212  };
213
214})(jQuery);

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.