Dotclear

source: plugins/dcCKEditor/_post_config.php @ 3670:eecd4bdb63f1

Revision 3670:eecd4bdb63f1, 8.0 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

Fix CSS variable setting for the lazy firefox, address #2263

RevLine 
[2738]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[2972]6# Copyright (c) 2003-2015 Olivier Meunier & Association Dotclear
[2738]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; }
[3367]14
[2738]15header('Content-type: text/javascript');
[3367]16
[2761]17if (!empty($_GET['context'])) {
18     $context = $_GET['context'];
19} else {
20     $context = '';
21}
[3367]22
[2738]23$__extraPlugins = new ArrayObject();
[2761]24$core->callBehavior('ckeditorExtraPlugins',$__extraPlugins,$context);
[2738]25$extraPlugins = $__extraPlugins->getArrayCopy();
[3367]26
[2738]27?>
[3367]28
[2738]29(function($) {
30     $.toolbarPopup = function toolbarPopup(url) {
[2962]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
[2835]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
[2738]45          var popup_params = 'alwaysRaised=yes,dependent=yes,toolbar=yes,';
[2835]46          popup_params += 'height='+height+',width='+width+',menubar=no,resizable=yes,scrollbars=yes,status=no';
[2738]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          }
[2751]57
[2738]58          return url;
59     };
60
[2751]61     /* Retrieve editor from popup */
[2816]62     $.active_editor = null;
[2751]63     $.getEditorName = function getEditorName() {
64          return $.active_editor;
[2738]65     }
[3367]66     chainHandler(window,'onbeforeunload',function(e) {
[2816]67          if (e == undefined && window.event) {
68               e = window.event;
69          }
70
71          var editor = CKEDITOR.instances[$.getEditorName()];
[3367]72          if (editor !== undefined && !confirmClosePage.formSubmit && editor.checkDirty()) {
[2816]73               e.returnValue = confirmClosePage.prompt;
74               return confirmClosePage.prompt;
75          }
76          return false;
77     });
[2738]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 = '';
[3367]86
87<?php if (!isset($dcckeditor_disable_native_spellchecker) || $dcckeditor_disable_native_spellchecker): ?>
[3056]88     CKEDITOR.config.disableNativeSpellChecker = true;
[3367]89<?php else: ?>
[3056]90     CKEDITOR.config.disableNativeSpellChecker = false;
[3367]91<?php endif; ?>
92
[2738]93     CKEDITOR.config.skin = 'dotclear,'+dotclear.dcckeditor_plugin_url+'/js/ckeditor-skins/dotclear/';
[3040]94     CKEDITOR.config.baseHref = dotclear.base_url;
[3367]95     CKEDITOR.config.height = '<?php echo $core->auth->getOption('edit_size') * 14; ?>px';
[2738]96
[3367]97<?php if (!empty($dcckeditor_cancollapse_button)): ?>
[2738]98     CKEDITOR.config.toolbarCanCollapse = true;
[3367]99<?php endif; ?>
[2751]100
101     CKEDITOR.plugins.addExternal('entrylink',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/entrylink/');
[2738]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/');
[2869]104     CKEDITOR.plugins.addExternal('img',dotclear.dcckeditor_plugin_url+'/js/ckeditor-plugins/img/');
[3367]105
106<?php if (!empty($dcckeditor_textcolor_button) || !empty($dcckeditor_background_textcolor_button)): ?>
[3090]107     // button add "More Colors..." can be added if colordialog plugin is enabled
108     CKEDITOR.config.colorButton_enableMore = true;
[3367]109<?php endif; ?>
[2738]110
[3367]111<?php
112     if (!empty($extraPlugins) && count($extraPlugins) > 0) {
113          foreach ($extraPlugins as $plugin) {
114               printf("\tCKEDITOR.plugins.addExternal('%s','%s');\n",$plugin['name'],$plugin['url']);
115          }
[2738]116     }
117?>
[3367]118     if (dotclear.ckeditor_context === undefined || dotclear.ckeditor_tags_context[dotclear.ckeditor_context] === undefined) {
[3052]119          return;
120     }
[2854]121     $(dotclear.ckeditor_tags_context[dotclear.ckeditor_context].join(',')).ckeditor({
[3367]122
[2738]123<?php
[3367]124     $defautExtraPlugins = 'entrylink,dclink,media,justify,colorbutton,format,img';
125     if (!empty($extraPlugins) && count($extraPlugins)>0) {
126          foreach ($extraPlugins as $plugin) {
127               $defautExtraPlugins .= ','. $plugin['name'];
128          }
[2738]129     }
130?>
[3367]131          extraPlugins: '<?php echo $defautExtraPlugins; ?>',
[2738]132
[3362]133          keystrokes: [
134               [ CKEDITOR.CTRL + (CKEDITOR.env.mac ? CKEDITOR.ALT : CKEDITOR.SHIFT) +
[3367]135                    dotclear.msg.link_accesskey.toUpperCase().charCodeAt(0),'dcLinkCommand' ],    // Ctrl+Alt+l
[3362]136               [ CKEDITOR.CTRL + (CKEDITOR.env.mac ? CKEDITOR.ALT : CKEDITOR.SHIFT) +
[3367]137                    dotclear.msg.img_select_accesskey.toUpperCase().charCodeAt(0),'mediaCommand' ],    // Ctrl+Alt+m
[3362]138          ],
139
[3367]140<?php if (!empty($dcckeditor_format_select)): ?>
[2738]141          // format tags
[3367]142
143     <?php if (!empty($dcckeditor_format_tags)): ?>
144          format_tags: '<?php echo $dcckeditor_format_tags; ?>',
145     <?php else: ?>
[2738]146          format_tags: 'p;h1;h2;h3;h4;h5;h6;pre;address',
[3367]147     <?php endif; ?>
148
[2738]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' },
[3367]159<?php endif; ?>
[2738]160
161          entities: false,
162          removeButtons: '',
163          allowedContent: true,
164          toolbar: [
165               {
166                    name: 'basicstyles',
167                    items: [
[3367]168
169<?php if (!empty($dcckeditor_format_select)): ?>
[2738]170                         'Format',
171<?php endif;?>
[3367]172
[2738]173                         'Bold','Italic','Underline','Strike','Subscript','Superscript','Code','Blockquote',
[2751]174
[3367]175<?php if (!empty($dcckeditor_list_buttons)): ?>
176                         'NumberedList','BulletedList',
177<?php endif; ?>
178
[2738]179                         'RemoveFormat'
180                    ]
181               },
[3367]182
183<?php if (!empty($dcckeditor_clipboard_buttons)): ?>
[2738]184               {
185                    name: 'clipoard',
186                    items: ['Cut','Copy','Paste','PasteText','PasteFromWord']
187               },
[3367]188<?php endif; ?>
189
190<?php if (!empty($dcckeditor_alignment_buttons)): ?>
[2738]191               {
192                    name: 'paragraph',
[3367]193                    items: ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock']
[2738]194               },
[3367]195<?php endif; ?>
196
197<?php if (!empty($dcckeditor_table_button)): ?>
[2738]198               {
199                    name: 'table',
200                    items: ['Table']
201               },
[3367]202<?php endif; ?>
203
[2738]204               {
205                    name: 'custom',
206                    items: [
[2869]207                         'EntryLink','dcLink','Media','img','-',
[2854]208                         'Source'
[3367]209
210<?php if (!empty($dcckeditor_textcolor_button)): ?>
[3090]211                         ,'TextColor'
[3367]212<?php endif; ?>
213
214<?php if (!empty($dcckeditor_background_textcolor_button)): ?>
[3090]215                         ,'BGColor'
[3367]216<?php endif; ?>
[2751]217                    ]
[2738]218               },
[3090]219               {
220                    name: 'special',
221                    items: [
222                         'Maximize'
223                    ]
224               },
[3367]225
226<?php // add extra buttons comming from dotclear plugins
227     if (!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?>
[2738]236          ]
237     });
238
[3367]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          }
[3669]253
[3670]254     });
255
256     CKEDITOR.on('instanceReady',function(e) {
[3669]257          if (typeof dotclear_htmlFontSize !== 'undefined') {
258               e.editor.document.$.documentElement.style.setProperty('--html-font-size',dotclear_htmlFontSize);
259          }
[3367]260
261          if ($('label[for="post_excerpt"] a img').attr('src') == dotclear.img_minus_src) {
[2738]262               $('#cke_post_excerpt').removeClass('hide');
263          } else {
264               $('#cke_post_excerpt').addClass('hide');
265          }
[2751]266
[2738]267          $('#excerpt-area label').click(function() {
268               $('#cke_post_excerpt').toggleClass('hide',$('#post_excerpt').hasClass('hide'));
269          });
[3640]270
[2738]271     });
[2751]272
273     // @TODO: find a better way to retrieve active editor
274     for (var id in CKEDITOR.instances) {
[3367]275          CKEDITOR.instances[id].on('focus',function(e) {
[2751]276               $.active_editor = e.editor.name;
277          });
278     }
[2738]279});
Note: See TracBrowser for help on using the repository browser.

Sites map