Merge branch '5.2' into 5.3
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / acp / templates / wysiwyg.tpl
CommitLineData
a8b5a8f5
AE
1{event name='beforeEditorJavaScript'}
2
ed3f188f 3<script data-relocate="true">
e709be77
AE
4 head.load([
5 {if ENABLE_DEBUG_MODE}
6 {* Imperavi *}
7 '{@$__wcf->getPath()}js/3rdParty/redactor2/redactor.js?v={@LAST_UPDATE_TIME}',
8 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/alignment.js?v={@LAST_UPDATE_TIME}',
9 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/source.js?v={@LAST_UPDATE_TIME}',
10 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/table.js?v={@LAST_UPDATE_TIME}',
11
12 {* WoltLab *}
13 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabAttachment.js?v={@LAST_UPDATE_TIME}',
21b3c837 14 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabAutosave.js?v={@LAST_UPDATE_TIME}',
eb104f97 15 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabBlock.js?v={@LAST_UPDATE_TIME}',
e709be77 16 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabButton.js?v={@LAST_UPDATE_TIME}',
5a7a1cd8 17 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabCaret.js?v={@LAST_UPDATE_TIME}',
d809bfdd 18 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabClean.js?v={@LAST_UPDATE_TIME}',
eb104f97 19 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabCode.js?v={@LAST_UPDATE_TIME}',
e709be77 20 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabColor.js?v={@LAST_UPDATE_TIME}',
26c8f1c3 21 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabDragAndDrop.js?v={@LAST_UPDATE_TIME}',
e709be77 22 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabEvent.js?v={@LAST_UPDATE_TIME}',
25a620ef 23 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabFont.js?v={@LAST_UPDATE_TIME}',
dbd05c9d 24 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabFullscreen.js?v={@LAST_UPDATE_TIME}',
20f61b75 25 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabHtml.js?v={@LAST_UPDATE_TIME}',
e709be77 26 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabImage.js?v={@LAST_UPDATE_TIME}',
09c146b3 27 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabIndent.js?v={@LAST_UPDATE_TIME}',
6d607cc8 28 //'{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInlineCode.js?v={@LAST_UPDATE_TIME}',
d809bfdd 29 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInsert.js?v={@LAST_UPDATE_TIME}',
8399847c 30 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}',
fc49b6d1 31 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeyup.js?v={@LAST_UPDATE_TIME}',
2e7c219b 32 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLine.js?v={@LAST_UPDATE_TIME}',
e709be77 33 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLink.js?v={@LAST_UPDATE_TIME}',
c7f3155d 34 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabList.js?v={@LAST_UPDATE_TIME}',
e709be77
AE
35 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}',
36 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMention.js?v={@LAST_UPDATE_TIME}',
37 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabModal.js?v={@LAST_UPDATE_TIME}',
25a620ef 38 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabObserve.js?v={@LAST_UPDATE_TIME}',
0ce51dff 39 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabPaste.js?v={@LAST_UPDATE_TIME}',
e709be77 40 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabQuote.js?v={@LAST_UPDATE_TIME}',
8e8cc420 41 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabReply.js?v={@LAST_UPDATE_TIME}',
e709be77 42 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSize.js?v={@LAST_UPDATE_TIME}',
eb104f97 43 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSmiley.js?v={@LAST_UPDATE_TIME}',
d809bfdd 44 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSource.js?v={@LAST_UPDATE_TIME}',
8dbbbdef 45 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSpoiler.js?v={@LAST_UPDATE_TIME}',
0c48ef64 46 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabTable.js?v={@LAST_UPDATE_TIME}',
8dbbbdef 47 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabUtils.js?v={@LAST_UPDATE_TIME}'
e709be77 48 {else}
08700b0e 49 '{@$__wcf->getPath()}js/3rdParty/redactor2/redactor.combined.min.js?v={@LAST_UPDATE_TIME}'
ed3f188f 50 {/if}
c540a503
AE
51
52 {if $__redactorJavaScript|isset}{@$__redactorJavaScript}{/if}
c516794d 53 {assign var=__redactorJavaScript value=''}
c540a503
AE
54
55 {event name='redactorJavaScript'}
e709be77 56 ], function () {
c6c30725 57 require(['Environment', 'Language', 'WoltLabSuite/Core/Ui/Redactor/Autosave', 'WoltLabSuite/Core/Ui/Redactor/Metacode'], function(Environment, Language, UiRedactorAutosave, UiRedactorMetacode) {
7d753078 58 Language.addObject({
e2e8c155
MW
59 'wcf.attachment.dragAndDrop.dropHere': '{jslang}wcf.attachment.dragAndDrop.dropHere{/jslang}',
60 'wcf.attachment.dragAndDrop.dropNow': '{jslang}wcf.attachment.dragAndDrop.dropNow{/jslang}',
26c8f1c3 61
e2e8c155
MW
62 'wcf.editor.autosave.discard': '{jslang}wcf.editor.autosave.discard{/jslang}',
63 'wcf.editor.autosave.keep': '{jslang}wcf.editor.autosave.keep{/jslang}',
64 'wcf.editor.autosave.restored': '{jslang}wcf.editor.autosave.restored{/jslang}',
41ad3366 65
e2e8c155
MW
66 'wcf.editor.code.edit': '{jslang}wcf.editor.code.edit{/jslang}',
67 'wcf.editor.code.file': '{jslang}wcf.editor.code.file{/jslang}',
68 'wcf.editor.code.file.description': '{jslang}wcf.editor.code.file.description{/jslang}',
69 'wcf.editor.code.highlighter': '{jslang}wcf.editor.code.highlighter{/jslang}',
70 'wcf.editor.code.highlighter.description': '{jslang}wcf.editor.code.highlighter.description{/jslang}',
71 'wcf.editor.code.highlighter.detect': '{jslang}wcf.editor.code.highlighter.detect{/jslang}',
72 'wcf.editor.code.highlighter.plain': '{jslang}wcf.editor.code.highlighter.plain{/jslang}',
73 'wcf.editor.code.line': '{jslang}wcf.editor.code.line{/jslang}',
74 'wcf.editor.code.line.description': '{jslang}wcf.editor.code.line.description{/jslang}',
75 'wcf.editor.code.title': '{jslang __literal=true}wcf.editor.code.title{/jslang}',
eb104f97 76
e2e8c155
MW
77 'wcf.editor.html.description': '{jslang}wcf.editor.html.description{/jslang}',
78 'wcf.editor.html.title': '{jslang}wcf.editor.html.title{/jslang}',
20f61b75 79
e2e8c155
MW
80 'wcf.editor.image.edit': '{jslang}wcf.editor.image.edit{/jslang}',
81 'wcf.editor.image.insert': '{jslang}wcf.editor.image.insert{/jslang}',
82 'wcf.editor.image.link': '{jslang}wcf.editor.image.link{/jslang}',
83 'wcf.editor.image.link.error.invalid': '{jslang}wcf.editor.image.link.error.invalid{/jslang}',
84 'wcf.editor.image.float': '{jslang}wcf.editor.image.float{/jslang}',
85 'wcf.editor.image.float.left': '{jslang}wcf.editor.image.float.left{/jslang}',
86 'wcf.editor.image.float.right': '{jslang}wcf.editor.image.float.right{/jslang}',
87 'wcf.editor.image.source': '{jslang}wcf.editor.image.source{/jslang}',
88 'wcf.editor.image.source.error.blocked': '{jslang}wcf.editor.image.source.error.blocked{/jslang}',
89 'wcf.editor.image.source.error.insecure': '{jslang}wcf.editor.image.source.error.insecure{/jslang}',
90 'wcf.editor.image.source.error.invalid': '{jslang}wcf.editor.image.source.error.invalid{/jslang}',
eb104f97 91
e2e8c155
MW
92 'wcf.editor.link.add': '{jslang}wcf.editor.link.add{/jslang}',
93 'wcf.editor.link.edit': '{jslang}wcf.editor.link.edit{/jslang}',
94 'wcf.editor.link.error.invalid': '{jslang}wcf.editor.link.error.invalid{/jslang}',
95 'wcf.editor.link.url': '{jslang}wcf.editor.link.url{/jslang}',
96 'wcf.editor.link.text': '{jslang}wcf.editor.link.text{/jslang}',
eb104f97 97
e2e8c155
MW
98 'wcf.editor.list.indent': '{jslang}wcf.editor.list.indent{/jslang}',
99 'wcf.editor.list.outdent': '{jslang}wcf.editor.list.outdent{/jslang}',
de61bfd1 100
e2e8c155
MW
101 'wcf.editor.quote.author': '{jslang}wcf.editor.quote.author{/jslang}',
102 'wcf.editor.quote.edit': '{jslang}wcf.editor.quote.edit{/jslang}',
103 'wcf.editor.quote.title': '{jslang __literal=true}wcf.editor.quote.title{/jslang}',
104 'wcf.editor.quote.url': '{jslang}wcf.editor.quote.url{/jslang}',
105 'wcf.editor.quote.url.description': '{jslang}wcf.editor.quote.url.description{/jslang}',
106 'wcf.editor.quote.url.error.invalid': '{jslang}wcf.editor.quote.url.error.invalid{/jslang}',
eb104f97 107
e2e8c155
MW
108 'wcf.editor.table.cols': '{jslang}wcf.editor.table.cols{/jslang}',
109 'wcf.editor.table.insertTable': '{jslang}wcf.editor.table.insertTable{/jslang}',
110 'wcf.editor.table.rows': '{jslang}wcf.editor.table.rows{/jslang}',
7b78fba2 111
e2e8c155 112 'wcf.editor.source.error.active': '{jslang}wcf.editor.source.error.active{/jslang}',
9cbd962f 113
e2e8c155
MW
114 'wcf.editor.spoiler.label': '{jslang}wcf.editor.spoiler.label{/jslang}',
115 'wcf.editor.spoiler.label.description': '{jslang}wcf.editor.spoiler.label.description{/jslang}',
116 'wcf.editor.spoiler.edit': '{jslang}wcf.editor.spoiler.edit{/jslang}',
117 'wcf.editor.spoiler.title': '{jslang __literal=true}wcf.editor.spoiler.title{/jslang}'
7d753078
AE
118 });
119
607ff92e 120 var allowedInlineStyles = [], buttons = [], buttonMobile = [], buttonOptions = [], customButtons = [];
e709be77
AE
121 {include file='wysiwygToolbar'}
122
f809f77a 123 var highlighters = '{@MESSAGE_PUBLIC_HIGHLIGHTERS|encodeJS}'.split(/\n/).filter(function (item) { return item != ''; });
eb104f97 124
e709be77
AE
125 {include file='mediaJavaScript'}
126
127 var element = elById('{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}');
e709be77 128
21b3c837 129 var autosave = elData(element, 'autosave') || null;
e709be77 130 if (autosave) {
21b3c837
AE
131 autosave = new UiRedactorAutosave(element);
132 element.value = autosave.getInitialValue();
e709be77
AE
133 }
134
0e1a9950
AE
135 var disableMedia = elDataBool(element, 'disable-media');
136
e709be77
AE
137 var config = {
138 buttons: buttons,
6d607cc8 139 clipboardImageUpload: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('attach')}true{else}false{/if},
e2e8c155 140 direction: '{jslang}wcf.global.pageDirection{/jslang}',
eb104f97 141 formatting: ['p', 'h2', 'h3', 'h4'],
e709be77 142 imageCaption: false,
6d607cc8 143 imageUpload: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('attach')}true{else}false{/if},
eb104f97
AE
144 lang: 'wsc', // fake language to offload phrases
145 langs: {
146 wsc: {
8399847c 147 // general
e2e8c155 148 edit: '{jslang}wcf.global.button.edit{/jslang}',
8399847c 149
eb104f97 150 // formatting dropdown
e2e8c155
MW
151 heading2: '{jslang}wcf.editor.format.heading2{/jslang}',
152 heading3: '{jslang}wcf.editor.format.heading3{/jslang}',
153 heading4: '{jslang}wcf.editor.format.heading4{/jslang}',
154 paragraph: '{jslang}wcf.editor.format.paragraph{/jslang}',
eb104f97 155
8399847c 156 // links
e2e8c155
MW
157 'link-edit': '{jslang}wcf.editor.link.edit{/jslang}',
158 'link-insert': '{jslang}wcf.editor.link.add{/jslang}',
159 unlink: '{jslang}wcf.editor.link.unlink{/jslang}',
8399847c
AE
160
161 // text alignment
e2e8c155
MW
162 'align-center': '{jslang}wcf.editor.alignment.center{/jslang}',
163 'align-justify': '{jslang}wcf.editor.alignment.justify{/jslang}',
164 'align-left': '{jslang}wcf.editor.alignment.left{/jslang}',
165 'align-right': '{jslang}wcf.editor.alignment.right{/jslang}',
dcb74ba6 166
eb104f97 167 // table plugin
e2e8c155
MW
168 'add-head': '{jslang}wcf.editor.table.addHead{/jslang}',
169 'delete-column': '{jslang}wcf.editor.table.deleteColumn{/jslang}',
170 'delete-head': '{jslang}wcf.editor.table.deleteHead{/jslang}',
171 'delete-row': '{jslang}wcf.editor.table.deleteRow{/jslang}',
172 'delete-table': '{jslang}wcf.editor.table.deleteTable{/jslang}',
173 'insert-table': '{jslang}wcf.editor.table.insertTable{/jslang}',
174 'insert-column-left': '{jslang}wcf.editor.table.insertColumnLeft{/jslang}',
175 'insert-column-right': '{jslang}wcf.editor.table.insertColumnRight{/jslang}',
176 'insert-row-above': '{jslang}wcf.editor.table.insertRowAbove{/jslang}',
177 'insert-row-below': '{jslang}wcf.editor.table.insertRowBelow{/jslang}',
25a620ef 178
2aadba64 179 // size
e2e8c155 180 'remove-size': '{jslang}wcf.editor.button.size.removeSize{/jslang}',
25a620ef 181
2aadba64 182 // color
e2e8c155 183 'remove-color': '{jslang}wcf.editor.button.color.removeColor{/jslang}',
25a620ef
AE
184
185 // font
e2e8c155 186 'remove-font': '{jslang}wcf.editor.button.font.removeFont{/jslang}'
eb104f97
AE
187 }
188 },
533094eb
AE
189 linkify: false,
190 linkSize: 0xBADC0DED, // some random value to disable truncating
e709be77 191 minHeight: 200,
6d607cc8 192 pasteImages: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('attach')}true{else}false{/if},
13046b4a 193 pastePlainText: {if !$__wcf->user->userID || $__wcf->user->editorPastePreserveFormatting}false{else}true{/if},
e709be77 194 plugins: [
8399847c 195 // Imperavi
e709be77
AE
196 'alignment',
197 'source',
198 'table',
8399847c
AE
199
200 // WoltLab specials
201 'WoltLabBlock',
3919fbc8 202 'WoltLabEvent',
8399847c
AE
203 'WoltLabKeydown',
204
205 // WoltLab core
e709be77 206 'WoltLabAttachment',
21b3c837 207 'WoltLabAutosave',
5a7a1cd8 208 'WoltLabCaret',
d809bfdd 209 'WoltLabClean',
eb104f97 210 'WoltLabCode',
26475eb3 211 {if $__wcf->getBBCodeHandler()->isAvailableBBCode('color')}'WoltLabColor',{/if}
26c8f1c3 212 'WoltLabDragAndDrop',
26475eb3 213 {if $__wcf->getBBCodeHandler()->isAvailableBBCode('font')}'WoltLabFont',{/if}
dbd05c9d 214 'WoltLabFullscreen',
20f61b75 215 {if $__wcf->getBBCodeHandler()->isAvailableBBCode('html')}'WoltLabHtml',{/if}
5c58a5a5 216 'WoltLabImage',
09c146b3 217 'WoltLabIndent',
6d607cc8 218 //'WoltLabInlineCode',
d809bfdd 219 'WoltLabInsert',
fc49b6d1 220 'WoltLabKeyup',
2e7c219b 221 'WoltLabLine',
26475eb3 222 {if $__wcf->getBBCodeHandler()->isAvailableBBCode('url')}'WoltLabLink',{/if}
c7f3155d 223 'WoltLabList',
e709be77 224 'WoltLabModal',
25a620ef 225 'WoltLabObserve',
0ce51dff 226 'WoltLabPaste',
e709be77 227 'WoltLabQuote',
8e8cc420 228 'WoltLabReply',
26475eb3 229 {if $__wcf->getBBCodeHandler()->isAvailableBBCode('size')}'WoltLabSize',{/if}
eb104f97 230 'WoltLabSmiley',
d809bfdd 231 'WoltLabSource',
8dbbbdef 232 'WoltLabSpoiler',
0c48ef64 233 'WoltLabTable',
8dbbbdef 234 'WoltLabUtils'
e709be77
AE
235 ],
236 toolbarFixed: false,
237 woltlab: {
5c58a5a5 238 allowImages: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('img')}true{else}false{/if},
223f2245 239 attachments: (elDataBool(element, 'disable-attachments') === false),
40ed23a5 240 attachmentThumbnailWidth: {@ATTACHMENT_THUMBNAIL_WIDTH},
e709be77 241 autosave: autosave,
607ff92e 242 allowedInlineStyles: allowedInlineStyles,
7d753078 243 buttons: buttonOptions,
8399847c 244 buttonMobile: buttonMobile,
eb104f97 245 customButtons: customButtons,
c8c7ec65 246 forceSecureImages: {if MESSAGE_FORCE_SECURE_IMAGES}true{else}false{/if},
a9255db0 247 highlighters: highlighters,
3913e673
AE
248 images: {
249 external: {if IMAGE_ALLOW_EXTERNAL_SOURCE}true{else}false{/if},
250 secureOnly: {if MESSAGE_FORCE_SECURE_IMAGES}true{else}false{/if},
251 whitelist: [
252 {implode from=$__wcf->getBBCodeHandler()->getImageExternalSourceWhitelist() item=$hostname}'{$hostname|encodeJS}'{/implode}
253 ]
254 },
2413a6e5 255 media: {if $__wcf->session->getPermission('admin.content.cms.canUseMedia')}true{else}false{/if},
a9255db0 256 mediaUrl: '{link controller='Media' id=-123456789 thumbnail='void' forceFrontend=true}{/link}'
e709be77
AE
257 }
258 };
259
5dfb8af8 260 // The caret is misaligned in Safari 13+ when using \u200b.
261 if (Environment.browser() === 'safari') {
262 config.emptyHtml = '<p><br></p>';
263 }
264
e709be77
AE
265 // user mentions
266 if (elDataBool(element, 'support-mention')) {
267 config.plugins.push('WoltLabMention');
268 }
269
270 // media
271 {if $__wcf->session->getPermission('admin.content.cms.canUseMedia')}
0e1a9950
AE
272 if (disableMedia) {
273 var index = config.buttons.indexOf('woltlabMedia');
274 if (index !== -1) {
275 config.buttons.splice(index, 1);
276 }
277 }
278 else {
279 config.plugins.push('WoltLabMedia');
280 }
e709be77
AE
281 {/if}
282
c540a503 283 {if $__redactorConfig|isset}{@$__redactorConfig}{/if}
c516794d 284 {assign var=__redactorConfig value=''}
c540a503
AE
285
286 {event name='redactorConfig'}
287
e5c625ac
AE
288 // load the button plugin last to ensure all buttons have been initialized
289 // already and we can safely add all icons
290 config.plugins.push('WoltLabButton');
291
2aadba64
AE
292 var content = element.value;
293 element.value = '';
294
295 config.callbacks = config.callbacks || { };
296 config.callbacks.init = function() {
297 // slight delay to allow Redactor to initialize itself
298 window.setTimeout(function() {
5dfb8af8 299 if (content === '' && (Environment.platform() === 'ios' || Environment.browser() === 'safari')) {
c6c30725
AE
300 content = '<p><br></p>';
301 }
302
a9255db0
AE
303 content = UiRedactorMetacode.convertFromHtml(element.id, content);
304
c6031daa
AE
305 var redactor = $(element).data('redactor');
306
307 // set code
308 redactor.code.start(content);
3913e673 309 redactor.WoltLabImage.validateImages();
c6031daa
AE
310
311 // set value
312 redactor.core.textarea().val(redactor.clean.onSync(redactor.$editor.html()));
078c3d3e 313 redactor.code.html = false;
0c94c594
AE
314
315 // work-around for autosave notice being stuck
316 window.setTimeout(function() {
317 var autosaveNotice = elBySel('.redactorAutosaveRestored.active', element.parentNode);
318 if (autosaveNotice) {
319 autosaveNotice.style.setProperty('position', 'static', '');
320
321 // force layout
322 //noinspection BadExpressionStatementJS
323 autosaveNotice.offsetTop;
324
325 autosaveNotice.style.removeProperty('position');
326 }
327 }, 10);
2aadba64
AE
328 }, 10);
329 };
330
9cf29007
AE
331 $(function () {
332 $(element).redactor(config);
333 });
e709be77 334 });
ed3f188f 335 });
ed3f188f 336</script>