aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/bootstrap/tabbable_widget.js
blob: c89eb164d9d75c0dd7bac7e0e9fdc619ae9e1bb2 (plain)
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
$(document).on('click', '.tabbable-widget > nav > a', function(event) {
    var selector = $(this).attr('href');
    $(this)
        .addClass('active')
        .siblings()
        .removeClass('active');
    $(selector)
        .addClass('active')
        .siblings('section')
        .removeClass('active')
        .end();

    // Delay resetting of scroll top until browser is no longer busy
    // (otherwise the scrolled element will not reset - at least in FF)
    setTimeout(function() {
        $(selector).scrollTop(0);
    }, 0);

    if (history.pushState) {
        history.pushState(null, null, selector);
    }

    event.preventDefault();
});
STUDIP.domReady(() => {
    if (!location.hash) {
        return;
    }

    $('.tabbable-widget > nav > a[href="' + location.hash + '"]').click();
});