Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *    http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /* Custom JavaScript code in the MarkDown docs */
0019 
0020 // Enable language-specific code tabs
0021 function codeTabs() {
0022   var counter = 0;
0023   var langImages = {
0024     "scala": "img/scala-sm.png",
0025     "python": "img/python-sm.png",
0026     "java": "img/java-sm.png"
0027   };
0028   $("div.codetabs").each(function() {
0029     $(this).addClass("tab-content");
0030 
0031     // Insert the tab bar
0032     var tabBar = $('<ul class="nav nav-tabs" data-tabs="tabs"></ul>');
0033     $(this).before(tabBar);
0034 
0035     // Add each code sample to the tab bar:
0036     var codeSamples = $(this).children("div");
0037     codeSamples.each(function() {
0038       $(this).addClass("tab-pane");
0039       var lang = $(this).data("lang");
0040       var image = $(this).data("image");
0041       var notabs = $(this).data("notabs");
0042       var capitalizedLang = lang.substr(0, 1).toUpperCase() + lang.substr(1);
0043       var id = "tab_" + lang + "_" + counter;
0044       $(this).attr("id", id);
0045       if (image != null && langImages[lang]) {
0046         var buttonLabel = "<img src='" +langImages[lang] + "' alt='" + capitalizedLang + "' />";
0047       } else if (notabs == null) {
0048         var buttonLabel = "<b>" + capitalizedLang + "</b>";
0049       } else {
0050         var buttonLabel = ""
0051       }
0052       tabBar.append(
0053         '<li><a class="tab_' + lang + '" href="#' + id + '">' + buttonLabel + '</a></li>'
0054       );
0055     });
0056 
0057     codeSamples.first().addClass("active");
0058     tabBar.children("li").first().addClass("active");
0059     counter++;
0060   });
0061   $("ul.nav-tabs a").click(function (e) {
0062     // Toggling a tab should switch all tabs corresponding to the same language
0063     // while retaining the scroll position
0064     e.preventDefault();
0065     var scrollOffset = $(this).offset().top - $(document).scrollTop();
0066     $("." + $(this).attr('class')).tab('show');
0067     $(document).scrollTop($(this).offset().top - scrollOffset);
0068   });
0069 }
0070 
0071 
0072 // A script to fix internal hash links because we have an overlapping top bar.
0073 // Based on https://github.com/twitter/bootstrap/issues/193#issuecomment-2281510
0074 function maybeScrollToHash() {
0075   if (window.location.hash && $(window.location.hash).length) {
0076     var newTop = $(window.location.hash).offset().top - 57;
0077     $(window).scrollTop(newTop);
0078   }
0079 }
0080 
0081 $(function() {
0082   codeTabs();
0083   // Display anchor links when hovering over headers. For documentation of the
0084   // configuration options, see the AnchorJS documentation.
0085   anchors.options = {
0086     placement: 'right'
0087   };
0088   anchors.add();
0089 
0090   $(window).bind('hashchange', function() {
0091     maybeScrollToHash();
0092   });
0093 
0094   // Scroll now too in case we had opened the page on a hash, but wait a bit because some browsers
0095   // will try to do *their* initial scroll after running the onReady handler.
0096   $(window).on('load', function() { setTimeout(function() { maybeScrollToHash(); }, 25); });
0097 });