Dotclear

source: plugins/dcCKEditor/_post_config.php @ 3917:5b2c978050b2

Revision 3917:5b2c978050b2, 9.6 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Show/Hide? mecanism now use button rather than input - fixes #2285

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    CKEDITOR.config.defaultLanguage = dotclear.user_language;
111    CKEDITOR.config.language = dotclear.user_language;
112    CKEDITOR.config.contentsLanguage = dotclear.user_language;
113
114<?php
115if (!empty($extraPlugins) && count($extraPlugins) > 0) {
116    foreach ($extraPlugins as $plugin) {
117        printf("\tCKEDITOR.plugins.addExternal('%s','%s');\n", $plugin['name'], $plugin['url']);
118    }
119}
120?>
121    if (dotclear.ckeditor_context === undefined || dotclear.ckeditor_tags_context[dotclear.ckeditor_context] === undefined) {
122        return;
123    }
124    $(dotclear.ckeditor_tags_context[dotclear.ckeditor_context].join(',')).ckeditor({
125
126<?php
127$defautExtraPlugins = 'entrylink,dclink,media,justify,colorbutton,format,img';
128if (!empty($extraPlugins) && count($extraPlugins) > 0) {
129    foreach ($extraPlugins as $plugin) {
130        $defautExtraPlugins .= ',' . $plugin['name'];
131    }
132}
133?>
134        extraPlugins: '<?php echo $defautExtraPlugins; ?>',
135
136        keystrokes: [
137            [ CKEDITOR.CTRL + (CKEDITOR.env.mac ? CKEDITOR.ALT : CKEDITOR.SHIFT) +
138                dotclear.msg.link_accesskey.toUpperCase().charCodeAt(0),'dcLinkCommand' ],    // Ctrl+Alt+l
139            [ CKEDITOR.CTRL + (CKEDITOR.env.mac ? CKEDITOR.ALT : CKEDITOR.SHIFT) +
140                dotclear.msg.img_select_accesskey.toUpperCase().charCodeAt(0),'mediaCommand' ],    // Ctrl+Alt+m
141        ],
142
143<?php if (!empty($dcckeditor_format_select)): ?>
144        // format tags
145
146    <?php if (!empty($dcckeditor_format_tags)): ?>
147        format_tags: '<?php echo $dcckeditor_format_tags; ?>',
148    <?php else: ?>
149        format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;address',
150    <?php endif;?>
151
152        // following definition are needed to be specialized
153        format_p: { element: 'p' },
154        format_h1: { element: 'h1' },
155        format_h2: { element: 'h2' },
156        format_h3: { element: 'h3' },
157        format_h4: { element: 'h4' },
158        format_h5: { element: 'h5' },
159        format_h6: { element: 'h6' },
160        format_pre: { element: 'pre' },
161        format_address: { element: 'address' },
162<?php endif;?>
163
164        entities: false,
165        removeButtons: '',
166        allowedContent: true,
167        toolbar: [
168            {
169                name: 'basicstyles',
170                items: [
171
172<?php if (!empty($dcckeditor_format_select)): ?>
173                    'Format',
174<?php endif;?>
175
176                    'Bold','Italic','Underline','Strike','Subscript','Superscript','Code','Blockquote',
177
178<?php if (!empty($dcckeditor_list_buttons)): ?>
179                    'NumberedList','BulletedList',
180<?php endif;?>
181
182                    'RemoveFormat'
183                ]
184            },
185
186<?php if (!empty($dcckeditor_clipboard_buttons)): ?>
187            {
188                name: 'clipoard',
189                items: ['Cut','Copy','Paste','PasteText','PasteFromWord']
190            },
191<?php endif;?>
192
193<?php if (!empty($dcckeditor_alignment_buttons)): ?>
194            {
195                name: 'paragraph',
196                items: ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock']
197            },
198<?php endif;?>
199
200<?php if (!empty($dcckeditor_table_button)): ?>
201            {
202                name: 'table',
203                items: ['Table']
204            },
205<?php endif;?>
206
207            {
208                name: 'custom',
209                items: [
210                    'EntryLink','dcLink','Media','img','-',
211                    'Source'
212
213<?php if (!empty($dcckeditor_textcolor_button)): ?>
214                    ,'TextColor'
215<?php endif;?>
216
217<?php if (!empty($dcckeditor_background_textcolor_button)): ?>
218                    ,'BGColor'
219<?php endif;?>
220                ]
221            },
222            {
223                name: 'special',
224                items: [
225                    'Maximize'
226                ]
227            },
228
229<?php // add extra buttons comming from dotclear plugins
230if (!empty($extraPlugins) && count($extraPlugins) > 0) {
231    $extraPlugins_str = "{name: 'extra', items: [%s]},\n";
232    $extra_icons      = '';
233    foreach ($extraPlugins as $plugin) {
234        $extra_icons .= sprintf("'%s',", $plugin['button']);
235    }
236    printf($extraPlugins_str, $extra_icons);
237}
238?>
239        ]
240    });
241
242    CKEDITOR.on('instanceLoaded',function(e) {
243        // Retrieve textarea element of the instance, then its line-height (in px) and rows values,
244        // then apply line-height * rows (min = 6) to the inner height of the instance.
245
246        var ta = document.getElementById(e.editor.name);
247        if (ta !== undefined) {
248            var ta_rows = ta.rows;
249            var ta_line_height = parseFloat(window.getComputedStyle(ta,null).getPropertyValue('line-height'));
250            if (ta_rows > 0 && ta_line_height > 0) {
251                var ta_height = String(Math.max(ta_rows,6) * ta_line_height);
252                e.editor.resize('100%',ta_height,true);
253            }
254        }
255    });
256
257    CKEDITOR.on('instanceReady',function(e) {
258        if (dotclear && dotclear.data && dotclear.data.htmlFontSize) {
259            e.editor.document.$.documentElement.style.setProperty('--html-font-size',dotclear.data.htmlFontSize);
260        }
261
262        if ($('label[for="post_excerpt"] button').attr('aria-label') == dotclear.img_minus_alt) {
263            $('#cke_post_excerpt').removeClass('hide');
264        } else {
265            $('#cke_post_excerpt').addClass('hide');
266        }
267
268        $('#excerpt-area label').click(function() {
269            $('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide'));
270        });
271
272        const ta = document.getElementById(e.editor.name);
273        if (ta !== undefined) {
274            if (ta.lang && e.editor.config.contentsLanguage !== ta.lang) {
275                let config = e.editor.config;
276                config.contentsLanguage = ta.lang;
277                e.editor.destroy();
278                CKEDITOR.replace(e.editor.name, config);
279            }
280        }
281    });
282
283    // @TODO: find a better way to retrieve active editor
284    for (var id in CKEDITOR.instances) {
285        CKEDITOR.instances[id].on('focus',function(e) {
286            $.active_editor = e.editor.name;
287        });
288    }
289});
Note: See TracBrowser for help on using the repository browser.

Sites map