mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 00:15:46 +01:00
closes #1273
This commit is contained in:
@@ -349,22 +349,10 @@ var socket,
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
app.scrollToTop = function () {
|
|
||||||
$('body,html').animate({
|
|
||||||
scrollTop: 0
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
app.scrollToBottom = function () {
|
|
||||||
$('body,html').animate({
|
|
||||||
scrollTop: $('html').height() - 100
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var previousScrollTop = 0;
|
var previousScrollTop = 0;
|
||||||
|
|
||||||
app.enableInfiniteLoading = function(callback) {
|
app.enableInfiniteLoading = function(callback) {
|
||||||
$(window).off('scroll').on('scroll', function() {
|
$(window).on('scroll', function() {
|
||||||
|
|
||||||
var top = $(window).height() * 0.1;
|
var top = $(window).height() * 0.1;
|
||||||
var bottom = ($(document).height() - $(window).height()) * 0.9;
|
var bottom = ($(document).height() - $(window).height()) * 0.9;
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
/* global define, config, templates, app, ajaxify, socket, translator */
|
/* global define, config, templates, app, ajaxify, socket, translator */
|
||||||
|
|
||||||
define(['composer', 'forum/pagination', 'share'], function(composer, pagination, share) {
|
define(['composer', 'forum/pagination', 'share', 'navigator'], function(composer, pagination, share, navigator) {
|
||||||
var Category = {},
|
var Category = {},
|
||||||
loadingMoreTopics = false;
|
loadingMoreTopics = false;
|
||||||
|
|
||||||
|
|
||||||
|
$(window).on('action:ajaxify.start', function(ev, data) {
|
||||||
|
if(data.url.indexOf('category') !== 0) {
|
||||||
|
navigator.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Category.init = function() {
|
Category.init = function() {
|
||||||
var cid = ajaxify.variables.get('category_id');
|
var cid = ajaxify.variables.get('category_id');
|
||||||
|
|
||||||
@@ -24,6 +31,10 @@ define(['composer', 'forum/pagination', 'share'], function(composer, pagination,
|
|||||||
|
|
||||||
enableInfiniteLoading();
|
enableInfiniteLoading();
|
||||||
|
|
||||||
|
if (!config.usePagination) {
|
||||||
|
navigator.init('#topics-container > .category-item', ajaxify.variables.get('topic_count'));
|
||||||
|
}
|
||||||
|
|
||||||
$('#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 clickedTid = $(this).parents('li.category-item[data-tid]').attr('data-tid');
|
||||||
$('#topics-container li.category-item').each(function(index, el) {
|
$('#topics-container li.category-item').each(function(index, el) {
|
||||||
@@ -110,6 +121,7 @@ define(['composer', 'forum/pagination', 'share'], function(composer, pagination,
|
|||||||
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px'
|
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px'
|
||||||
}, duration !== undefined ? duration : 400, function() {
|
}, duration !== undefined ? duration : 400, function() {
|
||||||
Category.highlightTopic(clickedTid);
|
Category.highlightTopic(clickedTid);
|
||||||
|
navigator.update();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,6 +129,7 @@ define(['composer', 'forum/pagination', 'share'], function(composer, pagination,
|
|||||||
|
|
||||||
function enableInfiniteLoading() {
|
function enableInfiniteLoading() {
|
||||||
if(!config.usePagination) {
|
if(!config.usePagination) {
|
||||||
|
|
||||||
app.enableInfiniteLoading(function(direction) {
|
app.enableInfiniteLoading(function(direction) {
|
||||||
|
|
||||||
if(!loadingMoreTopics && $('#topics-container').children().length) {
|
if(!loadingMoreTopics && $('#topics-container').children().length) {
|
||||||
@@ -193,12 +206,22 @@ define(['composer', 'forum/pagination', 'share'], function(composer, pagination,
|
|||||||
|
|
||||||
topic.find('span.timeago').timeago();
|
topic.find('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
|
updateTopicCount();
|
||||||
|
|
||||||
$(window).trigger('action:categories.new_topic.loaded');
|
$(window).trigger('action:categories.new_topic.loaded');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function updateTopicCount() {
|
||||||
|
socket.emit('categories.getTopicCount', ajaxify.variables.get('category_id'), function(err, topicCount) {
|
||||||
|
if(err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
navigator.setCount(topicCount);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Category.onTopicsLoaded = function(topics, callback) {
|
Category.onTopicsLoaded = function(topics, callback) {
|
||||||
if(!topics || !topics.length) {
|
if(!topics || !topics.length) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
/* globals define, app, templates, translator, socket, bootbox, config, ajaxify, RELATIVE_PATH */
|
/* globals define, app, templates, translator, socket, bootbox, config, ajaxify, RELATIVE_PATH, utils */
|
||||||
|
|
||||||
define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'], function(pagination, threadTools, postTools) {
|
define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools', 'navigator'], function(pagination, threadTools, postTools, navigator) {
|
||||||
var Topic = {},
|
var Topic = {},
|
||||||
infiniteLoaderActive = false,
|
infiniteLoaderActive = false,
|
||||||
scrollingToPost = false,
|
scrollingToPost = false,
|
||||||
@@ -17,7 +17,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
|
|
||||||
$(window).on('action:ajaxify.start', function(ev, data) {
|
$(window).on('action:ajaxify.start', function(ev, data) {
|
||||||
if(data.url.indexOf('topic') !== 0) {
|
if(data.url.indexOf('topic') !== 0) {
|
||||||
$('.pagination-block').addClass('hidden');
|
navigator.hide();
|
||||||
$('.header-topic-title').find('span').text('').hide();
|
$('.header-topic-title').find('span').text('').hide();
|
||||||
app.removeAlert('bookmark');
|
app.removeAlert('bookmark');
|
||||||
}
|
}
|
||||||
@@ -87,8 +87,8 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!window.location.hash && !config.usePagination) {
|
if (!config.usePagination) {
|
||||||
updateHeader();
|
navigator.init('.posts > .post-row', Topic.postCount, Topic.navigatorCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#post-container').on('mouseenter', '.favourite-tooltip', function(e) {
|
$('#post-container').on('mouseenter', '.favourite-tooltip', function(e) {
|
||||||
@@ -106,9 +106,6 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
|
|
||||||
function enableInfiniteLoading() {
|
function enableInfiniteLoading() {
|
||||||
if(!config.usePagination) {
|
if(!config.usePagination) {
|
||||||
$('.pagination-block').removeClass('hidden');
|
|
||||||
|
|
||||||
updatePaginationTextAndProgressBar(1);
|
|
||||||
|
|
||||||
app.enableInfiniteLoading(function(direction) {
|
app.enableInfiniteLoading(function(direction) {
|
||||||
|
|
||||||
@@ -138,7 +135,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$('.pagination-block').addClass('hidden');
|
navigator.hide();
|
||||||
|
|
||||||
pagination.init(currentPage, pageCount);
|
pagination.init(currentPage, pageCount);
|
||||||
}
|
}
|
||||||
@@ -511,79 +508,44 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(window).on('scroll', updateHeader);
|
$(window).on('scroll', updateTopicTitle);
|
||||||
|
|
||||||
$(window).trigger('action:topic.loaded');
|
$(window).trigger('action:topic.loaded');
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateHeader() {
|
function updateTopicTitle() {
|
||||||
|
|
||||||
$('.pagination-block a').off('click').on('click', function() {
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.pagination-block i:first').off('click').on('click', function() {
|
|
||||||
app.scrollToTop();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.pagination-block i:last').off('click').on('click', function() {
|
|
||||||
app.scrollToBottom();
|
|
||||||
});
|
|
||||||
|
|
||||||
if($(window).scrollTop() > 50) {
|
if($(window).scrollTop() > 50) {
|
||||||
$('.header-topic-title').find('span').text(ajaxify.variables.get('topic_name')).show();
|
$('.header-topic-title').find('span').text(ajaxify.variables.get('topic_name')).show();
|
||||||
} else {
|
} else {
|
||||||
$('.header-topic-title').find('span').text('').hide();
|
$('.header-topic-title').find('span').text('').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
$($('.posts > .post-row').get().reverse()).each(function() {
|
|
||||||
var el = $(this);
|
|
||||||
|
|
||||||
if (elementInView(el)) {
|
|
||||||
var index = parseInt(el.attr('data-index'), 10) + 1;
|
|
||||||
if(index > Topic.postCount) {
|
|
||||||
index = Topic.postCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePaginationTextAndProgressBar(index);
|
Topic.navigatorCallback = function(element) {
|
||||||
|
|
||||||
|
var pid = element.attr('data-pid');
|
||||||
|
console.log('derp', scrollingToPost, pid);
|
||||||
var currentBookmark = localStorage.getItem('topic:' + ajaxify.variables.get('topic_id') + ':bookmark');
|
var currentBookmark = localStorage.getItem('topic:' + ajaxify.variables.get('topic_id') + ':bookmark');
|
||||||
if (!currentBookmark || parseInt(el.attr('data-pid'), 10) >= parseInt(currentBookmark, 10)) {
|
|
||||||
localStorage.setItem('topic:' + ajaxify.variables.get('topic_id') + ':bookmark', el.attr('data-pid'));
|
if (!currentBookmark || parseInt(pid, 10) >= parseInt(currentBookmark, 10)) {
|
||||||
|
localStorage.setItem('topic:' + ajaxify.variables.get('topic_id') + ':bookmark', pid);
|
||||||
app.removeAlert('bookmark');
|
app.removeAlert('bookmark');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!scrollingToPost) {
|
if (!scrollingToPost) {
|
||||||
|
|
||||||
var newUrl = window.location.href.replace(window.location.hash, '') + '#' + el.attr('data-pid');
|
var newUrl = window.location.href.replace(window.location.hash, '') + '#' + pid;
|
||||||
|
|
||||||
if (newUrl !== currentUrl) {
|
if (newUrl !== currentUrl) {
|
||||||
if (history.replaceState) {
|
if (history.replaceState) {
|
||||||
history.replaceState({
|
history.replaceState({
|
||||||
url: window.location.pathname.slice(1) + (window.location.search ? window.location.search : '' ) + '#' + el.attr('data-pid')
|
url: window.location.pathname.slice(1) + (window.location.search ? window.location.search : '' ) + '#' + pid
|
||||||
}, null, newUrl);
|
}, null, newUrl);
|
||||||
}
|
}
|
||||||
currentUrl = newUrl;
|
currentUrl = newUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function updatePaginationTextAndProgressBar(index) {
|
|
||||||
$('#pagination').html(index + ' out of ' + Topic.postCount);
|
|
||||||
$('.progress-bar').width((index / Topic.postCount * 100) + '%');
|
|
||||||
}
|
|
||||||
|
|
||||||
function elementInView(el) {
|
|
||||||
var scrollTop = $(window).scrollTop() + $('#header-menu').height();
|
|
||||||
var scrollBottom = scrollTop + $(window).height();
|
|
||||||
|
|
||||||
var elTop = el.offset().top;
|
|
||||||
var elBottom = elTop + Math.floor(el.height());
|
|
||||||
return (elTop >= scrollTop && elBottom <= scrollBottom) || (elTop <= scrollTop && elBottom >= scrollTop);
|
|
||||||
}
|
|
||||||
|
|
||||||
Topic.scrollToPost = function(pid, highlight, duration, offset) {
|
Topic.scrollToPost = function(pid, highlight, duration, offset) {
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
@@ -594,6 +556,8 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scrollingToPost = true;
|
||||||
|
|
||||||
if($('#post_anchor_' + pid).length) {
|
if($('#post_anchor_' + pid).length) {
|
||||||
return scrollToPid(pid);
|
return scrollToPid(pid);
|
||||||
}
|
}
|
||||||
@@ -634,13 +598,11 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
tid = $('#post-container').attr('data-tid');
|
tid = $('#post-container').attr('data-tid');
|
||||||
|
|
||||||
function animateScroll() {
|
function animateScroll() {
|
||||||
scrollingToPost = true;
|
|
||||||
|
|
||||||
$("html, body").animate({
|
$("html, body").animate({
|
||||||
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + "px"
|
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + "px"
|
||||||
}, duration !== undefined ? duration : 400, function() {
|
}, duration !== undefined ? duration : 400, function() {
|
||||||
scrollingToPost = false;
|
scrollingToPost = false;
|
||||||
updateHeader();
|
navigator.update();
|
||||||
highlightPost();
|
highlightPost();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -659,7 +621,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
if($('#post-container li.post-row[data-pid="' + pid + '"]').attr('data-index') !== '0') {
|
if($('#post-container li.post-row[data-pid="' + pid + '"]').attr('data-index') !== '0') {
|
||||||
animateScroll();
|
animateScroll();
|
||||||
} else {
|
} else {
|
||||||
updateHeader();
|
navigator.update();
|
||||||
highlightPost();
|
highlightPost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -790,7 +752,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
if(!err) {
|
if(!err) {
|
||||||
Topic.postCount = postcount;
|
Topic.postCount = postcount;
|
||||||
$('#topic-post-count').html(Topic.postCount);
|
$('#topic-post-count').html(Topic.postCount);
|
||||||
updateHeader();
|
navigator.setCount(Topic.postCount);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -825,7 +787,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
if (data && data.posts && data.posts.length) {
|
if (data && data.posts && data.posts.length) {
|
||||||
createNewPosts(data, callback);
|
createNewPosts(data, callback);
|
||||||
} else {
|
} else {
|
||||||
updateHeader();
|
navigator.update();
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback(data.posts);
|
callback(data.posts);
|
||||||
}
|
}
|
||||||
|
|||||||
98
public/src/modules/navigator.js
Normal file
98
public/src/modules/navigator.js
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/* globals app, define, ajaxify */
|
||||||
|
|
||||||
|
|
||||||
|
define(function() {
|
||||||
|
|
||||||
|
var navigator = {};
|
||||||
|
var index = 1;
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
navigator.init = function(selector, count, callback) {
|
||||||
|
|
||||||
|
navigator.selector = selector;
|
||||||
|
navigator.callback = callback;
|
||||||
|
|
||||||
|
$(window).on('scroll', navigator.update);
|
||||||
|
|
||||||
|
$('.pagination-block a').off('click').on('click', function() {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.pagination-block i:first').off('click').on('click', function() {
|
||||||
|
navigator.scrollToTop();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.pagination-block i:last').off('click').on('click', function() {
|
||||||
|
navigator.scrollToBottom();
|
||||||
|
});
|
||||||
|
|
||||||
|
navigator.setCount(count);
|
||||||
|
navigator.update();
|
||||||
|
navigator.show();
|
||||||
|
};
|
||||||
|
|
||||||
|
navigator.setCount = function(value) {
|
||||||
|
count = value;
|
||||||
|
navigator.updateTextAndProgressBar();
|
||||||
|
};
|
||||||
|
|
||||||
|
navigator.show = function() {
|
||||||
|
$('.pagination-block').removeClass('hidden');
|
||||||
|
};
|
||||||
|
|
||||||
|
navigator.hide = function() {
|
||||||
|
$('.pagination-block').addClass('hidden');
|
||||||
|
};
|
||||||
|
|
||||||
|
navigator.update = function() {
|
||||||
|
$($(navigator.selector).get().reverse()).each(function() {
|
||||||
|
var el = $(this);
|
||||||
|
|
||||||
|
if (elementInView(el)) {
|
||||||
|
index = parseInt(el.attr('data-index'), 10) + 1;
|
||||||
|
if(index > count) {
|
||||||
|
index = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
navigator.updateTextAndProgressBar();
|
||||||
|
|
||||||
|
if (typeof navigator.callback === 'function') {
|
||||||
|
navigator.callback(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
navigator.updateTextAndProgressBar = function() {
|
||||||
|
$('#pagination').html(index + ' out of ' + count);
|
||||||
|
$('.progress-bar').width((index / count * 100) + '%');
|
||||||
|
};
|
||||||
|
|
||||||
|
navigator.scrollToTop = function () {
|
||||||
|
$('body,html').animate({
|
||||||
|
scrollTop: 0
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
navigator.scrollToBottom = function () {
|
||||||
|
$('body,html').animate({
|
||||||
|
scrollTop: $('html').height() - 100
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function elementInView(el) {
|
||||||
|
var scrollTop = $(window).scrollTop() + $('#header-menu').height();
|
||||||
|
var scrollBottom = scrollTop + $(window).height();
|
||||||
|
|
||||||
|
var elTop = el.offset().top;
|
||||||
|
var elBottom = elTop + Math.floor(el.height());
|
||||||
|
return (elTop >= scrollTop && elBottom <= scrollBottom) || (elTop <= scrollTop && elBottom >= scrollTop);
|
||||||
|
}
|
||||||
|
|
||||||
|
return navigator;
|
||||||
|
});
|
||||||
@@ -43,4 +43,8 @@ SocketCategories.getPageCount = function(socket, cid, callback) {
|
|||||||
categories.getPageCount(cid, socket.uid, callback);
|
categories.getPageCount(cid, socket.uid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketCategories.getTopicCount = function(socket, cid, callback) {
|
||||||
|
categories.getCategoryField(cid, 'topic_count', callback);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = SocketCategories;
|
module.exports = SocketCategories;
|
||||||
Reference in New Issue
Block a user