| 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'); | 
|---|
| 15 | if (!empty($_GET['context'])) { | 
|---|
| 16 | $context = $_GET['context']; | 
|---|
| 17 | } else { | 
|---|
| 18 | $context = ''; | 
|---|
| 19 | } | 
|---|
| 20 | $__extraPlugins = new ArrayObject(); | 
|---|
| 21 | $core->callBehavior('ckeditorExtraPlugins',$__extraPlugins,$context); | 
|---|
| 22 | $extraPlugins = $__extraPlugins->getArrayCopy(); | 
|---|
| 23 | ?> | 
|---|
| 24 | (function($) { | 
|---|
| 25 | $.toolbarPopup = function toolbarPopup(url) { | 
|---|
| 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 |  | 
|---|
| 33 | var popup_params = 'alwaysRaised=yes,dependent=yes,toolbar=yes,'; | 
|---|
| 34 | popup_params += 'height='+height+',width='+width+',menubar=no,resizable=yes,scrollbars=yes,status=no'; | 
|---|
| 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 | } | 
|---|
| 45 |  | 
|---|
| 46 | return url; | 
|---|
| 47 | }; | 
|---|
| 48 |  | 
|---|
| 49 | /* Retrieve editor from popup */ | 
|---|
| 50 | $.active_editor = null; | 
|---|
| 51 | $.getEditorName = function getEditorName() { | 
|---|
| 52 | return $.active_editor; | 
|---|
| 53 | } | 
|---|
| 54 | chainHandler(window, 'onbeforeunload', function(e) { | 
|---|
| 55 | if (e == undefined && window.event) { | 
|---|
| 56 | e = window.event; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | var editor = CKEDITOR.instances[$.getEditorName()]; | 
|---|
| 60 | if (editor!==undefined && !confirmClosePage.formSubmit && editor.checkDirty()) { | 
|---|
| 61 | e.returnValue = confirmClosePage.prompt; | 
|---|
| 62 | return confirmClosePage.prompt; | 
|---|
| 63 | } | 
|---|
| 64 | return false; | 
|---|
| 65 | }); | 
|---|
| 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/'; | 
|---|
| 75 | CKEDITOR.config.baseHref = dotclear.base_url; | 
|---|
| 76 |  | 
|---|
| 77 | <?php if (!empty($dcckeditor_cancollapse_button)):?> | 
|---|
| 78 | CKEDITOR.config.toolbarCanCollapse = true; | 
|---|
| 79 | <?php endif;?> | 
|---|
| 80 |  | 
|---|
| 81 | CKEDITOR.plugins.addExternal('entrylink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/entrylink/'); | 
|---|
| 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/'); | 
|---|
| 84 |  | 
|---|
| 85 | <?php if (!empty($extraPlugins) && count($extraPlugins)>0) { | 
|---|
| 86 | foreach ($extraPlugins as $plugin) { | 
|---|
| 87 | printf("\tCKEDITOR.plugins.addExternal('%s','%s');\n", $plugin['name'], $plugin['url']); | 
|---|
| 88 | } | 
|---|
| 89 | } | 
|---|
| 90 | ?> | 
|---|
| 91 | if (dotclear.ckeditor_context===undefined || dotclear.ckeditor_tags_context[dotclear.ckeditor_context]===undefined) { | 
|---|
| 92 | return; | 
|---|
| 93 | } | 
|---|
| 94 | $(dotclear.ckeditor_tags_context[dotclear.ckeditor_context].join(',')).ckeditor({ | 
|---|
| 95 | <?php | 
|---|
| 96 | $defautExtraPlugins = 'entrylink,dclink,media,justify,colorbutton,format'; | 
|---|
| 97 | if (!empty($extraPlugins) && count($extraPlugins)>0) { | 
|---|
| 98 | foreach ($extraPlugins as $plugin) { | 
|---|
| 99 | $defautExtraPlugins .= ','. $plugin['name']; | 
|---|
| 100 | } | 
|---|
| 101 | } | 
|---|
| 102 | ?> | 
|---|
| 103 | extraPlugins: '<?php echo $defautExtraPlugins;?>', | 
|---|
| 104 |  | 
|---|
| 105 | <?php if (!empty($dcckeditor_format_select)):?> | 
|---|
| 106 | // format tags | 
|---|
| 107 | format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;address', | 
|---|
| 108 |  | 
|---|
| 109 | // following definition are needed to be specialized | 
|---|
| 110 | format_p: { element: 'p' }, | 
|---|
| 111 | format_h1: { element: 'h1' }, | 
|---|
| 112 | format_h2: { element: 'h2' }, | 
|---|
| 113 | format_h3: { element: 'h3' }, | 
|---|
| 114 | format_h4: { element: 'h4' }, | 
|---|
| 115 | format_h5: { element: 'h5' }, | 
|---|
| 116 | format_h6: { element: 'h6' }, | 
|---|
| 117 | format_pre: { element: 'pre' }, | 
|---|
| 118 | format_address: { element: 'address' }, | 
|---|
| 119 | <?php endif;?> | 
|---|
| 120 |  | 
|---|
| 121 | entities: false, | 
|---|
| 122 | removeButtons: '', | 
|---|
| 123 | allowedContent: true, | 
|---|
| 124 | toolbar: [ | 
|---|
| 125 | { | 
|---|
| 126 | name: 'basicstyles', | 
|---|
| 127 | items: [ | 
|---|
| 128 | <?php if (!empty($dcckeditor_format_select)):?> | 
|---|
| 129 | 'Format', | 
|---|
| 130 | <?php endif;?> | 
|---|
| 131 | 'Bold','Italic','Underline','Strike','Subscript','Superscript','Code','Blockquote', | 
|---|
| 132 |  | 
|---|
| 133 | <?php if (!empty($dcckeditor_list_buttons)):?> | 
|---|
| 134 | 'NumberedList', 'BulletedList', | 
|---|
| 135 | <?php endif;?> | 
|---|
| 136 | 'RemoveFormat' | 
|---|
| 137 | ] | 
|---|
| 138 | }, | 
|---|
| 139 | <?php if (!empty($dcckeditor_clipboard_buttons)):?> | 
|---|
| 140 | { | 
|---|
| 141 | name: 'clipoard', | 
|---|
| 142 | items: ['Cut','Copy','Paste','PasteText','PasteFromWord'] | 
|---|
| 143 | }, | 
|---|
| 144 | <?php endif;?> | 
|---|
| 145 | <?php if (!empty($dcckeditor_alignment_buttons)):?> | 
|---|
| 146 | { | 
|---|
| 147 | name: 'paragraph', | 
|---|
| 148 | items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] | 
|---|
| 149 | }, | 
|---|
| 150 | <?php endif;?> | 
|---|
| 151 | <?php if (!empty($dcckeditor_table_button)):?> | 
|---|
| 152 | { | 
|---|
| 153 | name: 'table', | 
|---|
| 154 | items: ['Table'] | 
|---|
| 155 | }, | 
|---|
| 156 | <?php endif;?> | 
|---|
| 157 | { | 
|---|
| 158 | name: 'custom', | 
|---|
| 159 | items: [ | 
|---|
| 160 | 'EntryLink','dcLink','Media','-', | 
|---|
| 161 | 'Source' | 
|---|
| 162 | <?php if (!empty($dcckeditor_textcolor_button)):?> | 
|---|
| 163 | ,'TextColor' | 
|---|
| 164 | <?php endif;?> | 
|---|
| 165 | ] | 
|---|
| 166 | }, | 
|---|
| 167 | { | 
|---|
| 168 | name: 'special', | 
|---|
| 169 | items: [ | 
|---|
| 170 | 'Maximize' | 
|---|
| 171 | ] | 
|---|
| 172 | }, | 
|---|
| 173 | <?php // add extra buttons comming from dotclear plugins | 
|---|
| 174 | if (!empty($extraPlugins) && count($extraPlugins)>0) { | 
|---|
| 175 | $extraPlugins_str = "{name: 'extra', items: [%s]},\n"; | 
|---|
| 176 | $extra_icons = ''; | 
|---|
| 177 | foreach ($extraPlugins as $plugin) { | 
|---|
| 178 | $extra_icons .= sprintf("'%s',", $plugin['button']); | 
|---|
| 179 | } | 
|---|
| 180 | printf($extraPlugins_str, $extra_icons); | 
|---|
| 181 | } | 
|---|
| 182 | ?> | 
|---|
| 183 | ] | 
|---|
| 184 | }); | 
|---|
| 185 |  | 
|---|
| 186 | CKEDITOR.on('instanceReady', function(e) { | 
|---|
| 187 | if ($('label[for="post_excerpt"] a img').attr('src')==dotclear.img_minus_src) { | 
|---|
| 188 | $('#cke_post_excerpt').removeClass('hide'); | 
|---|
| 189 | } else { | 
|---|
| 190 | $('#cke_post_excerpt').addClass('hide'); | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 | $('#excerpt-area label').click(function() { | 
|---|
| 194 | $('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide')); | 
|---|
| 195 | }); | 
|---|
| 196 | }); | 
|---|
| 197 |  | 
|---|
| 198 | // @TODO: find a better way to retrieve active editor | 
|---|
| 199 | for (var id in CKEDITOR.instances) { | 
|---|
| 200 | CKEDITOR.instances[id].on('focus', function(e) { | 
|---|
| 201 | $.active_editor = e.editor.name; | 
|---|
| 202 | }); | 
|---|
| 203 | } | 
|---|
| 204 | }); | 
|---|