From f0dead7abae1448db19525e6e6e0c6f84a44416e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 14 Nov 2018 13:53:35 -0500 Subject: [PATCH] more tooltip work --- install/data/defaults.json | 3 +- public/src/modules/navigator.js | 61 +++++++++++++++++++++++---------- src/socket.io/posts.js | 34 ++++++++++++++++++ 3 files changed, 79 insertions(+), 19 deletions(-) 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); };