Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / com.woltlab.wcf / templates / wysiwyg.tpl
1 <script data-relocate="true">
2 var __REDACTOR_ICON_PATH = '{@$__wcf->getPath()}icon/';
3 var __REDACTOR_BUTTONS = [ {implode from=$__wcf->getBBCodeHandler()->getButtonBBCodes() item=__bbcode}{ icon: '{$__bbcode->wysiwygIcon}', label: '{$__bbcode->buttonLabel|language}', name: '{$__bbcode->bbcodeTag}' }{/implode} ];
4 var __REDACTOR_SMILIES = { {implode from=$__wcf->getSmileyCache()->getCategorySmilies() item=smiley}'{@$smiley->smileyCode|encodeJS}': '{@$smiley->getURL()|encodeJS}'{/implode} };
5 var __REDACTOR_SOURCE_BBCODES = [ {implode from=$__wcf->getBBCodeHandler()->getSourceBBCodes() item=__bbcode}'{@$__bbcode->bbcodeTag}'{/implode} ];
6 var __REDACTOR_CODE_HIGHLIGHTERS = { {implode from=$__wcf->getBBCodeHandler()->getHighlighters() item=__highlighter}'{@$__highlighter}': '{lang}wcf.bbcode.code.{@$__highlighter}.title{/lang}'{/implode} };
7 </script>
8 <script data-relocate="true">
9 $(function() {
10 WCF.Language.addObject({
11 'wcf.attachment.dragAndDrop.dropHere': '{lang}wcf.attachment.dragAndDrop.dropHere{/lang}',
12 'wcf.attachment.dragAndDrop.dropNow': '{lang}wcf.attachment.dragAndDrop.dropNow{/lang}',
13 'wcf.bbcode.button.fontColor': '{lang}wcf.bbcode.button.fontColor{/lang}',
14 'wcf.bbcode.button.fontFamily': '{lang}wcf.bbcode.button.fontFamily{/lang}',
15 'wcf.bbcode.button.fontSize': '{lang}wcf.bbcode.button.fontSize{/lang}',
16 'wcf.bbcode.button.image': '{lang}wcf.bbcode.button.image{/lang}',
17 'wcf.bbcode.button.redo': '{lang}wcf.bbcode.button.redo{/lang}',
18 'wcf.bbcode.button.subscript': '{lang}wcf.bbcode.button.subscript{/lang}',
19 'wcf.bbcode.button.superscript': '{lang}wcf.bbcode.button.superscript{/lang}',
20 'wcf.bbcode.button.toggleBBCode': '{lang}wcf.bbcode.button.toggleBBCode{/lang}',
21 'wcf.bbcode.button.toggleHTML': '{lang}wcf.bbcode.button.toggleHTML{/lang}',
22 'wcf.bbcode.button.undo': '{lang}wcf.bbcode.button.undo{/lang}',
23 'wcf.bbcode.code': '{lang}wcf.bbcode.code{/lang}',
24 'wcf.bbcode.code.edit': '{lang}wcf.bbcode.code.edit{/lang}',
25 'wcf.bbcode.code.filename': '{lang}wcf.bbcode.code.filename{/lang}',
26 'wcf.bbcode.code.filename.description': '{lang}wcf.bbcode.code.filename.description{/lang}',
27 'wcf.bbcode.code.highlighter': '{lang}wcf.bbcode.code.highlighter{/lang}',
28 'wcf.bbcode.code.highlighter.description': '{lang}wcf.bbcode.code.highlighter.description{/lang}',
29 'wcf.bbcode.code.highlighter.none': '{lang}wcf.bbcode.code.highlighter.none{/lang}',
30 'wcf.bbcode.code.insert': '{lang}wcf.bbcode.code.insert{/lang}',
31 'wcf.bbcode.code.lineNumber': '{lang}wcf.bbcode.code.lineNumber{/lang}',
32 'wcf.bbcode.code.lineNumber.description': '{lang}wcf.bbcode.code.lineNumber.description{/lang}',
33 'wcf.bbcode.code.settings': '{lang}wcf.bbcode.code.settings{/lang}',
34 'wcf.bbcode.image.source': '{lang}wcf.bbcode.image.source{/lang}',
35 'wcf.bbcode.quote.edit': '{lang}wcf.bbcode.quote.edit{/lang}',
36 'wcf.bbcode.quote.edit.author': '{lang}wcf.bbcode.quote.edit.author{/lang}',
37 'wcf.bbcode.quote.edit.link': '{lang}wcf.bbcode.quote.edit.link{/lang}',
38 'wcf.bbcode.quote.insert': '{lang}wcf.bbcode.quote.insert{/lang}',
39 'wcf.bbcode.quote.title.clickToSet': '{lang}wcf.bbcode.quote.title.clickToSet{/lang}',
40 'wcf.bbcode.quote.title.javascript': '{lang}wcf.bbcode.quote.title.javascript{/lang}',
41 'wcf.global.noSelection': '{lang}wcf.global.noSelection{/lang}',
42 'wcf.message.autosave.prompt': '{lang}wcf.message.autosave.prompt{/lang}',
43 'wcf.message.autosave.prompt.confirm': '{lang}wcf.message.autosave.prompt.confirm{/lang}',
44 'wcf.message.autosave.prompt.discard': '{lang}wcf.message.autosave.prompt.discard{/lang}',
45 'wcf.message.autosave.restored': '{lang}wcf.message.autosave.restored{/lang}',
46 'wcf.message.autosave.restored.confirm': '{lang}wcf.message.autosave.restored.confirm{/lang}',
47 'wcf.message.autosave.restored.revert': '{lang}wcf.message.autosave.restored.revert{/lang}',
48 'wcf.message.autosave.restored.revert.confirmMessage': '{lang}wcf.message.autosave.restored.revert.confirmMessage{/lang}',
49 'wcf.message.autosave.restored.version': '{lang __literal=true}wcf.message.autosave.restored.version{/lang}',
50 'wcf.message.autosave.saved': '{lang}wcf.message.autosave.saved{/lang}'
51 });
52
53 var $editorName = '{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}';
54 var $callbackIdentifier = 'Redactor_' + $editorName;
55
56 WCF.System.Dependency.Manager.setup($callbackIdentifier, function() {
57 var $textarea = $('#' + $editorName);
58 var $buttons = [ ];
59
60 {include file='wysiwygToolbar'}
61
62 var $autosave = $textarea.data('autosave');
63 var $autosaveLastEditTime = ($autosave && $textarea.data('autosaveLastEditTime')) ? (parseInt($textarea.data('autosaveLastEditTime')) || 0) : 0;
64 var $autosavePrompt = ($autosave && $textarea.data('autosavePrompt')) ? true : false;
65 var $config = {
66 autosave: false,
67 buttons: $buttons,
68 convertImageLinks: false,
69 convertUrlLinks: false,
70 convertVideoLinks: false,
71 direction: '{lang}wcf.global.pageDirection{/lang}',
72 lang: '{@$__wcf->getLanguage()->getFixedLanguageCode()}',
73 maxHeight: 500,
74 minHeight: 200,
75 plugins: [ 'wutil', 'wmonkeypatch', 'wbutton', 'wbbcode', 'wfontcolor', 'wfontfamily', 'wfontsize' ],
76 removeEmpty: false,
77 replaceDivs: false,
78 source: true,
79 tabifier: false,
80 toolbarFixed: false,
81 woltlab: {
82 autosave: {
83 active: ($autosave) ? true : false,
84 key: ($autosave) ? '{@$__wcf->getAutosavePrefix()}_' + $autosave : '',
85 lastEditTime: $autosaveLastEditTime,
86 prefix: '{@$__wcf->getAutosavePrefix()}',
87 prompt: $autosavePrompt,
88 saveOnInit: {if !$errorField|empty}true{else}false{/if}
89 },
90 originalValue: $textarea.val()
91 }
92 };
93
94 {if $__wcf->getBBCodeHandler()->isAvailableBBCode('table')}
95 $config.plugins.splice(2, 0, 'table');
96 {/if}
97
98 if ($.browser.iOS) {
99 // using a zero-width space breaks iOS' detection of the start of a sentence, causing the first word to be lowercased
100 $config.emptyHtml = '<p><br></p>';
101 }
102
103 {if MODULE_ATTACHMENT && !$attachmentHandler|empty && $attachmentHandler->canUpload()}
104 $config.plugins.push('wupload');
105 $config.woltlab.attachmentUrl = '{link controller='Attachment' id=987654321}{/link}';
106 $config.woltlab.attachmentThumbnailUrl = '{link controller='Attachment' id=987654321}thumbnail=1{/link}';
107 {/if}
108
109 {event name='javascriptInit'}
110
111 // clear textarea before init
112 $textarea.val('');
113
114 $textarea.redactor($config);
115 });
116
117 head.load([
118 '{@$__wcf->getPath()}js/3rdParty/redactor/redactor{if !ENABLE_DEBUG_MODE}.min{/if}.js?v={@LAST_UPDATE_TIME}',
119 {if $__wcf->getLanguage()->getFixedLanguageCode() != 'en'}'{@$__wcf->getPath()}js/3rdParty/redactor/languages/{@$__wcf->getLanguage()->getFixedLanguageCode()}.js?v={@LAST_UPDATE_TIME}',{/if}
120 {if !ENABLE_DEBUG_MODE}
121 '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wcombined.min.js?v={@LAST_UPDATE_TIME}'
122 {else}
123 {* official *}
124 '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/table.js?v={@LAST_UPDATE_TIME}',
125
126 {* WoltLab *}
127 '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wbbcode.js?v={@LAST_UPDATE_TIME}',
128 '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wbutton.js?v={@LAST_UPDATE_TIME}',
129 '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wfontcolor.js?v={@LAST_UPDATE_TIME}',
130 '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wfontfamily.js?v={@LAST_UPDATE_TIME}',
131 '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wfontsize.js?v={@LAST_UPDATE_TIME}',
132 '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wmonkeypatch.js?v={@LAST_UPDATE_TIME}',
133 '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wutil.js?v={@LAST_UPDATE_TIME}',
134 '{@$__wcf->getPath()}js/3rdParty/redactor/plugins/wupload.js?v={@LAST_UPDATE_TIME}'
135 {/if}
136 {event name='javascriptFiles'}
137 ], function() {
138 WCF.System.Dependency.Manager.invoke($callbackIdentifier);
139 });
140 });
141 </script>