Dotclear

source: plugins/dcCKEditor/_post_config.php @ 2751:a96ec5640056

Revision 2751:a96ec5640056, 5.0 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Each editor (ckeditor, legacy ones) loads its own context when it is active.
Add plugin_id parameter to transmit that context
Remove call of ckeditorExtraPlugins behavior until a good solution is found.
Closes #1983

Line 
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
13if (!defined('DC_CONTEXT_ADMIN')) { return; }
14header('Content-type: text/javascript');
15$__extraPlugins = new ArrayObject();
16$core->callBehavior('ckeditorExtraPlugins',$__extraPlugins);
17$extraPlugins = $__extraPlugins->getArrayCopy();
18?>
19(function($) {
20     $.toolbarPopup = function toolbarPopup(url) {
21          var popup_params = 'alwaysRaised=yes,dependent=yes,toolbar=yes,';
22          popup_params += 'height=420,width=520,menubar=no,resizable=yes,scrollbars=yes,status=no';
23          var popup_link = window.open(url,'dc_popup', popup_params);
24     };
25
26     $.stripBaseURL = function stripBaseURL(url) {
27          if (dotclear.base_url != '') {
28               var pos = url.indexOf(dotclear.base_url);
29               if (pos == 0) {
30                    url = url.substr(dotclear.base_url.length);
31               }
32          }
33
34          return url;
35     };
36
37     /* Retrieve editor from popup */
38    $.active_editor = null;
39     $.getEditorName = function getEditorName() {
40          return $.active_editor;
41     }
42})(jQuery);
43
44$(function() {
45     /* By default ckeditor load related resources with a timestamp to avoid cache problem when upgrading itself
46      * load_plugin_file.php does not allow other param that file to load (pf param), so remove timestamp
47      */
48
49     CKEDITOR.timestamp = '';
50     CKEDITOR.config.skin = 'dotclear,'+dotclear.dcckeditor_plugin_url+'/js/ckeditor-skins/dotclear/';
51
52<?php if (!empty($dcckeditor_cancollapse_button)):?>
53     CKEDITOR.config.toolbarCanCollapse = true;
54<?php endif;?>
55
56     CKEDITOR.plugins.addExternal('entrylink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/entrylink/');
57     CKEDITOR.plugins.addExternal('dclink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/dclink/');
58     CKEDITOR.plugins.addExternal('media',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/media/');
59
60<?php if (!empty($extraPlugins) && count($extraPlugins)>0) {
61     foreach ($extraPlugins as $plugin) {
62          printf("\tCKEDITOR.plugins.addExternal('%s','%s');\n", $plugin['name'], $plugin['url']);
63     }
64}
65?>
66
67     $('<?php echo $dcckeditor_textareas;?>').ckeditor({
68<?php
69$defautExtraPlugins = 'entrylink,dclink,media,justify,colorbutton,format';
70if (!empty($extraPlugins) && count($extraPlugins)>0) {
71     foreach ($extraPlugins as $plugin) {
72          $defautExtraPlugins .= ','. $plugin['name'];
73     }
74}
75?>
76          extraPlugins: '<?php echo $defautExtraPlugins;?>',
77
78          <?php if (!empty($dcckeditor_format_select)):?>
79          // format tags
80          format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;address',
81
82          // following definition are needed to be specialized
83          format_p: { element: 'p' },
84          format_h1: { element: 'h1' },
85          format_h2: { element: 'h2' },
86          format_h3: { element: 'h3' },
87          format_h4: { element: 'h4' },
88          format_h5: { element: 'h5' },
89          format_h6: { element: 'h6' },
90          format_pre: { element: 'pre' },
91          format_address: { element: 'address' },
92          <?php endif;?>
93
94          entities: false,
95          removeButtons: '',
96          allowedContent: true,
97          toolbar: [
98               {
99                    name: 'basicstyles',
100                    items: [
101<?php if (!empty($dcckeditor_format_select)):?>
102                         'Format',
103<?php endif;?>
104                         'Bold','Italic','Underline','Strike','Subscript','Superscript','Code','Blockquote',
105
106<?php if (!empty($dcckeditor_list_buttons)):?>
107                         'NumberedList', 'BulletedList',
108<?php endif;?>
109                         'RemoveFormat'
110                    ]
111               },
112<?php if (!empty($dcckeditor_clipboard_buttons)):?>
113               {
114                    name: 'clipoard',
115                    items: ['Cut','Copy','Paste','PasteText','PasteFromWord']
116               },
117<?php endif;?>
118<?php if (!empty($dcckeditor_alignment_buttons)):?>
119               {
120                    name: 'paragraph',
121                    items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']
122               },
123<?php endif;?>
124<?php if (!empty($dcckeditor_table_button)):?>
125               {
126                    name: 'table',
127                    items: ['Table']
128               },
129<?php endif;?>
130               {
131                    name: 'custom',
132                    items: [
133                         'EntryLink','dcLink','Media','-',
134                         'Source', 'Maximize'
135<?php if (!empty($dcckeditor_textcolor_button)):?>
136                ,'TextColor'
137<?php endif;?>
138                    ]
139               },
140               <?php // add extra buttons comming from dotclear plugins
141               if (!empty($extraPlugins) && count($extraPlugins)>0) {
142                    $extraPlugins_str = "{name: 'extra', items: [%s]},\n";
143                    $extra_icons = '';
144                    foreach ($extraPlugins as $plugin) {
145                         $extra_icons .= sprintf("'%s',", $plugin['button']);
146                    }
147                    printf($extraPlugins_str, $extra_icons);
148               }
149               ?>
150          ]
151     });
152
153     CKEDITOR.on('instanceReady', function(e) {
154          if ($('label[for="post_excerpt"] a img').attr('src')==dotclear.img_minus_src) {
155               $('#cke_post_excerpt').removeClass('hide');
156          } else {
157               $('#cke_post_excerpt').addClass('hide');
158          }
159
160          $('#excerpt-area label').click(function() {
161               $('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide'));
162          });
163     });
164
165     // @TODO: find a better way to retrieve active editor
166     for (var id in CKEDITOR.instances) {
167          CKEDITOR.instances[id].on('focus', function(e) {
168               $.active_editor = e.editor.name;
169          });
170     }
171});
Note: See TracBrowser for help on using the repository browser.

Sites map