Преглед изворни кода

Added: Add 'default' option to FontFamily options.

Maciej Gołaszewski пре 8 година
родитељ
комит
0556b3878a

+ 4 - 4
packages/ckeditor5-font/src/fontfamily/fontfamilycommand.js

@@ -40,25 +40,25 @@ export default class FontFamilyCommand extends Command {
 	 *
 	 *
 	 * @protected
 	 * @protected
 	 * @param {Object} [options] Options for the executed command.
 	 * @param {Object} [options] Options for the executed command.
-	 * @param {String} [options.fontSize] FontSize value to apply.
+	 * @param {String} [options.fontFamily] FontSize value to apply.
 	 */
 	 */
 	execute( options ) {
 	execute( options ) {
 		const model = this.editor.model;
 		const model = this.editor.model;
 		const document = model.document;
 		const document = model.document;
 		const selection = document.selection;
 		const selection = document.selection;
 
 
-		// Do not apply fontSize on collapsed selection.
+		// Do not apply fontFamily on collapsed selection.
 		if ( selection.isCollapsed ) {
 		if ( selection.isCollapsed ) {
 			return;
 			return;
 		}
 		}
 
 
-		const value = options.fontSize;
+		const value = options.fontFamily;
 
 
 		model.change( writer => {
 		model.change( writer => {
 			const ranges = model.schema.getValidRanges( selection.getRanges(), 'fontFamily' );
 			const ranges = model.schema.getValidRanges( selection.getRanges(), 'fontFamily' );
 
 
 			for ( const range of ranges ) {
 			for ( const range of ranges ) {
-				if ( value !== 'normal' ) {
+				if ( value !== 'default' ) {
 					writer.setAttribute( 'fontFamily', value, range );
 					writer.setAttribute( 'fontFamily', value, range );
 				} else {
 				} else {
 					writer.removeAttribute( 'fontFamily', range );
 					writer.removeAttribute( 'fontFamily', range );

+ 12 - 2
packages/ckeditor5-font/src/fontfamily/fontfamilyediting.js

@@ -30,6 +30,7 @@ export default class FontFamilyEditing extends Plugin {
 		// Define default configuration using named presets
 		// Define default configuration using named presets
 		editor.config.define( 'fontFamily', {
 		editor.config.define( 'fontFamily', {
 			items: [
 			items: [
+				'default',
 				'Arial, Helvetica, sans-serif',
 				'Arial, Helvetica, sans-serif',
 				'Courier New, Courier, monospace',
 				'Courier New, Courier, monospace',
 				'Georgia, serif',
 				'Georgia, serif',
@@ -46,12 +47,14 @@ export default class FontFamilyEditing extends Plugin {
 		const editing = editor.editing;
 		const editing = editor.editing;
 
 
 		// Add converters from view to model.
 		// Add converters from view to model.
-		for ( const item of this.configuredItems ) {
+		const items = this.configuredItems.filter( item => item.model !== 'default' );
+
+		for ( const item of items ) {
 			viewToModelAttribute( 'fontFamily', item, [ data.viewToModel ] );
 			viewToModelAttribute( 'fontFamily', item, [ data.viewToModel ] );
 		}
 		}
 
 
 		// Covert from model to view.
 		// Covert from model to view.
-		modelAttributeToViewAttributeElement( 'fontFamily', this.configuredItems, [ data.modelToView, editing.modelToView ] );
+		modelAttributeToViewAttributeElement( 'fontFamily', items, [ data.modelToView, editing.modelToView ] );
 
 
 		// Add FontSize command.
 		// Add FontSize command.
 		editor.commands.add( 'fontFamily', new FontFamilyCommand( editor ) );
 		editor.commands.add( 'fontFamily', new FontFamilyCommand( editor ) );
@@ -100,6 +103,13 @@ function getItemDefinition( item ) {
 		return item;
 		return item;
 	}
 	}
 
 
+	if ( item === 'default' ) {
+		return {
+			title: 'Default', // TODO localize us
+			model: 'default'
+		};
+	}
+
 	// Ignore falsy values
 	// Ignore falsy values
 	if ( typeof item !== 'string' ) {
 	if ( typeof item !== 'string' ) {
 		return;
 		return;

+ 5 - 1
packages/ckeditor5-font/src/fontfamily/fontfamilyui.js

@@ -39,9 +39,13 @@ export default class FontFamilyUI extends Plugin {
 				commandName: 'fontFamily',
 				commandName: 'fontFamily',
 				commandParam: option.model,
 				commandParam: option.model,
 				label: option.title,
 				label: option.title,
-				style: 'font-family:' + option.view.style[ 'font-family' ]
 			} );
 			} );
 
 
+			// Try to set style
+			if ( option.view && option.view.style ) {
+				itemModel.set( 'style', 'font-family:' + option.view.style[ 'font-family' ] );
+			}
+
 			// Add the option to the collection.
 			// Add the option to the collection.
 			dropdownItems.add( itemModel );
 			dropdownItems.add( itemModel );
 		}
 		}