Ticket #10740: messageEntry_config.js

File messageEntry_config.js, 6.0 KB (added by Nora, 11 years ago)

custom/messageEntry_config.js

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.toolbarCanCollapse = false;
101  config.skin = 'msgEntry';
102  config.startupFocus = 'true';
103  config.enterMode = CKEDITOR.ENTER_BR;
104  config.autoParagraph = false;
105  config.disableNativeSpellChecker = false;
106  /*
107   * Configurations specific to matching current web client RTE
108   */
109  config.toolbarLocation = 'bottom';
110  config.keystrokes = [
111    [13 /*Enter*/, 'enterBehavior'],
112
113    [CKEDITOR.ALT + 121 /*F10*/, 'toolbarFocus'],
114    [CKEDITOR.ALT + 122 /*F11*/, 'elementsPathFocus'],
115
116    [CKEDITOR.SHIFT + 121 /*F10*/, 'contextMenu'],
117
118    [CKEDITOR.CTRL + 90 /*Z*/, 'undo'],
119    [CKEDITOR.CTRL + 89 /*Y*/, 'redo'],
120    [CKEDITOR.CTRL + CKEDITOR.SHIFT + 90 /*Z*/, 'redo'],
121
122    [CKEDITOR.CTRL + 76 /*L*/, 'link'],
123
124    [CKEDITOR.CTRL + 66 /*B*/, 'bold'],
125    [CKEDITOR.CTRL + 73 /*I*/, 'italic'],
126    [CKEDITOR.CTRL + 85 /*U*/, 'underline']
127  ];
128  /*
129   * Clear preview text from image properties plugin
130   */
131  config.image_previewText = " ";
132  /*
133   * Dialog box configurations
134   */
135  config.dialog_backgroundCoverColor = 'black';
136  config.dialog_backgroundCoverOpacity = 0.25;
137  /*
138   * Simple HTML5 doctype
139   */
140  config.docType = '<!DOCTYPE HTML>';
141  /*
142   * Core styles to HTML instead of XHTML
143   */
144  config.coreStyles_bold = {element: 'b'};
145  config.coreStyles_italic = {element: 'i'};
146  config.coreStyles_underline = {element: 'u'};
147  config.coreStyles_strike = {element: 'strike'};
148  /*
149   * Font face
150   */
151  config.font_style = {
152    element: 'font',
153    attributes: {'face': '#(family)'}
154  };
155  /*
156   * Font sizes.
157   */
158  config.fontSize_sizes = 'xx-small/1;x-small/2;small/3;medium/4;large/5;x-large/6;xx-large/7';
159  config.fontSize_style = {
160    element   : 'font',
161    attributes  : { 'size' : '#(size)' }
162  };
163  /*
164   * Font colors.
165   */
166  config.colorButton_enableMore = true;
167  config.colorButton_foreStyle =  {
168    element : 'font',
169    attributes : { 'color' : '#(color)' }
170  };
171  config.colorButton_backStyle =  {
172    element : 'font',
173    styles  : { 'background-color' : '#(color)' }
174  };
175  /*
176   * Styles combo.
177   */
178  config.stylesSet =  [
179    { name : 'Computer Code', element : 'code' },
180    { name : 'Keyboard Phrase', element : 'kbd' },
181    { name : 'Sample Text', element : 'samp' },
182    { name : 'Variable', element : 'var' },
183    { name : 'Deleted Text', element : 'del' },
184    { name : 'Inserted Text', element : 'ins' },
185    { name : 'Cited Work', element : 'cite' },
186    { name : 'Inline Quotation', element : 'q' }
187  ];
188  config.on = { 'instanceReady' : configureHtmlOutput };
189};
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy