Dotclear

source: plugins/dcCKEditor/_post_config.php @ 2854:2d4e6314b899

Revision 2854:2d4e6314b899, 5.9 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Add tags into inject ckeditor for adminPostEditor behavior
Addresses #2011

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

Sites map