1(function ($) { 2 3Drupal.extlink = Drupal.extlink || {}; 4 5Drupal.extlink.attach = function (context, settings) { 6 if (!settings.hasOwnProperty('extlink')) { 7 return; 8 } 9 10 // Strip the host name down, removing ports, subdomains, or www. 11 var pattern = /^(([^\/:]+?\.)*)([^\.:]{4,})((\.[a-z]{1,4})*)(:[0-9]{1,5})?$/; 12 var host = window.location.host.replace(pattern, '$3$4'); 13 var subdomain = window.location.host.replace(pattern, '$1'); 14 15 // Determine what subdomains are considered internal. 16 var subdomains; 17 if (settings.extlink.extSubdomains) { 18 subdomains = "([^/]*\\.)?"; 19 } 20 else if (subdomain == 'www.' || subdomain == '') { 21 subdomains = "(www\\.)?"; 22 } 23 else { 24 subdomains = subdomain.replace(".", "\\."); 25 } 26 27 // Build regular expressions that define an internal link. 28 var internal_link = new RegExp("^https?://" + subdomains + host, "i"); 29 30 // Extra internal link matching. 31 var extInclude = false; 32 if (settings.extlink.extInclude) { 33 extInclude = new RegExp(settings.extlink.extInclude.replace(/\\/, '\\'), "i"); 34 } 35 36 // Extra external link matching. 37 var extExclude = false; 38 if (settings.extlink.extExclude) { 39 extExclude = new RegExp(settings.extlink.extExclude.replace(/\\/, '\\'), "i"); 40 } 41 42 // Extra external link CSS selector exclusion. 43 var extCssExclude = false; 44 if (settings.extlink.extCssExclude) { 45 extCssExclude = settings.extlink.extCssExclude; 46 } 47 48 // Extra external link CSS selector explicit. 49 var extCssExplicit = false; 50 if (settings.extlink.extCssExplicit) { 51 extCssExplicit = settings.extlink.extCssExplicit; 52 } 53 54 // Find all links which are NOT internal and begin with http as opposed 55 // to ftp://, javascript:, etc. other kinds of links. 56 // When operating on the 'this' variable, the host has been appended to 57 // all links by the browser, even local ones. 58 // In jQuery 1.1 and higher, we'd use a filter method here, but it is not 59 // available in jQuery 1.0 (Drupal 5 default). 60 var external_links = new Array(); 61 var mailto_links = new Array(); 62 $("a:not(." + settings.extlink.extClass + ", ." + settings.extlink.mailtoClass + "), area:not(." + settings.extlink.extClass + ", ." + settings.extlink.mailtoClass + ")", context).each(function(el) { 63 try { 64 var url = this.href.toLowerCase(); 65 if (url.indexOf('http') == 0 66 && ((!url.match(internal_link) && !(extExclude && url.match(extExclude))) || (extInclude && url.match(extInclude))) 67 && !(extCssExclude && $(this).parents(extCssExclude).length > 0) 68 && !(extCssExplicit && $(this).parents(extCssExplicit).length < 1)) { 69 external_links.push(this); 70 } 71 // Do not include area tags with begin with mailto: (this prohibits 72 // icons from being added to image-maps). 73 else if (this.tagName != 'AREA' 74 && url.indexOf('mailto:') == 0 75 && !(extCssExclude && $(this).parents(extCssExclude).length > 0) 76 && !(extCssExplicit && $(this).parents(extCssExplicit).length < 1)) { 77 mailto_links.push(this); 78 } 79 } 80 // IE7 throws errors often when dealing with irregular links, such as: 81 // <a href="node/10"></a> Empty tags. 82 // <a href="http://user:[email protected]">example</a> User:pass syntax. 83 catch (error) { 84 return false; 85 } 86 }); 87 88 if (settings.extlink.extClass) { 89 Drupal.extlink.applyClassAndSpan(external_links, settings.extlink.extClass); 90 } 91 92 if (settings.extlink.mailtoClass) { 93 Drupal.extlink.applyClassAndSpan(mailto_links, settings.extlink.mailtoClass); 94 } 95 96 if (settings.extlink.extTarget) { 97 // Apply the target attribute to all links. 98 $(external_links).attr('target', settings.extlink.extTarget); 99 } 100 101 Drupal.extlink = Drupal.extlink || {}; 102 103 // Set up default click function for the external links popup. This should be 104 // overridden by modules wanting to alter the popup. 105 Drupal.extlink.popupClickHandler = Drupal.extlink.popupClickHandler || function() { 106 if (settings.extlink.extAlert) { 107 return confirm(settings.extlink.extAlertText); 108 } 109 } 110 111 $(external_links).click(function(e) { 112 return Drupal.extlink.popupClickHandler(e); 113 }); 114}; 115 116/** 117 * Apply a class and a trailing <span> to all links not containing images. 118 * 119 * @param links 120 * An array of DOM elements representing the links. 121 * @param class_name 122 * The class to apply to the links. 123 */ 124Drupal.extlink.applyClassAndSpan = function (links, class_name) { 125 var $links_to_process; 126 if (Drupal.settings.extlink.extImgClass){ 127 $links_to_process = $(links); 128 } 129 else { 130 var links_with_images = $(links).find('img').parents('a'); 131 $links_to_process = $(links).not(links_with_images); 132 } 133 $links_to_process.addClass(class_name); 134 var i; 135 var length = $links_to_process.length; 136 for (i = 0; i < length; i++) { 137 var $link = $($links_to_process[i]); 138 if ($link.css('display') == 'inline' || $link.css('display') == 'inline-block') { 139 if (class_name == Drupal.settings.extlink.mailtoClass) { 140 $link.append('<span class="' + class_name + '"><span class="element-invisible"> ' + Drupal.settings.extlink.mailtoLabel + '</span></span>'); 141 } 142 else { 143 $link.append('<span class="' + class_name + '"><span class="element-invisible"> ' + Drupal.settings.extlink.extLabel + '</span></span>'); 144 } 145 } 146 } 147}; 148 149Drupal.behaviors.extlink = Drupal.behaviors.extlink || {}; 150Drupal.behaviors.extlink.attach = function (context, settings) { 151 // Backwards compatibility, for the benefit of modules overriding extlink 152 // functionality by defining an "extlinkAttach" global function. 153 if (typeof extlinkAttach === 'function') { 154 extlinkAttach(context); 155 } 156 else { 157 Drupal.extlink.attach(context, settings); 158 } 159}; 160 161})(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.