spark-instrumented-optimizer/docs/js/main.js
Matei Zaharia c86eec5843 SPARK-1135: fix broken anchors in docs
A recent PR that added Java vs Scala tabs for streaming also
inadvertently added some bad code to a document.ready handler, breaking
our other handler that manages scrolling to anchors correctly with the
floating top bar. As a result the section title ended up always being
hidden below the top bar. This removes the unnecessary JavaScript code.

Author: Matei Zaharia <matei@databricks.com>

Closes #3 from mateiz/doc-links and squashes the following commits:

e2a3488 [Matei Zaharia] SPARK-1135: fix broken anchors in docs
2014-02-26 11:20:16 -08:00

81 lines
2.5 KiB
JavaScript
Executable file

function codeTabs() {
var counter = 0;
var langImages = {
"scala": "img/scala-sm.png",
"python": "img/python-sm.png",
"java": "img/java-sm.png"
};
$("div.codetabs").each(function() {
$(this).addClass("tab-content");
// Insert the tab bar
var tabBar = $('<ul class="nav nav-tabs" data-tabs="tabs"></ul>');
$(this).before(tabBar);
// Add each code sample to the tab bar:
var codeSamples = $(this).children("div");
codeSamples.each(function() {
$(this).addClass("tab-pane");
var lang = $(this).data("lang");
var image = $(this).data("image");
var notabs = $(this).data("notabs");
var capitalizedLang = lang.substr(0, 1).toUpperCase() + lang.substr(1);
var id = "tab_" + lang + "_" + counter;
$(this).attr("id", id);
if (image != null && langImages[lang]) {
var buttonLabel = "<img src='" +langImages[lang] + "' alt='" + capitalizedLang + "' />";
} else if (notabs == null) {
var buttonLabel = "<b>" + capitalizedLang + "</b>";
} else {
var buttonLabel = ""
}
tabBar.append(
'<li><a class="tab_' + lang + '" href="#' + id + '">' + buttonLabel + '</a></li>'
);
});
codeSamples.first().addClass("active");
tabBar.children("li").first().addClass("active");
counter++;
});
$("ul.nav-tabs a").click(function (e) {
// Toggling a tab should switch all tabs corresponding to the same language
// while retaining the scroll position
e.preventDefault();
var scrollOffset = $(this).offset().top - $(document).scrollTop();
$("." + $(this).attr('class')).tab('show');
$(document).scrollTop($(this).offset().top - scrollOffset);
});
}
function makeCollapsable(elt, accordionClass, accordionBodyId, title) {
$(elt).addClass("accordion-inner");
$(elt).wrap('<div class="accordion ' + accordionClass + '"></div>')
$(elt).wrap('<div class="accordion-group"></div>')
$(elt).wrap('<div id="' + accordionBodyId + '" class="accordion-body collapse"></div>')
$(elt).parent().before(
'<div class="accordion-heading">' +
'<a class="accordion-toggle" data-toggle="collapse" href="#' + accordionBodyId + '">' +
title +
'</a>' +
'</div>'
);
}
function viewSolution() {
var counter = 0
$("div.solution").each(function() {
var id = "solution_" + counter
makeCollapsable(this, "", id,
'<i class="icon-ok-sign" style="text-decoration: none; color: #0088cc">' +
'</i>' + "View Solution");
counter++;
});
}
$(function() {
codeTabs();
viewSolution();
});