aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/lib/sidebar.js
blob: 6768a86e56a2713c3b107b0e1b54d8afab341934 (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
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
import Scroll from './scroll.js';

const Sidebar = {
    stickyEnabled: true,
    enableSticky() {
        this.stickyEnabled = true;
        this.setSticky();
    },
    disableSticky() {
        this.stickyEnabled = false;
        this.setSticky(false);
    },
    open () {
        this.toggle(true);
    },
    close () {
        this.toggle(false);
    },
    toggle (visible = null) {
        visible = visible ?? !$('#layout-sidebar').hasClass('visible-sidebar');

        // Hide navigation
        $('#responsive-toggle').prop('checked', false);
        $('#responsive-navigation').removeClass('visible');

        $('#layout-sidebar').toggleClass('visible-sidebar', visible);
    }
};

// This function inits the sticky sidebar by using the StickyKit lib
// <http://leafo.net/sticky-kit/>
Sidebar.setSticky = function(is_sticky) {
    if (!this.stickyEnabled) {
        return;
    }

    if (is_sticky === undefined || is_sticky) {
        $('#layout-sidebar .sidebar')
            .stick_in_parent({
                offset_top: $('#barBottomContainer').outerHeight(true) + 15,
                inner_scrolling: true
            })
            .on('sticky_kit:stick sticky_kit:unbottom', function() {
                var stuckHandler = function(top, left) {
                    $('#layout-sidebar .sidebar').css('margin-left', -left);
                };
                Scroll.addHandler('sticky.horizontal', stuckHandler);
                stuckHandler(0, $(window).scrollLeft());
            })
            .on('sticky_kit:unstick sticky_kit:bottom', function() {
                Scroll.removeHandler('sticky.horizontal');
                $(this).css('margin-left', 0);
            });
    } else {
        Scroll.removeHandler('sticky.horizontal');
        $('#layout-sidebar .sidebar')
            .trigger('sticky_kit:unstick')
            .trigger('sticky_kit:detach');
    }
};

Sidebar.checkActiveLineHeight = () => {
    $('#layout-sidebar .sidebar .sidebar-widget-content .widget-links li.active a.active').each(function() {
        var link = $(this);
        var actual_text = link.text();
        link.text('tmp');
        var default_height = link.outerHeight();
        link.text(actual_text);
        var actual_height = link.outerHeight();
        if (actual_height > default_height) { //it is rendered in more lines
            link.css('line-height', '20px');
        }
    });
}
export default Sidebar;