Fixed list elements being matched outside of Redactor
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / acp / templates / wysiwyg.tpl
CommitLineData
ed3f188f 1<script data-relocate="true">
e709be77
AE
2 head.load([
3 {if ENABLE_DEBUG_MODE}
4 {* Imperavi *}
5 '{@$__wcf->getPath()}js/3rdParty/redactor2/redactor.js?v={@LAST_UPDATE_TIME}',
6 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/alignment.js?v={@LAST_UPDATE_TIME}',
7 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/source.js?v={@LAST_UPDATE_TIME}',
8 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/table.js?v={@LAST_UPDATE_TIME}',
9
10 {* WoltLab *}
dcb74ba6 11 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabAlignment.js?v={@LAST_UPDATE_TIME}',
e709be77 12 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabAttachment.js?v={@LAST_UPDATE_TIME}',
21b3c837 13 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabAutosave.js?v={@LAST_UPDATE_TIME}',
eb104f97 14 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabBlock.js?v={@LAST_UPDATE_TIME}',
e709be77 15 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabButton.js?v={@LAST_UPDATE_TIME}',
5a7a1cd8 16 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabCaret.js?v={@LAST_UPDATE_TIME}',
d809bfdd 17 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabClean.js?v={@LAST_UPDATE_TIME}',
eb104f97 18 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabCode.js?v={@LAST_UPDATE_TIME}',
e709be77
AE
19 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabColor.js?v={@LAST_UPDATE_TIME}',
20 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabDropdown.js?v={@LAST_UPDATE_TIME}',
21 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabEvent.js?v={@LAST_UPDATE_TIME}',
22 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabImage.js?v={@LAST_UPDATE_TIME}',
eb104f97 23 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInlineCode.js?v={@LAST_UPDATE_TIME}',
d809bfdd 24 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInsert.js?v={@LAST_UPDATE_TIME}',
8399847c 25 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}',
e709be77 26 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLink.js?v={@LAST_UPDATE_TIME}',
2ccc7e0e 27 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabList.js?v={@LAST_UPDATE_TIME}',
e709be77
AE
28 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}',
29 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMention.js?v={@LAST_UPDATE_TIME}',
30 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabModal.js?v={@LAST_UPDATE_TIME}',
0ce51dff 31 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabPaste.js?v={@LAST_UPDATE_TIME}',
e709be77
AE
32 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabQuote.js?v={@LAST_UPDATE_TIME}',
33 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSize.js?v={@LAST_UPDATE_TIME}',
eb104f97 34 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSmiley.js?v={@LAST_UPDATE_TIME}',
d809bfdd 35 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSource.js?v={@LAST_UPDATE_TIME}',
8dbbbdef
AE
36 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabSpoiler.js?v={@LAST_UPDATE_TIME}',
37 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabUtils.js?v={@LAST_UPDATE_TIME}'
e709be77
AE
38 {else}
39 '{@$__wcf->getPath()}js/3rdParty/redactor2/redactor.min.js?v={@LAST_UPDATE_TIME}',
40 '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/combined.min.js?v={@LAST_UPDATE_TIME}'
ed3f188f 41 {/if}
c540a503
AE
42
43 {if $__redactorJavaScript|isset}{@$__redactorJavaScript}{/if}
c516794d 44 {assign var=__redactorJavaScript value=''}
c540a503
AE
45
46 {event name='redactorJavaScript'}
e709be77 47 ], function () {
58d7e8f8 48 require(['Language', 'WoltLabSuite/Core/Ui/Redactor/Autosave', 'WoltLabSuite/Core/Ui/Redactor/Metacode'], function(Language, UiRedactorAutosave, UiRedactorMetacode) {
7d753078 49 Language.addObject({
eb104f97
AE
50 'wcf.editor.code.edit': '{lang}wcf.editor.code.edit{/lang}',
51 'wcf.editor.code.file': '{lang}wcf.editor.code.file{/lang}',
52 'wcf.editor.code.file.description': '{lang}wcf.editor.code.file.description{/lang}',
53 'wcf.editor.code.highlighter': '{lang}wcf.editor.code.highlighter{/lang}',
54 'wcf.editor.code.highlighter.description': '{lang}wcf.editor.code.highlighter.description{/lang}',
55 'wcf.editor.code.highlighter.detect': '{lang}wcf.editor.code.highlighter.detect{/lang}',
56 'wcf.editor.code.line': '{lang}wcf.editor.code.line{/lang}',
57 'wcf.editor.code.line.description': '{lang}wcf.editor.code.line.description{/lang}',
58 'wcf.editor.code.title': '{lang __literal=true}wcf.editor.code.title{/lang}',
59
7d753078
AE
60 'wcf.editor.image.edit': '{lang}wcf.editor.image.edit{/lang}',
61 'wcf.editor.image.insert': '{lang}wcf.editor.image.insert{/lang}',
62 'wcf.editor.image.link': '{lang}wcf.editor.image.link{/lang}',
63 'wcf.editor.image.link.error.invalid': '{lang}wcf.editor.image.link.error.invalid{/lang}',
64 'wcf.editor.image.float': '{lang}wcf.editor.image.float{/lang}',
65 'wcf.editor.image.float.left': '{lang}wcf.editor.image.float.left{/lang}',
66 'wcf.editor.image.float.right': '{lang}wcf.editor.image.float.right{/lang}',
67 'wcf.editor.image.source': '{lang}wcf.editor.image.source{/lang}',
eb104f97
AE
68 'wcf.editor.image.source.error.invalid': '{lang}wcf.editor.image.source.error.invalid{/lang}',
69
70 'wcf.editor.link.add': '{lang}wcf.editor.link.add{/lang}',
71 'wcf.editor.link.edit': '{lang}wcf.editor.link.edit{/lang}',
72 'wcf.editor.link.url': '{lang}wcf.editor.link.url{/lang}',
73 'wcf.editor.link.text': '{lang}wcf.editor.link.text{/lang}',
74
75 'wcf.editor.quote.author': '{lang}wcf.editor.quote.author{/lang}',
76 'wcf.editor.quote.edit': '{lang}wcf.editor.quote.edit{/lang}',
77 'wcf.editor.quote.title': '{lang __literal=true}wcf.editor.quote.title{/lang}',
78 'wcf.editor.quote.url': '{lang}wcf.editor.quote.url{/lang}',
79 'wcf.editor.quote.url.description': '{lang}wcf.editor.quote.url.description{/lang}',
21b3c837 80 'wcf.editor.quote.url.error.invalid': '{lang}wcf.editor.quote.url.error.invalid{/lang}',
eb104f97
AE
81
82 'wcf.editor.spoiler.label': '{lang}wcf.editor.spoiler.label{/lang}',
83 'wcf.editor.spoiler.label.description': '{lang}wcf.editor.spoiler.label.description{/lang}',
84 'wcf.editor.spoiler.edit': '{lang}wcf.editor.spoiler.edit{/lang}',
85 'wcf.editor.spoiler.title': '{lang __literal=true}wcf.editor.spoiler.title{/lang}'
7d753078
AE
86 });
87
8399847c 88 var buttons = [], buttonMobile = [], buttonOptions = [], customButtons = [];
e709be77
AE
89 {include file='wysiwygToolbar'}
90
eb104f97
AE
91 var highlighters = { {implode from=$__wcf->getBBCodeHandler()->getHighlighters() item=__highlighter}'{$__highlighter}': '{lang}wcf.bbcode.code.{@$__highlighter}.title{/lang}'{/implode} };
92
e709be77
AE
93 {include file='mediaJavaScript'}
94
95 var element = elById('{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}');
96 UiRedactorMetacode.convert(element);
97
21b3c837 98 var autosave = elData(element, 'autosave') || null;
e709be77 99 if (autosave) {
21b3c837
AE
100 autosave = new UiRedactorAutosave(element);
101 element.value = autosave.getInitialValue();
e709be77
AE
102 }
103
2ccc7e0e
AE
104 var placeholderCallback = null, replyContainer = element.closest('.messageQuickReplyContent');
105 if (replyContainer) {
106 var container = elById('messageQuickReply');
107 if (container.classList.contains('messageQuickReplyCollapsed')) {
108 placeholderCallback = function (event) {
109 if (event instanceof Event) {
110 event.preventDefault();
111 }
112
113 if (container.classList.contains('messageQuickReplyCollapsed')) {
114 container.classList.remove('messageQuickReplyCollapsed');
115 $(element).redactor('focus.end');
116
117 replyContainer.removeEventListener(WCF_CLICK_EVENT, placeholderCallback);
118 }
119
120 return null;
121 };
122
123 replyContainer.addEventListener(WCF_CLICK_EVENT, placeholderCallback);
124 }
125 }
126
e709be77
AE
127 var config = {
128 buttons: buttons,
eb104f97 129 formatting: ['p', 'h2', 'h3', 'h4'],
e709be77 130 imageCaption: false,
eb104f97
AE
131 lang: 'wsc', // fake language to offload phrases
132 langs: {
133 wsc: {
8399847c
AE
134 // general
135 edit: '{lang}wcf.global.button.edit{/lang}',
136
eb104f97
AE
137 // formatting dropdown
138 heading2: '{lang}wcf.editor.format.heading2{/lang}',
139 heading3: '{lang}wcf.editor.format.heading3{/lang}',
140 heading4: '{lang}wcf.editor.format.heading4{/lang}',
141 paragraph: '{lang}wcf.editor.format.paragraph{/lang}',
142
8399847c
AE
143 // links
144 'link-edit': '{lang}wcf.editor.link.edit{/lang}',
145 'link-insert': '{lang}wcf.editor.link.add{/lang}',
146 unlink: '{lang}wcf.editor.link.unlink{/lang}',
147
148 // text alignment
dcb74ba6
AE
149 'align-center': '{lang}wcf.editor.alignment.center{/lang}',
150 'align-justify': '{lang}wcf.editor.alignment.justify{/lang}',
151 'align-left': '{lang}wcf.editor.alignment.left{/lang}',
152 'align-right': '{lang}wcf.editor.alignment.right{/lang}',
153
eb104f97
AE
154 // table plugin
155 'add-head': '{lang}wcf.editor.table.addHead{/lang}',
156 'delete-column': '{lang}wcf.editor.table.deleteColumn{/lang}',
157 'delete-head': '{lang}wcf.editor.table.deleteHead{/lang}',
158 'delete-row': '{lang}wcf.editor.table.deleteRow{/lang}',
159 'delete-table': '{lang}wcf.editor.table.deleteTable{/lang}',
160 'insert-table': '{lang}wcf.editor.table.insertTable{/lang}',
161 'insert-column-left': '{lang}wcf.editor.table.insertColumnLeft{/lang}',
162 'insert-column-right': '{lang}wcf.editor.table.insertColumnRight{/lang}',
163 'insert-row-above': '{lang}wcf.editor.table.insertRowAbove{/lang}',
2aadba64
AE
164 'insert-row-below': '{lang}wcf.editor.table.insertRowBelow{/lang}',
165
166 // size
167 'remove-size': '{lang}wcf.editor.button.size.removeSize{/lang}',
168
169 // color
d809bfdd 170 'remove-color': '{lang}wcf.editor.button.color.removeColor{/lang}'
eb104f97
AE
171 }
172 },
533094eb
AE
173 linkify: false,
174 linkSize: 0xBADC0DED, // some random value to disable truncating
e709be77 175 minHeight: 200,
2ccc7e0e 176 //placeholder: elData(element, 'placeholder') || '',
e709be77 177 plugins: [
8399847c 178 // Imperavi
e709be77
AE
179 'alignment',
180 'source',
181 'table',
8399847c
AE
182
183 // WoltLab specials
184 'WoltLabBlock',
3919fbc8 185 'WoltLabEvent',
8399847c
AE
186 'WoltLabKeydown',
187
188 // WoltLab core
dcb74ba6 189 'WoltLabAlignment',
e709be77 190 'WoltLabAttachment',
21b3c837 191 'WoltLabAutosave',
5a7a1cd8 192 'WoltLabCaret',
d809bfdd 193 'WoltLabClean',
eb104f97 194 'WoltLabCode',
e709be77
AE
195 'WoltLabColor',
196 'WoltLabDropdown',
e709be77 197 'WoltLabImage',
eb104f97 198 'WoltLabInlineCode',
d809bfdd 199 'WoltLabInsert',
e709be77 200 'WoltLabLink',
2ccc7e0e 201 'WoltLabList',
e709be77 202 'WoltLabModal',
0ce51dff 203 'WoltLabPaste',
e709be77
AE
204 'WoltLabQuote',
205 'WoltLabSize',
eb104f97 206 'WoltLabSmiley',
d809bfdd 207 'WoltLabSource',
8dbbbdef
AE
208 'WoltLabSpoiler',
209 'WoltLabUtils'
e709be77
AE
210 ],
211 toolbarFixed: false,
212 woltlab: {
213 autosave: autosave,
7d753078 214 buttons: buttonOptions,
8399847c 215 buttonMobile: buttonMobile,
eb104f97 216 customButtons: customButtons,
2ccc7e0e
AE
217 highlighters: highlighters,
218 placeholderCallback: placeholderCallback
e709be77
AE
219 }
220 };
221
222 // user mentions
223 if (elDataBool(element, 'support-mention')) {
224 config.plugins.push('WoltLabMention');
225 }
226
227 // media
228 {if $__wcf->session->getPermission('admin.content.cms.canUseMedia')}
229 config.plugins.push('WoltLabMedia');
230 {/if}
231
c540a503 232 {if $__redactorConfig|isset}{@$__redactorConfig}{/if}
c516794d 233 {assign var=__redactorConfig value=''}
c540a503
AE
234
235 {event name='redactorConfig'}
236
e5c625ac
AE
237 // load the button plugin last to ensure all buttons have been initialized
238 // already and we can safely add all icons
239 config.plugins.push('WoltLabButton');
240
2aadba64
AE
241 var content = element.value;
242 element.value = '';
243
244 config.callbacks = config.callbacks || { };
245 config.callbacks.init = function() {
2ccc7e0e
AE
246 var editor = element.previousElementSibling;
247 if (replyContainer) {
248 elData(editor, 'reply-placeholder', elData(element, 'reply-placeholder'));
249 }
250
2aadba64
AE
251 // slight delay to allow Redactor to initialize itself
252 window.setTimeout(function() {
253 $(element).redactor('code.set', content);
2ccc7e0e 254 editor.classList.add('redactorReady');
2aadba64
AE
255 }, 10);
256 };
257
e709be77
AE
258 $(element).redactor(config);
259 });
ed3f188f 260 });
ed3f188f 261</script>