Bladeren bron

[WIP] Introduced core.Feature and core.BoldFeature.

Szymon Cofalik 9 jaren geleden
bovenliggende
commit
8e743d6946
2 gewijzigde bestanden met toevoegingen van 70 en 0 verwijderingen
  1. 43 0
      packages/ckeditor5-engine/src/bold/boldfeature.js
  2. 27 0
      packages/ckeditor5-engine/src/feature.js

+ 43 - 0
packages/ckeditor5-engine/src/bold/boldfeature.js

@@ -0,0 +1,43 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+import Feature from '../feature.js';
+import AttributeCommand from '../attributecommand.js';
+
+/**
+ * Bold feature.
+ *
+ * Bold features bring in possibility to mark some of the content (most commonly some text) as "important" ("bold").
+ *
+ * @class features.Bold
+ */
+
+export default class BoldFeature extends Feature {
+	init() {
+		// Create instance of AttributeCommand which will handle bold attribute and add to commands registry.
+		this.editor.commands.set( 'bold', new AttributeCommand( this.editor, 'bold' ) );
+
+		// Something like this...........
+		this.editor.treeController.registerAttributeConverter( 'bold', true, 'strong' );
+		this.editor.treeController.registerViewToModelConverter(
+			[
+				[ 'tag', 'b' ],
+				[ 'tag', 'strong' ],
+				[ 'style', 'fontWeight', 'bold' ]
+			],
+			'bold',
+			true
+		);
+
+		this.editor.document.schema.allow( { name: 'inline', attribute: 'bold', inside: 'block' } );
+		this.editor.document.schema.allow( { name: 'block', attribute: 'bold', inside: 'root' } );
+	}
+
+	static get requires() {
+		return [];
+	}
+}

+ 27 - 0
packages/ckeditor5-engine/src/feature.js

@@ -0,0 +1,27 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+import Plugin from './plugin.js';
+
+/**
+ * The base class for CKEditor feature classes.
+ *
+ * @class core.Feature
+ */
+
+export default class Feature extends Plugin {
+	/**
+	 * Creates a new Plugin instance.
+	 *
+	 * @param {core.Editor} editor
+	 */
+	constructor( editor ) {
+		super( editor );
+	}
+
+	init() {}
+}