category and category/topic components; removed #topic-container selectors

v1.18.x
psychobunny 10 years ago
parent aeb7548a9d
commit 10eb617c6d

@ -32,7 +32,7 @@ define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'],
function onTopicsLoaded(topics, callback) {
infinitescroll.parseAndTranslate('account/topics', 'topics', {topics: topics}, function(html) {
$('#topics-container').append(html);
$('[component="category"]').append(html);
html.find('.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));

@ -30,7 +30,7 @@ define('forum/account/watched', ['forum/account/header', 'forum/infinitescroll']
function onTopicsLoaded(topics, callback) {
infinitescroll.parseAndTranslate('account/watched', 'topics', {topics: topics}, function(html) {
$('#topics-container').append(html);
$('[component="category"]').append(html);
html.find('.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));

@ -46,12 +46,12 @@ define('forum/category', [
enableInfiniteLoadingOrPagination();
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');
$('#topics-container li.category-item').each(function(index, el) {
$('[component="category/topic"]').each(function(index, el) {
if ($(el).offset().top - $(window).scrollTop() > 0) {
localStorage.setItem('category:' + cid + ':bookmark', $(el).attr('data-index'));
localStorage.setItem('category:' + cid + ':bookmark:clicked', clickedIndex);
@ -129,7 +129,7 @@ define('forum/category', [
bookmarkIndex = 0;
}
$('#topics-container').empty();
$('[component="category"]').empty();
loadTopicsAfter(bookmarkIndex, function() {
Category.scrollToTopic(bookmarkIndex, clickedIndex, 0);
@ -139,7 +139,7 @@ define('forum/category', [
});
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')) {
highlight.addClass('highlight');
setTimeout(function() {
@ -157,7 +157,7 @@ define('forum/category', [
offset = 0;
}
var scrollTo = $('#topics-container [data-index="' + bookmarkIndex + '"]');
var scrollTo = components.get('category/topic', 'index', bookmarkIndex);
var cid = ajaxify.variables.get('category_id');
if (scrollTo.length && cid) {
$('html, body').animate({
@ -192,11 +192,12 @@ define('forum/category', [
}, function(html) {
translator.translate(html, function(translatedHTML) {
var topic = $(translatedHTML),
container = $('#topics-container'),
topics = $('#topics-container').children('.category-item'),
container = $('[component="category"]'),
topics = $('[component="category/topic"]'),
numTopics = topics.length;
$('#topics-container, .category-sidebar').removeClass('hidden');
$('[component="category"]').removeClass('hidden');
$('.category-sidebar').removeClass('hidden');
var noTopicsWarning = $('#category-no-topics');
if (noTopicsWarning.length) {
@ -247,7 +248,7 @@ define('forum/category', [
function removeAlreadyAddedTopics(topics) {
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;
function findInsertionPoint() {
if (!$('#topics-container .category-item[data-tid]').length) {
var topics = components.get('category/topic');
if (!topics.length) {
return;
}
var last = $('#topics-container .category-item[data-tid]').last();
var lastIndex = last.attr('data-index');
var firstIndex = data.topics[data.topics.length - 1].index;
var last = topics.last(),
lastIndex = last.attr('data-index'),
firstIndex = data.topics[data.topics.length - 1].index;
if (firstIndex > lastIndex) {
after = last;
} 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) {
translator.translate(html, function(translatedHTML) {
var container = $('#topics-container'),
var container = $('[component="category"]'),
html = $(translatedHTML);
$('#topics-container, .category-sidebar').removeClass('hidden');
$('[component="category"]').removeClass('hidden');
$('.category-sidebar').removeClass('hidden');
$('#category-no-topics').remove();
if(config.usePagination) {
@ -306,11 +313,11 @@ define('forum/category', [
};
Category.loadMoreTopics = function(direction) {
if (!$('#topics-container').length || !$('#topics-container').children().length) {
if (!$('[component="category"]').length || !$('[component="category"]').children().length) {
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() {
if (direction < 0 && el) {
Category.scrollToTopic(el.attr('data-index'), null, 0, offset);
@ -320,7 +327,7 @@ define('forum/category', [
};
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;
}
@ -336,7 +343,7 @@ define('forum/category', [
done();
callback();
});
$('#topics-container').attr('data-nextstart', data.nextStart);
$('[component="category"]').attr('data-nextstart', data.nextStart);
} else {
done();
}

@ -173,7 +173,7 @@ define('forum/categoryTools', ['forum/topic/move', 'topicSelect'], function(move
}
function getTopicEl(tid) {
return $('#topics-container li[data-tid="' + tid + '"]');
return components.get('category/topic', 'tid', tid);
}
function setDeleteState(data) {

@ -94,17 +94,17 @@ define('forum/recent', ['forum/infinitescroll', 'composer'], function(infinitesc
};
Recent.loadMoreTopics = function(direction) {
if(direction < 0 || !$('#topics-container').length) {
if(direction < 0 || !$('[component="category"]').length) {
return;
}
infinitescroll.loadMore('topics.loadMoreFromSet', {
after: $('#topics-container').attr('data-nextstart'),
after: $('[component="category"]').attr('data-nextstart'),
set: 'topics:recent'
}, function(data, done) {
if (data.topics && data.topics.length) {
Recent.onTopicsLoaded('recent', data.topics, false, done);
$('#topics-container').attr('data-nextstart', data.nextStart);
$('[component="category"]').attr('data-nextstart', data.nextStart);
} else {
done();
}
@ -114,7 +114,7 @@ define('forum/recent', ['forum/infinitescroll', 'composer'], function(infinitesc
Recent.onTopicsLoaded = function(templateName, topics, showSelect, callback) {
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) {
@ -124,7 +124,7 @@ define('forum/recent', ['forum/infinitescroll', 'composer'], function(infinitesc
infinitescroll.parseAndTranslate(templateName, 'topics', {topics: topics, showSelect: showSelect}, function(html) {
$('#category-no-topics').remove();
$('#topics-container').append(html);
$('[component="category"]').append(html);
html.find('.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));

@ -8,7 +8,7 @@ define('forum/tag', ['forum/recent', 'forum/infinitescroll'], function(recent, i
Tag.init = function() {
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();
}
@ -19,17 +19,17 @@ define('forum/tag', ['forum/recent', 'forum/infinitescroll'], function(recent, i
infinitescroll.init(loadMoreTopics);
function loadMoreTopics(direction) {
if(direction < 0 || !$('#topics-container').length) {
if(direction < 0 || !$('[component="category"]').length) {
return;
}
infinitescroll.loadMore('topics.loadMoreFromSet', {
set: 'tag:' + ajaxify.variables.get('tag') + ':topics',
after: $('#topics-container').attr('data-nextstart')
after: $('[component="category"]').attr('data-nextstart')
}, function(data, done) {
if (data.topics && data.topics.length) {
recent.onTopicsLoaded('tag', data.topics, false, done);
$('#topics-container').attr('data-nextstart', data.nextStart);
$('[component="category"]').attr('data-nextstart', data.nextStart);
} else {
done();
$('#load-more-btn').hide();

@ -42,7 +42,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
app.alertSuccess('[[unread:topics_marked_as_read.success]]');
$('#topics-container').empty();
$('[component="category"]').empty();
$('#category-no-topics').removeClass('hidden');
$('.markread').addClass('hidden');
});
@ -51,7 +51,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
$('.markread').on('click', '.category', function() {
function getCategoryTids(cid) {
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'));
});
return tids;
@ -72,7 +72,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
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();
}
@ -83,16 +83,16 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
infinitescroll.init(loadMoreTopics);
function loadMoreTopics(direction) {
if(direction < 0 || !$('#topics-container').length) {
if(direction < 0 || !$('[component="category"]').length) {
return;
}
infinitescroll.loadMore('topics.loadMoreUnreadTopics', {
after: $('#topics-container').attr('data-nextstart')
after: $('[component="category"]').attr('data-nextstart')
}, function(data, done) {
if (data.topics && data.topics.length) {
recent.onTopicsLoaded('unread', data.topics, true, done);
$('#topics-container').attr('data-nextstart', data.nextStart);
$('[component="category"]').attr('data-nextstart', data.nextStart);
} else {
done();
$('#load-more-btn').hide();
@ -106,7 +106,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
app.alertSuccess('[[unread:topics_marked_as_read.success]]');
if (!$('#topics-container').children().length) {
if (!$('[component="category"]').children().length) {
$('#category-no-topics').removeClass('hidden');
$('.markread').addClass('hidden');
}
@ -114,7 +114,7 @@ define('forum/unread', ['forum/recent', 'topicSelect', 'forum/infinitescroll'],
function removeTids(tids) {
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) {
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;
TopicSelect.init = function(onSelect) {
topicsContainer = $('#topics-container');
topicsContainer = $('[component="category"]');
topicsContainer.on('selectstart', function() {
return false;
});
@ -78,7 +78,7 @@ define('topicSelect', function() {
}
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;

Loading…
Cancel
Save