diff --git a/public/src/client/register.js b/public/src/client/register.js index 62dbc41..ba66da2 100644 --- a/public/src/client/register.js +++ b/public/src/client/register.js @@ -131,7 +131,7 @@ define('forum/register', [ if (results.every(obj => obj.status === 'rejected')) { showSuccess(username_notify, successIcon); } else { - showError(username_notify, '[[error:username-taken]]'); + showError(username_notify, '[[error:username-taken, "${username}suffix"]]'); } callback(); diff --git a/public/src/modules/share.js b/public/src/modules/share.js index ea2f131..0f5ce4d 100644 --- a/public/src/modules/share.js +++ b/public/src/modules/share.js @@ -3,12 +3,11 @@ define('share', ['hooks'], function (hooks) { const module = {}; + const baseUrl = window.location.protocol + '//' + window.location.host; module.addShareHandlers = function (name) { - const baseUrl = window.location.protocol + '//' + window.location.host; - function openShare(url, urlToPost, width, height) { - window.open(url + encodeURIComponent(baseUrl + config.relative_path + urlToPost), '_blank', 'width=' + width + ',height=' + height + ',scrollbars=no,status=no'); + window.open(url, '_blank', 'width=' + width + ',height=' + height + ',scrollbars=no,status=no'); hooks.fire('action:share.open', { url: url, urlToPost: urlToPost, @@ -32,11 +31,36 @@ define('share', ['hooks'], function (hooks) { }); addHandler('[component="share/twitter"]', function () { - return openShare('https://twitter.com/intent/tweet?text=' + encodeURIComponent(name) + '&url=', getPostUrl($(this)), 550, 420); + const postUrl = getPostUrl($(this)); + const twitter_url = `https://twitter.com/intent/tweet?text=${encodeURIComponent(name)}&url=${encodeURIComponent(postUrl)}`; + return openShare(twitter_url, postUrl, 550, 420); }); addHandler('[component="share/facebook"]', function () { - return openShare('https://www.facebook.com/sharer/sharer.php?u=', getPostUrl($(this)), 626, 436); + const postUrl = getPostUrl($(this)); + const facebook_url = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(postUrl)}`; + return openShare(facebook_url, postUrl, 626, 436); + }); + + addHandler('[component="share/whatsapp"]', function () { + const postUrl = getPostUrl($(this)); + const message = encodeURIComponent(name) + ' - ' + encodeURIComponent(postUrl); + const whatsapp_url = config.useragent.isMobile ? + `whatsapp://send?text=${message}` : + `https://wa.me/?text=${message}`; + return openShare(whatsapp_url, postUrl, 626, 436); + }); + + addHandler('[component="share/telegram"]', function () { + const postUrl = getPostUrl($(this)); + const telegram_url = `https://t.me/share/url?text=${encodeURIComponent(name)}&url=${encodeURIComponent(postUrl)}`; + return openShare(telegram_url, postUrl, 626, 436); + }); + + addHandler('[component="share/linkedin"]', function () { + const postUrl = getPostUrl($(this)); + const linkedin_url = `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(postUrl)}`; + return openShare(linkedin_url, postUrl, 626, 436); }); hooks.fire('action:share.addHandlers', { openShare: openShare }); @@ -48,7 +72,8 @@ define('share', ['hooks'], function (hooks) { function getPostUrl(clickedElement) { const pid = parseInt(clickedElement.parents('[data-pid]').attr('data-pid'), 10); - return '/post' + (pid ? '/' + (pid) : ''); + const path = '/post' + (pid ? '/' + (pid) : ''); + return baseUrl + config.relative_path + path; } return module;