Subversion Repositories cheapmusic

Rev

Rev 43 | Rev 47 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15 - 1
$(document).ready(function() {
17 - 2
    $('[data-toggle="tooltip"]').tooltip({trigger : 'hover'});
3
    $('[data-toggle2="tooltip"]').tooltip({trigger : 'hover'});
28 - 4
    $('[rel="tooltip"]').on('click', function() {$(this).tooltip('hide');});
23 - 5
 
20 - 6
    $('.flexdatalist').flexdatalist();
7
    $(function() {
8
        $("input[id='searchTerm-flexdatalist']").clearer();
9
    });
10
    $('.flexdatalist').flexdatalist({minLength: 0, searchContain : true, noResultsText: ""}); /* reset after running clearer */
6 - 11
 
15 - 12
    $(window).on('beforeunload', function() {
13
        $(":submit").attr('disabled', 'disabled');
14
    });
15
 
43 - 16
    $(window).bind('resize orientationchange', paginationSetup);
17
 
15 - 18
    tableFilterButtons();
43 - 19
    paginationSetup();
6 - 20
});
11 - 21
 
15 - 22
function tableFilterButtons() {
23
    $(".filterButton").click(function() {
24
        $.post("filterTable.php", {
25
            submit: $(this).attr("value"),
26
            sessionTab: document.getElementById("sessionTab").value
27
        }, function(data, status) {
28
            if (status == "success") {
29
                document.getElementById("productTable").innerHTML = data;
30
                tableFilterButtons();
31
            }
32
        });
33
    });
34
}
35
 
36
function initProgressBarModal(title) {
37
    var elem = document.getElementById("progressBar");
38
    elem.style.width = '0%';
39
    elem.innerHTML = '0%';
40
 
41
    elem = document.getElementById("progressBarHeader");
42
    elem.innerHTML = title;
43
 
23 - 44
    $("#progressBarDiv").modal({backdrop: "static"});
15 - 45
}
46
 
47
function updateProgressBar(width, message) {
48
    var elem = document.getElementById("progressBar");
49
    elem.style.width = width + '%';
50
    elem.innerHTML = width.toFixed(0) + '%';
51
    // bugbug document.getElementById("progressBarMessage").innerHTML = message;
52
}
53
 
54
function endProgressBarModal() {
55
    $("#progressBarDiv").modal("hide");
56
}
57
 
58
// Refresh the progress bar.
59
function refreshProgress() {
60
    $.ajax({
61
        url: "pbChecker.php?file=" + document.getElementById("sessionId").value + "_" + document.getElementById("sessionTab").value,
62
        success: function(data) {
63
            updateProgressBar(data.percent, data.message);
64
            if (data.percent == 100) {
65
                window.clearInterval(timer);
66
                timer = window.setInterval(completeProgress, 1000);
67
            }
68
        }
69
    });
70
}
71
 
72
// End the progress bar.
73
function completeProgress() {
74
    updateProgressBar(100, "Completed");
75
    window.clearInterval(timer);
39 - 76
    endProgressBarModal();
15 - 77
}
78
 
79
// Start the progress bar.
80
function progressBar(title) {
81
    initProgressBarModal(title);
82
    timer = window.setInterval(refreshProgress, 1000);
28 - 83
}
84
 
85
function saveTransfer($url) {
86
    var xhttp = new XMLHttpRequest();
87
    xhttp.open("POST", "savetransfer.php", true);
88
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
89
    xhttp.send("target=" + btoa($url) + "&sessionTab=" + document.getElementById("sessionTab").value);
43 - 90
}
91
 
92
// Pagination
93
function paginationSetup(){
94
    $('#discogsDeck').paginate({
95
        paginateElement: '.card',
96
        elementsPerPage: paginationPerPage(),
97
        effect: 'default',
98
        firstButtonText: '<i class="fas fa-angle-double-left"></i>',
99
        lastButtonText: '<i class="fas fa-angle-double-right"></i>',
100
        prevButtonText: '<i class="fas fa-angle-left"></i>',
101
        nextButtonText: '<i class="fas fa-angle-right"></i>',
102
        extraButtonClasses: 'btn btn-primary px-2 shadow-sm'
103
    });
104
    $('[data-toggle="tooltip"]').tooltip({trigger : 'hover'});
105
    $('[data-toggle2="tooltip"]').tooltip({trigger : 'hover'});
106
}
107
 
46 - 108
// number of discogs entries per page according to screen size
43 - 109
function paginationPerPage() {
110
    width = $( document ).width();
111
    if (width < 576){
112
        return 1;
113
    } else if (width < 768){
114
        return 2;
115
    } else if (width < 992){
116
        return 3;
117
    } else if (width < 1200){
118
        return 4;
119
    } else {
120
        return 6;
121
    }
122
}
46 - 123
 
124
// sort table by column
125
function sortTable(table, col, colType) {
126
    var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
127
    table = document.getElementById(table);
128
    switching = true;
129
    // Set the sorting direction to ascending:
130
    dir = "asc";
131
    /* Make a loop that will continue until no switching has been done: */
132
    while (switching) {
133
        // Start by saying: no switching is done:
134
        switching = false;
135
        rows = table.rows;
136
        /* Loop through all table rows (except the first, which contains table headers): */
137
        for (i = 1; i < (rows.length - 1); i++) {
138
            // Start by saying there should be no switching:
139
            shouldSwitch = false;
140
            /* Get the two elements you want to compare, one from current row and one from the next: */
141
            x = rows[i].getElementsByTagName("TD")[col];
142
            y = rows[i + 1].getElementsByTagName("TD")[col];
143
            /* Check if the two rows should switch place, based on the direction, asc or desc: */
144
            if (dir == "asc") {
145
                if (colType == 'numeric') {
146
                    if (Number(x.innerHTML) > Number(y.innerHTML.toLowerCase)) {
147
                        // If so, mark as a switch and break the loop:
148
                        shouldSwitch = true;
149
                        break;
150
                    }
151
                } else /* if (colType == 'text') */ {
152
                    if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
153
                        // If so, mark as a switch and break the loop:
154
                        shouldSwitch = true;
155
                        break;
156
                    }
157
                }
158
            } else if (dir == "desc") {
159
                if (colType == 'numeric') {
160
                    if (Number(x.innerHTML) < Number(y.innerHTML)) {
161
                        // If so, mark as a switch and break the loop:
162
                        shouldSwitch = true;
163
                        break;
164
                    }
165
                } else /* if (colType == 'text') */ {
166
                    if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
167
                        // If so, mark as a switch and break the loop:
168
                        shouldSwitch = true;
169
                        break;
170
                    }
171
                }
172
            }
173
        }
174
        if (shouldSwitch) {
175
            /* If a switch has been marked, make the switch and mark that a switch has been done: */
176
            rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
177
            switching = true;
178
            // Each time a switch is done, increase this count by 1:
179
            switchcount++;
180
        } else {
181
            /* If no switching has been done AND the direction is "asc", set the direction to "desc" and run the while loop again. */
182
            if (switchcount == 0 && dir == "asc") {
183
                dir = "desc";
184
                switching = true;
185
            }
186
        }
187
    }
188
}
189