Ticket #7004: plugin.js

File plugin.js, 3.1 KB (added by Alfonso Martínez de Lizarrondo, 13 years ago)

Sample plugin that loads directly two translations

Line 
1/*
2 * @file Background plugin for CKEditor
3 * Copyright (C) 2011 Alfonso Martínez de Lizarrondo
4 *
5 * == BEGIN LICENSE ==
6 *
7 * Licensed under the terms of any of the following licenses at your
8 * choice:
9 *
10 *  - GNU General Public License Version 2 or later (the "GPL")
11 *    http://www.gnu.org/licenses/gpl.html
12 *
13 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14 *    http://www.gnu.org/licenses/lgpl.html
15 *
16 *  - Mozilla Public License Version 1.1 or later (the "MPL")
17 *    http://www.mozilla.org/MPL/MPL-1.1.html
18 *
19 * == END LICENSE ==
20 *
21 */
22
23// A placeholder just to notify that the plugin has been loaded
24CKEDITOR.plugins.add( 'backgrounds',
25{
26        init : function( editor )
27        {
28                // It doesn't add commands, buttons or dialogs, it doesn't do anything here
29        } //Init
30} );
31
32
33// This is the real code of the plugin
34CKEDITOR.on( 'dialogDefinition', function( ev )
35        {
36                // Take the dialog name and its definition from the event data.
37                var dialogName = ev.data.name,
38                        dialogDefinition = ev.data.definition,
39                        editor = ev.editor,
40                        tabName = '';
41
42                // Check if it's one of the dialogs that we want to modify and note the proper tab name.
43                if ( dialogName == 'table' || dialogName == 'tableProperties' )
44                        tabName = 'advanced';
45
46                if ( dialogName == 'cellProperties' )
47                        tabName = 'info';
48
49                // Not one of the managed dialogs.
50                if ( tabName == '' )
51                        return;
52
53                // Get a reference to the tab.
54                var tab = dialogDefinition.getContents( tabName );
55
56                // The text field
57                var textInput =  {
58                                type : 'text',
59                                label : editor.lang.backgrounds.label,
60                                id : 'background',
61                                setup : function( selectedElement )
62                                {
63                                        this.setValue( selectedElement.getAttribute( 'background' ) );
64                                },
65                                commit : function( data, selectedElement )
66                                {
67                                        var element = selectedElement || data,
68                                                value = this.getValue();
69                                        if ( value )
70                                                element.setAttribute( 'background', value );
71                                        else
72                                                element.removeAttribute( 'background' );
73                                }
74                        };
75
76                // File browser button
77                var browseButton =  {
78                                type : 'button',
79                                id : 'browse',
80                                hidden : 'true',
81                                filebrowser :
82                                {
83                                        action : 'Browse',
84                                        target: tabName + ':background',
85                                        url: editor.config.filebrowserImageBrowseUrl || editor.config.filebrowserBrowseUrl
86                                },
87                                label : editor.lang.common.browseServer
88                        };
89
90                // Add the elements to the dialog
91                if ( tabName == 'advanced')
92                {
93                        // Two rows
94                        tab.add(textInput);
95                        tab.add(browseButton);
96                }
97                else
98                {
99                        // In the cell dialog add it as a single row
100                        browseButton.style = 'display:inline-block;margin-top:10px;';
101                        tab.add({
102                                        type : 'hbox',
103                                        widths: [ '', '100px'],
104                                        children : [ textInput, browseButton]
105                        });
106                }
107
108        // inject this listener before the one from the fileBrowser plugin so there are no problems with the new fields.
109        }, null, null, 9 );
110
111
112// Translations for the label
113CKEDITOR.plugins.setLang( 'backgrounds', 'en', { backgrounds : { label  : 'Background image'} } );
114CKEDITOR.plugins.setLang( 'backgrounds', 'es', { backgrounds : { label  : 'Imagen de fondo'     } } );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy