nodebb-plugin-composer-default 10.0.18 → 10.0.19
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 +1 -1
- package/static/lib/client.js +16 -3
- package/static/lib/composer/drafts.js +21 -6
- package/static/lib/composer.js +49 -34
package/package.json
CHANGED
package/static/lib/client.js
CHANGED
|
@@ -30,7 +30,7 @@ $(document).ready(function () {
|
|
|
30
30
|
$(window).on('action:composer.post.edit', function (ev, data) {
|
|
31
31
|
if (config['composer-default'].composeRouteEnabled !== 'on') {
|
|
32
32
|
require(['composer'], function (composer) {
|
|
33
|
-
composer.editPost(data.pid);
|
|
33
|
+
composer.editPost({ pid: data.pid });
|
|
34
34
|
});
|
|
35
35
|
} else {
|
|
36
36
|
ajaxify.go('compose?pid=' + data.pid);
|
|
@@ -40,7 +40,12 @@ $(document).ready(function () {
|
|
|
40
40
|
$(window).on('action:composer.post.new', function (ev, data) {
|
|
41
41
|
if (config['composer-default'].composeRouteEnabled !== 'on') {
|
|
42
42
|
require(['composer'], function (composer) {
|
|
43
|
-
composer.newReply(
|
|
43
|
+
composer.newReply({
|
|
44
|
+
tid: data.tid,
|
|
45
|
+
pid: data.pid,
|
|
46
|
+
title: data.topicName,
|
|
47
|
+
body: data.text,
|
|
48
|
+
});
|
|
44
49
|
});
|
|
45
50
|
} else {
|
|
46
51
|
ajaxify.go(
|
|
@@ -56,7 +61,15 @@ $(document).ready(function () {
|
|
|
56
61
|
if (config['composer-default'].composeRouteEnabled !== 'on') {
|
|
57
62
|
require(['composer'], function (composer) {
|
|
58
63
|
var topicUUID = composer.findByTid(data.tid);
|
|
59
|
-
composer.addQuote(
|
|
64
|
+
composer.addQuote({
|
|
65
|
+
tid: data.tid,
|
|
66
|
+
toPid: data.pid,
|
|
67
|
+
selectedPid: data.selectedPid,
|
|
68
|
+
title: data.topicName,
|
|
69
|
+
username: data.username,
|
|
70
|
+
body: data.text,
|
|
71
|
+
uuid: topicUUID,
|
|
72
|
+
});
|
|
60
73
|
});
|
|
61
74
|
} else {
|
|
62
75
|
ajaxify.go('compose?tid=' + data.tid + '&toPid=' + data.pid + '"ed=1&username=' + data.username);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
|
|
4
4
|
const drafts = {};
|
|
5
|
-
|
|
5
|
+
const draftSaveDelay = 2000;
|
|
6
6
|
drafts.init = function (postContainer, postData) {
|
|
7
7
|
const draftIconEl = postContainer.find('.draft-icon');
|
|
8
8
|
function doSaveDraft() {
|
|
@@ -15,9 +15,10 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
|
|
|
15
15
|
saveDraft(postContainer, draftIconEl, postData);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
postContainer.on('keyup', 'textarea, input.handle, input.title', utils.debounce(doSaveDraft,
|
|
19
|
-
postContainer.on('click', 'input[type="checkbox"]', utils.debounce(doSaveDraft,
|
|
20
|
-
postContainer.on('click', '[component="category/list"] [data-cid]', utils.debounce(doSaveDraft,
|
|
18
|
+
postContainer.on('keyup', 'textarea, input.handle, input.title', utils.debounce(doSaveDraft, draftSaveDelay));
|
|
19
|
+
postContainer.on('click', 'input[type="checkbox"]', utils.debounce(doSaveDraft, draftSaveDelay));
|
|
20
|
+
postContainer.on('click', '[component="category/list"] [data-cid]', utils.debounce(doSaveDraft, draftSaveDelay));
|
|
21
|
+
postContainer.on('itemAdded', '.tags', utils.debounce(doSaveDraft, draftSaveDelay));
|
|
21
22
|
postContainer.on('thumb.uploaded', doSaveDraft);
|
|
22
23
|
|
|
23
24
|
draftIconEl.on('animationend', function () {
|
|
@@ -79,6 +80,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
|
|
|
79
80
|
|
|
80
81
|
if (raw.length || (title && title.length)) {
|
|
81
82
|
const draftData = {
|
|
83
|
+
save_id: postData.save_id,
|
|
82
84
|
action: postData.action,
|
|
83
85
|
text: raw,
|
|
84
86
|
uuid: postContainer.attr('data-uuid'),
|
|
@@ -95,6 +97,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
|
|
|
95
97
|
// new reply only
|
|
96
98
|
draftData.title = postData.title;
|
|
97
99
|
draftData.tid = postData.tid;
|
|
100
|
+
draftData.toPid = postData.toPid;
|
|
98
101
|
} else if (postData.action === 'posts.edit') {
|
|
99
102
|
draftData.pid = postData.pid;
|
|
100
103
|
}
|
|
@@ -269,6 +272,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
|
|
|
269
272
|
require(['composer'], function (composer) {
|
|
270
273
|
if (draft.action === 'topics.post') {
|
|
271
274
|
composer.newTopic({
|
|
275
|
+
save_id: draft.save_id,
|
|
272
276
|
cid: draft.cid,
|
|
273
277
|
handle: app.user && app.user.uid ? undefined : utils.escapeHTML(draft.handle),
|
|
274
278
|
title: utils.escapeHTML(draft.title),
|
|
@@ -280,10 +284,21 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
|
|
|
280
284
|
if (err) {
|
|
281
285
|
return alerts.error(err);
|
|
282
286
|
}
|
|
283
|
-
|
|
287
|
+
|
|
288
|
+
composer.newReply({
|
|
289
|
+
save_id: draft.save_id,
|
|
290
|
+
tid: draft.tid,
|
|
291
|
+
toPid: draft.toPid,
|
|
292
|
+
title: topicObj.title,
|
|
293
|
+
body: utils.escapeHTML(draft.text),
|
|
294
|
+
});
|
|
284
295
|
});
|
|
285
296
|
} else if (draft.action === 'posts.edit') {
|
|
286
|
-
composer.editPost(
|
|
297
|
+
composer.editPost({
|
|
298
|
+
save_id: draft.save_id,
|
|
299
|
+
pid: draft.pid,
|
|
300
|
+
body: utils.escapeHTML(draft.text),
|
|
301
|
+
});
|
|
287
302
|
}
|
|
288
303
|
});
|
|
289
304
|
}
|
package/static/lib/composer.js
CHANGED
|
@@ -188,7 +188,8 @@ define('composer', [
|
|
|
188
188
|
};
|
|
189
189
|
|
|
190
190
|
composer.newTopic = async (data) => {
|
|
191
|
-
|
|
191
|
+
let pushData = {
|
|
192
|
+
save_id: data.save_id,
|
|
192
193
|
action: 'topics.post',
|
|
193
194
|
cid: data.cid,
|
|
194
195
|
handle: data.handle,
|
|
@@ -207,76 +208,90 @@ define('composer', [
|
|
|
207
208
|
push(pushData);
|
|
208
209
|
};
|
|
209
210
|
|
|
210
|
-
composer.addQuote = function (
|
|
211
|
-
|
|
211
|
+
composer.addQuote = function (data) {
|
|
212
|
+
// tid, toPid, selectedPid, title, username, text, uuid
|
|
213
|
+
data.uuid = data.uuid || composer.active;
|
|
212
214
|
|
|
213
|
-
var escapedTitle = (title || '')
|
|
215
|
+
var escapedTitle = (data.title || '')
|
|
214
216
|
.replace(/([\\`*_{}[\]()#+\-.!])/g, '\\$1')
|
|
215
217
|
.replace(/\[/g, '[')
|
|
216
218
|
.replace(/\]/g, ']')
|
|
217
219
|
.replace(/%/g, '%')
|
|
218
220
|
.replace(/,/g, ',');
|
|
219
221
|
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
+
if (data.body) {
|
|
223
|
+
data.body = '> ' + data.body.replace(/\n/g, '\n> ') + '\n\n';
|
|
222
224
|
}
|
|
223
|
-
var link = '[' + escapedTitle + '](' + config.relative_path + '/post/' + (selectedPid || toPid) + ')';
|
|
224
|
-
if (uuid === undefined) {
|
|
225
|
-
if (title && (selectedPid || toPid)) {
|
|
226
|
-
composer.newReply(
|
|
225
|
+
var link = '[' + escapedTitle + '](' + config.relative_path + '/post/' + (data.selectedPid || data.toPid) + ')';
|
|
226
|
+
if (data.uuid === undefined) {
|
|
227
|
+
if (data.title && (data.selectedPid || data.toPid)) {
|
|
228
|
+
composer.newReply({
|
|
229
|
+
tid: data.tid,
|
|
230
|
+
toPid: data.toPid,
|
|
231
|
+
title: data.title,
|
|
232
|
+
body: '[[modules:composer.user_said_in, ' + data.username + ', ' + link + ']]\n' + data.body,
|
|
233
|
+
});
|
|
227
234
|
} else {
|
|
228
|
-
composer.newReply(
|
|
235
|
+
composer.newReply({
|
|
236
|
+
tid: data.tid,
|
|
237
|
+
toPid: data.toPid,
|
|
238
|
+
title: data.title,
|
|
239
|
+
body: '[[modules:composer.user_said, ' + data.username + ']]\n' + data.body,
|
|
240
|
+
});
|
|
229
241
|
}
|
|
230
242
|
return;
|
|
231
|
-
} else if (uuid !== composer.active) {
|
|
243
|
+
} else if (data.uuid !== composer.active) {
|
|
232
244
|
// If the composer is not currently active, activate it
|
|
233
|
-
composer.load(uuid);
|
|
245
|
+
composer.load(data.uuid);
|
|
234
246
|
}
|
|
235
247
|
|
|
236
|
-
var postContainer = $('.composer[data-uuid="' + uuid + '"]');
|
|
248
|
+
var postContainer = $('.composer[data-uuid="' + data.uuid + '"]');
|
|
237
249
|
var bodyEl = postContainer.find('textarea');
|
|
238
250
|
var prevText = bodyEl.val();
|
|
239
|
-
if (title && (selectedPid || toPid)) {
|
|
240
|
-
translator.translate('[[modules:composer.user_said_in, ' + username + ', ' + link + ']]\n', config.defaultLang, onTranslated);
|
|
251
|
+
if (data.title && (data.selectedPid || data.toPid)) {
|
|
252
|
+
translator.translate('[[modules:composer.user_said_in, ' + data.username + ', ' + link + ']]\n', config.defaultLang, onTranslated);
|
|
241
253
|
} else {
|
|
242
|
-
translator.translate('[[modules:composer.user_said, ' + username + ']]\n', config.defaultLang, onTranslated);
|
|
254
|
+
translator.translate('[[modules:composer.user_said, ' + data.username + ']]\n', config.defaultLang, onTranslated);
|
|
243
255
|
}
|
|
244
256
|
|
|
245
257
|
function onTranslated(translated) {
|
|
246
|
-
composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + translated +
|
|
247
|
-
bodyEl.val(composer.posts[uuid].body);
|
|
258
|
+
composer.posts[data.uuid].body = (prevText.length ? prevText + '\n\n' : '') + translated + data.body;
|
|
259
|
+
bodyEl.val(composer.posts[data.uuid].body);
|
|
248
260
|
focusElements(postContainer);
|
|
249
261
|
preview.render(postContainer);
|
|
250
262
|
}
|
|
251
263
|
};
|
|
252
264
|
|
|
253
|
-
composer.newReply = function (
|
|
254
|
-
translator.translate(
|
|
265
|
+
composer.newReply = function (data) {
|
|
266
|
+
translator.translate(data.body, config.defaultLang, function (translated) {
|
|
255
267
|
push({
|
|
268
|
+
save_id: data.save_id,
|
|
256
269
|
action: 'posts.reply',
|
|
257
|
-
tid: tid,
|
|
258
|
-
toPid: toPid,
|
|
259
|
-
title: title,
|
|
270
|
+
tid: data.tid,
|
|
271
|
+
toPid: data.toPid,
|
|
272
|
+
title: data.title,
|
|
260
273
|
body: translated,
|
|
261
|
-
modified: !!((title && title.length) || (translated && translated.length)),
|
|
274
|
+
modified: !!((data.title && data.title.length) || (translated && translated.length)),
|
|
262
275
|
isMain: false,
|
|
263
276
|
});
|
|
264
277
|
});
|
|
265
278
|
};
|
|
266
279
|
|
|
267
|
-
composer.editPost = function (
|
|
268
|
-
|
|
280
|
+
composer.editPost = function (data) {
|
|
281
|
+
// pid, text
|
|
282
|
+
socket.emit('plugins.composer.push', data.pid, function (err, postData) {
|
|
269
283
|
if (err) {
|
|
270
284
|
return alerts.error(err);
|
|
271
285
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
286
|
+
postData.save_id = data.save_id;
|
|
287
|
+
postData.action = 'posts.edit';
|
|
288
|
+
postData.pid = data.pid;
|
|
289
|
+
postData.modified = false;
|
|
290
|
+
if (data.body) {
|
|
291
|
+
postData.body = data.body;
|
|
292
|
+
postData.modified = true;
|
|
278
293
|
}
|
|
279
|
-
push(
|
|
294
|
+
push(postData);
|
|
280
295
|
});
|
|
281
296
|
};
|
|
282
297
|
|