18 | | } |
| 18 | |
| 19 | var defaultStyleDef = editor.config.defaultTextStyle, |
| 20 | defaultStyle; |
| 21 | |
| 22 | if ( defaultStyleDef ) |
| 23 | { |
| 24 | // Allow inline style overrides. |
| 25 | defaultStyleDef.fullMatch = 1; |
| 26 | defaultStyle = new CKEDITOR.style( defaultStyleDef ); |
| 27 | |
| 28 | // Check default text style on any new selection position. |
| 29 | editor.on( 'selectionChange', function( evt ) |
| 30 | { |
| 31 | var sel = this.getSelection(), ranges = sel.getRanges(), range; |
| 32 | if ( ranges.length == 1 ) |
| 33 | { |
| 34 | range = ranges[ 0 ]; |
| 35 | if ( !defaultStyle.checkActive( evt.data.path ) ) |
| 36 | { |
| 37 | var enlarged = range.clone(), bm = range.createBookmark(); |
| 38 | enlarged.enlarge( CKEDITOR.ENLARGE_BLOCK_CONTENTS ); |
| 39 | defaultStyle.applyToRange( enlarged ); |
| 40 | range.moveToBookmark( bm ); |
| 41 | range.select(); |
| 42 | // Cancel this selection change in favor of the new (correct). |
| 43 | evt.cancel(); |
| 44 | } |
| 45 | } |
| 46 | }, editor, null, 2 ); |
| 47 | |
| 48 | // Ensure document wide default style on load. |
| 49 | editor.on( 'contentDom', function() |
| 50 | { |
| 51 | var range = new CKEDITOR.dom.range( this.document ); |
| 52 | range.selectNodeContents( this.document.getBody() ); |
| 53 | defaultStyle.applyToRange( range ); |
| 54 | }) |
| 55 | } |
| 56 | } |
| 1711 | |
| 1712 | /** |
| 1713 | * Set a default (global) font style for all inputted text in the editor, |
| 1714 | * which will be applied as inline style. |
| 1715 | * <strong>Note:</strong> In order to allow a different user style to override the default, |
| 1716 | * this style definition has to be a multi-valued style, like font size, but not a single valued |
| 1717 | * style like bold. |
| 1718 | * @name CKEDITOR.config.defaultTextStyle |
| 1719 | * @type Object. |
| 1720 | * @default null |
| 1721 | * @example |
| 1722 | * config.defaultTextStyle = |
| 1723 | * { |
| 1724 | * element : 'span', |
| 1725 | * styles : { 'font-size' : '16px', 'font-family' : 'Arial,Helvetica,Sans-serif' } |
| 1726 | * }; |
| 1727 | */ |
| 1728 | |