Skip to content

Commit 3f1837f

Browse files
committed
v1.3.1
- Changed function for renumbering the attachmend BBCode
1 parent 4bc9f75 commit 3f1837f

File tree

1 file changed

+17
-57
lines changed

1 file changed

+17
-57
lines changed

imcger/imgupload/styles/all/template/event/overall_footer_body_after.html

Lines changed: 17 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@
6060
return parseInt(b.attach_id) - parseInt(a.attach_id);
6161
});
6262

63+
// Replace [attachment=index] with [attachment=imc-ger]
64+
let messageText = document.getElementById('message').value,
65+
regex = new RegExp('\\[attachment=' + index + '\\]', 'gm');
66+
67+
messageText = messageText.replaceAll(regex, '[attachment=imc-ger]');
68+
document.getElementById('message').value = messageText;
69+
70+
// update attach index in message text
71+
phpbb.plupload.updateBbcode('removal', index);
72+
phpbb.plupload.updateBbcode('add', 0);
73+
74+
// Replace [attachment=imc-ger] with [attachment=0]
75+
messageText = document.getElementById('message').value;
76+
messageText = messageText.replaceAll(/\[attachment=imc-ger\]/gm, '[attachment=0]');
77+
document.getElementById('message').value = messageText;
78+
79+
phpbb.plupload.updateRows();
6380
phpbb.plupload.clearParams();
6481
phpbb.plupload.updateMultipartParams(phpbb.plupload.getSerializedData());
6582
}
@@ -249,63 +266,6 @@
249266
// When load the document, update AttachmentBox in preview
250267
document.addEventListener('DOMContentLoaded', () => {imcgerShowAttachImage();});
251268

252-
// When form send, update attachment row id in message text
253-
document.getElementById('postform').addEventListener('submit', function(e) {
254-
imcgerIuplUpdateMessageBeforeSend(document.getElementById('postform').getAttribute('action').includes('#preview'));
255-
});
256-
257-
/**
258-
* When form send, update attachment row id in message text
259-
*
260-
* @param bool isPreview Specify, preview or save submit
261-
* @var array phpbb.plupload.ids Array of attachment id's
262-
* @var array phpbb.plupload.data
263-
*/
264-
function imcgerIuplUpdateMessageBeforeSend(isPreview) {
265-
let messageText = document.getElementById('message').value,
266-
attachRows = document.querySelectorAll('.attach-row .attach-comment'),
267-
rowIndex = 0;
268-
269-
// Return if the bbcode isn't used at all.
270-
if (messageText.indexOf('[attachment=') === -1) {
271-
return;
272-
}
273-
274-
// Order arrays by attach ids descending
275-
phpbb.plupload.ids.sort(function(a,b) {
276-
return b - a;
277-
});
278-
phpbb.plupload.data.sort(function(a,b) {
279-
return parseInt(b.attach_id) - parseInt(a.attach_id);
280-
});
281-
282-
attachRows.forEach((attachRow) => {
283-
let attachId = document.getElementsByName('attachment_data[' + rowIndex + '][attach_id]')[0].value,
284-
realFilename = document.getElementsByName('attachment_data[' + rowIndex + '][real_filename]')[0].value,
285-
idsIndex = phpbb.plupload.ids.indexOf(parseInt(attachId));
286-
287-
if (isPreview) { // Order attatchments like rows
288-
if (idsIndex >= 0) {
289-
let regex = new RegExp('\\[attachment=' + idsIndex + '\\]' + realFilename + '\\[\\/attachment\\]', 'gm'),
290-
newAttach = '[attachment=' + rowIndex + ']' + realFilename + '[/attachment]';
291-
292-
messageText = messageText.replaceAll(regex, newAttach);
293-
}
294-
} else { // Order attachments like attach_id
295-
if (idsIndex >= 0) {
296-
let regex = new RegExp('\\[attachment=' + rowIndex + '\\]' + realFilename + '\\[\\/attachment\\]', 'gm'),
297-
newAttach = '[attachment=' + idsIndex + ']' + realFilename + '[/attachment]';
298-
299-
messageText = messageText.replaceAll(regex, newAttach);
300-
}
301-
}
302-
303-
rowIndex++;
304-
});
305-
306-
document.getElementById('message').value = messageText;
307-
}
308-
309269
(function($) { // Avoid conflicts with other libraries
310270

311271
'use strict';

0 commit comments

Comments
 (0)