|
60 | 60 | return parseInt(b.attach_id) - parseInt(a.attach_id); |
61 | 61 | }); |
62 | 62 |
|
| 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(); |
63 | 80 | phpbb.plupload.clearParams(); |
64 | 81 | phpbb.plupload.updateMultipartParams(phpbb.plupload.getSerializedData()); |
65 | 82 | } |
|
249 | 266 | // When load the document, update AttachmentBox in preview |
250 | 267 | document.addEventListener('DOMContentLoaded', () => {imcgerShowAttachImage();}); |
251 | 268 |
|
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 | | - |
309 | 269 | (function($) { // Avoid conflicts with other libraries |
310 | 270 |
|
311 | 271 | 'use strict'; |
|
0 commit comments