@nodebb/nodebb-plugin-reactions 2.1.5 → 2.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/client.js +34 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodebb/nodebb-plugin-reactions",
3
- "version": "2.1.5",
3
+ "version": "2.1.7",
4
4
  "nbbpm": {
5
5
  "compatibility": "^3.3.0"
6
6
  },
package/public/client.js CHANGED
@@ -217,11 +217,18 @@ $(document).ready(function () {
217
217
 
218
218
  function createReactionTooltips() {
219
219
  require(['bootstrap', 'translator'], function (bootstrap, translator) {
220
- async function createTooltip(data) {
221
- if (!mouseOverReactionEl || !mouseOverReactionEl.length) {
222
- return;
220
+ function disposeTooltip(el) {
221
+ if (el && el.length) {
222
+ const tooltip = bootstrap.Tooltip.getInstance(el.get(0));
223
+ if (tooltip) {
224
+ tooltip.dispose();
225
+ el.attr('title', '');
226
+ }
223
227
  }
228
+ }
229
+ async function createTooltip(data) {
224
230
  const el = mouseOverReactionEl;
231
+ disposeTooltip(el);
225
232
  let usernames = data.usernames.filter(name => name !== '[[global:former_user]]');
226
233
  if (!usernames.length) {
227
234
  return;
@@ -242,37 +249,45 @@ $(document).ready(function () {
242
249
  animation: false,
243
250
  })).show();
244
251
  }
252
+ function clearTooltipTimeout() {
253
+ if (tooltipTimeoutId) {
254
+ clearTimeout(tooltipTimeoutId);
255
+ tooltipTimeoutId = 0;
256
+ }
257
+ }
245
258
 
246
259
  if (!utils.isTouchDevice()) {
247
260
  $('#content').on('mouseenter', '.reaction', function () {
248
261
  const $this = $(this);
249
262
  mouseOverReactionEl = $this;
250
- const mid = $this.attr('data-mid');
251
- const pid = $this.attr('data-pid');
263
+ clearTooltipTimeout();
252
264
  tooltipTimeoutId = setTimeout(async () => {
253
265
  if (mouseOverReactionEl && mouseOverReactionEl.length) {
254
- const d = await socket.emit('plugins.reactions.getReactionUsernames', {
255
- type: pid ? 'post' : 'message',
266
+ const pid = mouseOverReactionEl.attr('data-pid');
267
+ const mid = mouseOverReactionEl.attr('data-mid');
268
+ const type = pid ? 'post' : 'message';
269
+ const data = await socket.emit('plugins.reactions.getReactionUsernames', {
270
+ type: type,
256
271
  mid: mid,
257
272
  pid: pid,
258
- reaction: $this.attr('data-reaction'),
273
+ reaction: mouseOverReactionEl.attr('data-reaction'),
259
274
  });
260
- createTooltip(d);
275
+
276
+ if (mouseOverReactionEl && mouseOverReactionEl.length &&
277
+ (
278
+ (type === 'post' && pid === mouseOverReactionEl.attr('data-pid')) ||
279
+ (type === 'message' && mid === mouseOverReactionEl.attr('data-mid'))
280
+ )
281
+ ) {
282
+ createTooltip(data);
283
+ }
261
284
  }
262
285
  }, 200);
263
286
  });
264
287
  $('#content').on('mouseleave', '.reaction', function () {
265
- if (tooltipTimeoutId) {
266
- clearTimeout(tooltipTimeoutId);
267
- tooltipTimeoutId = 0;
268
- }
288
+ clearTooltipTimeout();
269
289
  mouseOverReactionEl = null;
270
- const $this = $(this);
271
- const tooltip = bootstrap.Tooltip.getInstance(this);
272
- if (tooltip) {
273
- tooltip.dispose();
274
- $this.attr('title', '');
275
- }
290
+ disposeTooltip($(this));
276
291
  });
277
292
  }
278
293
  });