aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/bootstrap/article.js
blob: 04316f5f18b26d53e4421a05b274ddf1bd49d837 (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
(function ($, STUDIP) {
    'use strict';

    $(document).on('click', 'article.studip.toggle header h1 a', function (e) {
        e.preventDefault();

        var article = $(this).closest('article');

        // If the contentbox article is new send an ajax request
        if (article.hasClass('new') && article.data('visiturl')) {
            $.post(STUDIP.URLHelper.getURL(decodeURIComponent(article.data('visiturl') + $(this).attr('href'))));
        }

        // Open the contentbox
        article.toggleClass('open').removeClass('new');
        article.attr('aria-expanded', article.attr('aria-expanded') === 'true' ? 'false' : 'true');
    });

    // Open closed article contents when location hash matches
    $(window).on('hashchange', (event) => {
        const hash = location.hash.split('#').pop();
        $(`article.studip.toggle:not(.open) header h1 a[name="${hash}"]`).click();
    });

    STUDIP.ready(() => {
        const hash = location.hash.split('#').pop();
        if (hash.length > 0) {
            $(`article.studip.toggle:not(.open) header h1 a[name="${hash}"]`).click();
        }
    });
}(jQuery, STUDIP));