Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/src/client/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
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"]]');

Check failure on line 134 in public/src/client/register.js

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 16)

Unexpected template string expression
}

callback();
Expand Down
37 changes: 31 additions & 6 deletions public/src/modules/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 });
Expand All @@ -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;
Expand Down
Loading