nexo
28.Июль.2019 18:58:17
1
I use this script to change icons throughout my site successfully, and this changes the solved-check icon for the Solved plugin to a thumbs-up.
However, it doesn’t change in all instances of the site, such as within the notification list:
~
Here’s how it looks in other places of the site where it does work:
1 лайк
Some icons, including all of the notifications, need special treatment because we use different names. In this case you’re looking for notification.solved.accepted_notification (all these outlier icon names are listed in the replacements section in https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse-common/lib/icon-library.js.es6 )
<script type="text/discourse-plugin" version="0.8">
api.replaceIcon('notification.solved.accepted_notification', 'thumbs-up')
</script>
12 лайков
nexo
21.Август.2019 21:02:42
3
Sorry to bring this up again, but, do you know why the icon isn’t changing in the post controls?
This is the code I’m using:
tshenry
(Taylor)
21.Август.2019 21:26:02
4
Are you trying to change it specifically for that icon location and state? If you are still trying to change the icon globally the code you originally posted is still correct:
api.replaceIcon('far-check-square', 'thumbs-up')
api.replaceIcon('check-square', 'thumbs-up')
That checkmark icon next to “Kudos” is not the default, so might you have conflicting code somewhere?
4 лайка
nexo
21.Август.2019 21:29:01
5
Specifically in that area, because as Kris aforementioned, sometimes the code has to be very specific. This is all the code I’ve added for changing icons:
tshenry
(Taylor)
21.Август.2019 22:12:36
6
As Kris mentioned, only some icons need special treatment. Notifications are one of those, so that’s why you needed to use notification.solved.accepted_notification. In the case of the solved icon in the post controls, it’s using the generic icon name, so you will only be able to change it globally when using the replaceIcon method.
If you want to get really specific, I think you will need to override the addPostMenuButton function that’s defined in the solved plugin. Try this:
<script type="text/discourse-plugin" version="0.8">
const { iconNode } = require("discourse-common/lib/icon-library");
api.addPostMenuButton("solved", attrs => {
const currentUser = api.getCurrentUser();
const canAccept = attrs.can_accept_answer;
const canUnaccept = attrs.can_unaccept_answer;
const accepted = attrs.accepted_answer;
const isOp = currentUser && currentUser.id === attrs.topicCreatedById;
const position =
!accepted && canAccept && !isOp ? "second-last-hidden" : "first";
if (canAccept) {
return {
action: "acceptAnswer",
icon: "far-check-square",
className: "unaccepted",
title: "solved.accept_answer",
label: "solved.solution",
position
};
} else if (canUnaccept && accepted) {
const title = canUnaccept
? "solved.unaccept_answer"
: "solved.accepted_answer";
return {
action: "unacceptAnswer",
icon: "thumbs-up", // MODIFIED HERE
title,
className: "accepted fade-out",
position,
label: "solved.solution"
};
} else if (!canAccept && accepted) {
return {
className: "hidden",
disabled: "true",
position,
beforeButton(h) {
return h(
"span.accepted-text",
{
title: I18n.t("solved.accepted_description")
},
[
h("span", iconNode("thumbs-up")), // MODIFIED HERE
h("span.accepted-label", I18n.t("solved.solution"))
]
);
}
};
}
});
</script>
6 лайков
nexo
30.Август.2019 17:05:33
7
This works, but oddly this script makes it so only me with the admin account can see the topic with a solved reply, any other users are unable to see it.
1 лайк
tshenry
(Taylor)
30.Август.2019 17:20:59
8
Oh weird! I’m not sure why that only fails for non-admin users… In any case, I’ve updated the script with the missing piece.
5 лайков
nexo
30.Август.2019 19:00:36
9
It’s no longer broken, but, the icon change only displays for admins and for non-admins it still has the solved/check icon:
Admin :
1 лайк
system
(system)
Закрыл(а) тему
29.Сентябрь.2019 20:36:47
14
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.