mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-15 18:26:15 +01:00
category and category/topic components; removed #topic-container selectors
This commit is contained in:
@@ -32,7 +32,7 @@ define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'],
|
|||||||
|
|
||||||
function onTopicsLoaded(topics, callback) {
|
function onTopicsLoaded(topics, callback) {
|
||||||
infinitescroll.parseAndTranslate('account/topics', 'topics', {topics: topics}, function(html) {
|
infinitescroll.parseAndTranslate('account/topics', 'topics', {topics: topics}, function(html) {
|
||||||
$('#topics-container').append(html);
|
$('[component="category"]').append(html);
|
||||||
html.find('.timeago').timeago();
|
html.find('.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ define('forum/account/watched', ['forum/account/header', 'forum/infinitescroll']
|
|||||||
|
|
||||||
function onTopicsLoaded(topics, callback) {
|
function onTopicsLoaded(topics, callback) {
|
||||||
infinitescroll.parseAndTranslate('account/watched', 'topics', {topics: topics}, function(html) {
|
infinitescroll.parseAndTranslate('account/watched', 'topics', {topics: topics}, function(html) {
|
||||||
$('#topics-container').append(html);
|
$('[component="category"]').append(html);
|
||||||
html.find('.timeago').timeago();
|
html.find('.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ define('forum/category', [
|
|||||||
enableInfiniteLoadingOrPagination();
|
enableInfiniteLoadingOrPagination();
|
||||||
|
|
||||||
if (!config.usePagination) {
|
if (!config.usePagination) {
|
||||||
navigator.init('#topics-container > .category-item', ajaxify.variables.get('topic_count'), Category.toTop, Category.toBottom, Category.navigatorCallback);
|
navigator.init('[component="category/topic"]', ajaxify.variables.get('topic_count'), Category.toTop, Category.toBottom, Category.navigatorCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#topics-container').on('click', '[component="post/header"]', function() {
|
$('[component="category"]').on('click', '[component="post/header"]', function() {
|
||||||
var clickedIndex = $(this).parents('[data-index]').attr('data-index');
|
var clickedIndex = $(this).parents('[data-index]').attr('data-index');
|
||||||
$('#topics-container li.category-item').each(function(index, el) {
|
$('[component="category/topic"]').each(function(index, el) {
|
||||||
if ($(el).offset().top - $(window).scrollTop() > 0) {
|
if ($(el).offset().top - $(window).scrollTop() > 0) {
|
||||||
localStorage.setItem('category:' + cid + ':bookmark', $(el).attr('data-index'));
|
localStorage.setItem('category:' + cid + ':bookmark', $(el).attr('data-index'));
|
||||||
localStorage.setItem('category:' + cid + ':bookmark:clicked', clickedIndex);
|
localStorage.setItem('category:' + cid + ':bookmark:clicked', clickedIndex);
|
||||||
@@ -129,7 +129,7 @@ define('forum/category', [
|
|||||||
bookmarkIndex = 0;
|
bookmarkIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#topics-container').empty();
|
$('[component="category"]').empty();
|
||||||
|
|
||||||
loadTopicsAfter(bookmarkIndex, function() {
|
loadTopicsAfter(bookmarkIndex, function() {
|
||||||
Category.scrollToTopic(bookmarkIndex, clickedIndex, 0);
|
Category.scrollToTopic(bookmarkIndex, clickedIndex, 0);
|
||||||
@@ -139,7 +139,7 @@ define('forum/category', [
|
|||||||
});
|
});
|
||||||
|
|
||||||
Category.highlightTopic = function(topicIndex) {
|
Category.highlightTopic = function(topicIndex) {
|
||||||
var highlight = $('#topics-container [data-index="' + topicIndex + '"]');
|
var highlight = components.get('category/topic', 'index', topicIndex);
|
||||||
if (highlight.length && !highlight.hasClass('highlight')) {
|
if (highlight.length && !highlight.hasClass('highlight')) {
|
||||||
highlight.addClass('highlight');
|
highlight.addClass('highlight');
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@@ -157,7 +157,7 @@ define('forum/category', [
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var scrollTo = $('#topics-container [data-index="' + bookmarkIndex + '"]');
|
var scrollTo = components.get('category/topic', 'index', bookmarkIndex);
|
||||||
var cid = ajaxify.variables.get('category_id');
|
var cid = ajaxify.variables.get('category_id');
|
||||||
if (scrollTo.length && cid) {
|
if (scrollTo.length && cid) {
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
@@ -192,11 +192,12 @@ define('forum/category', [
|
|||||||
}, function(html) {
|
}, function(html) {
|
||||||
translator.translate(html, function(translatedHTML) {
|
translator.translate(html, function(translatedHTML) {
|
||||||
var topic = $(translatedHTML),
|
var topic = $(translatedHTML),
|
||||||
container = $('#topics-container'),
|
container = $('[component="category"]'),
|
||||||
topics = $('#topics-container').children('.category-item'),
|
topics = $('[component="category/topic"]'),
|
||||||
numTopics = topics.length;
|
numTopics = topics.length;
|
||||||
|
|
||||||
$('#topics-container, .category-sidebar').removeClass('hidden');
|
$('[component="category"]').removeClass('hidden');
|
||||||
|
$('.category-sidebar').removeClass('hidden');
|
||||||
|
|
||||||
var noTopicsWarning = $('#category-no-topics');
|
var noTopicsWarning = $('#category-no-topics');
|
||||||
if (noTopicsWarning.length) {
|
if (noTopicsWarning.length) {
|
||||||
@@ -247,7 +248,7 @@ define('forum/category', [
|
|||||||
|
|
||||||
function removeAlreadyAddedTopics(topics) {
|
function removeAlreadyAddedTopics(topics) {
|
||||||
return topics.filter(function(topic) {
|
return topics.filter(function(topic) {
|
||||||
return $('#topics-container li[data-tid="' + topic.tid +'"]').length === 0;
|
return components.get('category/topic', 'tid', topic.tid).length === 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,16 +256,20 @@ define('forum/category', [
|
|||||||
before = null;
|
before = null;
|
||||||
|
|
||||||
function findInsertionPoint() {
|
function findInsertionPoint() {
|
||||||
if (!$('#topics-container .category-item[data-tid]').length) {
|
var topics = components.get('category/topic');
|
||||||
|
|
||||||
|
if (!topics.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var last = $('#topics-container .category-item[data-tid]').last();
|
|
||||||
var lastIndex = last.attr('data-index');
|
var last = topics.last(),
|
||||||
var firstIndex = data.topics[data.topics.length - 1].index;
|
lastIndex = last.attr('data-index'),
|
||||||
|
firstIndex = data.topics[data.topics.length - 1].index;
|
||||||
|
|
||||||
if (firstIndex > lastIndex) {
|
if (firstIndex > lastIndex) {
|
||||||
after = last;
|
after = last;
|
||||||
} else {
|
} else {
|
||||||
before = $('#topics-container .category-item[data-tid]').first();
|
before = topics.first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,10 +282,12 @@ define('forum/category', [
|
|||||||
|
|
||||||
templates.parse('category', 'topics', data, function(html) {
|
templates.parse('category', 'topics', data, function(html) {
|
||||||
translator.translate(html, function(translatedHTML) {
|
translator.translate(html, function(translatedHTML) {
|
||||||
var container = $('#topics-container'),
|
var container = $('[component="category"]'),
|
||||||
html = $(translatedHTML);
|
html = $(translatedHTML);
|
||||||
|
|
||||||
$('#topics-container, .category-sidebar').removeClass('hidden');
|
$('[component="category"]').removeClass('hidden');
|
||||||
|
$('.category-sidebar').removeClass('hidden');
|
||||||
|
|
||||||
$('#category-no-topics').remove();
|
$('#category-no-topics').remove();
|
||||||
|
|
||||||
if(config.usePagination) {
|
if(config.usePagination) {
|
||||||
@@ -306,11 +313,11 @@ define('forum/category', [
|
|||||||
};
|
};
|
||||||
|
|
||||||
Category.loadMoreTopics = function(direction) {
|
Category.loadMoreTopics = function(direction) {
|
||||||
if (!$('#topics-container').length || !$('#topics-container').children().length) {
|
if (!$('[component="category"]').length || !$('[component="category"]').children().length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
infinitescroll.calculateAfter(direction, '#topics-container .category-item[data-tid]', config.topicsPerPage, false, function(after, offset, el) {
|
infinitescroll.calculateAfter(direction, components.get('category/topic'), config.topicsPerPage, false, function(after, offset, el) {
|
||||||
loadTopicsAfter(after, function() {
|
loadTopicsAfter(after, function() {
|
||||||
if (direction < 0 && el) {
|
if (direction < 0 && el) {
|
||||||
Category.scrollToTopic(el.attr('data-index'), null, 0, offset);
|
Category.scrollToTopic(el.attr('data-index'), null, 0, offset);
|
||||||
@@ -320,7 +327,7 @@ define('forum/category', [
|
|||||||
};
|
};
|
||||||
|
|
||||||
function loadTopicsAfter(after, callback) {
|
function loadTopicsAfter(after, callback) {
|
||||||
if(!utils.isNumber(after) || (after === 0 && $('#topics-container li.category-item[data-index="0"]').length)) {
|
if(!utils.isNumber(after) || (after === 0 && components.get('category/topic', 'index', 0).length)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +343,7 @@ define('forum/category', [
|
|||||||
done();
|
done();
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
$('#topics-container').attr('data-nextstart', data.nextStart);
|
$('[component="category"]').attr('data-nextstart', data.nextStart);
|
||||||
} else {
|
} else {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTopicEl(tid) {
|
function getTopicEl(tid) {
|
||||||
return $('#topics-container li[data-tid="' + tid + '"]');
|
return components.get('category/topic', 'tid', tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDeleteState(data) {
|
function setDeleteState(data) {
|
||||||
|
|||||||
@@ -94,17 +94,17 @@ define('forum/recent', ['forum/infinitescroll', 'composer'], function(infinitesc
|
|||||||
};
|
};
|
||||||
|
|
||||||
Recent.loadMoreTopics = function(direction) {
|
Recent.loadMoreTopics = function(direction) {
|
||||||
if(direction < 0 || !$('#topics-container').length) {
|
if(direction < 0 || !$('[component="category"]').length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
||||||
after: $('#topics-container').attr('data-nextstart'),
|
after: $('[component="category"]').attr('data-nextstart'),
|
||||||
set: 'topics:recent'
|
set: 'topics:recent'
|
||||||
}, function(data, done) {
|
}, function(data, done) {
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
Recent.onTopicsLoaded('recent', data.topics, false, done);
|
Recent.onTopicsLoaded('recent', data.topics, false, done);
|
||||||
$('#topics-container').attr('data-nextstart', data.nextStart);
|
$('[component="category"]').attr('data-nextstart', data.nextStart);
|
||||||
} else {
|
} else {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ define('forum/recent', ['forum/infinitescroll', 'composer'], function(infinitesc
|
|||||||
Recent.onTopicsLoaded = function(templateName, topics, showSelect, callback) {
|
Recent.onTopicsLoaded = function(templateName, topics, showSelect, callback) {
|
||||||
|
|
||||||
topics = topics.filter(function(topic) {
|
topics = topics.filter(function(topic) {
|
||||||
return !$('#topics-container li[data-tid=' + topic.tid + ']').length;
|
return !components.get('category/topic', 'tid', topic.tid).length;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!topics.length) {
|
if (!topics.length) {
|
||||||
@@ -124,7 +124,7 @@ define('forum/recent', ['forum/infinitescroll', 'composer'], function(infinitesc
|
|||||||
infinitescroll.parseAndTranslate(templateName, 'topics', {topics: topics, showSelect: showSelect}, function(html) {
|
infinitescroll.parseAndTranslate(templateName, 'topics', {topics: topics, showSelect: showSelect}, function(html) {
|
||||||
$('#category-no-topics').remove();
|
$('#category-no-topics').remove();
|
||||||
|
|
||||||
$('#topics-container').append(html);
|
$('[component="category"]').append(html);
|
||||||
html.find('.timeago').timeago();
|
html.find('.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ define('forum/tag', ['forum/recent', 'forum/infinitescroll'], function(recent, i
|
|||||||
Tag.init = function() {
|
Tag.init = function() {
|
||||||
app.enterRoom('tags');
|
app.enterRoom('tags');
|
||||||
|
|
||||||
if ($('body').height() <= $(window).height() && $('#topics-container').children().length >= 20) {
|
if ($('body').height() <= $(window).height() && $('[component="category"]').children().length >= 20) {
|
||||||
$('#load-more-btn').show();
|
$('#load-more-btn').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,17 +19,17 @@ define('forum/tag', ['forum/recent', 'forum/infinitescroll'], function(recent, i
|
|||||||
infinitescroll.init(loadMoreTopics);
|
infinitescroll.init(loadMoreTopics);
|
||||||
|
|
||||||
function loadMoreTopics(direction) {
|
function loadMoreTopics(direction) {
|
||||||
if(direction < 0 || !$('#topics-container').length) {
|
if(direction < 0 || !$('[component="category"]').length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
infinitescroll.loadMore('topics.loadMoreFromSet', {
|
||||||
set: 'tag:' + ajaxify.variables.get('tag') + ':topics',
|
set: 'tag:' + ajaxify.variables.get('tag') + ':topics',
|
||||||
after: $('#topics-container').attr('data-nextstart')
|
after: $('[component="category"]').attr('data-nextstart')
|
||||||
}, function(data, done) {
|
}, function(data, done) {
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
recent.onTopicsLoaded('tag', data.topics, false, done);
|
recent.onTopicsLoaded('tag', data.topics, false, done);
|
||||||
$('#topics-container').attr('data-nextstart', data.nextStart);
|
$('[component="category"]').attr('data-nextstart', data.nextStart);
|
||||||
} else {
|
} else {
|
||||||
done();
|
done();
|
||||||
$('#load-more-btn').hide();
|
$('#load-more-btn').hide();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
|||||||
|
|
||||||
app.alertSuccess('[[unread:topics_marked_as_read.success]]');
|
app.alertSuccess('[[unread:topics_marked_as_read.success]]');
|
||||||
|
|
||||||
$('#topics-container').empty();
|
$('[component="category"]').empty();
|
||||||
$('#category-no-topics').removeClass('hidden');
|
$('#category-no-topics').removeClass('hidden');
|
||||||
$('.markread').addClass('hidden');
|
$('.markread').addClass('hidden');
|
||||||
});
|
});
|
||||||
@@ -51,7 +51,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
|||||||
$('.markread').on('click', '.category', function() {
|
$('.markread').on('click', '.category', function() {
|
||||||
function getCategoryTids(cid) {
|
function getCategoryTids(cid) {
|
||||||
var tids = [];
|
var tids = [];
|
||||||
$('#topics-container .category-item[data-cid="' + cid + '"]').each(function() {
|
components.get('category/topic', 'cid', cid).each(function() {
|
||||||
tids.push($(this).attr('data-tid'));
|
tids.push($(this).attr('data-tid'));
|
||||||
});
|
});
|
||||||
return tids;
|
return tids;
|
||||||
@@ -72,7 +72,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
|||||||
|
|
||||||
topicSelect.init();
|
topicSelect.init();
|
||||||
|
|
||||||
if ($("body").height() <= $(window).height() && $('#topics-container').children().length >= 20) {
|
if ($("body").height() <= $(window).height() && $('[component="category"]').children().length >= 20) {
|
||||||
$('#load-more-btn').show();
|
$('#load-more-btn').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,16 +83,16 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
|||||||
infinitescroll.init(loadMoreTopics);
|
infinitescroll.init(loadMoreTopics);
|
||||||
|
|
||||||
function loadMoreTopics(direction) {
|
function loadMoreTopics(direction) {
|
||||||
if(direction < 0 || !$('#topics-container').length) {
|
if(direction < 0 || !$('[component="category"]').length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
infinitescroll.loadMore('topics.loadMoreUnreadTopics', {
|
infinitescroll.loadMore('topics.loadMoreUnreadTopics', {
|
||||||
after: $('#topics-container').attr('data-nextstart')
|
after: $('[component="category"]').attr('data-nextstart')
|
||||||
}, function(data, done) {
|
}, function(data, done) {
|
||||||
if (data.topics && data.topics.length) {
|
if (data.topics && data.topics.length) {
|
||||||
recent.onTopicsLoaded('unread', data.topics, true, done);
|
recent.onTopicsLoaded('unread', data.topics, true, done);
|
||||||
$('#topics-container').attr('data-nextstart', data.nextStart);
|
$('[component="category"]').attr('data-nextstart', data.nextStart);
|
||||||
} else {
|
} else {
|
||||||
done();
|
done();
|
||||||
$('#load-more-btn').hide();
|
$('#load-more-btn').hide();
|
||||||
@@ -106,7 +106,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
|||||||
|
|
||||||
app.alertSuccess('[[unread:topics_marked_as_read.success]]');
|
app.alertSuccess('[[unread:topics_marked_as_read.success]]');
|
||||||
|
|
||||||
if (!$('#topics-container').children().length) {
|
if (!$('[component="category"]').children().length) {
|
||||||
$('#category-no-topics').removeClass('hidden');
|
$('#category-no-topics').removeClass('hidden');
|
||||||
$('.markread').addClass('hidden');
|
$('.markread').addClass('hidden');
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
|
|||||||
|
|
||||||
function removeTids(tids) {
|
function removeTids(tids) {
|
||||||
for(var i=0; i<tids.length; ++i) {
|
for(var i=0; i<tids.length; ++i) {
|
||||||
$('#topics-container .category-item[data-tid="' + tids[i] + '"]').remove();
|
components.get('category/topic', 'tid', tids[i]).remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ var components = components || {};
|
|||||||
},
|
},
|
||||||
'user/reputation': function(uid) {
|
'user/reputation': function(uid) {
|
||||||
return $('[component="user/reputation"][data-uid="' + uid + '"]');
|
return $('[component="user/reputation"][data-uid="' + uid + '"]');
|
||||||
|
},
|
||||||
|
|
||||||
|
'category/topic': function(name, value) {
|
||||||
|
return $('[data-' + name + '="' + value + '"]');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ define('topicSelect', function() {
|
|||||||
var topicsContainer;
|
var topicsContainer;
|
||||||
|
|
||||||
TopicSelect.init = function(onSelect) {
|
TopicSelect.init = function(onSelect) {
|
||||||
topicsContainer = $('#topics-container');
|
topicsContainer = $('[component="category"]');
|
||||||
topicsContainer.on('selectstart', function() {
|
topicsContainer.on('selectstart', function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@@ -78,7 +78,7 @@ define('topicSelect', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getIndex(tid) {
|
function getIndex(tid) {
|
||||||
return $('.category-item[data-tid="' + tid + '"]').index('#topics-container .category-item');
|
return components.get('category/topic', 'tid', tid).index('[component="category/topic"]');
|
||||||
}
|
}
|
||||||
|
|
||||||
return TopicSelect;
|
return TopicSelect;
|
||||||
|
|||||||
Reference in New Issue
Block a user