This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
fontfamilyediting.js
71 lines (61 loc) · 2.16 KB
/
fontfamilyediting.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module font/fontfamily/fontfamilyediting
*/
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import FontFamilyCommand from './fontfamilycommand';
import { normalizeOptions } from './utils';
import { buildDefinition, FONT_FAMILY } from '../utils';
/**
* The font family editing feature.
*
* It introduces the {@link module:font/fontfamily/fontfamilycommand~FontFamilyCommand command} and
* the `fontFamily` attribute in the {@link module:engine/model/model~Model model} which renders
* in the {@link module:engine/view/view view} as an inline `<span>` element (`<span style="font-family: Arial">`),
* depending on the {@link module:font/fontfamily~FontFamilyConfig configuration}.
*
* @extends module:core/plugin~Plugin
*/
export default class FontFamilyEditing extends Plugin {
/**
* @inheritDoc
*/
constructor( editor ) {
super( editor );
// Define default configuration using font families shortcuts.
editor.config.define( FONT_FAMILY, {
options: [
'default',
'Arial, Helvetica, sans-serif',
'Courier New, Courier, monospace',
'Georgia, serif',
'Lucida Sans Unicode, Lucida Grande, sans-serif',
'Tahoma, Geneva, sans-serif',
'Times New Roman, Times, serif',
'Trebuchet MS, Helvetica, sans-serif',
'Verdana, Geneva, sans-serif'
]
} );
}
/**
* @inheritDoc
*/
init() {
const editor = this.editor;
// Allow fontFamily attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: FONT_FAMILY } );
editor.model.schema.setAttributeProperties( FONT_FAMILY, {
isFormatting: true,
copyOnEnter: true
} );
// Get configured font family options without "default" option.
const options = normalizeOptions( editor.config.get( 'fontFamily.options' ) ).filter( item => item.model );
const definition = buildDefinition( FONT_FAMILY, options );
// Set-up the two-way conversion.
editor.conversion.attributeToElement( definition );
editor.commands.add( FONT_FAMILY, new FontFamilyCommand( editor ) );
}
}