[2738] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @brief dcCKEditor, a plugin for Dotclear 2 |
---|
| 4 | * |
---|
| 5 | * @package Dotclear |
---|
| 6 | * @subpackage Plugins |
---|
| 7 | * |
---|
| 8 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 9 | * @copyright GPL-2.0-only |
---|
| 10 | */ |
---|
[2738] | 11 | |
---|
[3730] | 12 | if (!defined('DC_CONTEXT_ADMIN')) {return;} |
---|
[3367] | 13 | |
---|
[2738] | 14 | header('Content-type: text/javascript'); |
---|
[3367] | 15 | |
---|
[2761] | 16 | if (!empty($_GET['context'])) { |
---|
[3730] | 17 | $context = $_GET['context']; |
---|
[2761] | 18 | } else { |
---|
[3730] | 19 | $context = ''; |
---|
[2761] | 20 | } |
---|
[3367] | 21 | |
---|
[2738] | 22 | $__extraPlugins = new ArrayObject(); |
---|
[3730] | 23 | $core->callBehavior('ckeditorExtraPlugins', $__extraPlugins, $context); |
---|
[2738] | 24 | $extraPlugins = $__extraPlugins->getArrayCopy(); |
---|
[3367] | 25 | |
---|
[2738] | 26 | ?> |
---|
[3367] | 27 | |
---|
[2738] | 28 | (function($) { |
---|
[3730] | 29 | $.toolbarPopup = function toolbarPopup(url) { |
---|
| 30 | if (dotclear.admin_base_url != '') { |
---|
| 31 | var pos = url.indexOf(dotclear.admin_base_url); |
---|
| 32 | if (pos == -1) { |
---|
| 33 | url = dotclear.admin_base_url + url; |
---|
| 34 | } |
---|
| 35 | } |
---|
[2962] | 36 | |
---|
[3730] | 37 | var args = Array.prototype.slice.call(arguments); |
---|
| 38 | var width = 520, height = 420; |
---|
| 39 | if (args[1]!==undefined) { |
---|
| 40 | width = args[1].width || width; |
---|
| 41 | height = args[1].height || height; |
---|
| 42 | } |
---|
[2835] | 43 | |
---|
[3730] | 44 | var popup_params = 'alwaysRaised=yes,dependent=yes,toolbar=yes,'; |
---|
| 45 | popup_params += 'height='+height+',width='+width+',menubar=no,resizable=yes,scrollbars=yes,status=no'; |
---|
| 46 | var popup_link = window.open(url,'dc_popup', popup_params); |
---|
| 47 | }; |
---|
[2738] | 48 | |
---|
[3730] | 49 | $.stripBaseURL = function stripBaseURL(url) { |
---|
| 50 | if (dotclear.base_url != '') { |
---|
| 51 | var pos = url.indexOf(dotclear.base_url); |
---|
| 52 | if (pos == 0) { |
---|
| 53 | url = url.substr(dotclear.base_url.length); |
---|
| 54 | } |
---|
| 55 | } |
---|
[2751] | 56 | |
---|
[3730] | 57 | return url; |
---|
| 58 | }; |
---|
[2738] | 59 | |
---|
[3730] | 60 | /* Retrieve editor from popup */ |
---|
| 61 | $.active_editor = null; |
---|
| 62 | $.getEditorName = function getEditorName() { |
---|
| 63 | return $.active_editor; |
---|
| 64 | } |
---|
| 65 | chainHandler(window,'onbeforeunload',function(e) { |
---|
| 66 | if (e == undefined && window.event) { |
---|
| 67 | e = window.event; |
---|
| 68 | } |
---|
[2816] | 69 | |
---|
[3730] | 70 | var editor = CKEDITOR.instances[$.getEditorName()]; |
---|
| 71 | if (editor !== undefined && !confirmClosePage.formSubmit && editor.checkDirty()) { |
---|
| 72 | e.returnValue = confirmClosePage.prompt; |
---|
| 73 | return confirmClosePage.prompt; |
---|
| 74 | } |
---|
| 75 | return false; |
---|
| 76 | }); |
---|
[2738] | 77 | })(jQuery); |
---|
| 78 | |
---|
| 79 | $(function() { |
---|
[3730] | 80 | /* By default ckeditor load related resources with a timestamp to avoid cache problem when upgrading itself |
---|
| 81 | * load_plugin_file.php does not allow other param that file to load (pf param), so remove timestamp |
---|
| 82 | */ |
---|
[2738] | 83 | |
---|
[3730] | 84 | CKEDITOR.timestamp = ''; |
---|
[3367] | 85 | |
---|
| 86 | <?php if (!isset($dcckeditor_disable_native_spellchecker) || $dcckeditor_disable_native_spellchecker): ?> |
---|
[3730] | 87 | CKEDITOR.config.disableNativeSpellChecker = true; |
---|
[3367] | 88 | <?php else: ?> |
---|
[3730] | 89 | CKEDITOR.config.disableNativeSpellChecker = false; |
---|
| 90 | <?php endif;?> |
---|
[3367] | 91 | |
---|
[3730] | 92 | CKEDITOR.config.skin = 'dotclear,'+dotclear.dcckeditor_plugin_url+'/js/ckeditor-skins/dotclear/'; |
---|
| 93 | CKEDITOR.config.baseHref = dotclear.base_url; |
---|
| 94 | CKEDITOR.config.height = '<?php echo $core->auth->getOption('edit_size') * 14; ?>px'; |
---|
[2738] | 95 | |
---|
[3367] | 96 | <?php if (!empty($dcckeditor_cancollapse_button)): ?> |
---|
[3730] | 97 | CKEDITOR.config.toolbarCanCollapse = true; |
---|
| 98 | <?php endif;?> |
---|
[2751] | 99 | |
---|
[3730] | 100 | CKEDITOR.plugins.addExternal('entrylink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/entrylink/'); |
---|
| 101 | CKEDITOR.plugins.addExternal('dclink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/dclink/'); |
---|
| 102 | CKEDITOR.plugins.addExternal('media',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/media/'); |
---|
| 103 | CKEDITOR.plugins.addExternal('img',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/img/'); |
---|
[3367] | 104 | |
---|
| 105 | <?php if (!empty($dcckeditor_textcolor_button) || !empty($dcckeditor_background_textcolor_button)): ?> |
---|
[3730] | 106 | // button add "More Colors..." can be added if colordialog plugin is enabled |
---|
| 107 | CKEDITOR.config.colorButton_enableMore = true; |
---|
| 108 | <?php endif;?> |
---|
[2738] | 109 | |
---|
[3367] | 110 | <?php |
---|
[3730] | 111 | if (!empty($extraPlugins) && count($extraPlugins) > 0) { |
---|
| 112 | foreach ($extraPlugins as $plugin) { |
---|
| 113 | printf("\tCKEDITOR.plugins.addExternal('%s','%s');\n", $plugin['name'], $plugin['url']); |
---|
| 114 | } |
---|
| 115 | } |
---|
[2738] | 116 | ?> |
---|
[3730] | 117 | if (dotclear.ckeditor_context === undefined || dotclear.ckeditor_tags_context[dotclear.ckeditor_context] === undefined) { |
---|
| 118 | return; |
---|
| 119 | } |
---|
| 120 | $(dotclear.ckeditor_tags_context[dotclear.ckeditor_context].join(',')).ckeditor({ |
---|
[3367] | 121 | |
---|
[2738] | 122 | <?php |
---|
[3730] | 123 | $defautExtraPlugins = 'entrylink,dclink,media,justify,colorbutton,format,img'; |
---|
| 124 | if (!empty($extraPlugins) && count($extraPlugins) > 0) { |
---|
| 125 | foreach ($extraPlugins as $plugin) { |
---|
| 126 | $defautExtraPlugins .= ',' . $plugin['name']; |
---|
| 127 | } |
---|
| 128 | } |
---|
[2738] | 129 | ?> |
---|
[3730] | 130 | extraPlugins: '<?php echo $defautExtraPlugins; ?>', |
---|
[2738] | 131 | |
---|
[3730] | 132 | keystrokes: [ |
---|
| 133 | [ CKEDITOR.CTRL + (CKEDITOR.env.mac ? CKEDITOR.ALT : CKEDITOR.SHIFT) + |
---|
| 134 | dotclear.msg.link_accesskey.toUpperCase().charCodeAt(0),'dcLinkCommand' ], // Ctrl+Alt+l |
---|
| 135 | [ CKEDITOR.CTRL + (CKEDITOR.env.mac ? CKEDITOR.ALT : CKEDITOR.SHIFT) + |
---|
| 136 | dotclear.msg.img_select_accesskey.toUpperCase().charCodeAt(0),'mediaCommand' ], // Ctrl+Alt+m |
---|
| 137 | ], |
---|
[3362] | 138 | |
---|
[3367] | 139 | <?php if (!empty($dcckeditor_format_select)): ?> |
---|
[3730] | 140 | // format tags |
---|
[3367] | 141 | |
---|
[3730] | 142 | <?php if (!empty($dcckeditor_format_tags)): ?> |
---|
| 143 | format_tags: '<?php echo $dcckeditor_format_tags; ?>', |
---|
| 144 | <?php else: ?> |
---|
| 145 | format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;address', |
---|
| 146 | <?php endif;?> |
---|
[3367] | 147 | |
---|
[3730] | 148 | // following definition are needed to be specialized |
---|
| 149 | format_p: { element: 'p' }, |
---|
| 150 | format_h1: { element: 'h1' }, |
---|
| 151 | format_h2: { element: 'h2' }, |
---|
| 152 | format_h3: { element: 'h3' }, |
---|
| 153 | format_h4: { element: 'h4' }, |
---|
| 154 | format_h5: { element: 'h5' }, |
---|
| 155 | format_h6: { element: 'h6' }, |
---|
| 156 | format_pre: { element: 'pre' }, |
---|
| 157 | format_address: { element: 'address' }, |
---|
| 158 | <?php endif;?> |
---|
[2738] | 159 | |
---|
[3730] | 160 | entities: false, |
---|
| 161 | removeButtons: '', |
---|
| 162 | allowedContent: true, |
---|
| 163 | toolbar: [ |
---|
| 164 | { |
---|
| 165 | name: 'basicstyles', |
---|
| 166 | items: [ |
---|
[3367] | 167 | |
---|
| 168 | <?php if (!empty($dcckeditor_format_select)): ?> |
---|
[3730] | 169 | 'Format', |
---|
[2738] | 170 | <?php endif;?> |
---|
[3367] | 171 | |
---|
[3730] | 172 | 'Bold','Italic','Underline','Strike','Subscript','Superscript','Code','Blockquote', |
---|
[2751] | 173 | |
---|
[3367] | 174 | <?php if (!empty($dcckeditor_list_buttons)): ?> |
---|
[3730] | 175 | 'NumberedList','BulletedList', |
---|
| 176 | <?php endif;?> |
---|
[3367] | 177 | |
---|
[3730] | 178 | 'RemoveFormat' |
---|
| 179 | ] |
---|
| 180 | }, |
---|
[3367] | 181 | |
---|
| 182 | <?php if (!empty($dcckeditor_clipboard_buttons)): ?> |
---|
[3730] | 183 | { |
---|
| 184 | name: 'clipoard', |
---|
| 185 | items: ['Cut','Copy','Paste','PasteText','PasteFromWord'] |
---|
| 186 | }, |
---|
| 187 | <?php endif;?> |
---|
[3367] | 188 | |
---|
| 189 | <?php if (!empty($dcckeditor_alignment_buttons)): ?> |
---|
[3730] | 190 | { |
---|
| 191 | name: 'paragraph', |
---|
| 192 | items: ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'] |
---|
| 193 | }, |
---|
| 194 | <?php endif;?> |
---|
[3367] | 195 | |
---|
| 196 | <?php if (!empty($dcckeditor_table_button)): ?> |
---|
[3730] | 197 | { |
---|
| 198 | name: 'table', |
---|
| 199 | items: ['Table'] |
---|
| 200 | }, |
---|
| 201 | <?php endif;?> |
---|
[3367] | 202 | |
---|
[3730] | 203 | { |
---|
| 204 | name: 'custom', |
---|
| 205 | items: [ |
---|
| 206 | 'EntryLink','dcLink','Media','img','-', |
---|
| 207 | 'Source' |
---|
[3367] | 208 | |
---|
| 209 | <?php if (!empty($dcckeditor_textcolor_button)): ?> |
---|
[3730] | 210 | ,'TextColor' |
---|
| 211 | <?php endif;?> |
---|
[3367] | 212 | |
---|
| 213 | <?php if (!empty($dcckeditor_background_textcolor_button)): ?> |
---|
[3730] | 214 | ,'BGColor' |
---|
| 215 | <?php endif;?> |
---|
| 216 | ] |
---|
| 217 | }, |
---|
| 218 | { |
---|
| 219 | name: 'special', |
---|
| 220 | items: [ |
---|
| 221 | 'Maximize' |
---|
| 222 | ] |
---|
| 223 | }, |
---|
[3367] | 224 | |
---|
| 225 | <?php // add extra buttons comming from dotclear plugins |
---|
[3730] | 226 | if (!empty($extraPlugins) && count($extraPlugins) > 0) { |
---|
| 227 | $extraPlugins_str = "{name: 'extra', items: [%s]},\n"; |
---|
| 228 | $extra_icons = ''; |
---|
| 229 | foreach ($extraPlugins as $plugin) { |
---|
| 230 | $extra_icons .= sprintf("'%s',", $plugin['button']); |
---|
| 231 | } |
---|
| 232 | printf($extraPlugins_str, $extra_icons); |
---|
| 233 | } |
---|
[3367] | 234 | ?> |
---|
[3730] | 235 | ] |
---|
| 236 | }); |
---|
[2738] | 237 | |
---|
[3730] | 238 | CKEDITOR.on('instanceLoaded',function(e) { |
---|
[3367] | 239 | |
---|
[3730] | 240 | // Retrieve textarea element of the instance, then its line-height (in px) and rows values, |
---|
| 241 | // then apply line-height * rows (min = 6) to the inner height of the instance. |
---|
[3367] | 242 | |
---|
[3730] | 243 | var ta = document.getElementById(e.editor.name); |
---|
| 244 | if (ta !== undefined) { |
---|
| 245 | var ta_rows = ta.rows; |
---|
| 246 | var ta_line_height = parseFloat(window.getComputedStyle(ta,null).getPropertyValue('line-height')); |
---|
| 247 | if (ta_rows > 0 && ta_line_height > 0) { |
---|
| 248 | var ta_height = String(Math.max(ta_rows,6) * ta_line_height); |
---|
| 249 | e.editor.resize('100%',ta_height,true); |
---|
| 250 | } |
---|
| 251 | } |
---|
[3669] | 252 | |
---|
[3730] | 253 | }); |
---|
[3670] | 254 | |
---|
[3730] | 255 | CKEDITOR.on('instanceReady',function(e) { |
---|
| 256 | if (typeof dotclear_htmlFontSize !== 'undefined') { |
---|
| 257 | e.editor.document.$.documentElement.style.setProperty('--html-font-size',dotclear_htmlFontSize); |
---|
| 258 | } |
---|
[3367] | 259 | |
---|
[3769] | 260 | if ($('label[for="post_excerpt"] input').attr('aria-label') == dotclear.img_minus_alt) { |
---|
[3730] | 261 | $('#cke_post_excerpt').removeClass('hide'); |
---|
| 262 | } else { |
---|
| 263 | $('#cke_post_excerpt').addClass('hide'); |
---|
| 264 | } |
---|
[2751] | 265 | |
---|
[3730] | 266 | $('#excerpt-area label').click(function() { |
---|
| 267 | $('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide')); |
---|
| 268 | }); |
---|
[3640] | 269 | |
---|
[3730] | 270 | }); |
---|
[2751] | 271 | |
---|
[3730] | 272 | // @TODO: find a better way to retrieve active editor |
---|
| 273 | for (var id in CKEDITOR.instances) { |
---|
| 274 | CKEDITOR.instances[id].on('focus',function(e) { |
---|
| 275 | $.active_editor = e.editor.name; |
---|
| 276 | }); |
---|
| 277 | } |
---|
[2738] | 278 | }); |
---|