more tooltip work

v1.18.x
Barış Soner Uşaklı 6 years ago
parent 4b6b3d5436
commit f0dead7aba

@ -113,5 +113,6 @@
"eventLoopCheckEnabled": 1, "eventLoopCheckEnabled": 1,
"eventLoopLagThreshold": 100, "eventLoopLagThreshold": 100,
"eventLoopInterval": 500, "eventLoopInterval": 500,
"onlineCutoff": 30 "onlineCutoff": 30,
"timeagoCutoff": 30
} }

@ -5,7 +5,11 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
var index = 1; var index = 1;
var count = 0; var count = 0;
var navigatorUpdateTimeoutId; var navigatorUpdateTimeoutId;
var tooltipEl;
var touchTooltipEl;
var touchIntervalId;
var touchX;
var touchIndex;
navigator.scrollActive = false; navigator.scrollActive = false;
@ -58,25 +62,28 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
}); });
$('.pagination-block.visible-xs').on('touchstart', function (e) { $('.pagination-block.visible-xs').on('touchstart', function (e) {
$(this).tooltip('show'); touchTooltipEl = $('.navigator-thumb');
tooltipEl = $(this).next(); touchTooltipEl.removeClass('hidden');
var x = Math.min($(window).width(), Math.max(0, e.touches[0].clientX)); touchX = Math.min($(window).width(), Math.max(0, e.touches[0].clientX));
updateTooltip(x); updateTooltip();
touchIntervalId = setInterval(updateTooltip, 100);
}).on('touchmove', function (e) { }).on('touchmove', function (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
var windowWidth = $(window).width(); var windowWidth = $(window).width();
var x = Math.min(windowWidth, Math.max(0, e.touches[0].clientX)); touchX = Math.min(windowWidth, Math.max(0, e.touches[0].clientX));
var percent = x / windowWidth; var percent = touchX / windowWidth;
var newIndex = Math.max(1, Math.floor(count * percent)); index = Math.max(1, Math.ceil(count * percent));
if (newIndex === index) { index = index > count ? count : index;
return;
}
index = newIndex;
navigator.updateTextAndProgressBar(); navigator.updateTextAndProgressBar();
updateTooltip(x);
}).on('touchend', function () { }).on('touchend', function () {
$(this).tooltip('hide'); if (touchIntervalId) {
clearInterval(touchIntervalId);
touchIntervalId = 0;
}
touchTooltipEl.addClass('hidden');
navigator.scrollToIndex(index - 1, true, 0); navigator.scrollToIndex(index - 1, true, 0);
}); });
@ -86,10 +93,28 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
navigator.update(0); navigator.update(0);
}; };
function updateTooltip(x) { function updateTooltip() {
var relIndex = getRelativeIndex(); if (touchIndex === index) {
tooltipEl.find('.tooltip-inner').translateText('[[global:pagination.out_of, ' + relIndex + ', ' + count + ']]'); return;
tooltipEl.css({ left: Math.min($(window).width() - tooltipEl.width(), Math.max(x - (tooltipEl.width() / 2), 0)) }); }
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() { function handleKeys() {

@ -92,6 +92,40 @@ SocketPosts.getRawPost = function (socket, pid, callback) {
], 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) { SocketPosts.getPost = function (socket, pid, callback) {
apiController.getPostData(pid, socket.uid, callback); apiController.getPostData(pid, socket.uid, callback);
}; };

Loading…
Cancel
Save