39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
|
let compareItems = [];
|
||
|
|
||
|
$('.history-compare').on('click', function () {
|
||
|
const hashID = $(this).data('hashid');
|
||
|
if(compareItems.includes(this)) {
|
||
|
compareItems.splice(compareItems.indexOf(this));
|
||
|
|
||
|
if(compareItems.length === 0) {
|
||
|
$('.history-compare').text('Vergleichen mit ...');
|
||
|
} else {
|
||
|
$(this).text('Zum Vergleich hinzufügen');
|
||
|
}
|
||
|
} else {
|
||
|
if(compareItems.length === 0) {
|
||
|
$('.history-compare').text('Zum Vergleich hinzufügen');
|
||
|
} else {
|
||
|
|
||
|
}
|
||
|
compareItems.push(this);
|
||
|
$(this).text('Vom Vergleich entfernen');
|
||
|
}
|
||
|
updateCompareItemsView();
|
||
|
});
|
||
|
|
||
|
function updateCompareItemsView() {
|
||
|
$('.compare-items').empty();
|
||
|
compareItems.forEach(item => {
|
||
|
$('.compare-items').append(`<span class="badge badge-primary">${item.dataset.hashid.substring(0, 6)}</span>`);
|
||
|
});
|
||
|
|
||
|
if(compareItems.length >= 2) {
|
||
|
const url = window.location.pathname + '/compare/' + compareItems[0].dataset.hashid + '/' + compareItems[1].dataset.hashid;
|
||
|
$('.compare-btn').attr('disabled', false)
|
||
|
.attr('href', url);
|
||
|
} else {
|
||
|
$('.compare-btn').attr('disabled', true)
|
||
|
.attr('href', '#');
|
||
|
}
|
||
|
}
|