Skip to content

Node.js based forum software built for the modern web

more tooltip work

Barış Soner Uşaklıf0dead7abae1
diff --git a/install/data/defaults.json b/install/data/defaults.json
index a4377ea7d3..587167f662 100644
--- a/install/data/defaults.json
+++ b/install/data/defaults.json
@@ -113,5 +113,6 @@
"eventLoopCheckEnabled": 1,
"eventLoopLagThreshold": 100,
"eventLoopInterval": 500,
- "onlineCutoff": 30
+ "onlineCutoff": 30,
+ "timeagoCutoff": 30
}
\ No newline at end of file
diff --git a/public/src/modules/navigator.js b/public/src/modules/navigator.js
index 3f041ceeca..e02a8910c9 100644
--- a/public/src/modules/navigator.js
+++ b/public/src/modules/navigator.js
@@ -5,7 +5,11 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
var index = 1;
var count = 0;
var navigatorUpdateTimeoutId;
- var tooltipEl;
+
+ var touchTooltipEl;
+ var touchIntervalId;
+ var touchX;
+ var touchIndex;
navigator.scrollActive = false;
@@ -58,25 +62,28 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
});
$('.pagination-block.visible-xs').on('touchstart', function (e) {
- $(this).tooltip('show');
- tooltipEl = $(this).next();
- var x = Math.min($(window).width(), Math.max(0, e.touches[0].clientX));
- updateTooltip(x);
+ touchTooltipEl = $('.navigator-thumb');
+ touchTooltipEl.removeClass('hidden');
+ touchX = Math.min($(window).width(), Math.max(0, e.touches[0].clientX));
+ updateTooltip();
+ touchIntervalId = setInterval(updateTooltip, 100);
}).on('touchmove', function (e) {
e.preventDefault();
e.stopPropagation();
var windowWidth = $(window).width();
- var x = Math.min(windowWidth, Math.max(0, e.touches[0].clientX));
- var percent = x / windowWidth;
- var newIndex = Math.max(1, Math.floor(count * percent));
- if (newIndex === index) {
- return;
- }
- index = newIndex;
+ touchX = Math.min(windowWidth, Math.max(0, e.touches[0].clientX));
+ var percent = touchX / windowWidth;
+ index = Math.max(1, Math.ceil(count * percent));
+ index = index > count ? count : index;
+
navigator.updateTextAndProgressBar();
- updateTooltip(x);
}).on('touchend', function () {
- $(this).tooltip('hide');
+ if (touchIntervalId) {
+ clearInterval(touchIntervalId);
+ touchIntervalId = 0;
+ }
+
+ touchTooltipEl.addClass('hidden');
navigator.scrollToIndex(index - 1, true, 0);
});
@@ -86,10 +93,28 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
navigator.update(0);
};
- function updateTooltip(x) {
- var relIndex = getRelativeIndex();
- tooltipEl.find('.tooltip-inner').translateText('[[global:pagination.out_of, ' + relIndex + ', ' + count + ']]');
- tooltipEl.css({ left: Math.min($(window).width() - tooltipEl.width(), Math.max(x - (tooltipEl.width() / 2), 0)) });
+ function updateTooltip() {
+ if (touchIndex === index) {
+ return;
+ }
+ touchIndex = index;
+ touchTooltipEl.css({ left: Math.min($(window).width() - touchTooltipEl.outerWidth(), Math.max(touchX - (touchTooltipEl.outerWidth() / 2), 0)) });
+
+ socket.emit('posts.getTimestampByIndex', { tid: ajaxify.data.tid, index: index - 1 }, function (err, timestamp) {
+ if (err) {
+ return app.alertError(err.message);
+ }
+
+ var relIndex = getRelativeIndex();
+ var date = new Date(timestamp);
+ var ds = date.toLocaleString(config.userLang, { month: 'long' });
+ touchTooltipEl.find('.text').translateText('[[global:pagination.out_of, ' + relIndex + ', ' + count + ']]');
+ if (timestamp > Date.now() - (30 * 24 * 60 * 60 * 1000)) {
+ touchTooltipEl.find('.time').text(ds + ' ' + date.getDate());
+ } else {
+ touchTooltipEl.find('.time').text(ds + ' ' + date.getFullYear());
+ }
+ });
}
function handleKeys() {
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index 663534ba03..923ed43280 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -92,6 +92,40 @@ SocketPosts.getRawPost = function (socket, pid, callback) {
], callback);
};
+SocketPosts.getTimestampByIndex = function (socket, data, callback) {
+ var pid;
+ var db = require('../database');
+
+ async.waterfall([
+ function (next) {
+ if (data.index < 0) {
+ data.index = 0;
+ }
+ if (data.index === 0) {
+ topics.getTopicField(data.tid, 'mainPid', next);
+ } else {
+ db.getSortedSetRange('tid:' + data.tid + ':posts', data.index - 1, data.index - 1, next);
+ }
+ },
+ function (_pid, next) {
+ pid = Array.isArray(_pid) ? _pid[0] : _pid;
+ if (!pid) {
+ return callback(null, 0);
+ }
+ privileges.posts.can('read', pid, socket.uid, next);
+ },
+ function (canRead, next) {
+ if (!canRead) {
+ return next(new Error('[[error:no-privileges]]'));
+ }
+ posts.getPostFields(pid, ['timestamp'], next);
+ },
+ function (postData, next) {
+ next(null, postData.timestamp);
+ },
+ ], callback);
+};
+
SocketPosts.getPost = function (socket, pid, callback) {
apiController.getPostData(pid, socket.uid, callback);
};