test
12/**3* jQuery Plugin: Sticky Tabs4*5* @author Aidan Lister <[email protected]>6* adapted by Ruben Arslan to activate parent tabs too7* http://www.aidanlister.com/2014/03/persisting-the-tab-state-in-bootstrap/8*/9(function($) {10"use strict";11$.fn.rmarkdownStickyTabs = function() {12var context = this;13// Show the tab corresponding with the hash in the URL, or the first tab14var showStuffFromHash = function() {15var hash = window.location.hash;16var selector = hash ? 'a[href="' + hash + '"]' : 'li.active > a';17var $selector = $(selector, context);18if($selector.data('toggle') === "tab") {19$selector.tab('show');20// walk up the ancestors of this element, show any hidden tabs21$selector.parents('.section.tabset').each(function(i, elm) {22var link = $('a[href="#' + $(elm).attr('id') + '"]');23if(link.data('toggle') === "tab") {24link.tab("show");25}26});27}28};293031// Set the correct tab when the page loads32showStuffFromHash(context);3334// Set the correct tab when a user uses their back/forward button35$(window).on('hashchange', function() {36showStuffFromHash(context);37});3839// Change the URL when tabs are clicked40$('a', context).on('click', function(e) {41history.pushState(null, null, this.href);42showStuffFromHash(context);43});4445return this;46};47}(jQuery));4849window.buildTabsets = function(tocID) {5051// build a tabset from a section div with the .tabset class52function buildTabset(tabset) {5354// check for fade and pills options55var fade = tabset.hasClass("tabset-fade");56var pills = tabset.hasClass("tabset-pills");57var navClass = pills ? "nav-pills" : "nav-tabs";5859// determine the heading level of the tabset and tabs60var match = tabset.attr('class').match(/level(\d) /);61if (match === null)62return;63var tabsetLevel = Number(match[1]);64var tabLevel = tabsetLevel + 1;6566// find all subheadings immediately below67var tabs = tabset.find("div.section.level" + tabLevel);68if (!tabs.length)69return;7071// create tablist and tab-content elements72var tabList = $('<ul class="nav ' + navClass + '" role="tablist"></ul>');73$(tabs[0]).before(tabList);74var tabContent = $('<div class="tab-content"></div>');75$(tabs[0]).before(tabContent);7677// build the tabset78var activeTab = 0;79tabs.each(function(i) {8081// get the tab div82var tab = $(tabs[i]);8384// get the id then sanitize it for use with bootstrap tabs85var id = tab.attr('id');8687// see if this is marked as the active tab88if (tab.hasClass('active'))89activeTab = i;9091// remove any table of contents entries associated with92// this ID (since we'll be removing the heading element)93$("div#" + tocID + " li a[href='#" + id + "']").parent().remove();9495// sanitize the id for use with bootstrap tabs96id = id.replace(/[.\/?&!#<>]/g, '').replace(/\s/g, '_');97tab.attr('id', id);9899// get the heading element within it, grab it's text, then remove it100var heading = tab.find('h' + tabLevel + ':first');101var headingText = heading.html();102heading.remove();103104// build and append the tab list item105var a = $('<a role="tab" data-toggle="tab">' + headingText + '</a>');106a.attr('href', '#' + id);107a.attr('aria-controls', id);108var li = $('<li role="presentation"></li>');109li.append(a);110tabList.append(li);111112// set it's attributes113tab.attr('role', 'tabpanel');114tab.addClass('tab-pane');115tab.addClass('tabbed-pane');116if (fade)117tab.addClass('fade');118119// move it into the tab content div120tab.detach().appendTo(tabContent);121});122123// set active tab124$(tabList.children('li')[activeTab]).addClass('active');125var active = $(tabContent.children('div.section')[activeTab]);126active.addClass('active');127if (fade)128active.addClass('in');129130if (tabset.hasClass("tabset-sticky"))131tabset.rmarkdownStickyTabs();132}133134// convert section divs with the .tabset class to tabsets135var tabsets = $("div.section.tabset");136tabsets.each(function(i) {137buildTabset($(tabsets[i]));138});139};140141142143