v1.18.x
barisusakli 10 years ago
parent 046bcef800
commit f7f453f8cd

@ -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() { function removeListeners() {
socket.removeListener('event:new_topic', Category.onNewTopic); socket.removeListener('event:new_topic', Category.onNewTopic);
categoryTools.removeListeners(); categoryTools.removeListeners();
@ -50,11 +56,11 @@ define('forum/category', [
} }
$('#topics-container').on('click', '.topic-title', function() { $('#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) { $('#topics-container li.category-item').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-tid')); localStorage.setItem('category:' + cid + ':bookmark', $(el).attr('data-index'));
localStorage.setItem('category:' + cid + ':bookmark:clicked', clickedTid); localStorage.setItem('category:' + cid + ':bookmark:clicked', clickedIndex);
return false; return false;
} }
}); });
@ -94,7 +100,7 @@ define('forum/category', [
}; };
$(window).on('action:popstate', function(ev, data) { $(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+)/); var cid = data.url.match(/^category\/(\d+)/);
if (cid && cid[1]) { if (cid && cid[1]) {
cid = cid[1]; cid = cid[1];
@ -103,52 +109,44 @@ define('forum/category', [
return; return;
} }
var bookmark = localStorage.getItem('category:' + cid + ':bookmark'); var bookmarkIndex = localStorage.getItem('category:' + cid + ':bookmark');
var clicked = localStorage.getItem('category:' + cid + ':bookmark:clicked'); var clickedIndex = localStorage.getItem('category:' + cid + ':bookmark:clicked');
if (!bookmark) { if (!bookmarkIndex) {
return; return;
} }
if(config.usePagination) { if (config.usePagination) {
socket.emit('topics.getTidPage', bookmark, function(err, page) { var page = Math.ceil((parseInt(bookmarkIndex, 10) + 1) / config.topicsPerPage);
if (err) { if (parseInt(page, 10) !== pagination.currentPage) {
return; pagination.loadPage(page, function() {
} Category.scrollToTopic(bookmarkIndex, clickedIndex, 400);
if(parseInt(page, 10) !== pagination.currentPage) { });
pagination.loadPage(page); } else {
} else { Category.scrollToTopic(bookmarkIndex, clickedIndex, 400);
Category.scrollToTopic(bookmark, clicked, 400); }
}
});
} else { } else {
socket.emit('topics.getTidIndex', bookmark, function(err, index) { if (bookmarkIndex === 0) {
if (err) { Category.highlightTopic(clickedIndex);
return; return;
} }
if (index === 0) {
Category.highlightTopic(clicked);
return;
}
if (index < 0) { if (bookmarkIndex < 0) {
index = 0; bookmarkIndex = 0;
} }
$('#topics-container').empty(); $('#topics-container').empty();
loadTopicsAfter(index, function() { loadTopicsAfter(bookmarkIndex, function() {
Category.scrollToTopic(bookmark, clicked, 0); Category.scrollToTopic(bookmarkIndex, clickedIndex, 0);
});
}); });
} }
} }
}); });
Category.highlightTopic = function(tid) { Category.highlightTopic = function(topicIndex) {
var highlight = $('#topics-container li.category-item[data-tid="' + tid + '"]'); var highlight = $('#topics-container [data-index="' + topicIndex + '"]');
if(highlight.length && !highlight.hasClass('highlight')) { if (highlight.length && !highlight.hasClass('highlight')) {
highlight.addClass('highlight'); highlight.addClass('highlight');
setTimeout(function() { setTimeout(function() {
highlight.removeClass('highlight'); highlight.removeClass('highlight');
@ -156,27 +154,24 @@ define('forum/category', [
} }
}; };
Category.scrollToTopic = function(tid, clickedTid, duration, offset) { Category.scrollToTopic = function(bookmarkIndex, clickedIndex, duration, offset) {
if(!tid) { if (!bookmarkIndex) {
return; return;
} }
if(!offset) { if (!offset) {
offset = 0; offset = 0;
} }
if($('#topics-container li.category-item[data-tid="' + tid + '"]').length) { var scrollTo = $('#topics-container [data-index="' + bookmarkIndex + '"]');
var cid = ajaxify.variables.get('category_id'); var cid = ajaxify.variables.get('category_id');
var scrollTo = $('#topics-container li.category-item[data-tid="' + tid + '"]'); if (scrollTo.length && cid) {
$('html, body').animate({
if (cid && scrollTo.length) { scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px'
$('html, body').animate({ }, duration !== undefined ? duration : 400, function() {
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px' Category.highlightTopic(clickedIndex);
}, duration !== undefined ? duration : 400, function() { navigator.update();
Category.highlightTopic(clickedTid); });
navigator.update();
});
}
} }
}; };
@ -191,7 +186,7 @@ define('forum/category', [
Category.onNewTopic = function(topic) { Category.onNewTopic = function(topic) {
var cid = ajaxify.variables.get('category_id'); 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; return;
} }
@ -324,7 +319,7 @@ define('forum/category', [
infinitescroll.calculateAfter(direction, '#topics-container .category-item[data-tid]', config.topicsPerPage, false, function(after, offset, el) { infinitescroll.calculateAfter(direction, '#topics-container .category-item[data-tid]', 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-tid'), null, 0, offset); Category.scrollToTopic(el.attr('data-index'), null, 0, offset);
} }
}); });
}); });

@ -432,13 +432,7 @@ define('composer', [
}; };
action = 'topics.post'; action = 'topics.post';
socket.emit(action, composerData, function(err, topic) { socket.emit(action, composerData, done);
done(err);
if (!err) {
ajaxify.go('topic/' + topic.slug);
}
});
} else if (parseInt(postData.tid, 10) > 0) { } else if (parseInt(postData.tid, 10) > 0) {
composerData = { composerData = {
tid: postData.tid, tid: postData.tid,
@ -463,7 +457,7 @@ define('composer', [
socket.emit(action, composerData, done); socket.emit(action, composerData, done);
} }
function done(err) { function done(err, data) {
$('.action-bar button').removeAttr('disabled'); $('.action-bar button').removeAttr('disabled');
if (err) { if (err) {
if (err.message === '[[error:email-not-confirmed]]') { if (err.message === '[[error:email-not-confirmed]]') {
@ -476,7 +470,7 @@ define('composer', [
discard(post_uuid); discard(post_uuid);
drafts.removeDraft(postData.save_id); drafts.removeDraft(postData.save_id);
$(window).trigger('action:composer.' + action, composerData); $(window).trigger('action:composer.' + action, {composerData: composerData, data: data});
} }
} }

@ -248,8 +248,8 @@ var async = require('async'),
plugins.fireHook('filter:group.get', {group: results.base}, function(err, data) { plugins.fireHook('filter:group.get', {group: results.base}, function(err, data) {
callback(err, data ? data.group : null); callback(err, data ? data.group : null);
}); });
}); });
}); });
}; };
@ -906,10 +906,10 @@ var async = require('async'),
} }
return group; return group;
}); });
plugins.fireHook('filter:groups.get', {groups: groupData}, function(err, data) { plugins.fireHook('filter:groups.get', {groups: groupData}, function(err, data) {
callback(err, data ? data.groups : null); callback(err, data ? data.groups : null);
}); });
}); });
}; };

@ -518,14 +518,6 @@ SocketTopics.getPageCount = function(socket, tid, callback) {
topics.getPageCount(tid, socket.uid, 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) { SocketTopics.searchTags = function(socket, data, callback) {
topics.searchTags(data, callback); topics.searchTags(data, callback);
}; };

@ -3,11 +3,11 @@
var async = require('async'), var async = require('async'),
_ = require('underscore'), _ = require('underscore'),
categories = require('../categories'), categories = require('../categories'),
search = require('../search'), search = require('../search'),
db = require('../database'); db = require('../database');
module.exports = function(Topics) { module.exports = function(Topics) {
@ -21,7 +21,7 @@ module.exports = function(Topics) {
}, },
categoryTids: function(next) { categoryTids: function(next) {
getCategoryTids(tid, next); getCategoryTids(tid, next);
} }
}, function(err, results) { }, function(err, results) {
if (err) { if (err) {
return callback(err); return callback(err);
@ -29,8 +29,8 @@ module.exports = function(Topics) {
var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids); var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids);
tids = tids.filter(function(_tid, index, array) { tids = tids.filter(function(_tid, index, array) {
return parseInt(_tid, 10) !== parseInt(tid, 10) && array.indexOf(_tid) === index; return parseInt(_tid, 10) !== parseInt(tid, 10) && array.indexOf(_tid) === index;
}).slice(start, end + 1); }).slice(start, end + 1);
Topics.getTopics(tids, uid, callback); Topics.getTopics(tids, uid, callback);
}); });
}; };
@ -48,18 +48,18 @@ module.exports = function(Topics) {
function(data, next) { function(data, next) {
next(null, _.unique(_.flatten(data))); next(null, _.unique(_.flatten(data)));
} }
], callback); ], callback);
} }
function getSearchTids(tid, callback) { function getSearchTids(tid, callback) {
async.waterfall([ async.waterfall([
function(next) { function(next) {
Topics.getTopicField(tid, 'title', next); Topics.getTopicField(tid, 'title', next);
}, },
function(title, next) { function(title, next) {
search.searchQuery('topic', title, next); search.searchQuery('topic', title, next);
} }
], callback); ], callback);
} }
function getCategoryTids(tid, callback) { function getCategoryTids(tid, callback) {
@ -68,7 +68,7 @@ module.exports = function(Topics) {
return callback(err, []); return callback(err, []);
} }
categories.getTopicIds('cid:' + cid + ':tids', true, 0, 9, callback); categories.getTopicIds('cid:' + cid + ':tids', true, 0, 9, callback);
}); });
} }
}; };
Loading…
Cancel
Save