Dotclear

source: plugins/dcCKEditor/_post_config.php @ 2828:49b3d90f9cd9

Revision 2828:49b3d90f9cd9, 5.4 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Fix small issue with CKEditor : an entry could not be saved without prompt for leaving page.

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

Sites map