|
1 | 1 | // any link that is not part of the current domain is modified
|
2 | 2 |
|
3 |
| -(function() { |
| 3 | +(function () { |
4 | 4 | var links = document.links;
|
5 | 5 | for (var i = 0; i < links.length; i++) {
|
6 |
| - if (links[i].hostname != window.location.hostname && links[i].target == "" ) { |
| 6 | + if (links[i].hostname != window.location.hostname && links[i].target == "") { |
7 | 7 | links[i].target = '_blank';
|
8 | 8 | }
|
9 | 9 | }
|
10 | 10 | })();
|
11 | 11 |
|
| 12 | +$(document).ready(function () { |
| 13 | + var index, store; |
| 14 | + |
| 15 | + $('pre code').each(function(i, block) { |
| 16 | + hljs.highlightBlock(block); |
| 17 | + }); |
| 18 | + |
| 19 | + $(".show-snippet-link").click(function (e) { |
| 20 | + e.preventDefault(); |
| 21 | + var language = $(this).data("language"); |
| 22 | + $(".snippet").hide(); |
| 23 | + $(".snippet-" + language).show(); |
| 24 | + $(".show-snippet-tab").removeClass("active"); |
| 25 | + $(this.parentNode).addClass("active"); |
| 26 | + }); |
| 27 | + |
| 28 | + function switchSearchBox() { |
| 29 | + if ($("#search-box").is(":visible")) { |
| 30 | + $("#search-box").fadeOut('fast'); |
| 31 | + } else { |
| 32 | + $("#search-box").fadeIn('fast'); |
| 33 | + $("#search-term").val("").focus(); |
| 34 | + $("#search-results").empty().hide(); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + // show search view when icon is clicked |
| 39 | + $("#search-icon").on("click", function (e) { |
| 40 | + e.stopPropagation(); |
| 41 | + $(this).blur(); |
| 42 | + switchSearchBox(); |
| 43 | + }); |
| 44 | + |
| 45 | + $("#search-term").on('keyup', function (e) { |
| 46 | + if (e.keyCode == 27) { |
| 47 | + switchSearchBox(); |
| 48 | + return; |
| 49 | + } |
| 50 | + if (index) { |
| 51 | + var query = this.value; |
| 52 | + var result = index.search(query); |
| 53 | + var resultDiv = $("#search-results"); |
| 54 | + resultDiv.empty(); |
| 55 | + if (result.length == 0) { |
| 56 | + resultDiv.append("<p class='csmall'>No results</p>"); |
| 57 | + } else { |
| 58 | + resultDiv.append("<p class='csmall'>Results</p>"); |
| 59 | + for (var i in result.slice(0, 9)) { |
| 60 | + var ref = result[i].ref; |
| 61 | + var searchItem = "<p><a href='" + store[ref].href + "'>" + store[ref].title + "</a></p>"; |
| 62 | + resultDiv.append(searchItem); |
| 63 | + } |
| 64 | + resultDiv.show(); |
| 65 | + } |
| 66 | + } |
| 67 | + }); |
| 68 | + |
| 69 | + // hide search-box when clicked outside it |
| 70 | + $(document).click(function (event) { |
| 71 | + if (!$(event.target).closest('#search-box').length) { |
| 72 | + if ($("#search-box").is(":visible")) { |
| 73 | + $("#search-box").fadeOut('fast'); |
| 74 | + } |
| 75 | + } |
| 76 | + }); |
| 77 | + |
| 78 | + $(".navbar-toggle").on("click", function (e) { |
| 79 | + // check if menu is collapsed and hide search window as well |
| 80 | + var btn = $(this); |
| 81 | + window.setTimeout(function () { |
| 82 | + // delayed execution to allow Bootstrap code to do its thing first |
| 83 | + if (btn.hasClass("collapsed")) { |
| 84 | + $("#search-box").fadeOut(); |
| 85 | + } |
| 86 | + }, 0); |
| 87 | + }); |
| 88 | + |
| 89 | + // load search index |
| 90 | + $.getJSON('/search_data.json', function (response) { |
| 91 | + // Create index |
| 92 | + index = lunr.Index.load(response.index); |
| 93 | + // Create store |
| 94 | + store = response.store; |
| 95 | + }); |
| 96 | +}); |
| 97 | + |
12 | 98 | hljs.initHighlightingOnLoad();
|
13 | 99 |
|
14 | 100 | $(document).ready(function () {
|
|
0 commit comments