diff --git a/extlink.js b/extlink.js
index ad03f79..8f14d81 100644
--- a/extlink.js
+++ b/extlink.js
@@ -51,6 +51,9 @@ Drupal.extlink.attach = function (context, settings) {
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
@@ -86,11 +89,11 @@ Drupal.extlink.attach = function (context, settings) {
});
if (settings.extlink.extClass) {
- Drupal.extlink.applyClassAndSpan(external_links, settings.extlink.extClass);
+ Drupal.extlink.applyClassAndSpan(external_links, settings.extlink.extClass, extIconPlacement);
}
if (settings.extlink.mailtoClass) {
- Drupal.extlink.applyClassAndSpan(mailto_links, settings.extlink.mailtoClass);
+ Drupal.extlink.applyClassAndSpan(mailto_links, settings.extlink.mailtoClass, extIconPlacement);
}
if (settings.extlink.extTarget) {
@@ -120,8 +123,10 @@ Drupal.extlink.attach = function (context, settings) {
* An array of DOM elements representing the links.
* @param class_name
* The class to apply to the links.
+ * @param icon_placement
+ * 'append' or 'prepend' the icon to the link.
*/
-Drupal.extlink.applyClassAndSpan = function (links, class_name) {
+Drupal.extlink.applyClassAndSpan = function (links, class_name, icon_placement) {
var $links_to_process;
if (Drupal.settings.extlink.extImgClass){
$links_to_process = $(links);
@@ -137,10 +142,10 @@ Drupal.extlink.applyClassAndSpan = function (links, class_name) {
var $link = $($links_to_process[i]);
if ($link.css('display') == 'inline' || $link.css('display') == 'inline-block') {
if (class_name == Drupal.settings.extlink.mailtoClass) {
- $link.append(' ' + Drupal.settings.extlink.mailtoLabel + '');
+ $link[icon_placement](' ' + Drupal.settings.extlink.mailtoLabel + '');
}
else {
- $link.append(' ' + Drupal.settings.extlink.extLabel + '');
+ $link[icon_placement](' ' + Drupal.settings.extlink.extLabel + '');
}
}
}
diff --git a/extlink.module b/extlink.module
index fcaae5b..9e9d1bd 100644
--- a/extlink.module
+++ b/extlink.module
@@ -26,6 +26,7 @@ function extlink_page_build() {
'extClass' => variable_get('extlink_class', 'ext'),
'extLabel' => check_plain(variable_get('extlink_label', t('(link is external)'))),
'extImgClass' => variable_get('extlink_img_class', 0),
+ 'extIconPlacement' => variable_get('extlink_icon_placement', 'append'),
'extSubdomains' => variable_get('extlink_subdomains', 1),
'extExclude' => variable_get('extlink_exclude', ''),
'extInclude' => variable_get('extlink_include', ''),
@@ -65,6 +66,14 @@ function extlink_admin_settings() {
'#description' => t('If checked, images wrapped in an anchor tag will be treated as external links.'),
);
+ $form['extlink_icon_placement'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Add icon in front of any processed link'),
+ '#return_value' => 'prepend',
+ '#default_value' => variable_get('extlink_icon_placement', 'append'),
+ '#description' => t('If checked, the icon will be placed in front of any external link, otherwise it will be placed behind it.'),
+ );
+
$form['extlink_subdomains'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude links with the same primary domain.'),