MediaWiki:InterTabLinking.js

function getQuery { var query = {}; for (var part of window.location.search.substring(1).split("&")) { var kv = part.split("="); if (kv.length === 2) { query[kv[0]] = kv[1]; }   }    return query; }

(function(mw, $) {

"use strict";

$(document).ready(function {

function scrollTo(content, selector) { var element = content.find(selector).get(0); if (element) { element.scrollIntoView; }       }

var initial_hash = window.location.hash && window.location.hash !== "" ? window.location.hash : true, initial_tab = getQuery.tab, switch_hash = null, outer_element = $(initial_hash).get(0);

function switchToTab(tab, hash) { $("ul.tabs li a span:contains('" + tab + "')").parent.trigger("click"); switch_hash = hash; }

function processTabBody(content) { var $content = $(content); if ($content.attr("class") === "tabBody selected") { $content.ready(function {

if (initial_hash) { if (initial_tab) { switchToTab(initial_tab, initial_hash); initial_tab = null; } else { if (!outer_element) { scrollTo($content, initial_hash); }                           initial_hash = null; }                   } else { if (switch_hash) { scrollTo($content, switch_hash); switch_hash = null; }                   }

$content.find(".tabview_link a").each(function {                       $(this).click(function(link_element) { link_element.preventDefault; var href = $(this).attr("href"), parts = href.split("/").pop.split("#"), tab = parts[0], hash = "#" + parts[1]; window.location.hash = hash; switchToTab(tab, hash); scrollTo($(".tabBody.selected"), hash); });                   });

});           }        }

mw.hook("wikipage.content").add(processTabBody);

});

}(mediaWiki, jQuery));