mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2026-03-22 08:38:11 +05:00
preference to dynamically load comments and small fixes
This commit is contained in:
25
static/assets/comments.js
Normal file
25
static/assets/comments.js
Normal file
@@ -0,0 +1,25 @@
|
||||
var comm = document.getElementById('comments');
|
||||
function comments(self) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '/_/partials/comments/'+self.getAttribute('data-id')+self.getAttribute('href'), true);
|
||||
xhr.onerror = function(e) {
|
||||
alert('Something went wrong. Check console');
|
||||
console.error(e);
|
||||
}
|
||||
xhr.onload = function() {
|
||||
if (xhr.status != 200) {
|
||||
alert(xhr.responseText);
|
||||
return;
|
||||
}
|
||||
|
||||
comm.innerHTML += xhr.responseText;
|
||||
var next = xhr.getResponseHeader('next');
|
||||
if (next == 'done') {
|
||||
self.remove();
|
||||
} else {
|
||||
self.setAttribute('href', next);
|
||||
}
|
||||
self.textContent = 'more comments';
|
||||
}
|
||||
xhr.send();
|
||||
}
|
||||
Reference in New Issue
Block a user