From d1bfb2049c1c4d5e34223941c2443aa33a123f68 Mon Sep 17 00:00:00 2001
From: Matthew Grasmick <matthew.grasmick@acquia.com>
Date: Wed, 23 Apr 2014 13:59:39 -0400
Subject: [PATCH] Issue #2248159: Making JS redirection independent of modal
 markup.

---
 extlink_extra.js | 49 ++++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/extlink_extra.js b/extlink_extra.js
index a6e1900..7369d6b 100644
--- a/extlink_extra.js
+++ b/extlink_extra.js
@@ -11,18 +11,19 @@ Drupal.settings.extlink_extra.colorboxSettings = Drupal.settings.extlink_extra.c
   width:'50%',
   initialWidth:'50%',
   initialHeight:'50%',
-  onComplete:function(){ //Note - drupal colorbox module automatically attaches drupal behaviors to loaded content
-    //Allow our cancel link to close the colorbox
+  onComplete:function(){
+    // Note - drupal colorbox module automatically attaches drupal behaviors to loaded content.
+    // Allow our cancel link to close the colorbox.
     jQuery('div.extlink-extra-back-action a').click(function(e){jQuery.colorbox.close(); return false;})
     extlink_extra_timer();
   },
   onClosed:extlink_stop_timer
 };
-  
+
 Drupal.behaviors.extlink_extra = {
   //Function mostly duplicated from extlink.js
   //Returns an array of DOM elements of all external links
-  extlinkAttach : function(context) { 
+  extlinkAttach : function(context) {
     // Strip the host name down, removing ports, subdomains, or www.
     var pattern = /^(([^\/:]+?\.)*)([^\.:]{4,})((\.[a-z]{1,4})*)(:[0-9]{1,5})?$/;
     var host = window.location.host.replace(pattern, '$3$4');
@@ -54,7 +55,7 @@ Drupal.behaviors.extlink_extra = {
       extExclude = new RegExp(Drupal.settings.extlink.extExclude.replace(/\\/, '\\'));
     }
 
-    //This next stanza copied verbatim from extlink:
+    // This next stanza copied verbatim from extlink:
     // 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
@@ -80,7 +81,7 @@ Drupal.behaviors.extlink_extra = {
         return false;
       }
     });
-    
+
     return external_links;
   },
 
@@ -91,7 +92,7 @@ Drupal.behaviors.extlink_extra = {
     if(isInExtraLeavingContainer(this)) {
       return true;
     }
-    
+
     var external_url = jQuery(this).attr('href');
     var back_url = window.location.href;
     var alerturl = Drupal.settings.extlink_extra.extlink_alert_url;
@@ -122,6 +123,7 @@ Drupal.behaviors.extlink_extra = {
     $.cookie("back_url", back_url, { path: '/' });
 
     if(Drupal.settings.extlink_extra.extlink_alert_type == 'colorbox') {
+      Drupal.settings.extlink_extra.colorboxSettings.externalUrl = external_url;
       jQuery.colorbox(Drupal.settings.extlink_extra.colorboxSettings);
       return false;
     }
@@ -136,12 +138,12 @@ Drupal.behaviors.extlink_extra = {
   attach: function(context){
     //Build an array of external_links exactly like extlink does
     var external_links = this.extlinkAttach(context);
-    
+
     //Unbind the click handlers added by extlink and replace with our own
     //This whole section of code that does the finding, unbinding, and rebinding
     //could be made a lot less redundant and more efficient if this issue could be resolved: http://drupal.org/node/1715520
     $(external_links).unbind('click').not('.ext-override, .extlink-extra-leaving a').click(this.clickReaction);
-    
+
     $(document).ready(function() {
       if(Drupal.settings.extlink_extra.extlink_url_override == 1) {
         if(Drupal.settings.extlink_extra.extlink_url_params.external_url) {
@@ -152,7 +154,7 @@ Drupal.behaviors.extlink_extra = {
         }
       }
     });
-    
+
     //Dynamically replace hrefs of back and external links on page load.  This is to compensate for aggressive caching situations
     //where the now-leaving is returning cached results
     if(Drupal.settings.extlink_extra.extlink_cache_fix == 1) {
@@ -174,7 +176,7 @@ Drupal.behaviors.extlink_extra = {
         //Either that or I was compensating for some other weird JS behavior, either way, this fixes it.
         jQuery('.extlink-extra-back-action a').attr('href', back_url);
         jQuery('.extlink-extra-go-action a').attr('href', external_url);
-        
+
         if (Drupal.settings.extlink.extTarget) {
           // Apply the target attribute action links
           $('.extlink-extra-back-action a').attr('target', Drupal.settings.extlink.extTarget);
@@ -215,28 +217,29 @@ Drupal.behaviors.extlink_extra = {
 var extlink_int;
 
 function extlink_extra_timer() {
-  if(Drupal.settings.extlink_extra.extlink_alert_timer == 0 || Drupal.settings.extlink_extra.extlink_alert_timer ==  null) {
+  if (Drupal.settings.extlink_extra.extlink_alert_timer == 0 || Drupal.settings.extlink_extra.extlink_alert_timer ==  null) {
     return;
   }
+  var count = Drupal.settings.extlink_extra.extlink_alert_timer;
+  var container = jQuery('.automatic-redirect-countdown');
+  extlink_update_countdown_markup(container, count);
+
   extlink_int = setInterval(function(){
-    var container = jQuery('.automatic-redirect-countdown');
-    var count = container.attr('rel');
-    if(count == null) {
-      count = Drupal.settings.extlink_extra.extlink_alert_timer;
-    }
-    if(count >= 0) {
-      container.html('<span class="extlink-timer-text">Automatically redirecting in: </span><span class="extlink-count">'+count+'</span><span class="extlink-timer-text"> seconds.</span>');
-      container.attr('rel',--count);
+    if (count >= 0) {
+      extlink_update_countdown_markup(container, count);
+      count--;
     }
     else {
       extlink_stop_timer();
-      container.remove();
-      var href = jQuery('div.extlink-extra-go-action a').attr('href');  
-      window.location = href;
+      window.location = Drupal.settings.extlink_extra.colorboxSettings.externalUrl;
     }
   },1000);
 }
 
+function extlink_update_countdown_markup(container, count) {
+  container.html('<span class="extlink-timer-text">Automatically redirecting in: </span><span class="extlink-count">'+count+'</span><span class="extlink-timer-text"> seconds.</span>');
+}
+
 function extlink_stop_timer() {
   clearInterval(extlink_int);
 }
-- 
1.8.5.2 (Apple Git-48)

