Ticket #10407: config.js

File config.js, 6.3 KB (added by Nora, 11 years ago)

Config file for my ckeditor

Line 
1/*
2Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
3For licensing, see LICENSE.html or http://ckeditor.com/license
4*/
5/*
6 * Adjust the behavior of the dataProcessor to avoid styles
7 * and make it look like FCKeditor HTML output.
8 */
9function configureHtmlOutput( ev ){     
10        var editor = ev.editor,         
11                dataProcessor = editor.dataProcessor,           
12                htmlFilter = dataProcessor && dataProcessor.htmlFilter;
13
14        // Out self closing tags the HTML4 way, like <br>.     
15        dataProcessor.writer.selfClosingEnd = '>';     
16
17        // Make output formatting behave similar to FCKeditor   
18        var dtd = CKEDITOR.dtd; 
19        for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) {               dataProcessor.writer.setRules( e, {                             
20                        indent : true,                         
21                        breakBeforeOpen : true,                         
22                        breakAfterOpen : false,                         
23                        breakBeforeClose : !dtd[ e ][ '#' ],                           
24                        breakAfterClose : true                 
25                });     
26        }       
27
28        // Output properties as attributes, not styles.
29        htmlFilter.addRules({                   
30                elements : {                           
31                        $ : function( element ) {                                       
32                                // Output dimensions of images as width and height                                     
33                                if ( element.name === 'img' ) {                                         
34                                        var style = element.attributes.style;                                           
35                                        if ( style ) {                                                 
36                                                // Get the width from the style.                                                       
37                                                var match = /(?:^|\s)width\s*:\s*(\d+)px/i.exec( style ),                                                               
38                                                        width = match && match[1];                                                     
39
40                                                // Get the height from the style.                                                       
41                                                match = /(?:^|\s)height\s*:\s*(\d+)px/i.exec( style );                                                 
42                                                var height = match && match[1];                                                 
43                                                if ( width ) {                                                         
44                                                        element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' );
45                                                        element.attributes.width = width;
46                                                }
47                                                if ( height ) {                                                         
48                                                        element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' ); 
49                                                        element.attributes.height = height;                                                     
50                                                }                                               
51                                        }                               
52                                }                                       
53                                // Output alignment of paragraphs using align                                   
54                                if ( element.name === 'p' ) {                                           
55                                        style = element.attributes.style;                                               
56                                        if ( style ) {                                                 
57                                                // Get the align from the style.                                                       
58                                                match = /(?:^|\s)text-align\s*:\s*(\w*);/i.exec( style );                                                       
59                                                var align = match && match[1];                                                 
60                                                if ( align ) {                                                         
61                                                        element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' );
62                                                        element.attributes.align = align;                                                       
63                                                }                                               
64                                        }                                       
65                                }                                       
66                                if ( !element.attributes.style )
67                                        delete element.attributes.style;                                       
68                                return element;                         
69                        }                       
70                },     
71                attributes : {                                 
72                        style : function( value, element ) {                                           
73                        // Return #RGB for background and border colors                                         
74                                return convertRGBToHex( value );                                       
75                        }               
76                }               
77        });
78}
79
80/**
81 * Convert a CSS rgb(R, G, B) color back to #RRGGBB format.
82 * @param Css style string (can include more than one color
83 * @return Converted css style.
84 */
85function convertRGBToHex( cssStyle ){   
86        return cssStyle.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue ) {                     
87                red = parseInt( red, 10 ).toString( 16 );                       
88                green = parseInt( green, 10 ).toString( 16 );                   
89                blue = parseInt( blue, 10 ).toString( 16 );                     
90                var color = [red, green, blue] ;                       
91                // Add padding zeros if the hex value is less than 0x10.                       
92                for ( var i = 0 ; i < color.length ; i++ )                             
93                        color[i] = String( '0' + color[i] ).slice( -2 ) ;                       
94                return '#' + color.join( '' ) ; 
95        });
96}
97
98CKEDITOR.editorConfig = function( config ) {
99        config.removePlugins = 'elementspath,resize,magicline';
100        config.extraPlugins = 'insertReference';
101        config.toolbar = [ 
102                { name: 'document',    items : [ 'Cut','Copy','Paste','PasteText' ] },
103            { name: 'editing',     items : [ 'Undo','Redo', '-', 'SelectAll' ] },
104            { name: 'colors',      items : [ 'TextColor','BGColor' ] },
105            { name: 'styles',      items : [ 'Font','FontSize' ] },
106            { name: 'osn',                 items : [ 'InsertReference' ] },
107            '/',
108            { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
109            { name: 'paragraph',   items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },
110            { name: 'links',       items : [ 'Link','Unlink','-','Image'] }                               
111        ];
112        config.toolbarCanCollapse = false;
113        config.skin = 'osn';
114        config.startupFocus = 'true';
115        config.enterMode = CKEDITOR.ENTER_BR;
116        config.autoParagraph = false;
117        config.disableNativeSpellChecker = false;
118        config.resize_enabled = false;
119        /*
120         * Clear preview text from image properties plugin
121         */
122        config.image_previewText = " ";
123        /*
124         * Dialog box configurations
125         */
126        config.dialog_backgroundCoverColor = 'black';
127        config.dialog_backgroundCoverOpacity = 0.25;
128        /*
129         * Simple HTML5 doctype
130         */
131        config.docType = '<!DOCTYPE HTML>';
132        /*
133         * Core styles to HTML instead of XHTML
134         */
135        config.coreStyles_bold = {element: 'b'};
136        config.coreStyles_italic = {element: 'i'};
137        config.coreStyles_underline = {element: 'u'};
138        config.coreStyles_strike = {element: 'strike'};
139        /*
140         * Font face
141         */
142        config.font_style = {
143                element: 'font',
144                attributes: {'face': '#(family)'}
145        };
146        /*                                               
147         * Font sizes.                                           
148         */                                             
149        config.fontSize_sizes = 'xx-small/1;x-small/2;small/3;medium/4;large/5;x-large/6;xx-large/7';
150        config.fontSize_style = {
151                element         : 'font',                                                               
152                attributes      : { 'size' : '#(size)' }                                                       
153        };
154        /*                                               
155         * Font colors.                                         
156         */                                             
157        config.colorButton_enableMore = true;
158        config.colorButton_foreStyle =  {                                                               
159                element : 'font',                                                               
160                attributes : { 'color' : '#(color)' }                                                   
161        };                             
162        config.colorButton_backStyle =  {                                                               
163                element : 'font',                                                               
164                styles  : { 'background-color' : '#(color)' }                                                   
165        };                             
166        /*                                               
167         * Styles combo.                                                 
168         */                                             
169        config.stylesSet =      [                                                                       
170                { name : 'Computer Code', element : 'code' },                                                                   
171                { name : 'Keyboard Phrase', element : 'kbd' },                                                                 
172                { name : 'Sample Text', element : 'samp' },                                                                     
173                { name : 'Variable', element : 'var' },                                                                 
174                { name : 'Deleted Text', element : 'del' },                                                                     
175                { name : 'Inserted Text', element : 'ins' },                                                                   
176                { name : 'Cited Work', element : 'cite' },
177                { name : 'Inline Quotation', element : 'q' }
178        ];
179        config.on = { 'instanceReady' : configureHtmlOutput };
180};
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy