Skip to content

Node.js based forum software built for the modern web

feat: add new client side hooks

Barış Soner Uşaklıa15ef53c7074
diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js
index b483c653b1..7661bb19be 100644
--- a/public/src/client/topic/postTools.js
+++ b/public/src/client/topic/postTools.js
@@ -338,7 +338,13 @@ define('forum/topic/postTools', [
function bookmarkPost(button, pid) {
var method = button.attr('data-bookmarked') === 'false' ? 'put' : 'del';
- api[method](`/posts/${pid}/bookmark`, undefined, undefined, 'default');
+ api[method](`/posts/${pid}/bookmark`, undefined, function (err) {
+ if (err) {
+ return app.alertError(err);
+ }
+ var type = method === 'put' ? 'bookmark' : 'unbookmark';
+ $(window).trigger('action:post.' + type, { pid: pid });
+ });
return false;
}
@@ -429,6 +435,7 @@ define('forum/topic/postTools', [
$(window).trigger('action:composer.topic.new', {
cid: ajaxify.data.cid,
body: body,
+ fromStaleTopic: true,
});
});
},
diff --git a/public/src/client/topic/votes.js b/public/src/client/topic/votes.js
index 731b7f63ba..076ff1ef5c 100644
--- a/public/src/client/topic/votes.js
+++ b/public/src/client/topic/votes.js
@@ -58,14 +58,22 @@ define('forum/topic/votes', [
var currentState = post.find(className).length;
const method = currentState ? 'del' : 'put';
- api[method](`/posts/${post.attr('data-pid')}/vote`, {
+ var pid = post.attr('data-pid');
+ api[method](`/posts/${pid}/vote`, {
delta: delta,
- }).catch((err) => {
- app.alertError(err.message);
-
- if (err.message === '[[error:not-logged-in]]') {
- ajaxify.go('login');
+ }, function (err) {
+ if (err) {
+ if (err.message === '[[error:not-logged-in]]') {
+ ajaxify.go('login');
+ return;
+ }
+ return app.alertError(err.message);
}
+ $(window).trigger('action:post.toggleVote', {
+ pid: pid,
+ delta: delta,
+ unvote: method === 'del',
+ });
});
return false;
diff --git a/public/src/modules/share.js b/public/src/modules/share.js
index fe45f26d0f..e8d4633e08 100644
--- a/public/src/modules/share.js
+++ b/public/src/modules/share.js
@@ -9,6 +9,10 @@ define('share', function () {
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).trigger('action:share.open', {
+ url: url,
+ urlToPost: urlToPost,
+ });
return false;
}