Dotclear

source: plugins/dcCKEditor/_post_config.php @ 3052:6bd009da1432

Revision 3052:6bd009da1432, 6.5 KB checked in by Nicolas <nikrou77@…>, 10 years ago (diff)

Allow user to disable (or not) native spellchecker for CKEditor
Fix #2092

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

Sites map