[2738] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[2972] | 6 | # Copyright (c) 2003-2015 Olivier Meunier & Association Dotclear |
---|
[2738] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | |
---|
| 13 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
| 14 | header('Content-type: text/javascript'); |
---|
[2761] | 15 | if (!empty($_GET['context'])) { |
---|
| 16 | $context = $_GET['context']; |
---|
| 17 | } else { |
---|
| 18 | $context = ''; |
---|
| 19 | } |
---|
[2738] | 20 | $__extraPlugins = new ArrayObject(); |
---|
[2761] | 21 | $core->callBehavior('ckeditorExtraPlugins',$__extraPlugins,$context); |
---|
[2738] | 22 | $extraPlugins = $__extraPlugins->getArrayCopy(); |
---|
| 23 | ?> |
---|
| 24 | (function($) { |
---|
| 25 | $.toolbarPopup = function toolbarPopup(url) { |
---|
[2962] | 26 | if (dotclear.admin_base_url != '') { |
---|
| 27 | var pos = url.indexOf(dotclear.admin_base_url); |
---|
| 28 | if (pos == -1) { |
---|
| 29 | url = dotclear.admin_base_url + url; |
---|
| 30 | } |
---|
| 31 | } |
---|
| 32 | |
---|
[2835] | 33 | var args = Array.prototype.slice.call(arguments); |
---|
| 34 | var width = 520, height = 420; |
---|
| 35 | if (args[1]!==undefined) { |
---|
| 36 | width = args[1].width || width; |
---|
| 37 | height = args[1].height || height; |
---|
| 38 | } |
---|
| 39 | |
---|
[2738] | 40 | var popup_params = 'alwaysRaised=yes,dependent=yes,toolbar=yes,'; |
---|
[2835] | 41 | popup_params += 'height='+height+',width='+width+',menubar=no,resizable=yes,scrollbars=yes,status=no'; |
---|
[2738] | 42 | var popup_link = window.open(url,'dc_popup', popup_params); |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | $.stripBaseURL = function stripBaseURL(url) { |
---|
| 46 | if (dotclear.base_url != '') { |
---|
| 47 | var pos = url.indexOf(dotclear.base_url); |
---|
| 48 | if (pos == 0) { |
---|
| 49 | url = url.substr(dotclear.base_url.length); |
---|
| 50 | } |
---|
| 51 | } |
---|
[2751] | 52 | |
---|
[2738] | 53 | return url; |
---|
| 54 | }; |
---|
| 55 | |
---|
[2751] | 56 | /* Retrieve editor from popup */ |
---|
[2816] | 57 | $.active_editor = null; |
---|
[2751] | 58 | $.getEditorName = function getEditorName() { |
---|
| 59 | return $.active_editor; |
---|
[2738] | 60 | } |
---|
[2816] | 61 | chainHandler(window, 'onbeforeunload', function(e) { |
---|
| 62 | if (e == undefined && window.event) { |
---|
| 63 | e = window.event; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | var editor = CKEDITOR.instances[$.getEditorName()]; |
---|
[2854] | 67 | if (editor!==undefined && !confirmClosePage.formSubmit && editor.checkDirty()) { |
---|
[2816] | 68 | e.returnValue = confirmClosePage.prompt; |
---|
| 69 | return confirmClosePage.prompt; |
---|
| 70 | } |
---|
| 71 | return false; |
---|
| 72 | }); |
---|
[2738] | 73 | })(jQuery); |
---|
| 74 | |
---|
| 75 | $(function() { |
---|
| 76 | /* By default ckeditor load related resources with a timestamp to avoid cache problem when upgrading itself |
---|
| 77 | * load_plugin_file.php does not allow other param that file to load (pf param), so remove timestamp |
---|
| 78 | */ |
---|
| 79 | |
---|
| 80 | CKEDITOR.timestamp = ''; |
---|
[3055] | 81 | <?php if (!isset($dcckeditor_disable_native_spellchecker) || $dcckeditor_disable_native_spellchecker):?> |
---|
| 82 | CKEDITOR.disableNativeSpellChecker = true; |
---|
| 83 | <?php else:?> |
---|
[3052] | 84 | CKEDITOR.disableNativeSpellChecker = false; |
---|
| 85 | <?php endif;?> |
---|
[2738] | 86 | CKEDITOR.config.skin = 'dotclear,'+dotclear.dcckeditor_plugin_url+'/js/ckeditor-skins/dotclear/'; |
---|
[3040] | 87 | CKEDITOR.config.baseHref = dotclear.base_url; |
---|
| 88 | CKEDITOR.config.height = '<?php echo $core->auth->getOption('edit_size') * 14;?>px'; |
---|
[2738] | 89 | |
---|
[2751] | 90 | <?php if (!empty($dcckeditor_cancollapse_button)):?> |
---|
[2738] | 91 | CKEDITOR.config.toolbarCanCollapse = true; |
---|
| 92 | <?php endif;?> |
---|
[2751] | 93 | |
---|
| 94 | CKEDITOR.plugins.addExternal('entrylink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/entrylink/'); |
---|
[2738] | 95 | CKEDITOR.plugins.addExternal('dclink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/dclink/'); |
---|
| 96 | CKEDITOR.plugins.addExternal('media',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/media/'); |
---|
[2869] | 97 | CKEDITOR.plugins.addExternal('img',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/img/'); |
---|
[2738] | 98 | |
---|
| 99 | <?php if (!empty($extraPlugins) && count($extraPlugins)>0) { |
---|
| 100 | foreach ($extraPlugins as $plugin) { |
---|
| 101 | printf("\tCKEDITOR.plugins.addExternal('%s','%s');\n", $plugin['name'], $plugin['url']); |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | ?> |
---|
[3052] | 105 | if (dotclear.ckeditor_context===undefined || dotclear.ckeditor_tags_context[dotclear.ckeditor_context]===undefined) { |
---|
| 106 | return; |
---|
| 107 | } |
---|
[2854] | 108 | $(dotclear.ckeditor_tags_context[dotclear.ckeditor_context].join(',')).ckeditor({ |
---|
[2738] | 109 | <?php |
---|
[2869] | 110 | $defautExtraPlugins = 'entrylink,dclink,media,justify,colorbutton,format,img'; |
---|
[2738] | 111 | if (!empty($extraPlugins) && count($extraPlugins)>0) { |
---|
| 112 | foreach ($extraPlugins as $plugin) { |
---|
| 113 | $defautExtraPlugins .= ','. $plugin['name']; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | ?> |
---|
| 117 | extraPlugins: '<?php echo $defautExtraPlugins;?>', |
---|
| 118 | |
---|
[2751] | 119 | <?php if (!empty($dcckeditor_format_select)):?> |
---|
[2738] | 120 | // format tags |
---|
[2972] | 121 | <?php if (!empty($dcckeditor_format_tags)):?> |
---|
| 122 | format_tags: '<?php echo $dcckeditor_format_tags;?>', |
---|
| 123 | <?php else:?> |
---|
[2738] | 124 | format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;address', |
---|
[2972] | 125 | <?php endif;?> |
---|
[2738] | 126 | // following definition are needed to be specialized |
---|
| 127 | format_p: { element: 'p' }, |
---|
| 128 | format_h1: { element: 'h1' }, |
---|
| 129 | format_h2: { element: 'h2' }, |
---|
| 130 | format_h3: { element: 'h3' }, |
---|
| 131 | format_h4: { element: 'h4' }, |
---|
| 132 | format_h5: { element: 'h5' }, |
---|
| 133 | format_h6: { element: 'h6' }, |
---|
| 134 | format_pre: { element: 'pre' }, |
---|
| 135 | format_address: { element: 'address' }, |
---|
| 136 | <?php endif;?> |
---|
| 137 | |
---|
| 138 | entities: false, |
---|
| 139 | removeButtons: '', |
---|
| 140 | allowedContent: true, |
---|
| 141 | toolbar: [ |
---|
| 142 | { |
---|
| 143 | name: 'basicstyles', |
---|
| 144 | items: [ |
---|
| 145 | <?php if (!empty($dcckeditor_format_select)):?> |
---|
| 146 | 'Format', |
---|
| 147 | <?php endif;?> |
---|
| 148 | 'Bold','Italic','Underline','Strike','Subscript','Superscript','Code','Blockquote', |
---|
[2751] | 149 | |
---|
[2738] | 150 | <?php if (!empty($dcckeditor_list_buttons)):?> |
---|
| 151 | 'NumberedList', 'BulletedList', |
---|
| 152 | <?php endif;?> |
---|
| 153 | 'RemoveFormat' |
---|
| 154 | ] |
---|
| 155 | }, |
---|
| 156 | <?php if (!empty($dcckeditor_clipboard_buttons)):?> |
---|
| 157 | { |
---|
| 158 | name: 'clipoard', |
---|
| 159 | items: ['Cut','Copy','Paste','PasteText','PasteFromWord'] |
---|
| 160 | }, |
---|
| 161 | <?php endif;?> |
---|
| 162 | <?php if (!empty($dcckeditor_alignment_buttons)):?> |
---|
| 163 | { |
---|
| 164 | name: 'paragraph', |
---|
| 165 | items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] |
---|
| 166 | }, |
---|
| 167 | <?php endif;?> |
---|
| 168 | <?php if (!empty($dcckeditor_table_button)):?> |
---|
| 169 | { |
---|
| 170 | name: 'table', |
---|
| 171 | items: ['Table'] |
---|
| 172 | }, |
---|
| 173 | <?php endif;?> |
---|
| 174 | { |
---|
| 175 | name: 'custom', |
---|
| 176 | items: [ |
---|
[2869] | 177 | 'EntryLink','dcLink','Media','img','-', |
---|
[2854] | 178 | 'Source' |
---|
[2738] | 179 | <?php if (!empty($dcckeditor_textcolor_button)):?> |
---|
| 180 | ,'TextColor' |
---|
| 181 | <?php endif;?> |
---|
[2751] | 182 | ] |
---|
[2738] | 183 | }, |
---|
[2854] | 184 | { |
---|
| 185 | name: 'special', |
---|
| 186 | items: [ |
---|
| 187 | 'Maximize' |
---|
| 188 | ] |
---|
| 189 | }, |
---|
[2738] | 190 | <?php // add extra buttons comming from dotclear plugins |
---|
| 191 | if (!empty($extraPlugins) && count($extraPlugins)>0) { |
---|
| 192 | $extraPlugins_str = "{name: 'extra', items: [%s]},\n"; |
---|
| 193 | $extra_icons = ''; |
---|
| 194 | foreach ($extraPlugins as $plugin) { |
---|
| 195 | $extra_icons .= sprintf("'%s',", $plugin['button']); |
---|
| 196 | } |
---|
| 197 | printf($extraPlugins_str, $extra_icons); |
---|
| 198 | } |
---|
| 199 | ?> |
---|
| 200 | ] |
---|
| 201 | }); |
---|
| 202 | |
---|
| 203 | CKEDITOR.on('instanceReady', function(e) { |
---|
| 204 | if ($('label[for="post_excerpt"] a img').attr('src')==dotclear.img_minus_src) { |
---|
| 205 | $('#cke_post_excerpt').removeClass('hide'); |
---|
| 206 | } else { |
---|
| 207 | $('#cke_post_excerpt').addClass('hide'); |
---|
| 208 | } |
---|
[2751] | 209 | |
---|
[2738] | 210 | $('#excerpt-area label').click(function() { |
---|
| 211 | $('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide')); |
---|
| 212 | }); |
---|
| 213 | }); |
---|
[2751] | 214 | |
---|
| 215 | // @TODO: find a better way to retrieve active editor |
---|
| 216 | for (var id in CKEDITOR.instances) { |
---|
| 217 | CKEDITOR.instances[id].on('focus', function(e) { |
---|
| 218 | $.active_editor = e.editor.name; |
---|
| 219 | }); |
---|
| 220 | } |
---|
[2738] | 221 | }); |
---|