Sfoglia il codice sorgente

Updated classicreator MT with Dropdown UI component integration.

Aleksander Nowodzinski 9 anni fa
parent
commit
a3a59ecf91

+ 38 - 0
packages/ckeditor5-editor-classic/src/utils/imitatefeatures.js

@@ -9,6 +9,11 @@ import Model from '/ckeditor5/ui/model.js';
 import Button from '/ckeditor5/ui/button/button.js';
 import ButtonView from '/ckeditor5/ui/button/buttonview.js';
 
+import Collection from '/ckeditor5/utils/collection.js';
+
+import ListDropdown from '/ckeditor5/ui/dropdown/list/listdropdown.js';
+import DropdownView from '/ckeditor5/ui/dropdown/dropdownview.js';
+
 /**
  * Immitates that some features were loaded and did their job.
  *
@@ -37,6 +42,8 @@ export function imitateFeatures( editor ) {
 
 	editor.ui.featureComponents.add( 'bold', Button, ButtonView, boldModel );
 
+	// -------------------------------------------------------------------------------------------
+
 	/* istanbul ignore next */
 	const italicModel = new Model( {
 		isEnabled: true,
@@ -57,9 +64,40 @@ export function imitateFeatures( editor ) {
 
 	window.boldModel = boldModel;
 	window.italicModel = italicModel;
+
+	// -------------------------------------------------------------------------------------------
+
+	const fontCollection = new Collection( { idProperty: 'label' } );
+
+	/* istanbul ignore next */
+	[ 'Arial', 'Times New Roman', 'Comic Sans MS', 'Georgia', 'Trebuchet MS', 'Verdana' ]
+		.sort()
+		.forEach( font => {
+			fontCollection.add( new Model( { label: font, style: `font-family: "${ font }"` } ) );
+		} );
+
+	/* istanbul ignore next */
+	const fontListModel = new Model( {
+		items: fontCollection
+	} );
+
+	/* istanbul ignore next */
+	const fontModel = new Model( {
+		label: t( 'Font' ),
+		isEnabled: true,
+		isOn: false,
+		content: fontListModel
+	} );
+
+	editor.ui.featureComponents.add( 'font', ListDropdown, DropdownView, fontModel );
+
+	window.fontCollection = fontCollection;
+	window.Model = Model;
 }
 
 export function imitateDestroyFeatures() {
 	delete window.boldModel;
 	delete window.italicModel;
+	delete window.fontCollection;
+	delete window.Model;
 }

+ 3 - 1
packages/ckeditor5-editor-classic/tests/manual/classiccreator.js

@@ -16,7 +16,7 @@ let editor, editable, observer;
 function initEditor() {
 	CKEDITOR.create( '#editor', {
 		creator: ClassicCreator,
-		toolbar: [ 'bold', 'italic' ]
+		toolbar: [ 'bold', 'italic', 'font' ]
 	} )
 	.then( ( newEditor ) => {
 		console.log( 'Editor was initialized', newEditor );
@@ -45,3 +45,5 @@ function destroyEditor() {
 
 document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
 document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );
+
+initEditor();