Dotclear

source: plugins/dcCKEditor/_post_config.php @ 3769:12b632aaedc1

Revision 3769:12b632aaedc1, 9.0 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Some modifications were missing from previous commit, my bad!

Line 
1<?php
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 */
11
12if (!defined('DC_CONTEXT_ADMIN')) {return;}
13
14header('Content-type: text/javascript');
15
16if (!empty($_GET['context'])) {
17    $context = $_GET['context'];
18} else {
19    $context = '';
20}
21
22$__extraPlugins = new ArrayObject();
23$core->callBehavior('ckeditorExtraPlugins', $__extraPlugins, $context);
24$extraPlugins = $__extraPlugins->getArrayCopy();
25
26?>
27
28(function($) {
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        }
36
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        }
43
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    };
48
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        }
56
57        return url;
58    };
59
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        }
69
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    });
77})(jQuery);
78
79$(function() {
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     */
83
84    CKEDITOR.timestamp = '';
85
86<?php if (!isset($dcckeditor_disable_native_spellchecker) || $dcckeditor_disable_native_spellchecker): ?>
87    CKEDITOR.config.disableNativeSpellChecker = true;
88<?php else: ?>
89    CKEDITOR.config.disableNativeSpellChecker = false;
90<?php endif;?>
91
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';
95
96<?php if (!empty($dcckeditor_cancollapse_button)): ?>
97    CKEDITOR.config.toolbarCanCollapse = true;
98<?php endif;?>
99
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/');
104
105<?php if (!empty($dcckeditor_textcolor_button) || !empty($dcckeditor_background_textcolor_button)): ?>
106    // button add "More Colors..." can be added if colordialog plugin is enabled
107    CKEDITOR.config.colorButton_enableMore = true;
108<?php endif;?>
109
110<?php
111if (!empty($extraPlugins) && count($extraPlugins) > 0) {
112    foreach ($extraPlugins as $plugin) {
113        printf("\tCKEDITOR.plugins.addExternal('%s','%s');\n", $plugin['name'], $plugin['url']);
114    }
115}
116?>
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({
121
122<?php
123$defautExtraPlugins = 'entrylink,dclink,media,justify,colorbutton,format,img';
124if (!empty($extraPlugins) && count($extraPlugins) > 0) {
125    foreach ($extraPlugins as $plugin) {
126        $defautExtraPlugins .= ',' . $plugin['name'];
127    }
128}
129?>
130        extraPlugins: '<?php echo $defautExtraPlugins; ?>',
131
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        ],
138
139<?php if (!empty($dcckeditor_format_select)): ?>
140        // format tags
141
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;?>
147
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;?>
159
160        entities: false,
161        removeButtons: '',
162        allowedContent: true,
163        toolbar: [
164            {
165                name: 'basicstyles',
166                items: [
167
168<?php if (!empty($dcckeditor_format_select)): ?>
169                    'Format',
170<?php endif;?>
171
172                    'Bold','Italic','Underline','Strike','Subscript','Superscript','Code','Blockquote',
173
174<?php if (!empty($dcckeditor_list_buttons)): ?>
175                    'NumberedList','BulletedList',
176<?php endif;?>
177
178                    'RemoveFormat'
179                ]
180            },
181
182<?php if (!empty($dcckeditor_clipboard_buttons)): ?>
183            {
184                name: 'clipoard',
185                items: ['Cut','Copy','Paste','PasteText','PasteFromWord']
186            },
187<?php endif;?>
188
189<?php if (!empty($dcckeditor_alignment_buttons)): ?>
190            {
191                name: 'paragraph',
192                items: ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock']
193            },
194<?php endif;?>
195
196<?php if (!empty($dcckeditor_table_button)): ?>
197            {
198                name: 'table',
199                items: ['Table']
200            },
201<?php endif;?>
202
203            {
204                name: 'custom',
205                items: [
206                    'EntryLink','dcLink','Media','img','-',
207                    'Source'
208
209<?php if (!empty($dcckeditor_textcolor_button)): ?>
210                    ,'TextColor'
211<?php endif;?>
212
213<?php if (!empty($dcckeditor_background_textcolor_button)): ?>
214                    ,'BGColor'
215<?php endif;?>
216                ]
217            },
218            {
219                name: 'special',
220                items: [
221                    'Maximize'
222                ]
223            },
224
225<?php // add extra buttons comming from dotclear plugins
226if (!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}
234?>
235        ]
236    });
237
238    CKEDITOR.on('instanceLoaded',function(e) {
239
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.
242
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        }
252
253    });
254
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        }
259
260        if ($('label[for="post_excerpt"] input').attr('aria-label') == dotclear.img_minus_alt) {
261            $('#cke_post_excerpt').removeClass('hide');
262        } else {
263            $('#cke_post_excerpt').addClass('hide');
264        }
265
266        $('#excerpt-area label').click(function() {
267            $('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide'));
268        });
269
270    });
271
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    }
278});
Note: See TracBrowser for help on using the repository browser.

Sites map