8
0
Просмотр исходного кода

Merge pull request #19 from ckeditor/t/18

t/18: Updated feature to support event delegation mechanism implemented in …
Szymon Cofalik 9 лет назад
Родитель
Сommit
612fd41ce7

+ 8 - 9
packages/ckeditor5-heading/src/headings.js

@@ -42,27 +42,26 @@ export default class Headings extends Feature {
 			} ) );
 		}
 
-		// Create item list model.
-		const itemListModel = new Model( {
-			items: collection
-		} );
-
 		// Create dropdown model.
 		const dropdownModel = new Model( {
 			isEnabled: true,
 			isOn: false,
 			label: 'Headings',
 			withText: true,
-			content: itemListModel
+
+			// Create item list model.
+			content: new Model( {
+				items: collection
+			} )
 		} );
 
 		// Bind dropdown model to command.
 		dropdownModel.bind( 'isEnabled' ).to( command, 'isEnabled' );
 		dropdownModel.bind( 'label' ).to( command, 'value', format => format.label );
 
-		// Execute command when item from dropdown is selected.
-		this.listenTo( itemListModel, 'execute', ( evt, itemModel ) => {
-			editor.execute( 'headings', itemModel.id );
+		// Execute command when an item from the dropdown is selected.
+		this.listenTo( dropdownModel, 'execute', ( evt ) => {
+			editor.execute( 'headings', evt.source.id );
 			editor.editing.view.focus();
 		} );
 

+ 6 - 5
packages/ckeditor5-heading/tests/headings.js

@@ -49,20 +49,21 @@ describe( 'Headings', () => {
 	it( 'should execute format command on model execute event', () => {
 		const executeSpy = testUtils.sinon.spy( editor, 'execute' );
 		const controller = editor.ui.featureComponents.create( 'headings' );
-		const model = controller.model.content;
+		const model = controller.model;
 
-		model.fire( 'execute', { id: 'paragraph', label: 'Paragraph' } );
+		model.id = 'foo';
+		model.fire( 'execute' );
 
 		sinon.assert.calledOnce( executeSpy );
-		sinon.assert.calledWithExactly( executeSpy, 'headings', 'paragraph' );
+		sinon.assert.calledWithExactly( executeSpy, 'headings', 'foo' );
 	} );
 
 	it( 'should focus view after command execution', () => {
 		const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
 		const controller = editor.ui.featureComponents.create( 'headings' );
-		const model = controller.model.content;
+		const model = controller.model;
 
-		model.fire( 'execute', { id: 'paragraph', label: 'Paragraph' } );
+		model.fire( 'execute' );
 
 		sinon.assert.calledOnce( focusSpy );
 	} );