Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/assets/js/blog-history.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

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', '#');
}
}