2014-03-15 17:50:19 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
/* globals define, app, templates, translator, socket, bootbox, config, ajaxify, RELATIVE_PATH, utils */
|
2014-03-15 17:50:19 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools', 'forum/topic/events', 'navigator'], function(pagination, threadTools, postTools, events, navigator) {
|
2013-11-23 17:07:31 -05:00
|
|
|
var Topic = {},
|
2014-02-25 16:33:22 -05:00
|
|
|
infiniteLoaderActive = false,
|
2014-02-25 22:05:07 -05:00
|
|
|
scrollingToPost = false,
|
|
|
|
|
currentUrl = '';
|
2013-08-23 13:45:57 -04:00
|
|
|
|
2013-11-29 14:42:58 -05:00
|
|
|
|
2014-02-12 15:44:48 -05:00
|
|
|
$(window).on('action:ajaxify.start', function(ev, data) {
|
2014-02-14 21:41:53 -05:00
|
|
|
if(data.url.indexOf('topic') !== 0) {
|
2014-04-04 12:42:41 -04:00
|
|
|
navigator.hide();
|
2014-03-04 16:48:07 -05:00
|
|
|
$('.header-topic-title').find('span').text('').hide();
|
2014-02-26 21:58:04 -05:00
|
|
|
app.removeAlert('bookmark');
|
2014-05-03 20:56:26 -04:00
|
|
|
|
|
|
|
|
events.removeListeners();
|
|
|
|
|
|
|
|
|
|
socket.removeListener('event:new_post', onNewPost);
|
2014-01-27 19:58:03 -05:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
Topic.init = function() {
|
2014-03-28 13:02:13 -04:00
|
|
|
var tid = ajaxify.variables.get('topic_id'),
|
2013-10-03 15:04:25 -04:00
|
|
|
thread_state = {
|
2014-03-28 13:02:13 -04:00
|
|
|
locked: ajaxify.variables.get('locked'),
|
|
|
|
|
deleted: ajaxify.variables.get('deleted'),
|
|
|
|
|
pinned: ajaxify.variables.get('pinned')
|
2013-10-03 15:04:25 -04:00
|
|
|
},
|
2014-05-03 20:56:26 -04:00
|
|
|
postCount = ajaxify.variables.get('postcount');
|
2013-05-29 12:17:44 -04:00
|
|
|
|
2014-02-08 00:53:35 -05:00
|
|
|
$(window).trigger('action:topic.loading');
|
2013-05-29 12:17:44 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
app.enterRoom('topic_' + tid);
|
2014-03-01 21:59:51 -05:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
showBottomPostBar();
|
2014-01-31 15:13:52 -05:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
postTools.init(tid, thread_state);
|
|
|
|
|
threadTools.init(tid, thread_state);
|
|
|
|
|
events.init();
|
|
|
|
|
|
|
|
|
|
hidePostToolsForDeletedPosts();
|
|
|
|
|
|
|
|
|
|
enableInfiniteLoading();
|
|
|
|
|
|
2014-05-05 12:15:17 -04:00
|
|
|
addBlockquoteEllipses($('.topic .post-content > blockquote'));
|
|
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');
|
|
|
|
|
if (window.location.hash) {
|
|
|
|
|
Topic.scrollToPost(window.location.hash.substr(1), true);
|
|
|
|
|
} else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1)) && postCount > 1) {
|
|
|
|
|
app.alert({
|
|
|
|
|
alert_id: 'bookmark',
|
|
|
|
|
message: '[[topic:bookmark_instructions]]',
|
|
|
|
|
timeout: 0,
|
|
|
|
|
type: 'info',
|
|
|
|
|
clickfn : function() {
|
|
|
|
|
Topic.scrollToPost(parseInt(bookmark, 10), true);
|
|
|
|
|
},
|
|
|
|
|
closefn : function() {
|
|
|
|
|
localStorage.removeItem('topic:' + tid + ':bookmark');
|
2014-04-20 15:07:53 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
if (!config.usePagination) {
|
|
|
|
|
navigator.init('.posts > .post-row', postCount, Topic.navigatorCallback);
|
2014-04-09 20:55:49 -04:00
|
|
|
}
|
|
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
socket.on('event:new_post', onNewPost);
|
2013-05-29 12:17:44 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
$(window).on('scroll', updateTopicTitle);
|
2014-03-25 14:17:00 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
$(window).trigger('action:topic.loaded');
|
|
|
|
|
};
|
2014-03-25 14:17:00 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
function showBottomPostBar() {
|
|
|
|
|
if($('#post-container .post-row').length > 1 || !$('#post-container li[data-index="0"]').length) {
|
|
|
|
|
$('.bottom-post-bar').removeClass('hide');
|
2014-03-25 14:17:00 -04:00
|
|
|
}
|
2014-05-03 20:56:26 -04:00
|
|
|
}
|
2014-03-25 14:17:00 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
function onNewPost(data) {
|
|
|
|
|
var tid = ajaxify.variables.get('topic_id');
|
|
|
|
|
if(data && data.posts && data.posts.length && data.posts[0].tid !== tid) {
|
|
|
|
|
return;
|
2014-03-15 17:50:19 -04:00
|
|
|
}
|
2013-05-29 12:17:44 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
if(config.usePagination) {
|
|
|
|
|
return onNewPostPagination(data);
|
2014-03-15 17:50:19 -04:00
|
|
|
}
|
2014-02-06 14:48:05 -05:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
for (var i=0; i<data.posts.length; ++i) {
|
|
|
|
|
var postcount = $('.user_postcount_' + data.posts[i].uid);
|
|
|
|
|
postcount.html(parseInt(postcount.html(), 10) + 1);
|
2014-03-15 17:50:19 -04:00
|
|
|
}
|
2013-10-03 15:04:25 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
socket.emit('topics.markAsRead', {tid: tid, uid: app.uid});
|
|
|
|
|
createNewPosts(data);
|
|
|
|
|
}
|
2013-10-03 15:04:25 -04:00
|
|
|
|
2014-05-05 12:15:17 -04:00
|
|
|
function addBlockquoteEllipses(blockquotes) {
|
|
|
|
|
blockquotes.each(function() {
|
|
|
|
|
var $this = $(this);
|
2014-05-06 15:04:02 -04:00
|
|
|
if ($this.find(':hidden').length && !$this.find('.toggle').length) {
|
2014-05-05 12:15:17 -04:00
|
|
|
$this.append('<i class="fa fa-ellipsis-h pointer toggle"></i>');
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-05-08 19:17:31 -04:00
|
|
|
|
2014-05-05 12:15:17 -04:00
|
|
|
$('blockquote .toggle').on('click', function() {
|
|
|
|
|
$(this).parent('blockquote').toggleClass('uncollapsed');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
function enableInfiniteLoading() {
|
|
|
|
|
if(!config.usePagination) {
|
2013-10-03 15:04:25 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
app.enableInfiniteLoading(function(direction) {
|
2013-10-03 15:04:25 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
if (!infiniteLoaderActive && $('#post-container').children().length) {
|
|
|
|
|
var after = 0;
|
|
|
|
|
var el = null;
|
|
|
|
|
if(direction > 0) {
|
|
|
|
|
el = $('#post-container .post-row').last();
|
|
|
|
|
after = parseInt(el.attr('data-index'), 10) + 1;
|
|
|
|
|
} else {
|
|
|
|
|
el = $('#post-container .post-row').first();
|
|
|
|
|
after = parseInt(el.attr('data-index'), 10);
|
|
|
|
|
after -= config.postsPerPage;
|
|
|
|
|
if(after < 0) {
|
|
|
|
|
after = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-29 12:17:44 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
var offset = el.offset().top - $('#header-menu').offset().top + $('#header-menu').height();
|
2013-05-29 12:17:44 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
loadMorePosts(ajaxify.variables.get('topic_id'), after, function() {
|
|
|
|
|
hidePostToolsForDeletedPosts();
|
|
|
|
|
if(direction < 0 && el) {
|
|
|
|
|
Topic.scrollToPost(el.attr('data-pid'), false, 0, offset);
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-02-10 12:41:29 -05:00
|
|
|
}
|
|
|
|
|
});
|
2014-05-03 20:56:26 -04:00
|
|
|
} else {
|
|
|
|
|
navigator.hide();
|
2014-01-16 22:06:23 -05:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
pagination.init(parseInt(ajaxify.variables.get('currentPage'), 10), parseInt(ajaxify.variables.get('pageCount'), 10));
|
2014-03-15 17:50:19 -04:00
|
|
|
}
|
2014-05-03 20:56:26 -04:00
|
|
|
}
|
2013-10-03 15:04:25 -04:00
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
function hidePostToolsForDeletedPosts() {
|
|
|
|
|
$('#post-container li.deleted').each(function() {
|
|
|
|
|
postTools.toggle($(this).attr('data-pid'), true);
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-04-04 12:42:41 -04:00
|
|
|
|
2013-08-27 06:36:49 +08:00
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
function updateTopicTitle() {
|
2014-02-25 14:29:19 -05:00
|
|
|
if($(window).scrollTop() > 50) {
|
2014-03-28 13:02:13 -04:00
|
|
|
$('.header-topic-title').find('span').text(ajaxify.variables.get('topic_name')).show();
|
2014-02-12 16:02:07 -05:00
|
|
|
} else {
|
2014-03-04 16:48:07 -05:00
|
|
|
$('.header-topic-title').find('span').text('').hide();
|
2014-02-12 16:02:07 -05:00
|
|
|
}
|
2014-04-04 12:42:41 -04:00
|
|
|
}
|
2014-02-12 16:02:07 -05:00
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
Topic.navigatorCallback = function(element) {
|
|
|
|
|
var pid = element.attr('data-pid');
|
2014-04-04 16:20:13 -04:00
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
var currentBookmark = localStorage.getItem('topic:' + ajaxify.variables.get('topic_id') + ':bookmark');
|
2013-10-03 15:04:25 -04:00
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
if (!currentBookmark || parseInt(pid, 10) >= parseInt(currentBookmark, 10)) {
|
|
|
|
|
localStorage.setItem('topic:' + ajaxify.variables.get('topic_id') + ':bookmark', pid);
|
|
|
|
|
app.removeAlert('bookmark');
|
|
|
|
|
}
|
2014-02-25 15:10:50 -05:00
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
if (!scrollingToPost) {
|
2014-03-02 16:58:49 -05:00
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
var newUrl = window.location.href.replace(window.location.hash, '') + '#' + pid;
|
2014-03-02 16:58:49 -05:00
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
if (newUrl !== currentUrl) {
|
|
|
|
|
if (history.replaceState) {
|
|
|
|
|
history.replaceState({
|
|
|
|
|
url: window.location.pathname.slice(1) + (window.location.search ? window.location.search : '' ) + '#' + pid
|
|
|
|
|
}, null, newUrl);
|
2013-09-23 17:41:54 -04:00
|
|
|
}
|
2014-04-04 12:42:41 -04:00
|
|
|
currentUrl = newUrl;
|
2013-12-01 17:42:26 -05:00
|
|
|
}
|
2014-04-04 12:42:41 -04:00
|
|
|
}
|
|
|
|
|
};
|
2013-08-27 04:30:00 +08:00
|
|
|
|
2014-02-24 19:26:26 -05:00
|
|
|
Topic.scrollToPost = function(pid, highlight, duration, offset) {
|
2013-11-23 17:07:31 -05:00
|
|
|
if (!pid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-18 01:18:37 -05:00
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
if(!offset) {
|
|
|
|
|
offset = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
scrollingToPost = true;
|
|
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
if($('#post_anchor_' + pid).length) {
|
|
|
|
|
return scrollToPid(pid);
|
|
|
|
|
}
|
2013-11-23 17:07:31 -05:00
|
|
|
|
2014-01-25 19:19:25 -05:00
|
|
|
if(config.usePagination) {
|
|
|
|
|
socket.emit('posts.getPidPage', pid, function(err, page) {
|
2014-01-25 19:50:50 -05:00
|
|
|
if(err) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-01-25 19:19:25 -05:00
|
|
|
if(parseInt(page, 10) !== pagination.currentPage) {
|
2014-03-02 16:58:49 -05:00
|
|
|
pagination.loadPage(page, function() {
|
|
|
|
|
scrollToPid(pid);
|
|
|
|
|
});
|
2014-01-25 19:19:25 -05:00
|
|
|
} else {
|
|
|
|
|
scrollToPid(pid);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2014-02-17 20:57:12 -05:00
|
|
|
socket.emit('posts.getPidIndex', pid, function(err, index) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var tid = $('#post-container').attr('data-tid');
|
|
|
|
|
$('#post-container').empty();
|
|
|
|
|
var after = index - config.postsPerPage + 1;
|
|
|
|
|
if(after < 0) {
|
|
|
|
|
after = 0;
|
|
|
|
|
}
|
2014-03-02 16:58:49 -05:00
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
loadMorePosts(tid, after, function() {
|
|
|
|
|
scrollToPid(pid);
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-01-25 19:19:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scrollToPid(pid) {
|
2014-02-17 20:57:12 -05:00
|
|
|
var scrollTo = $('#post_anchor_' + pid),
|
|
|
|
|
tid = $('#post-container').attr('data-tid');
|
2013-11-23 17:07:31 -05:00
|
|
|
|
2014-01-25 19:19:25 -05:00
|
|
|
function animateScroll() {
|
2014-02-24 15:23:26 -05:00
|
|
|
$("html, body").animate({
|
|
|
|
|
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + "px"
|
2014-02-17 20:57:12 -05:00
|
|
|
}, duration !== undefined ? duration : 400, function() {
|
2014-02-25 16:33:22 -05:00
|
|
|
scrollingToPost = false;
|
2014-04-04 12:42:41 -04:00
|
|
|
navigator.update();
|
2014-03-24 14:30:11 -04:00
|
|
|
highlightPost();
|
2014-02-17 20:57:12 -05:00
|
|
|
});
|
2014-01-25 19:19:25 -05:00
|
|
|
}
|
2013-11-23 17:07:31 -05:00
|
|
|
|
2014-03-24 14:30:11 -04:00
|
|
|
function highlightPost() {
|
|
|
|
|
if (highlight) {
|
|
|
|
|
scrollTo.parent().find('.topic-item').addClass('highlight');
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
scrollTo.parent().find('.topic-item').removeClass('highlight');
|
|
|
|
|
}, 5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-18 12:40:13 -05:00
|
|
|
if (tid && scrollTo.length) {
|
|
|
|
|
if($('#post-container li.post-row[data-pid="' + pid + '"]').attr('data-index') !== '0') {
|
|
|
|
|
animateScroll();
|
|
|
|
|
} else {
|
2014-04-04 12:42:41 -04:00
|
|
|
navigator.update();
|
2014-03-24 14:30:11 -04:00
|
|
|
highlightPost();
|
2014-02-18 12:40:13 -05:00
|
|
|
}
|
2014-01-25 19:19:25 -05:00
|
|
|
}
|
2013-11-23 17:07:31 -05:00
|
|
|
}
|
2014-02-26 21:55:29 -05:00
|
|
|
};
|
2013-11-23 17:07:31 -05:00
|
|
|
|
2014-01-25 19:19:25 -05:00
|
|
|
function onNewPostPagination(data) {
|
|
|
|
|
var posts = data.posts;
|
2014-03-28 13:02:13 -04:00
|
|
|
socket.emit('topics.getPageCount', ajaxify.variables.get('topic_id'), function(err, newPageCount) {
|
2014-01-25 19:19:25 -05:00
|
|
|
|
2014-01-25 21:35:09 -05:00
|
|
|
pagination.recreatePaginationLinks(newPageCount);
|
2014-01-25 19:19:25 -05:00
|
|
|
|
|
|
|
|
if(pagination.currentPage === pagination.pageCount) {
|
|
|
|
|
createNewPosts(data);
|
|
|
|
|
} else if(data.posts && data.posts.length && parseInt(data.posts[0].uid, 10) === parseInt(app.uid, 10)) {
|
|
|
|
|
pagination.loadPage(pagination.pageCount);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-25 13:24:51 -04:00
|
|
|
function createNewPosts(data, callback) {
|
2013-11-29 13:09:26 -05:00
|
|
|
if(!data || (data.posts && !data.posts.length)) {
|
2013-11-23 17:07:31 -05:00
|
|
|
return;
|
2013-11-29 13:09:26 -05:00
|
|
|
}
|
2013-11-23 17:07:31 -05:00
|
|
|
|
|
|
|
|
function removeAlreadyAddedPosts() {
|
|
|
|
|
data.posts = data.posts.filter(function(post) {
|
|
|
|
|
return $('#post-container li[data-pid="' + post.pid +'"]').length === 0;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
var after = null,
|
|
|
|
|
before = null;
|
|
|
|
|
|
2013-11-23 17:07:31 -05:00
|
|
|
function findInsertionPoint() {
|
2014-02-17 20:57:12 -05:00
|
|
|
var firstPid = parseInt(data.posts[0].pid, 10);
|
2014-01-24 20:50:55 -05:00
|
|
|
|
2013-11-23 17:07:31 -05:00
|
|
|
$('#post-container li[data-pid]').each(function() {
|
2014-05-05 12:15:17 -04:00
|
|
|
var $this = $(this);
|
|
|
|
|
|
|
|
|
|
if(firstPid > parseInt($this.attr('data-pid'), 10)) {
|
|
|
|
|
after = $this;
|
2013-11-29 14:42:58 -05:00
|
|
|
if(after.next().length && after.next().hasClass('post-bar')) {
|
2013-11-24 13:58:06 -05:00
|
|
|
after = after.next();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-11-23 17:07:31 -05:00
|
|
|
});
|
2014-02-17 20:57:12 -05:00
|
|
|
|
|
|
|
|
if(!after) {
|
|
|
|
|
var firstPost = $('#post-container .post-row').first();
|
|
|
|
|
if(firstPid < parseInt(firstPost.attr('data-pid'), 10)) {
|
|
|
|
|
before = firstPost;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-23 17:07:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeAlreadyAddedPosts();
|
|
|
|
|
if(!data.posts.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-11-26 14:25:46 -05:00
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
findInsertionPoint();
|
2013-11-23 17:07:31 -05:00
|
|
|
|
2014-03-28 13:02:13 -04:00
|
|
|
data.title = ajaxify.variables.get('topic_name');
|
|
|
|
|
data.viewcount = ajaxify.variables.get('viewcount');
|
2014-03-09 23:48:22 -04:00
|
|
|
|
2014-01-26 16:22:50 -05:00
|
|
|
parseAndTranslatePosts(data, function(translatedHTML) {
|
2013-11-23 17:07:31 -05:00
|
|
|
var translated = $(translatedHTML);
|
2013-11-28 18:45:36 -05:00
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
if(after) {
|
2014-03-15 17:50:19 -04:00
|
|
|
translated.insertAfter(after);
|
2014-02-17 20:57:12 -05:00
|
|
|
} else if(before) {
|
|
|
|
|
translated.insertBefore(before);
|
|
|
|
|
} else {
|
|
|
|
|
$('#post-container').append(translated);
|
|
|
|
|
}
|
2013-11-23 17:07:31 -05:00
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
translated.hide().fadeIn('slow');
|
2014-05-06 15:09:35 -04:00
|
|
|
addBlockquoteEllipses(translated.find('.post-content > blockquote'));
|
2014-02-17 20:57:12 -05:00
|
|
|
|
|
|
|
|
onNewPostsLoaded(translated, data.posts);
|
2014-02-10 11:41:25 -05:00
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
if(typeof callback === 'function') {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
2014-01-24 20:50:55 -05:00
|
|
|
});
|
|
|
|
|
}
|
2013-11-23 17:07:31 -05:00
|
|
|
|
2014-01-26 16:22:50 -05:00
|
|
|
function parseAndTranslatePosts(data, callback) {
|
2014-03-28 13:29:51 -04:00
|
|
|
ajaxify.loadTemplate('topic', function(topicTemplate) {
|
|
|
|
|
var html = templates.parse(templates.getBlock(topicTemplate, 'posts'), data);
|
2014-03-09 22:35:09 -04:00
|
|
|
translator.translate(html, callback);
|
|
|
|
|
});
|
2013-11-23 17:07:31 -05:00
|
|
|
}
|
|
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
function onNewPostsLoaded(html, posts) {
|
2014-04-02 13:58:10 -04:00
|
|
|
function getPostPrivileges(pid) {
|
2014-04-04 12:42:41 -04:00
|
|
|
socket.emit('posts.getPrivileges', pid, function(err, privileges) {
|
2014-04-02 13:58:10 -04:00
|
|
|
if(err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
2014-05-03 20:56:26 -04:00
|
|
|
toggleModTools(html, privileges);
|
2014-04-02 13:58:10 -04:00
|
|
|
});
|
2014-04-04 12:42:41 -04:00
|
|
|
}
|
2014-04-02 13:58:10 -04:00
|
|
|
|
2014-04-04 12:42:41 -04:00
|
|
|
for (var x = 0, numPosts = posts.length; x < numPosts; x++) {
|
2014-04-02 13:58:10 -04:00
|
|
|
getPostPrivileges(posts[x].pid);
|
2014-04-04 12:42:41 -04:00
|
|
|
}
|
2014-03-15 17:50:19 -04:00
|
|
|
|
2014-01-24 20:50:55 -05:00
|
|
|
infiniteLoaderActive = false;
|
|
|
|
|
|
|
|
|
|
app.populateOnlineUsers();
|
|
|
|
|
app.createUserTooltips();
|
2014-03-31 14:43:44 -04:00
|
|
|
utils.addCommasToNumbers(html.find('.formatted-number'));
|
|
|
|
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
2014-02-17 20:57:12 -05:00
|
|
|
html.find('span.timeago').timeago();
|
|
|
|
|
html.find('.post-content img').addClass('img-responsive');
|
2014-05-03 20:56:26 -04:00
|
|
|
postTools.updatePostCount();
|
2014-01-24 20:50:55 -05:00
|
|
|
showBottomPostBar();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-03 20:56:26 -04:00
|
|
|
function toggleModTools(postHtml, privileges) {
|
2014-04-02 13:58:10 -04:00
|
|
|
postHtml.find('.edit, .delete').toggleClass('none', !privileges.editable);
|
|
|
|
|
postHtml.find('.move').toggleClass('none', !privileges.move);
|
2014-01-12 15:37:33 -05:00
|
|
|
}
|
|
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
function loadMorePosts(tid, after, callback) {
|
2013-11-23 18:05:19 -05:00
|
|
|
var indicatorEl = $('.loading-indicator');
|
2013-11-23 17:07:31 -05:00
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
if (infiniteLoaderActive || !$('#post-container').length) {
|
2013-11-23 17:07:31 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 18:02:35 -04:00
|
|
|
if (!utils.isNumber(after) || (after === 0 && $('#post-container li.post-row[data-index="0"]').length)) {
|
2014-02-17 20:57:12 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2014-01-17 14:47:18 -05:00
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
infiniteLoaderActive = true;
|
|
|
|
|
indicatorEl.fadeIn();
|
|
|
|
|
|
|
|
|
|
socket.emit('topics.loadMore', {
|
|
|
|
|
tid: tid,
|
|
|
|
|
after: after
|
|
|
|
|
}, function (err, data) {
|
2014-03-06 20:53:41 -05:00
|
|
|
|
|
|
|
|
indicatorEl.fadeOut(function() {
|
|
|
|
|
infiniteLoaderActive = false;
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
if(err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
2014-01-17 14:47:18 -05:00
|
|
|
|
2014-02-17 20:57:12 -05:00
|
|
|
if (data && data.posts && data.posts.length) {
|
2014-03-25 13:24:51 -04:00
|
|
|
createNewPosts(data, callback);
|
2014-02-17 20:57:12 -05:00
|
|
|
} else {
|
2014-04-04 12:42:41 -04:00
|
|
|
navigator.update();
|
2014-02-17 20:57:12 -05:00
|
|
|
if (typeof callback === 'function') {
|
2014-01-17 14:47:18 -05:00
|
|
|
callback(data.posts);
|
|
|
|
|
}
|
2014-02-17 20:57:12 -05:00
|
|
|
}
|
|
|
|
|
});
|
2013-11-23 17:07:31 -05:00
|
|
|
}
|
|
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
return Topic;
|
2014-04-10 20:31:57 +01:00
|
|
|
});
|