aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/bootstrap/startpage.js
blob: 2af7955ac713806a2de1d0d3722256fe562b91af (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
STUDIP.domReady(() => {
    if ($('html').is(':not(.responsive-display)')) {
        STUDIP.startpage.init();
    }
});

// Add handler for "read all" on news widget
$(document).on('click', '#start-index a[href*="newswidget/read_all"]', function(event) {
    var icon = $(this),
        url = icon.attr('href'),
        widget = icon.closest('.studip-widget');

    icon.prop('disabled', true).addClass('ajaxing');

    $.getJSON(url).then(function(response) {
        if (response) {
            $('article.new', widget).removeClass('new');
            $('.news-comments-unread', widget)
                .removeClass('news-comments-unread')
                .removeAttr('title');

            // It is approriate to use attr() to modify data here since
            // the attribute's value is displayed via css, thus it needs
            // to be actually in the DOM.
            $('#nav_start [data-badge]')
                .attr('data-badge', 0)
                .trigger('badgechange');

            icon.remove();
        }
    });

    event.preventDefault();
});