~linuxgoose/bocpress

ref: 936ac6d885385d9e80ea4b9852e3d7b0390ec758 bocpress/main/templates/assets/make-draft-button.js -rw-r--r-- 1.5 KiB
936ac6d8 — Jordan update readme wording 2 months ago
                                                                                
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
function initPubDateButtons() {
    // check if form instantiation is to create new post or edit existing one
    var isCreateOp = {{ form.initial|yesno:"false,true" }};

    var pubDateElem = document.querySelector('input[name="published_at"]');
    if (pubDateElem.value === '') {

        // add 'set to today' functionality on publication date
        var setTodaySpan = document.getElementById('set-today');
        var setTodayAnchor = document.createElement('a');
        setTodayAnchor.innerText = 'set to today';
        setTodayAnchor.href='javascript:';
        setTodaySpan.appendChild(document.createTextNode(' — '));
        setTodaySpan.appendChild(setTodayAnchor);
        setTodaySpan.addEventListener('click', function () {
            var isoDate = new Date().toISOString().substring(0,10);
            document.querySelector('input[name="published_at"]').value = isoDate;
        });

    } else if (isCreateOp) {
        // add 'make draft / set to empty' functionality
        var setEmptySpan = document.getElementById('set-empty');
        var setEmptyAnchor = document.createElement('a');
        setEmptyAnchor.innerText = 'set as draft';
        setEmptyAnchor.href='javascript:';
        setEmptySpan.appendChild(document.createTextNode(' — '));
        setEmptySpan.appendChild(setEmptyAnchor);
        setEmptySpan.addEventListener('click', function () {
            document.querySelector('input[name="published_at"]').value = '';
        });
    }
}

// init
initPubDateButtons();