summaryrefslogtreecommitdiff
path: root/assets/js/core/utils.js
blob: e8e74b171a59f28127f76e6e64e22a6bdb90928c (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
KB.utils.formatDuration = function (d) {
    if (d >= 86400) {
        return Math.round(d/86400) + "d";
    }
    else if (d >= 3600) {
        return Math.round(d/3600) + "h";
    }
    else if (d >= 60) {
        return Math.round(d/60) + "m";
    }

    return d + "s";
};

KB.utils.getSelectionPosition = function (element) {
    var selectionStart, selectionEnd;

    if (element.value.length < element.selectionStart) {
        selectionStart = element.value.length;
    } else {
        selectionStart = element.selectionStart;
    }

    if (element.selectionStart === element.selectionEnd) {
        selectionEnd = selectionStart;
    } else {
        selectionEnd = element.selectionEnd;
    }

    return {
        selectionStart: selectionStart,
        selectionEnd: selectionEnd
    };
};