Reload a quicktab on second click

There are some old topics on drupal.org about this subject, but they apply to older versions of QT (D6) or just didn't work for my situation.

I found it easy to force an ajax Quicktab to reload it's content on every click, but to do it only when you click the currently active tab again, I had to write my own magic.

The good news is, it's actually very simple, and you only need to add some new JS to the page (no patching / hacking / heavy module required!).

This JS will do it, (I do it in a Drupal.behaviors.xyz attach):

        if (Drupal.ajax) {
          /**
           * Handle an event that triggers an AJAX response.
           *
           * We unfortunately need to override this function, which originally comes from
           * misc/ajax.js, in order to be able to cache loaded tabs, i.e. once a tab
           * content has loaded it should not need to be loaded again.
           *
           * Well Mr. Quicktabs, we unfortunately need to override your overridden
           * function, in order to be able to refresh an ajax cached tab on new requests.
           * -drastik.
           */

          Drupal.ajax.prototype.eventResponse = function (element, event) {
            var ajax = this;

            if (ajax.ajaxing) {
              return false;
            }

            try {
              if (ajax.form) {
                if (ajax.setClick) {
                  element.form.clk = element;
                }

                ajax.form.ajaxSubmit(ajax.options);
              }
              else {
                // Do not perform an ajax request for already loaded Quicktabs content.
                if ($(element).parents('ul').hasClass('quicktabs-tabs')) {
                  if ($(element).hasClass('quicktabs-loaded')) {
                      tab = new Drupal.quicktabs.tab(element);
                    if ($(element).parents('li').hasClass('active')) {
                      tab.tabpage.removeClass("quicktabs-tabpage");
                      tab.tabpage.remove();
                    } else {
                      return false;
                    }
                  } else {
                    $(element).addClass('quicktabs-loaded');
                  }
                }
                ajax.beforeSerialize(ajax.element, ajax.options);
                $.ajax(ajax.options);
            }
          }
            catch (e) {
              ajax.ajaxing = false;
              alert("An error occurred while attempting to process " + ajax.options.url + ": " + e.message);
            }
            return false;
          };

        }

Joshua Walker