Dotclear

source: plugins/dcCKEditor/_post_config.php @ 3730:5c45a5df9a59

Revision 3730:5c45a5df9a59, 9.2 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Code formatting (PSR-2)

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2015 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;}
14
15header('Content-type: text/javascript');
16
17if (!empty($_GET['context'])) {
18    $context = $_GET['context'];
19} else {
20    $context = '';
21}
22
23$__extraPlugins = new ArrayObject();
24$core->callBehavior('ckeditorExtraPlugins', $__extraPlugins, $context);
25$extraPlugins = $__extraPlugins->getArrayCopy();
26
27?>
28
29(function($) {
30    $.toolbarPopup = function toolbarPopup(url) {
31        if (dotclear.admin_base_url != '') {
32            var pos = url.indexOf(dotclear.admin_base_url);
33            if (pos == -1) {
34                url = dotclear.admin_base_url + url;
35            }
36        }
37
38        var args = Array.prototype.slice.call(arguments);
39        var width = 520, height = 420;
40        if (args[1]!==undefined) {
41            width = args[1].width || width;
42            height = args[1].height || height;
43        }
44
45        var popup_params = 'alwaysRaised=yes,dependent=yes,toolbar=yes,';
46        popup_params += 'height='+height+',width='+width+',menubar=no,resizable=yes,scrollbars=yes,status=no';
47        var popup_link = window.open(url,'dc_popup', popup_params);
48    };
49
50    $.stripBaseURL = function stripBaseURL(url) {
51        if (dotclear.base_url != '') {
52            var pos = url.indexOf(dotclear.base_url);
53            if (pos == 0) {
54                url = url.substr(dotclear.base_url.length);
55            }
56        }
57
58        return url;
59    };
60
61    /* Retrieve editor from popup */
62    $.active_editor = null;
63    $.getEditorName = function getEditorName() {
64        return $.active_editor;
65    }
66    chainHandler(window,'onbeforeunload',function(e) {
67        if (e == undefined && window.event) {
68            e = window.event;
69        }
70
71        var editor = CKEDITOR.instances[$.getEditorName()];
72        if (editor !== undefined && !confirmClosePage.formSubmit && editor.checkDirty()) {
73            e.returnValue = confirmClosePage.prompt;
74            return confirmClosePage.prompt;
75        }
76        return false;
77    });
78})(jQuery);
79
80$(function() {
81    /* By default ckeditor load related resources with a timestamp to avoid cache problem when upgrading itself
82     * load_plugin_file.php does not allow other param that file to load (pf param), so remove timestamp
83     */
84
85    CKEDITOR.timestamp = '';
86
87<?php if (!isset($dcckeditor_disable_native_spellchecker) || $dcckeditor_disable_native_spellchecker): ?>
88    CKEDITOR.config.disableNativeSpellChecker = true;
89<?php else: ?>
90    CKEDITOR.config.disableNativeSpellChecker = false;
91<?php endif;?>
92
93    CKEDITOR.config.skin = 'dotclear,'+dotclear.dcckeditor_plugin_url+'/js/ckeditor-skins/dotclear/';
94    CKEDITOR.config.baseHref = dotclear.base_url;
95    CKEDITOR.config.height = '<?php echo $core->auth->getOption('edit_size') * 14; ?>px';
96
97<?php if (!empty($dcckeditor_cancollapse_button)): ?>
98    CKEDITOR.config.toolbarCanCollapse = true;
99<?php endif;?>
100
101    CKEDITOR.plugins.addExternal('entrylink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/entrylink/');
102    CKEDITOR.plugins.addExternal('dclink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/dclink/');
103    CKEDITOR.plugins.addExternal('media',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/media/');
104    CKEDITOR.plugins.addExternal('img',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/img/');
105
106<?php if (!empty($dcckeditor_textcolor_button) || !empty($dcckeditor_background_textcolor_button)): ?>
107    // button add "More Colors..." can be added if colordialog plugin is enabled
108    CKEDITOR.config.colorButton_enableMore = true;
109<?php endif;?>
110
111<?php
112if (!empty($extraPlugins) && count($extraPlugins) > 0) {
113    foreach ($extraPlugins as $plugin) {
114        printf("\tCKEDITOR.plugins.addExternal('%s','%s');\n", $plugin['name'], $plugin['url']);
115    }
116}
117?>
118    if (dotclear.ckeditor_context === undefined || dotclear.ckeditor_tags_context[dotclear.ckeditor_context] === undefined) {
119        return;
120    }
121    $(dotclear.ckeditor_tags_context[dotclear.ckeditor_context].join(',')).ckeditor({
122
123<?php
124$defautExtraPlugins = 'entrylink,dclink,media,justify,colorbutton,format,img';
125if (!empty($extraPlugins) && count($extraPlugins) > 0) {
126    foreach ($extraPlugins as $plugin) {
127        $defautExtraPlugins .= ',' . $plugin['name'];
128    }
129}
130?>
131        extraPlugins: '<?php echo $defautExtraPlugins; ?>',
132
133        keystrokes: [
134            [ CKEDITOR.CTRL + (CKEDITOR.env.mac ? CKEDITOR.ALT : CKEDITOR.SHIFT) +
135                dotclear.msg.link_accesskey.toUpperCase().charCodeAt(0),'dcLinkCommand' ],    // Ctrl+Alt+l
136            [ CKEDITOR.CTRL + (CKEDITOR.env.mac ? CKEDITOR.ALT : CKEDITOR.SHIFT) +
137                dotclear.msg.img_select_accesskey.toUpperCase().charCodeAt(0),'mediaCommand' ],    // Ctrl+Alt+m
138        ],
139
140<?php if (!empty($dcckeditor_format_select)): ?>
141        // format tags
142
143    <?php if (!empty($dcckeditor_format_tags)): ?>
144        format_tags: '<?php echo $dcckeditor_format_tags; ?>',
145    <?php else: ?>
146        format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;address',
147    <?php endif;?>
148
149        // following definition are needed to be specialized
150        format_p: { element: 'p' },
151        format_h1: { element: 'h1' },
152        format_h2: { element: 'h2' },
153        format_h3: { element: 'h3' },
154        format_h4: { element: 'h4' },
155        format_h5: { element: 'h5' },
156        format_h6: { element: 'h6' },
157        format_pre: { element: 'pre' },
158        format_address: { element: 'address' },
159<?php endif;?>
160
161        entities: false,
162        removeButtons: '',
163        allowedContent: true,
164        toolbar: [
165            {
166                name: 'basicstyles',
167                items: [
168
169<?php if (!empty($dcckeditor_format_select)): ?>
170                    'Format',
171<?php endif;?>
172
173                    'Bold','Italic','Underline','Strike','Subscript','Superscript','Code','Blockquote',
174
175<?php if (!empty($dcckeditor_list_buttons)): ?>
176                    'NumberedList','BulletedList',
177<?php endif;?>
178
179                    'RemoveFormat'
180                ]
181            },
182
183<?php if (!empty($dcckeditor_clipboard_buttons)): ?>
184            {
185                name: 'clipoard',
186                items: ['Cut','Copy','Paste','PasteText','PasteFromWord']
187            },
188<?php endif;?>
189
190<?php if (!empty($dcckeditor_alignment_buttons)): ?>
191            {
192                name: 'paragraph',
193                items: ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock']
194            },
195<?php endif;?>
196
197<?php if (!empty($dcckeditor_table_button)): ?>
198            {
199                name: 'table',
200                items: ['Table']
201            },
202<?php endif;?>
203
204            {
205                name: 'custom',
206                items: [
207                    'EntryLink','dcLink','Media','img','-',
208                    'Source'
209
210<?php if (!empty($dcckeditor_textcolor_button)): ?>
211                    ,'TextColor'
212<?php endif;?>
213
214<?php if (!empty($dcckeditor_background_textcolor_button)): ?>
215                    ,'BGColor'
216<?php endif;?>
217                ]
218            },
219            {
220                name: 'special',
221                items: [
222                    'Maximize'
223                ]
224            },
225
226<?php // add extra buttons comming from dotclear plugins
227if (!empty($extraPlugins) && count($extraPlugins) > 0) {
228    $extraPlugins_str = "{name: 'extra', items: [%s]},\n";
229    $extra_icons      = '';
230    foreach ($extraPlugins as $plugin) {
231        $extra_icons .= sprintf("'%s',", $plugin['button']);
232    }
233    printf($extraPlugins_str, $extra_icons);
234}
235?>
236        ]
237    });
238
239    CKEDITOR.on('instanceLoaded',function(e) {
240
241        // Retrieve textarea element of the instance, then its line-height (in px) and rows values,
242        // then apply line-height * rows (min = 6) to the inner height of the instance.
243
244        var ta = document.getElementById(e.editor.name);
245        if (ta !== undefined) {
246            var ta_rows = ta.rows;
247            var ta_line_height = parseFloat(window.getComputedStyle(ta,null).getPropertyValue('line-height'));
248            if (ta_rows > 0 && ta_line_height > 0) {
249                var ta_height = String(Math.max(ta_rows,6) * ta_line_height);
250                e.editor.resize('100%',ta_height,true);
251            }
252        }
253
254    });
255
256    CKEDITOR.on('instanceReady',function(e) {
257        if (typeof dotclear_htmlFontSize !== 'undefined') {
258            e.editor.document.$.documentElement.style.setProperty('--html-font-size',dotclear_htmlFontSize);
259        }
260
261        if ($('label[for="post_excerpt"] a img').attr('src') == dotclear.img_minus_src) {
262            $('#cke_post_excerpt').removeClass('hide');
263        } else {
264            $('#cke_post_excerpt').addClass('hide');
265        }
266
267        $('#excerpt-area label').click(function() {
268            $('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide'));
269        });
270
271    });
272
273    // @TODO: find a better way to retrieve active editor
274    for (var id in CKEDITOR.instances) {
275        CKEDITOR.instances[id].on('focus',function(e) {
276            $.active_editor = e.editor.name;
277        });
278    }
279});
Note: See TracBrowser for help on using the repository browser.

Sites map