mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
closes #2794
This commit is contained in:
@@ -20,6 +20,12 @@ 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();
|
||||
@@ -50,11 +56,11 @@ define('forum/category', [
|
||||
}
|
||||
|
||||
$('#topics-container').on('click', '.topic-title', function() {
|
||||
var clickedTid = $(this).parents('li.category-item[data-tid]').attr('data-tid');
|
||||
var clickedIndex = $(this).parents('[data-index]').attr('data-index');
|
||||
$('#topics-container li.category-item').each(function(index, el) {
|
||||
if($(el).offset().top - $(window).scrollTop() > 0) {
|
||||
localStorage.setItem('category:' + cid + ':bookmark', $(el).attr('data-tid'));
|
||||
localStorage.setItem('category:' + cid + ':bookmark:clicked', clickedTid);
|
||||
if ($(el).offset().top - $(window).scrollTop() > 0) {
|
||||
localStorage.setItem('category:' + cid + ':bookmark', $(el).attr('data-index'));
|
||||
localStorage.setItem('category:' + cid + ':bookmark:clicked', clickedIndex);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
@@ -94,7 +100,7 @@ define('forum/category', [
|
||||
};
|
||||
|
||||
$(window).on('action:popstate', function(ev, data) {
|
||||
if(data.url.indexOf('category/') === 0) {
|
||||
if (data.url.indexOf('category/') === 0) {
|
||||
var cid = data.url.match(/^category\/(\d+)/);
|
||||
if (cid && cid[1]) {
|
||||
cid = cid[1];
|
||||
@@ -103,52 +109,44 @@ define('forum/category', [
|
||||
return;
|
||||
}
|
||||
|
||||
var bookmark = localStorage.getItem('category:' + cid + ':bookmark');
|
||||
var clicked = localStorage.getItem('category:' + cid + ':bookmark:clicked');
|
||||
var bookmarkIndex = localStorage.getItem('category:' + cid + ':bookmark');
|
||||
var clickedIndex = localStorage.getItem('category:' + cid + ':bookmark:clicked');
|
||||
|
||||
if (!bookmark) {
|
||||
if (!bookmarkIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(config.usePagination) {
|
||||
socket.emit('topics.getTidPage', bookmark, function(err, page) {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
if(parseInt(page, 10) !== pagination.currentPage) {
|
||||
pagination.loadPage(page);
|
||||
} else {
|
||||
Category.scrollToTopic(bookmark, clicked, 400);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
socket.emit('topics.getTidIndex', bookmark, function(err, index) {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (index === 0) {
|
||||
Category.highlightTopic(clicked);
|
||||
return;
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
$('#topics-container').empty();
|
||||
|
||||
loadTopicsAfter(index, function() {
|
||||
Category.scrollToTopic(bookmark, clicked, 0);
|
||||
if (config.usePagination) {
|
||||
var page = Math.ceil((parseInt(bookmarkIndex, 10) + 1) / config.topicsPerPage);
|
||||
if (parseInt(page, 10) !== pagination.currentPage) {
|
||||
pagination.loadPage(page, function() {
|
||||
Category.scrollToTopic(bookmarkIndex, clickedIndex, 400);
|
||||
});
|
||||
} else {
|
||||
Category.scrollToTopic(bookmarkIndex, clickedIndex, 400);
|
||||
}
|
||||
} else {
|
||||
if (bookmarkIndex === 0) {
|
||||
Category.highlightTopic(clickedIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bookmarkIndex < 0) {
|
||||
bookmarkIndex = 0;
|
||||
}
|
||||
|
||||
$('#topics-container').empty();
|
||||
|
||||
loadTopicsAfter(bookmarkIndex, function() {
|
||||
Category.scrollToTopic(bookmarkIndex, clickedIndex, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Category.highlightTopic = function(tid) {
|
||||
var highlight = $('#topics-container li.category-item[data-tid="' + tid + '"]');
|
||||
if(highlight.length && !highlight.hasClass('highlight')) {
|
||||
Category.highlightTopic = function(topicIndex) {
|
||||
var highlight = $('#topics-container [data-index="' + topicIndex + '"]');
|
||||
if (highlight.length && !highlight.hasClass('highlight')) {
|
||||
highlight.addClass('highlight');
|
||||
setTimeout(function() {
|
||||
highlight.removeClass('highlight');
|
||||
@@ -156,27 +154,24 @@ define('forum/category', [
|
||||
}
|
||||
};
|
||||
|
||||
Category.scrollToTopic = function(tid, clickedTid, duration, offset) {
|
||||
if(!tid) {
|
||||
Category.scrollToTopic = function(bookmarkIndex, clickedIndex, duration, offset) {
|
||||
if (!bookmarkIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!offset) {
|
||||
if (!offset) {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
if($('#topics-container li.category-item[data-tid="' + tid + '"]').length) {
|
||||
var cid = ajaxify.variables.get('category_id');
|
||||
var scrollTo = $('#topics-container li.category-item[data-tid="' + tid + '"]');
|
||||
|
||||
if (cid && scrollTo.length) {
|
||||
$('html, body').animate({
|
||||
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px'
|
||||
}, duration !== undefined ? duration : 400, function() {
|
||||
Category.highlightTopic(clickedTid);
|
||||
navigator.update();
|
||||
});
|
||||
}
|
||||
var scrollTo = $('#topics-container [data-index="' + bookmarkIndex + '"]');
|
||||
var cid = ajaxify.variables.get('category_id');
|
||||
if (scrollTo.length && cid) {
|
||||
$('html, body').animate({
|
||||
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px'
|
||||
}, duration !== undefined ? duration : 400, function() {
|
||||
Category.highlightTopic(clickedIndex);
|
||||
navigator.update();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -191,7 +186,7 @@ define('forum/category', [
|
||||
|
||||
Category.onNewTopic = function(topic) {
|
||||
var cid = ajaxify.variables.get('category_id');
|
||||
if(!topic || parseInt(topic.cid, 10) !== parseInt(cid, 10)) {
|
||||
if (!topic || parseInt(topic.cid, 10) !== parseInt(cid, 10)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -324,7 +319,7 @@ define('forum/category', [
|
||||
infinitescroll.calculateAfter(direction, '#topics-container .category-item[data-tid]', config.topicsPerPage, false, function(after, offset, el) {
|
||||
loadTopicsAfter(after, function() {
|
||||
if (direction < 0 && el) {
|
||||
Category.scrollToTopic(el.attr('data-tid'), null, 0, offset);
|
||||
Category.scrollToTopic(el.attr('data-index'), null, 0, offset);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -432,13 +432,7 @@ define('composer', [
|
||||
};
|
||||
|
||||
action = 'topics.post';
|
||||
socket.emit(action, composerData, function(err, topic) {
|
||||
done(err);
|
||||
|
||||
if (!err) {
|
||||
ajaxify.go('topic/' + topic.slug);
|
||||
}
|
||||
});
|
||||
socket.emit(action, composerData, done);
|
||||
} else if (parseInt(postData.tid, 10) > 0) {
|
||||
composerData = {
|
||||
tid: postData.tid,
|
||||
@@ -463,7 +457,7 @@ define('composer', [
|
||||
socket.emit(action, composerData, done);
|
||||
}
|
||||
|
||||
function done(err) {
|
||||
function done(err, data) {
|
||||
$('.action-bar button').removeAttr('disabled');
|
||||
if (err) {
|
||||
if (err.message === '[[error:email-not-confirmed]]') {
|
||||
@@ -476,7 +470,7 @@ define('composer', [
|
||||
discard(post_uuid);
|
||||
drafts.removeDraft(postData.save_id);
|
||||
|
||||
$(window).trigger('action:composer.' + action, composerData);
|
||||
$(window).trigger('action:composer.' + action, {composerData: composerData, data: data});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -518,14 +518,6 @@ SocketTopics.getPageCount = function(socket, tid, callback) {
|
||||
topics.getPageCount(tid, socket.uid, callback);
|
||||
};
|
||||
|
||||
SocketTopics.getTidPage = function(socket, tid, callback) {
|
||||
topics.getTidPage(tid, socket.uid, callback);
|
||||
};
|
||||
|
||||
SocketTopics.getTidIndex = function(socket, tid, callback) {
|
||||
categories.getTopicIndex(tid, callback);
|
||||
};
|
||||
|
||||
SocketTopics.searchTags = function(socket, data, callback) {
|
||||
topics.searchTags(data, callback);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user