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