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

FormatCommand class added.

Szymon Kupś пре 9 година
родитељ
комит
dc72932f51
1 измењених фајлова са 35 додато и 0 уклоњено
  1. 35 0
      packages/ckeditor5-heading/src/formatcommand.js

+ 35 - 0
packages/ckeditor5-heading/src/formatcommand.js

@@ -0,0 +1,35 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+import Command from '../command.js';
+
+export default class FormatCommand extends Command {
+	constructor( editor ) {
+		super( editor );
+
+		this.set( 'value', 'paragraph' );
+
+		this.listenTo( editor.document.selection, 'change', () => {
+			const position = editor.document.selection.getFirstPosition();
+			const parent = position.parent;
+
+			switch ( parent.name ) {
+				case 'h2':
+					this.value = 'heading1';
+					break;
+
+				case 'h3':
+					this.value = 'heading2';
+					break;
+
+				case 'h4':
+					this.value = 'heading3';
+					break;
+			}
+		} );
+	}
+}