nodebb-plugin-composer-default 10.2.35 → 10.2.37

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-composer-default",
3
- "version": "10.2.35",
3
+ "version": "10.2.37",
4
4
  "description": "Default composer for NodeBB",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -71,37 +71,40 @@ define('composer/tags', ['alerts'], function (alerts) {
71
71
  } else if (reachedMaxTags) {
72
72
  return alerts.error('[[error:too-many-tags, ' + maxTags + ']]');
73
73
  }
74
+ var cid = postData.hasOwnProperty('cid') ? postData.cid : ajaxify.data.cid;
75
+ $(window).trigger('action:tag.beforeAdd', {
76
+ cid,
77
+ tagEl,
78
+ tag: event.item,
79
+ event,
80
+ inputAutocomplete: input,
81
+ });
74
82
  if (different) {
75
83
  tagEl.tagsinput('add', cleanTag);
76
84
  }
85
+ if (event.cancel && input.length) {
86
+ input.autocomplete('close');
87
+ }
77
88
  });
78
89
 
79
- var skipAddCheck = false;
80
- var skipRemoveCheck = false;
81
90
  tagEl.on('itemRemoved', function (event) {
82
- if (skipRemoveCheck) {
83
- skipRemoveCheck = false;
91
+ if (!event.item || (event.options && event.options.skipRemoveCheck)) {
84
92
  return;
85
93
  }
86
94
 
87
- if (!event.item) {
88
- return;
89
- }
90
95
  socket.emit('topics.canRemoveTag', { tag: event.item }, function (err, allowed) {
91
96
  if (err) {
92
97
  return alerts.error(err);
93
98
  }
94
99
  if (!allowed) {
95
100
  alerts.error('[[error:cant-remove-system-tag]]');
96
- skipAddCheck = true;
97
- tagEl.tagsinput('add', event.item);
101
+ tagEl.tagsinput('add', event.item, { skipAddCheck: true });
98
102
  }
99
103
  });
100
104
  });
101
105
 
102
106
  tagEl.on('itemAdded', function (event) {
103
- if (skipAddCheck) {
104
- skipAddCheck = false;
107
+ if (event.options && event.options.skipAddCheck) {
105
108
  return;
106
109
  }
107
110
  var cid = postData.hasOwnProperty('cid') ? postData.cid : ajaxify.data.cid;
@@ -110,10 +113,14 @@ define('composer/tags', ['alerts'], function (alerts) {
110
113
  return alerts.error(err);
111
114
  }
112
115
  if (!allowed) {
113
- skipRemoveCheck = true;
114
- return tagEl.tagsinput('remove', event.item);
116
+ return tagEl.tagsinput('remove', event.item, { skipRemoveCheck: true });
115
117
  }
116
- $(window).trigger('action:tag.added', { cid: cid, tagEl: tagEl, tag: event.item });
118
+ $(window).trigger('action:tag.added', {
119
+ cid,
120
+ tagEl,
121
+ tag: event.item,
122
+ inputAutocomplete: input,
123
+ });
117
124
  if (input.length) {
118
125
  input.autocomplete('close');
119
126
  }
@@ -411,6 +411,9 @@ define('composer', [
411
411
  preview.matchScroll(postContainer);
412
412
  });
413
413
 
414
+ if (!utils.isNumber(postData.pid)) {
415
+ handleRemotePid(postContainer);
416
+ }
414
417
  handleHelp(postContainer);
415
418
  handleSearch(postContainer);
416
419
  focusElements(postContainer);
@@ -579,6 +582,16 @@ define('composer', [
579
582
  }, path, `${config.relative_path}/${returnPath}`);
580
583
  }
581
584
 
585
+ function handleRemotePid(postContainer) {
586
+ alerts.alert({
587
+ title: '[[modules:composer.remote-pid-editing]]',
588
+ message: '[[modules:composer.remote-pid-content-immutable]]',
589
+ timeout: 15000,
590
+ });
591
+ var container = postContainer.find('.write-container');
592
+ container.addClass('hidden');
593
+ }
594
+
582
595
  function handleHelp(postContainer) {
583
596
  const helpBtn = postContainer.find('[data-action="help"]');
584
597
  helpBtn.on('click', async function () {
@@ -731,7 +744,7 @@ define('composer', [
731
744
  };
732
745
  } else if (action === 'posts.edit') {
733
746
  method = 'put';
734
- route = `/posts/${postData.pid}`;
747
+ route = `/posts/${encodeURIComponent(postData.pid)}`;
735
748
  composerData = {
736
749
  ...composerData,
737
750
  pid: postData.pid,
@@ -873,17 +886,11 @@ define('composer', [
873
886
  calls.push(topicThumbs.getByPid(composerObj.pid));
874
887
  }
875
888
  Promise.all(calls).then((thumbs) => {
876
- thumbs = thumbs.reduce((memo, cur) => {
877
- memo = memo.concat(cur);
878
- return memo;
879
- });
880
-
881
- if (thumbs.length) {
882
- const formatEl = postContainer.find('[data-format="thumbs"]');
883
- formatEl.find('.badge')
884
- .text(thumbs.length)
885
- .toggleClass('hidden', !thumbs.length);
886
- }
889
+ const thumbCount = thumbs.flat().length;
890
+ const formatEl = postContainer.find('[data-format="thumbs"]');
891
+ formatEl.find('.badge')
892
+ .text(thumbCount)
893
+ .toggleClass('hidden', !thumbCount);
887
894
  });
888
895
  }
889
896
  };