resp.json()) .then(function (data) { const results = []; for (const user of data) { results.push({ value: '@' + user.nickname, text: user.nickname, icon: '' }); } results.sort((a, b) => a.text.toLowerCase().localeCompare(b.text.toLowerCase())) resolve(results); }); }); }, onAction: function (autocompleteApi, rng, value) { editor.selection.setRng(rng); editor.insertContent(value); autocompleteApi.hide(); }, }); }); }()); })(); "; } $js .= ' tinymce.init({ verify_html: ' . ($admin ? 'false' : 'true') . ", selector: '#$name', browser_spellcheck: true, contextmenu: false, branding: false, menubar: 'table', convert_urls: false, plugins: [ 'autolink', 'codesample', 'directionality', 'emoticons', " . ($mentions ? "'mentions', " : '') . " 'hr', 'image', 'link', 'lists', 'spoiler', 'code', 'table', ], external_plugins: { 'spoiler': '" . (defined('CONFIG_PATH') ? CONFIG_PATH : '') . "/core/assets/plugins/tinymce_spoiler/plugin.min.js', }, toolbar: 'undo redo | bold italic underline strikethrough formatselect fontsizeselect fontselect forecolor backcolor ltr rtl emoticons | alignleft aligncenter alignright alignjustify | codesample " . ($admin ? 'code' : '') . " hr image link numlist bullist | spoiler-add spoiler-remove', spoiler_caption: '{$language->get('general', 'spoiler')}', default_link_target: '_blank', skin: '$skin'," . ($content ? ' setup: (editor) => { editor.on(\'init\', () => { editor.setContent(' . json_encode($content) . '); }); }, ' : '') . " images_upload_handler: function (blobInfo, success, failure, progress) { let xhr, formData; xhr = new XMLHttpRequest(); xhr.withCredentials = false; xhr.open('POST', '" . URL::build('/queries/tinymce_image_upload') . "'); xhr.upload.onprogress = function (e) { progress(e.loaded / e.total * 100); }; xhr.onload = function() { let json; if (xhr.status !== 200) { failure('HTTP Error ' + xhr.status + ': ' + xhr.responseText); return; } json = JSON.parse(xhr.responseText); if (!json || typeof json.location != 'string') { failure('Invalid JSON: ' + xhr.responseText); return; } success(json.location); }; xhr.onerror = function () { failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status); }; formData = new FormData(); formData.append('file', blobInfo.blob(), blobInfo.filename()); formData.append('token', '" . Token::get() . "'); xhr.send(formData); }, " . ($admin ? 'valid_children: "+body[style],+body[link],+*[*]",' : '') . ' extended_valid_elements: ' . ($admin ? '"script[src|async|defer|type|charset],+@[data-options]"' : 'undefined') . ' }); '; return $js; } }