Do you really want to purge this category "' + $('form.category').find('input[data-name="name"]').val() + '"?
Warning! All topics and posts in this category will be purged!
', function(confirm) { + if (!confirm) { + return; + } + socket.emit('admin.categories.purge', ajaxify.variables.get('cid'), function(err) { + if (err) { + return app.alertError(err.message); + } + app.alertSuccess('Category purged!'); + ajaxify.go('admin/manage/categories'); + }); + }); + }); + + // Image Uploader + $('.upload-button').on('click', function() { + var inputEl = $(this), + cid = inputEl.attr('data-cid'); + + uploader.open(RELATIVE_PATH + '/api/admin/category/uploadpicture', { cid: cid }, 0, function(imageUrlOnServer) { + inputEl.val(imageUrlOnServer); + var previewBox = inputEl.parent().parent().siblings('.category-preview'); + previewBox.css('background', 'url(' + imageUrlOnServer + '?' + new Date().getTime() + ')') + .css('background-size', 'cover'); + modified(inputEl[0]); + }); + }); + + // Image Remover + $('.delete-image').on('click', function(e) { + e.preventDefault(); + + var inputEl = $('.upload-button'), + previewBox = inputEl.parent().parent().siblings('.category-preview'); + + inputEl.val(''); + previewBox.css('background-image', ''); + modified(inputEl[0]); + $(this).parent().addClass('hide').hide(); + }); + + // Icon selection + $('.category-preview').on('click', function(ev) { + iconSelect.init($(this).find('i'), modified); + }); + + // Parent Category Selector + $('button[data-action="setParent"]').on('click', Category.launchParentSelector); + $('button[data-action="removeParent"]').on('click', function() { + var payload= {}; + payload[ajaxify.variables.get('cid')] = { + parentCid: 0 + }; + + socket.emit('admin.categories.update', payload, function(err) { + if (err) { + return app.alertError(err.message); + } + ajaxify.refresh(); + }); + }); + + setupEditTargets(); + Category.setupPrivilegeTable(); + }; + + Category.setupPrivilegeTable = function() { + var searchEl = $('.privilege-search'), + searchObj = autocomplete.user(searchEl); + + // User search + addition to table + searchObj.on('autocompleteselect', function(ev, ui) { + socket.emit('admin.categories.setPrivilege', { + cid: ajaxify.variables.get('cid'), + privilege: 'read', + set: true, + member: ui.item.user.uid + }, function(err) { + if (err) { + return app.alertError(err.message); + } + + Category.refreshPrivilegeTable(); + searchEl.val(''); + }); + }); + + // Checkbox event capture + $('.privilege-table-container').on('change', 'input[type="checkbox"]', function() { + var checkboxEl = $(this), + privilege = checkboxEl.parent().attr('data-privilege'), + state = checkboxEl.prop('checked'), + rowEl = checkboxEl.parents('tr'), + member = rowEl.attr('data-group-name') || rowEl.attr('data-uid'), + isPrivate = parseInt(rowEl.attr('data-private') || 0, 10), + isGroup = rowEl.attr('data-group-name') !== undefined; + + if (member) { + if (isGroup && privilege === 'groups:moderate' && !isPrivate && state) { + bootbox.confirm('Are you sure you wish to grant the moderation privilege to this user group? This group is public, and any users can join at will.', function(confirm) { + if (confirm) { + Category.setPrivilege(member, privilege, state, checkboxEl); + } else { + checkboxEl.prop('checked', checkboxEl.prop('checked') ^ 1); + } + }); + } else { + Category.setPrivilege(member, privilege, state, checkboxEl); + } + } else { + app.alertError('[[error:invalid-data]]'); + } + }) + }; + + Category.refreshPrivilegeTable = function() { + socket.emit('admin.categories.getPrivilegeSettings', ajaxify.variables.get('cid'), function(err, privileges) { + if (err) { + return app.alertError(err.message); + } + + templates.parse('admin/partials/categories/privileges', { + privileges: privileges + }, function(html) { + $('.privilege-table-container').html(html); + }); + }); + }; + + Category.setPrivilege = function(member, privilege, state, checkboxEl) { + socket.emit('admin.categories.setPrivilege', { + cid: ajaxify.variables.get('cid'), + privilege: privilege, + set: state, + member: member + }, function(err) { + if (err) { + return app.alertError(err.message); + } + + checkboxEl.replaceWith(''); + Category.refreshPrivilegeTable(); + }); + }; + + Category.launchParentSelector = function() { + socket.emit('categories.get', function(err, categories) { + templates.parse('partials/category_list', { + categories: categories + }, function(html) { + var modal = bootbox.dialog({ + message: html, + title: 'Set Parent Category' + }); + + modal.find('li[data-cid]').on('click', function() { + var parentCid = $(this).attr('data-cid'), + payload = {}; + + payload[ajaxify.variables.get('cid')] = { + parentCid: parentCid + }; + + socket.emit('admin.categories.update', payload, function(err) { + if (err) { + return app.alertError(err.message); + } + + modal.modal('hide'); + ajaxify.refresh(); + }); + }); + }); + }); + }; + + return Category; +}); \ No newline at end of file diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 6178587423..ed5d3e8b69 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -25,6 +25,8 @@ $(document).ready(function() { ajaxify.go = function (url, callback, quiet) { if (ajaxify.handleACPRedirect(url)) { return true; + } else if (ajaxify.handleNonAPIRoutes(url)) { + return true; } app.enterRoom(''); @@ -39,8 +41,6 @@ $(document).ready(function() { $('#footer, #content').removeClass('hide').addClass('ajaxifying'); - var startTime = (new Date()).getTime(); - ajaxify.variables.flush(); ajaxify.loadData(url, function(err, data) { if (err) { @@ -51,7 +51,7 @@ $(document).ready(function() { translator.load(config.defaultLang, data.template.name); - renderTemplate(url, data.template.name, data, startTime, callback); + renderTemplate(url, data.template.name, data, callback); require(['search'], function(search) { search.topicDOM.end(); @@ -64,12 +64,21 @@ $(document).ready(function() { ajaxify.handleACPRedirect = function(url) { // If ajaxifying into an admin route from regular site, do a cold load. url = ajaxify.removeRelativePath(url.replace(/\/$/, '')); - if (url.indexOf('admin') === 0 && window.location.pathname.indexOf('/admin') !== 0) { + if (url.indexOf('admin') === 0 && window.location.pathname.indexOf(RELATIVE_PATH + '/admin') !== 0) { window.open(RELATIVE_PATH + '/' + url, '_blank'); return true; } return false; - } + }; + + ajaxify.handleNonAPIRoutes = function(url) { + url = ajaxify.removeRelativePath(url.replace(/\/$/, '')); + if (url.indexOf('uploads') === 0) { + window.open(RELATIVE_PATH + '/' + url, '_blank'); + return true; + } + return false; + }; ajaxify.start = function(url, quiet, search) { url = ajaxify.removeRelativePath(url.replace(/\/$/, '')); @@ -118,25 +127,22 @@ $(document).ready(function() { } } - function renderTemplate(url, tpl_url, data, startTime, callback) { - var animationDuration = parseFloat($('#content').css('transition-duration')) || 0.2; + function renderTemplate(url, tpl_url, data, callback) { $(window).trigger('action:ajaxify.loadingTemplates', {}); templates.parse(tpl_url, data, function(template) { translator.translate(template, function(translatedTemplate) { - setTimeout(function() { - $('#content').html(translatedTemplate); + $('#content').html(translatedTemplate); - ajaxify.end(url, tpl_url); + ajaxify.end(url, tpl_url); - if (typeof callback === 'function') { - callback(); - } + if (typeof callback === 'function') { + callback(); + } - $('#content, #footer').removeClass('ajaxifying'); + $('#content, #footer').removeClass('ajaxifying'); - app.refreshTitle(url); - }, animationDuration * 1000 - ((new Date()).getTime() - startTime)); + app.refreshTitle(url); }); }); } @@ -162,7 +168,11 @@ $(document).ready(function() { return url; }; - ajaxify.refresh = function() { + ajaxify.refresh = function(e) { + if (e && e instanceof jQuery.Event) { + e.preventDefault(); + } + ajaxify.go(ajaxify.currentPage); }; diff --git a/public/src/app.js b/public/src/app.js index fdfe7856b3..dadf141702 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -105,8 +105,8 @@ app.cacheBuster = null; case 'admin': room = 'admin'; break; - case 'home': - room = 'home'; + case 'categories': + room = 'categories'; break; } app.currentRoom = ''; @@ -234,7 +234,7 @@ app.cacheBuster = null; app.processPage = function () { highlightNavigationLink(); - $('span.timeago').timeago(); + $('.timeago').timeago(); utils.makeNumbersHumanReadable($('.human-readable-number')); diff --git a/public/src/client/account/favourites.js b/public/src/client/account/favourites.js index 6a08a814a5..f73e1d4f20 100644 --- a/public/src/client/account/favourites.js +++ b/public/src/client/account/favourites.js @@ -34,7 +34,7 @@ define('forum/account/favourites', ['forum/account/header', 'forum/infinitescrol infinitescroll.parseAndTranslate('account/favourites', 'posts', {posts: posts}, function(html) { $('.user-favourite-posts').append(html); html.find('img').addClass('img-responsive'); - html.find('span.timeago').timeago(); + html.find('.timeago').timeago(); app.createUserTooltips(); utils.makeNumbersHumanReadable(html.find('.human-readable-number')); callback(); diff --git a/public/src/client/account/posts.js b/public/src/client/account/posts.js index 70410e0819..c4759b9016 100644 --- a/public/src/client/account/posts.js +++ b/public/src/client/account/posts.js @@ -35,7 +35,7 @@ define('forum/account/posts', ['forum/account/header', 'forum/infinitescroll'], infinitescroll.parseAndTranslate('account/posts', 'posts', {posts: posts}, function(html) { $('.user-favourite-posts').append(html); html.find('img').addClass('img-responsive'); - html.find('span.timeago').timeago(); + html.find('.timeago').timeago(); app.createUserTooltips(); utils.makeNumbersHumanReadable(html.find('.human-readable-number')); callback(); diff --git a/public/src/client/account/profile.js b/public/src/client/account/profile.js index 89a555a702..5bbf48fe85 100644 --- a/public/src/client/account/profile.js +++ b/public/src/client/account/profile.js @@ -116,7 +116,7 @@ define('forum/account/profile', ['forum/account/header', 'forum/infinitescroll'] infinitescroll.parseAndTranslate('account/profile', 'posts', {posts: posts}, function(html) { $('.user-recent-posts .loading-indicator').before(html); - html.find('span.timeago').timeago(); + html.find('.timeago').timeago(); callback(); }); diff --git a/public/src/client/account/topics.js b/public/src/client/account/topics.js index c556ef2891..c6c93f4262 100644 --- a/public/src/client/account/topics.js +++ b/public/src/client/account/topics.js @@ -18,12 +18,12 @@ define('forum/account/topics', ['forum/account/header', 'forum/infinitescroll'], infinitescroll.loadMore('topics.loadMoreFromSet', { set: 'uid:' + $('.account-username-box').attr('data-uid') + ':topics', - after: $('.user-topics').attr('data-nextstart') + after: $('[component="category"]').attr('data-nextstart') }, function(data, done) { if (data.topics && data.topics.length) { onTopicsLoaded(data.topics, done); - $('.user-topics').attr('data-nextstart', data.nextStart); + $('[component="category"]').attr('data-nextstart', data.nextStart); } else { done(); } @@ -32,8 +32,8 @@ 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); - html.find('span.timeago').timeago(); + $('[component="category"]').append(html); + html.find('.timeago').timeago(); app.createUserTooltips(); utils.makeNumbersHumanReadable(html.find('.human-readable-number')); $(window).trigger('action:topics.loaded'); diff --git a/public/src/client/account/watched.js b/public/src/client/account/watched.js index 9a502b1ee8..08feb89344 100644 --- a/public/src/client/account/watched.js +++ b/public/src/client/account/watched.js @@ -17,11 +17,11 @@ define('forum/account/watched', ['forum/account/header', 'forum/infinitescroll'] infinitescroll.loadMore('topics.loadMoreFromSet', { set: 'uid:' + $('.account-username-box').attr('data-uid') + ':followed_tids', - after: $('.user-topics').attr('data-nextstart') + after: $('[component="category"]').attr('data-nextstart') }, function(data, done) { if (data.topics && data.topics.length) { onTopicsLoaded(data.topics, done); - $('.user-topics').attr('data-nextstart', data.nextStart); + $('[component="category"]').attr('data-nextstart', data.nextStart); } else { done(); } @@ -30,8 +30,8 @@ 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); - html.find('span.timeago').timeago(); + $('[component="category"]').append(html); + html.find('.timeago').timeago(); app.createUserTooltips(); utils.makeNumbersHumanReadable(html.find('.human-readable-number')); $(window).trigger('action:topics.loaded'); diff --git a/public/src/client/categories.js b/public/src/client/categories.js index d3cf1cae43..e3882ff831 100644 --- a/public/src/client/categories.js +++ b/public/src/client/categories.js @@ -29,7 +29,7 @@ define('forum/categories', function() { }; function renderNewPost(cid, post) { - var category = $('.category-item[data-cid="' + cid + '"]'); + var category = components.get('category/topic', 'cid', cid); if (!category.length) { return; } @@ -67,7 +67,7 @@ define('forum/categories', function() { translator.translate(html, function(translatedHTML) { translatedHTML = $(translatedHTML); translatedHTML.find('img').addClass('img-responsive'); - translatedHTML.find('span.timeago').timeago(); + translatedHTML.find('.timeago').timeago(); callback(translatedHTML); }); }); diff --git a/public/src/client/category.js b/public/src/client/category.js index 3b6a0e69b9..1e6c0e94c4 100644 --- a/public/src/client/category.js +++ b/public/src/client/category.js @@ -20,12 +20,6 @@ define('forum/category', [ } }); - $(window).on('action:composer.topics.post', function(ev, data) { - localStorage.removeItem('category:' + data.data.cid + ':bookmark'); - localStorage.removeItem('category:' + data.data.cid + ':bookmark:clicked'); - ajaxify.go('topic/' + data.data.slug); - }); - function removeListeners() { socket.removeListener('event:new_topic', Category.onNewTopic); categoryTools.removeListeners(); @@ -52,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', '.topic-title', 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); @@ -95,8 +89,8 @@ define('forum/category', [ }); }; - Category.navigatorCallback = function(element, elementCount) { - return parseInt(element.attr('data-index'), 10) + 1; + Category.navigatorCallback = function(topIndex, bottomIndex, elementCount) { + return bottomIndex; }; $(window).on('action:popstate', function(ev, data) { @@ -135,7 +129,7 @@ define('forum/category', [ bookmarkIndex = 0; } - $('#topics-container').empty(); + $('[component="category"]').empty(); loadTopicsAfter(bookmarkIndex, function() { Category.scrollToTopic(bookmarkIndex, clickedIndex, 0); @@ -145,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() { @@ -163,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({ @@ -198,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) { @@ -228,7 +223,7 @@ define('forum/category', [ topic.hide().fadeIn('slow'); - topic.find('span.timeago').timeago(); + topic.find('.timeago').timeago(); app.createUserTooltips(); updateTopicCount(); @@ -253,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; }); } @@ -261,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(); } } @@ -283,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) { @@ -304,7 +305,7 @@ define('forum/category', [ if (typeof callback === 'function') { callback(); } - html.find('span.timeago').timeago(); + html.find('.timeago').timeago(); app.createUserTooltips(); utils.makeNumbersHumanReadable(html.find('.human-readable-number')); }); @@ -312,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); @@ -326,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; } @@ -342,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..e711bce436 100644 --- a/public/src/client/categoryTools.js +++ b/public/src/client/categoryTools.js @@ -173,26 +173,26 @@ 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) { var topic = getTopicEl(data.tid); topic.toggleClass('deleted', data.isDeleted); - topic.find('.fa-lock').toggleClass('hide', !data.isDeleted); + topic.find('[component="topic/locked"]').toggleClass('hide', !data.isDeleted); } function setPinnedState(data) { var topic = getTopicEl(data.tid); topic.toggleClass('pinned', data.isPinned); - topic.find('.fa-thumb-tack').toggleClass('hide', !data.isPinned); + topic.find('[component="topic/pinned"]').toggleClass('hide', !data.isPinned); ajaxify.refresh(); } function setLockedState(data) { var topic = getTopicEl(data.tid); topic.toggleClass('locked', data.isLocked); - topic.find('.fa-lock').toggleClass('hide', !data.isLocked); + topic.find('[component="topic/locked"]').toggleClass('hide', !data.isLocked); } function onTopicMoved(data) { diff --git a/public/src/client/chats.js b/public/src/client/chats.js index cde94aa71a..9ea8beea57 100644 --- a/public/src/client/chats.js +++ b/public/src/client/chats.js @@ -122,7 +122,7 @@ define('forum/chats', ['string', 'sounds', 'forum/infinitescroll'], function(S, function onMessagesParsed(html) { var newMessage = $(html); newMessage.insertBefore($('.user-typing')); - newMessage.find('span.timeago').timeago(); + newMessage.find('.timeago').timeago(); newMessage.find('img:not(".chat-user-image")').addClass('img-responsive'); Chats.scrollToBottom($('.expanded-chat .chat-content')); } diff --git a/public/src/client/footer.js b/public/src/client/footer.js index 6462e3e39a..4e7c2fa9ee 100644 --- a/public/src/client/footer.js +++ b/public/src/client/footer.js @@ -22,7 +22,7 @@ define('forum/footer', ['notifications', 'chat'], function(Notifications, Chat) return console.warn('Error updating unread count', err); } - $('#chat-count') + components.get('chat/icon') .toggleClass('unread-count', count > 0) .attr('data-content', count > 20 ? '20+' : count); } diff --git a/public/src/client/notifications.js b/public/src/client/notifications.js index fb778ec18f..4e7244f83f 100644 --- a/public/src/client/notifications.js +++ b/public/src/client/notifications.js @@ -16,7 +16,7 @@ define('forum/notifications', function() { }); }); - $('span.timeago').timeago(); + $('.timeago').timeago(); $('.notifications .delete').on('click', function() { socket.emit('notifications.markAllRead', function(err) { diff --git a/public/src/client/recent.js b/public/src/client/recent.js index 05e936a577..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,8 +124,8 @@ 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); - html.find('span.timeago').timeago(); + $('[component="category"]').append(html); + html.find('.timeago').timeago(); app.createUserTooltips(); utils.makeNumbersHumanReadable(html.find('.human-readable-number')); $(window).trigger('action:topics.loaded'); diff --git a/public/src/client/reset.js b/public/src/client/reset.js index 7e272c3284..568d0739a1 100644 --- a/public/src/client/reset.js +++ b/public/src/client/reset.js @@ -24,6 +24,7 @@ define('forum/reset', function() { successEl.addClass('hide').hide(); errorEl.removeClass('hide').show(); } + return false; }); }; diff --git a/public/src/client/reset_code.js b/public/src/client/reset_code.js index c0f46dc356..846feffb42 100644 --- a/public/src/client/reset_code.js +++ b/public/src/client/reset_code.js @@ -31,22 +31,8 @@ define('forum/reset_code', function() { window.location.href = RELATIVE_PATH + '/login'; }); } + return false; }); - - // socket.emit('user.reset.valid', reset_code, function(err, valid) { - // if(err) { - // return app.alertError(err.message); - // } - - // if (valid) { - // resetEl.prop('disabled', false); - // } else { - // var formEl = $('#reset-form'); - // // Show error message - // $('#error').show(); - // formEl.remove(); - // } - // }); }; return ResetCode; 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/topic.js b/public/src/client/topic.js index 9acd1a4d73..f28a9097c8 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -1,7 +1,7 @@ 'use strict'; -/* globals define, app, templates, translator, socket, bootbox, config, ajaxify, RELATIVE_PATH, utils */ +/* globals define, app, components, templates, translator, socket, bootbox, config, ajaxify, RELATIVE_PATH, utils */ define('forum/topic', [ 'forum/pagination', @@ -20,7 +20,7 @@ define('forum/topic', [ $(window).on('action:ajaxify.start', function(ev, data) { if (ajaxify.currentPage !== data.url) { navigator.hide(); - $('.header-topic-title').find('span').text('').hide(); + components.get('navbar/title').find('span').text('').hide(); app.removeAlert('bookmark'); events.removeListeners(); @@ -53,7 +53,7 @@ define('forum/topic', [ handleBookmark(tid); - navigator.init('.posts > .post-row', ajaxify.variables.get('postcount'), Topic.toTop, Topic.toBottom, Topic.navigatorCallback, Topic.calculateIndex); + navigator.init('[component="post"]', ajaxify.variables.get('postcount'), Topic.toTop, Topic.toBottom, Topic.navigatorCallback, Topic.calculateIndex); $(window).on('scroll', updateTopicTitle); @@ -112,7 +112,7 @@ define('forum/topic', [ } function addBlockQuoteHandler() { - $('#post-container').on('click', 'blockquote .toggle', function() { + components.get('topic').on('click', 'blockquote .toggle', function() { var blockQuote = $(this).parent('blockquote'); var toggle = $(this); blockQuote.toggleClass('uncollapsed'); @@ -124,7 +124,7 @@ define('forum/topic', [ function enableInfiniteLoadingOrPagination() { if(!config.usePagination) { - infinitescroll.init(posts.loadMorePosts, $('#post-container .post-row[data-index="0"]').height()); + infinitescroll.init(posts.loadMorePosts, components.get('post', 'index', 0).height()); } else { navigator.hide(); @@ -135,9 +135,9 @@ define('forum/topic', [ function updateTopicTitle() { if($(window).scrollTop() > 50) { - $('.header-topic-title').find('span').text(ajaxify.variables.get('topic_name')).show(); + components.get('navbar/title').find('span').text(ajaxify.variables.get('topic_name')).show(); } else { - $('.header-topic-title').find('span').text('').hide(); + components.get('navbar/title').find('span').text('').hide(); } } @@ -148,18 +148,18 @@ define('forum/topic', [ return index; }; - Topic.navigatorCallback = function(element, elementCount) { + Topic.navigatorCallback = function(topPostIndex, bottomPostIndex, elementCount) { var path = ajaxify.removeRelativePath(window.location.pathname.slice(1)); if (!path.startsWith('topic')) { return 1; } - var postIndex = parseInt(element.attr('data-index'), 10); - var index = postIndex + 1; + var postIndex = topPostIndex; + var index = bottomPostIndex; if (config.topicPostSort !== 'oldest_to_newest') { - if (postIndex === 0) { + if (bottomPostIndex === 0) { index = 1; } else { - index = Math.max(elementCount - postIndex + 1, 1); + index = Math.max(elementCount - bottomPostIndex + 2, 1); } } @@ -175,8 +175,8 @@ define('forum/topic', [ var topicId = parts[1], slug = parts[2]; var newUrl = 'topic/' + topicId + '/' + (slug ? slug : ''); - if (postIndex > 0) { - newUrl += '/' + (postIndex + 1); + if (postIndex > 1) { + newUrl += '/' + postIndex; } if (newUrl !== currentUrl) { diff --git a/public/src/client/topic/browsing.js b/public/src/client/topic/browsing.js index 935439fa88..7c14fab158 100644 --- a/public/src/client/topic/browsing.js +++ b/public/src/client/topic/browsing.js @@ -10,7 +10,7 @@ define('forum/topic/browsing', function() { Browsing.onUpdateUsersInRoom = function(data) { if (data && data.room.indexOf('topic_' + ajaxify.variables.get('topic_id')) !== -1) { - $('.browsing-users').toggleClass('hidden', !data.users.length); + $('[component="topic/browsing/list"]').parent().toggleClass('hidden', !data.users.length); for(var i=0; i{events.jsonString}
diff --git a/src/views/admin/general/dashboard.tpl b/src/views/admin/general/dashboard.tpl
index 759144152d..db18b7cf02 100644
--- a/src/views/admin/general/dashboard.tpl
+++ b/src/views/admin/general/dashboard.tpl
@@ -1,6 +1,5 @@