From 10eb617c6d7972f544d0cbc3e035e714f6643a05 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 19 Mar 2015 13:56:12 -0400 Subject: [PATCH] category and category/topic components; removed #topic-container selectors --- public/src/client/account/topics.js | 2 +- public/src/client/account/watched.js | 2 +- public/src/client/category.js | 49 ++++++++++++++++------------ public/src/client/categoryTools.js | 2 +- public/src/client/recent.js | 10 +++--- public/src/client/tag.js | 8 ++--- public/src/client/unread.js | 16 ++++----- public/src/components.js | 4 +++ public/src/modules/topicSelect.js | 4 +-- 9 files changed, 54 insertions(+), 43 deletions(-) diff --git a/public/src/client/account/topics.js b/public/src/client/account/topics.js index 107352db97..3d3923ceef 100644 --- a/public/src/client/account/topics.js +++ b/public/src/client/account/topics.js @@ -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')); diff --git a/public/src/client/account/watched.js b/public/src/client/account/watched.js index 3514301c4d..c9d4bed788 100644 --- a/public/src/client/account/watched.js +++ b/public/src/client/account/watched.js @@ -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')); diff --git a/public/src/client/category.js b/public/src/client/category.js index bf91059a25..1e6c0e94c4 100644 --- a/public/src/client/category.js +++ b/public/src/client/category.js @@ -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(); } diff --git a/public/src/client/categoryTools.js b/public/src/client/categoryTools.js index 0e9bae608b..0464a3ee65 100644 --- a/public/src/client/categoryTools.js +++ b/public/src/client/categoryTools.js @@ -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) { diff --git a/public/src/client/recent.js b/public/src/client/recent.js index 2be859f65c..30d635ea0d 100644 --- a/public/src/client/recent.js +++ b/public/src/client/recent.js @@ -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')); diff --git a/public/src/client/tag.js b/public/src/client/tag.js index 3565c7e151..7328934e2d 100644 --- a/public/src/client/tag.js +++ b/public/src/client/tag.js @@ -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(); diff --git a/public/src/client/unread.js b/public/src/client/unread.js index 7e08037f5a..c8c1c96de9 100644 --- a/public/src/client/unread.js +++ b/public/src/client/unread.js @@ -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