misc.js 2.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Fix the hero text effect on large screens
function resetHeroHidden() {
    const scrollAmount = window.scrollY;
    if (window.matchMedia("only screen and (min-width: 76.25em)").matches) {
        // only enable this on large screens
        if (scrollAmount == 0) {
            $(".md-hero").attr("data-md-state", "");
        } else {
            $(".md-hero").attr("data-md-state", "hidden");
        }
    }
}

// https://github.com/bashtage/sphinx-material/blob/6e0ef822e58df57d6a9de5a58dc40c17fc34f557/sphinx_material/sphinx_material/static/javascripts/application.js#L1384
$(window).on("scroll", resetHeroHidden);
$(window).on("resize", resetHeroHidden);
$(window).on("orientationchange", resetHeroHidden);


// Sidebar header
$(document).ready(function() {
    let language = "en";  // default english
    try {
        language = READTHEDOCS_DATA["language"];
    } catch (e) {}

    const title = $(".md-sidebar--secondary .md-nav--secondary label.md-nav__title");
    if (language == "en") {
        title.text("On this page");
    } else if (language == "zh") {
        title.text("本页内容");
    }
});


// Hide navigation bar when it's too short
// Hide TOC header when it coincides with page title
function hide_nav() {
    const d = $('nav.md-tabs[data-md-component="tabs"]');
    if (d.find('li').length <= 1) {
        d.addClass('hidden');
    }
}

// Expand link
function expand_link() {
    // on load, collapse all links without active on the inside
    $(".md-nav__expand").filter(function (index) {
        return $(".md-nav__link--active", this).length >= 1;
    }).addClass("md-nav__expand--active");

    function toggleExpand(event) {
        event.preventDefault();

        $(event.target)
            .closest(".md-nav__expand")
            .toggleClass("md-nav__expand--active");

        return false;
    }

    // bind click events
    $(".md-nav__expand > a").click(toggleExpand);
    $(".md-nav__expand > a > .md-nav__tocarrow").click(toggleExpand);
}

// Propagate card link from another element
function propagate_card_link() {
    $(".card-link-clickable").each(function() {
        $(this).attr("href", $(this).next("a.reference").attr("href"));
    });
}

$(document).ready(function() {
    hide_nav();
    expand_link();
    propagate_card_link();
});