|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
var topicsListEl = document.querySelector('.topics');
|
|
|
|
|
var topicsListEl = document.querySelector('.topics'),
|
|
|
|
|
loadMoreEl = document.getElementById('topics_loadmore');
|
|
|
|
|
|
|
|
|
|
$(topicsListEl).on('click', '[data-action]', function() {
|
|
|
|
|
var $this = $(this),
|
|
|
|
@ -22,6 +23,19 @@ $(document).ready(function() {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
loadMoreEl.addEventListener('click', function() {
|
|
|
|
|
if (this.className.indexOf('disabled') === -1) {
|
|
|
|
|
var topics = document.querySelectorAll('.topics li[data-tid]'),
|
|
|
|
|
lastTid = parseInt(topics[topics.length - 1].getAttribute('data-tid'));
|
|
|
|
|
|
|
|
|
|
this.innerHTML = '<i class="icon-refresh icon-spin"></i> Retrieving topics';
|
|
|
|
|
socket.emit('api:admin.topics.getMore', {
|
|
|
|
|
limit: 10,
|
|
|
|
|
after: lastTid
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
// Resolve proper button state for all topics
|
|
|
|
|
var topicEls = topicsListEl.querySelectorAll('li'),
|
|
|
|
|
numTopics = topicEls.length;
|
|
|
|
@ -81,4 +95,24 @@ socket.on('api:topic.restore', function(response) {
|
|
|
|
|
|
|
|
|
|
$(btnEl).removeClass('active');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
socket.on('api:admin.topics.getMore', function(topics) {
|
|
|
|
|
var btnEl = document.getElementById('topics_loadmore');
|
|
|
|
|
|
|
|
|
|
topics = JSON.parse(topics);
|
|
|
|
|
console.log(topics);
|
|
|
|
|
if (topics.length > 0) {
|
|
|
|
|
var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({
|
|
|
|
|
topics: topics
|
|
|
|
|
}),
|
|
|
|
|
topicsListEl = document.querySelector('.topics');
|
|
|
|
|
|
|
|
|
|
topicsListEl.innerHTML += html;
|
|
|
|
|
btnEl.innerHTML = 'Load More Topics';
|
|
|
|
|
} else {
|
|
|
|
|
// Exhausted all topics
|
|
|
|
|
btnEl.className += ' disabled';
|
|
|
|
|
btnEl.innerHTML = 'No more topics';
|
|
|
|
|
}
|
|
|
|
|
});
|