mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
Merge branch 'master' of https://github.com/designcreateplay/NodeBB
This commit is contained in:
@@ -29,8 +29,22 @@ noscript {
|
||||
}
|
||||
|
||||
.teaser {
|
||||
margin-left: 16px;
|
||||
margin-top: 8px;
|
||||
|
||||
img {
|
||||
float: left;
|
||||
width: 32px;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #666;
|
||||
font-size: 13px;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
margin-left: 64px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -82,3 +96,23 @@ 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';
|
||||
}
|
||||
});
|
||||
@@ -27,20 +27,21 @@
|
||||
jQuery('#category-no-topics').remove();
|
||||
|
||||
topic.innerHTML = html;
|
||||
topic = topic.querySelector('a');
|
||||
|
||||
if (numTopics > 0) {
|
||||
for(x=0;x<numTopics;x++) {
|
||||
if (topics[x].querySelector('.icon-pushpin')) continue;
|
||||
container.insertBefore(topic.querySelector('a'), topics[x]);
|
||||
container.insertBefore(topic, topics[x]);
|
||||
$(topic).hide().fadeIn('slow');
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
container.insertBefore(topic.querySelector('a'), null);
|
||||
container.insertBefore(topic, null);
|
||||
$(topic).hide().fadeIn('slow');
|
||||
}
|
||||
|
||||
// jQuery('<div></div>').appendTo("#topics-container").hide().append(html).fadeIn('slow');
|
||||
// set_up_posts(uniqueid);
|
||||
ajaxify.enable();
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -5,18 +5,23 @@ define(function() {
|
||||
var categories = null,
|
||||
overlay = null,
|
||||
menuBtn = null,
|
||||
postBtn = null;
|
||||
postBtn = null,
|
||||
initialized = false;
|
||||
|
||||
|
||||
function loadCategories(callback) {
|
||||
if (categories) {
|
||||
displayCategories();
|
||||
callback(true);
|
||||
return;
|
||||
}
|
||||
|
||||
jQuery.getJSON('/api/home', function(data) {
|
||||
categories = data.categories;
|
||||
displayCategories();
|
||||
initialized = true;
|
||||
|
||||
if (callback) {
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -65,6 +70,8 @@ define(function() {
|
||||
|
||||
|
||||
mobileMenu.onNavigate = function() {
|
||||
if (initialized == false) return false;
|
||||
|
||||
var cid = templates.get('category_id'),
|
||||
tid = templates.get('topic_id');
|
||||
|
||||
@@ -100,9 +107,11 @@ define(function() {
|
||||
animateIcons();
|
||||
}
|
||||
|
||||
|
||||
loadCategories(displayCategories);
|
||||
loadCategories(function() {
|
||||
displayCategories();
|
||||
mobileMenu.onNavigate();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -250,19 +250,23 @@
|
||||
if (data[d] === null) {
|
||||
template = replace(namespace + d, '', template);
|
||||
} else if (data[d].constructor == Array) {
|
||||
namespace += d;
|
||||
namespace += d + '.';
|
||||
|
||||
regex = makeRegex(d),
|
||||
block = getBlock(regex, namespace, template)
|
||||
if (block == null) continue;
|
||||
var regex = makeRegex(d),
|
||||
block = getBlock(regex, namespace.substring(0, namespace.length-1), template);
|
||||
|
||||
if (block == null) {
|
||||
namespace = namespace.replace(d + '.', '');
|
||||
continue;
|
||||
}
|
||||
|
||||
var numblocks = data[d].length - 1, i = 0, result = "";
|
||||
|
||||
do {
|
||||
result += parse(data[d][i], namespace + '.', block);
|
||||
result += parse(data[d][i], namespace, block);
|
||||
} while (i++ < numblocks);
|
||||
|
||||
namespace = namespace.replace(d, '');
|
||||
namespace = namespace.replace(d + '.', '');
|
||||
template = setBlock(regex, result, template);
|
||||
} else if (data[d] instanceof Object) {
|
||||
namespace += d + '.';
|
||||
|
||||
@@ -19,4 +19,8 @@
|
||||
<!-- END topics -->
|
||||
</ul>
|
||||
|
||||
<div class="text-center">
|
||||
<button id="topics_loadmore" class="btn btn-large">Load More Topics</button>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="../../src/forum/admin/topics.js"></script>
|
||||
@@ -6,7 +6,7 @@
|
||||
<ul class="topics">
|
||||
<!-- BEGIN topics -->
|
||||
<li>
|
||||
<a href="topic/{topics.slug}">{topics.title}</a>
|
||||
<a href="../../topic/{topics.slug}">{topics.title} ({topics.post_count})</a>
|
||||
<div class="teaser">
|
||||
<img class="img-polaroid" src="../../graph/users/{topics.teaser_username}/picture" />
|
||||
<p>
|
||||
|
||||
@@ -57,10 +57,7 @@ var user = require('./../user.js'),
|
||||
}
|
||||
break;
|
||||
case 'topics':
|
||||
topics.getAllTopics(function(topics) {
|
||||
topics.sort(function(a, b) {
|
||||
return b.timestamp - a.timestamp;
|
||||
});
|
||||
topics.getAllTopics(10, null, function(topics) {
|
||||
res.json({
|
||||
topics: topics
|
||||
});
|
||||
|
||||
@@ -185,9 +185,33 @@ marked.setOptions({
|
||||
});
|
||||
}
|
||||
|
||||
Topics.getAllTopics = function(callback) {
|
||||
Topics.getAllTopics = function(limit, after, callback) {
|
||||
RDB.smembers('topics:tid', function(err, tids) {
|
||||
var topics = [];
|
||||
var topics = [],
|
||||
numTids, x;
|
||||
|
||||
// Sort into ascending order
|
||||
tids.sort(function(a, b) { return a - b; });
|
||||
|
||||
// Eliminate everything after the "after" tid
|
||||
if (after) {
|
||||
for(x=0,numTids=tids.length;x<numTids;x++) {
|
||||
if (tids[x] >= after) {
|
||||
tids = tids.slice(0, x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (limit) {
|
||||
if (limit > 0 && limit < tids.length) {
|
||||
tids = tids.slice(tids.length - limit);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort into descending order
|
||||
tids.sort(function(a, b) { return b - a; });
|
||||
|
||||
async.each(tids, function(tid, next) {
|
||||
Topics.get_topic(tid, 0, function(topicData) {
|
||||
topics.push(topicData);
|
||||
|
||||
@@ -126,7 +126,6 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
});
|
||||
|
||||
// BEGIN: API calls (todo: organize)
|
||||
// julian: :^)
|
||||
|
||||
socket.on('api:updateHeader', function(data) {
|
||||
if(uid) {
|
||||
@@ -396,6 +395,12 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('api:admin.topics.getMore', function(data) {
|
||||
topics.getAllTopics(data.limit, data.after, function(topics) {
|
||||
socket.emit('api:admin.topics.getMore', JSON.stringify(topics));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}(SocketIO));
|
||||
|
||||
Reference in New Issue
Block a user