Skip to content
Snippets Groups Projects
Commit 9b3f477e authored by Lachlan Ennis's avatar Lachlan Ennis
Browse files

Issue #2887225 by arunkumark, jayesh_makwana, chishah92, Sivaprasad C,...

Issue #2887225 by arunkumark, jayesh_makwana, chishah92, Sivaprasad C, elachlan: Coding Standard issues
parent f22d5030
No related branches found
No related tags found
No related merge requests found
......@@ -50,4 +50,4 @@ MAINTAINERS
Current maintainers:
- Lachlan Ennis (elachlan) - https://www.drupal.org/u/elachlan
- Nate Haug (quicksketch) - https://www.drupal.org/u/quicksketch
\ No newline at end of file
- Nate Haug (quicksketch) - https://www.drupal.org/u/quicksketch
......@@ -9,196 +9,196 @@
Drupal.extlink = Drupal.extlink || {};
Drupal.extlink.attach = function (context, settings) {
if (!settings.hasOwnProperty('extlink')) {
return;
}
// Strip the host name down, removing ports, subdomains, or www.
var pattern = /^(([^\/:]+?\.)*)([^\.:]{1,})((\.[a-z0-9]{1,253})*)(:[0-9]{1,5})?$/;
var host = window.location.host.replace(pattern, '$3$4');
var subdomain = window.location.host.replace(pattern, '$1');
// Determine what subdomains are considered internal.
var subdomains;
if (settings.extlink.extSubdomains) {
subdomains = '([^/]*\\.)?';
}
else if (subdomain === 'www.' || subdomain === '') {
subdomains = '(www\\.)?';
}
else {
subdomains = subdomain.replace('.', '\\.');
}
// Build regular expressions that define an internal link.
var internal_link = new RegExp('^https?://([^@]*@)?' + subdomains + host, 'i');
// Extra internal link matching.
var extInclude = false;
if (settings.extlink.extInclude) {
extInclude = new RegExp(settings.extlink.extInclude.replace(/\\/, '\\'), 'i');
}
// Extra external link matching.
var extExclude = false;
if (settings.extlink.extExclude) {
extExclude = new RegExp(settings.extlink.extExclude.replace(/\\/, '\\'), 'i');
}
// Extra external link CSS selector exclusion.
var extCssExclude = false;
if (settings.extlink.extCssExclude) {
extCssExclude = settings.extlink.extCssExclude;
}
// Extra external link CSS selector explicit.
var extCssExplicit = false;
if (settings.extlink.extCssExplicit) {
extCssExplicit = settings.extlink.extCssExplicit;
}
// Define the jQuery method (either 'append' or 'prepend') of placing the icon, defaults to 'append'.
var extIconPlacement = settings.extlink.extIconPlacement || 'append';
// Find all links which are NOT internal and begin with http as opposed
// to ftp://, javascript:, etc. other kinds of links.
// When operating on the 'this' variable, the host has been appended to
// all links by the browser, even local ones.
// In jQuery 1.1 and higher, we'd use a filter method here, but it is not
// available in jQuery 1.0 (Drupal 5 default).
var external_links = [];
var mailto_links = [];
$('a:not(.' + settings.extlink.extClass + ', .' + settings.extlink.mailtoClass + '), area:not(.' + settings.extlink.extClass + ', .' + settings.extlink.mailtoClass + ')', context).each(function (el) {
try {
var url = '';
if (typeof this.href == 'string') {
url = this.href.toLowerCase();
}
// Handle SVG links (xlink:href).
else if (typeof this.href == 'object') {
url = this.href.baseVal;
}
if (url.indexOf('http') === 0
&& ((!url.match(internal_link) && !(extExclude && url.match(extExclude))) || (extInclude && url.match(extInclude)))
&& !(extCssExclude && $(this).is(extCssExclude))
&& !(extCssExclude && $(this).parents(extCssExclude).length > 0)
&& !(extCssExplicit && $(this).parents(extCssExplicit).length < 1)) {
external_links.push(this);
}
// Do not include area tags with begin with mailto: (this prohibits
// icons from being added to image-maps).
else if (this.tagName !== 'AREA'
&& url.indexOf('mailto:') === 0
&& !(extCssExclude && $(this).parents(extCssExclude).length > 0)
&& !(extCssExplicit && $(this).parents(extCssExplicit).length < 1)) {
mailto_links.push(this);
}
if (!settings.hasOwnProperty('extlink')) {
return;
}
// IE7 throws errors often when dealing with irregular links, such as:
// <a href="node/10"></a> Empty tags.
// <a href="http://user:pass@example.com">example</a> User:pass syntax.
catch (error) {
return false;
}
});
if (settings.extlink.extClass) {
Drupal.extlink.applyClassAndSpan(external_links, settings.extlink.extClass, extIconPlacement);
}
if (settings.extlink.mailtoClass) {
Drupal.extlink.applyClassAndSpan(mailto_links, settings.extlink.mailtoClass, extIconPlacement);
}
if (settings.extlink.extTarget) {
// Apply the target attribute to all links.
$(external_links).attr('target', settings.extlink.extTarget);
// Add rel attributes noopener and noreferrer.
$(external_links).attr('rel', function (i, val) {
// If no rel attribute is present, create one with the values noopener and noreferrer.
if (val == null) {
return 'noopener noreferrer';
}
// Check to see if rel contains noopener or noreferrer. Add what doesn't exist.
if (val.indexOf('noopener') > -1 || val.indexOf('noreferrer') > -1) {
if (val.indexOf('noopener') === -1) {
return val + ' noopener';
// Strip the host name down, removing ports, subdomains, or www.
var pattern = /^(([^\/:]+?\.)*)([^\.:]{1,})((\.[a-z0-9]{1,253})*)(:[0-9]{1,5})?$/;
var host = window.location.host.replace(pattern, '$3$4');
var subdomain = window.location.host.replace(pattern, '$1');
// Determine what subdomains are considered internal.
var subdomains;
if (settings.extlink.extSubdomains) {
subdomains = '([^/]*\\.)?';
}
else if (subdomain === 'www.' || subdomain === '') {
subdomains = '(www\\.)?';
}
else {
subdomains = subdomain.replace('.', '\\.');
}
// Build regular expressions that define an internal link.
var internal_link = new RegExp('^https?://([^@]*@)?' + subdomains + host, 'i');
// Extra internal link matching.
var extInclude = false;
if (settings.extlink.extInclude) {
extInclude = new RegExp(settings.extlink.extInclude.replace(/\\/, '\\'), 'i');
}
// Extra external link matching.
var extExclude = false;
if (settings.extlink.extExclude) {
extExclude = new RegExp(settings.extlink.extExclude.replace(/\\/, '\\'), 'i');
}
// Extra external link CSS selector exclusion.
var extCssExclude = false;
if (settings.extlink.extCssExclude) {
extCssExclude = settings.extlink.extCssExclude;
}
// Extra external link CSS selector explicit.
var extCssExplicit = false;
if (settings.extlink.extCssExplicit) {
extCssExplicit = settings.extlink.extCssExplicit;
}
// Define the jQuery method (either 'append' or 'prepend') of placing the icon, defaults to 'append'.
var extIconPlacement = settings.extlink.extIconPlacement || 'append';
// Find all links which are NOT internal and begin with http as opposed
// to ftp://, javascript:, etc. other kinds of links.
// When operating on the 'this' variable, the host has been appended to
// all links by the browser, even local ones.
// In jQuery 1.1 and higher, we'd use a filter method here, but it is not
// available in jQuery 1.0 (Drupal 5 default).
var external_links = [];
var mailto_links = [];
$('a:not(.' + settings.extlink.extClass + ', .' + settings.extlink.mailtoClass + '), area:not(.' + settings.extlink.extClass + ', .' + settings.extlink.mailtoClass + ')', context).each(function (el) {
try {
var url = '';
if (typeof this.href == 'string') {
url = this.href.toLowerCase();
}
if (val.indexOf('noreferrer') === -1) {
return val + ' noreferrer';
// Handle SVG links (xlink:href).
else if (typeof this.href == 'object') {
url = this.href.baseVal;
}
// Both noopener and noreferrer exist. Nothing needs to be added.
else {
return val;
if (url.indexOf('http') === 0
&& ((!url.match(internal_link) && !(extExclude && url.match(extExclude))) || (extInclude && url.match(extInclude)))
&& !(extCssExclude && $(this).is(extCssExclude))
&& !(extCssExclude && $(this).parents(extCssExclude).length > 0)
&& !(extCssExplicit && $(this).parents(extCssExplicit).length < 1)) {
external_links.push(this);
}
// Do not include area tags with begin with mailto: (this prohibits
// icons from being added to image-maps).
else if (this.tagName !== 'AREA'
&& url.indexOf('mailto:') === 0
&& !(extCssExclude && $(this).parents(extCssExclude).length > 0)
&& !(extCssExplicit && $(this).parents(extCssExplicit).length < 1)) {
mailto_links.push(this);
}
}
// Else, append noopener and noreferrer to val.
else {
return val + ' noopener noreferrer';
// IE7 throws errors often when dealing with irregular links, such as:
// <a href="node/10"></a> Empty tags.
// <a href="http://user:pass@example.com">example</a> User:pass syntax.
catch (error) {
return false;
}
});
}
Drupal.extlink = Drupal.extlink || {};
if (settings.extlink.extClass) {
Drupal.extlink.applyClassAndSpan(external_links, settings.extlink.extClass, extIconPlacement);
}
// Set up default click function for the external links popup. This should be
// overridden by modules wanting to alter the popup.
Drupal.extlink.popupClickHandler = Drupal.extlink.popupClickHandler || function () {
if (settings.extlink.extAlert) {
return confirm(settings.extlink.extAlertText);
if (settings.extlink.mailtoClass) {
Drupal.extlink.applyClassAndSpan(mailto_links, settings.extlink.mailtoClass, extIconPlacement);
}
if (settings.extlink.extTarget) {
// Apply the target attribute to all links.
$(external_links).attr('target', settings.extlink.extTarget);
// Add rel attributes noopener and noreferrer.
$(external_links).attr('rel', function (i, val) {
// If no rel attribute is present, create one with the values noopener and noreferrer.
if (val == null) {
return 'noopener noreferrer';
}
// Check to see if rel contains noopener or noreferrer. Add what doesn't exist.
if (val.indexOf('noopener') > -1 || val.indexOf('noreferrer') > -1) {
if (val.indexOf('noopener') === -1) {
return val + ' noopener';
}
if (val.indexOf('noreferrer') === -1) {
return val + ' noreferrer';
}
// Both noopener and noreferrer exist. Nothing needs to be added.
else {
return val;
}
}
// Else, append noopener and noreferrer to val.
else {
return val + ' noopener noreferrer';
}
});
}
};
$(external_links).click(function (e) {
return Drupal.extlink.popupClickHandler(e, this);
});
};
Drupal.extlink = Drupal.extlink || {};
/**
* Apply a class and a trailing <span> to all links not containing images.
*
* @param {object[]} links
* An array of DOM elements representing the links.
* @param {string} class_name
* The class to apply to the links.
* @param {string} icon_placement
* 'append' or 'prepend' the icon to the link.
*/
Drupal.extlink.applyClassAndSpan = function (links, class_name, icon_placement) {
var $links_to_process;
if (Drupal.settings.extlink.extImgClass) {
$links_to_process = $(links);
}
else {
var links_with_images = $(links).find('img').parents('a');
$links_to_process = $(links).not(links_with_images);
}
$links_to_process.addClass(class_name);
var i;
var length = $links_to_process.length;
for (i = 0; i < length; i++) {
var $link = $($links_to_process[i]);
if ($link.css('display') === 'inline' || $link.css('display') === 'inline-block') {
if (class_name === Drupal.settings.extlink.mailtoClass) {
$link[icon_placement]('<span class="' + class_name + '"><span class="element-invisible">' + Drupal.settings.extlink.mailtoLabel + '</span></span>');
// Set up default click function for the external links popup. This should be
// overridden by modules wanting to alter the popup.
Drupal.extlink.popupClickHandler = Drupal.extlink.popupClickHandler || function () {
if (settings.extlink.extAlert) {
return confirm(settings.extlink.extAlertText);
}
else {
$link[icon_placement]('<span class="' + class_name + '"><span class="element-invisible">' + Drupal.settings.extlink.extLabel + '</span></span>');
};
$(external_links).click(function (e) {
return Drupal.extlink.popupClickHandler(e, this);
});
};
/**
* Apply a class and a trailing <span> to all links not containing images.
*
* @param {object[]} links
* An array of DOM elements representing the links.
* @param {string} class_name
* The class to apply to the links.
* @param {string} icon_placement
* 'append' or 'prepend' the icon to the link.
*/
Drupal.extlink.applyClassAndSpan = function (links, class_name, icon_placement) {
var $links_to_process;
if (Drupal.settings.extlink.extImgClass) {
$links_to_process = $(links);
}
else {
var links_with_images = $(links).find('img').parents('a');
$links_to_process = $(links).not(links_with_images);
}
$links_to_process.addClass(class_name);
var i;
var length = $links_to_process.length;
for (i = 0; i < length; i++) {
var $link = $($links_to_process[i]);
if ($link.css('display') === 'inline' || $link.css('display') === 'inline-block') {
if (class_name === Drupal.settings.extlink.mailtoClass) {
$link[icon_placement]('<span class="' + class_name + '"><span class="element-invisible">' + Drupal.settings.extlink.mailtoLabel + '</span></span>');
}
else {
$link[icon_placement]('<span class="' + class_name + '"><span class="element-invisible">' + Drupal.settings.extlink.extLabel + '</span></span>');
}
}
}
}
};
};
Drupal.behaviors.extlink = Drupal.behaviors.extlink || {};
Drupal.behaviors.extlink.attach = function (context, settings) {
// Backwards compatibility, for the benefit of modules overriding extlink
// functionality by defining an "extlinkAttach" global function.
if (typeof extlinkAttach === 'function') {
extlinkAttach(context);
}
else {
Drupal.extlink.attach(context, settings);
}
};
// Backwards compatibility, for the benefit of modules overriding extlink
// functionality by defining an "extlinkAttach" global function.
if (typeof extlinkAttach === 'function') {
extlinkAttach(context);
}
else {
Drupal.extlink.attach(context, settings);
}
};
})(jQuery);
......@@ -6,15 +6,15 @@
*/
/**
* Implementation of hook_help().
* Implements hook_help().
*/
function extlink_help($path, $arg) {
switch ($path) {
case 'admin/help#extlink':
$output = '';
$output .= '<p>' . t('External Links is used to differentiate between internal and external links. Using jQuery, it will find all external links on a page and add an external icon indicating it will take you offsite or a mail icon for mailto links.') . '</p>';
return $output;
}
switch ($path) {
case 'admin/help#extlink':
$output = '';
$output .= '<p>' . t('External Links is used to differentiate between internal and external links. Using jQuery, it will find all external links on a page and add an external icon indicating it will take you offsite or a mail icon for mailto links.') . '</p>';
return $output;
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment