summaryrefslogtreecommitdiff
path: root/media/js/forms.js
blob: 1c694e09d92abe22972d17e89cf41a43571f09e2 (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
$(document).ready(function(){
    $('textarea.markdown-content').each(function(idx, e) {
        attach_markdown_preview(e.id, 0);
    });

    $('input.toggle-checkbox').each(function(idx, e) {
        $(this).change(function(e) {
            update_form_toggles($(this));
        });
        update_form_toggles($(e));
    });

});

function update_form_toggles(e) {
    var toggles = e.data('toggles').split(',');
    var invert = e.data('toggle-invert');
    var show = e.is(':checked');
    if (invert) {
        show = !show;
    }
    $.each(toggles, function(i, name) {
        var e = $('#id_' + name);
        if (show) {
            $(e).parents('div.form-group').show();
        } else {
            $(e).parents('div.form-group').hide();
        }
    });
}