瀏覽代碼

Switched to the limiterElement passed via StickyToolbarModel instead of View constructor.

Aleksander Nowodzinski 9 年之前
父節點
當前提交
c3f13678b4

+ 14 - 9
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -29,6 +29,14 @@ export default class ClassicEditorUI extends BoxedEditorUI {
 		super( editor );
 
 		/**
+		 * Toolbar controller.
+		 *
+		 * @readonly
+		 * @member {ui.toolbar.Toolbar} editor-classic.ClassicEditorUI#toolbar
+		 */
+		this.toolbar = this._createToolbar();
+
+		/**
 		 * Editable UI controller.
 		 *
 		 * @readonly
@@ -37,14 +45,11 @@ export default class ClassicEditorUI extends BoxedEditorUI {
 		this.editable = this._createEditableUI();
 	}
 
+	/**
+	 * @inheritDoc
+	 */
 	init() {
-		/**
-		 * Toolbar controller.
-		 *
-		 * @readonly
-		 * @member {ui.toolbar.Toolbar} editor-classic.ClassicEditorUI#toolbar
-		 */
-		this.toolbar = this._createToolbar( this.editor.ui.view.element );
+		this.toolbar.model.set( 'limiterElement', this.editor.ui.view.element );
 
 		return super.init();
 	}
@@ -65,7 +70,7 @@ export default class ClassicEditorUI extends BoxedEditorUI {
 	 * @protected
 	 * @returns {ui.toolbar.Toolbar}
 	 */
-	_createToolbar( editorUiElement ) {
+	_createToolbar() {
 		const editor = this.editor;
 		const model = new Model( {
 			config: this.editor.config.get( 'toolbar' )
@@ -73,7 +78,7 @@ export default class ClassicEditorUI extends BoxedEditorUI {
 
 		model.bind( 'isActive' ).to( editor.editing.view.getRoot(), 'isFocused' );
 
-		const toolbar = new StickyToolbar( model, new StickyToolbarView( editor.locale, editorUiElement ), editor );
+		const toolbar = new StickyToolbar( model, new StickyToolbarView( editor.locale ), editor );
 		this.add( 'top', toolbar );
 
 		return toolbar;

+ 7 - 11
packages/ckeditor5-editor-classic/tests/classiceditorui.js

@@ -40,6 +40,11 @@ describe( 'ClassicEditorUI', () => {
 	} );
 
 	describe( 'constructor', () => {
+		it( 'creates toolbar', () => {
+			expect( editorUI.toolbar ).to.be.instanceof( Toolbar );
+			expect( editorUI.toolbar.view ).to.be.instanceof( StickyToolbarView );
+		} );
+
 		it( 'creates editable', () => {
 			expect( editorUI.editable ).to.be.instanceof( EditableUI );
 			expect( editorUI.editable.view ).to.be.instanceof( InlineEditableUIView );
@@ -64,10 +69,9 @@ describe( 'ClassicEditorUI', () => {
 			expect( editorUI.init() ).to.be.instanceof( Promise );
 		} );
 
-		it( 'creates toolbar', ( done ) => {
+		it( 'sets toolbar.model#limiterElement', ( done ) => {
 			return editorUI.init().then( () => {
-				expect( editorUI.toolbar ).to.be.instanceof( Toolbar );
-				expect( editorUI.toolbar.view ).to.be.instanceof( StickyToolbarView );
+				expect( editorUI.toolbar.model.limiterElement ).to.equal( editorUI.view.element );
 
 				done();
 			} );
@@ -75,16 +79,8 @@ describe( 'ClassicEditorUI', () => {
 	} );
 
 	describe( '_createToolbar', () => {
-		beforeEach( () => {
-			return editorUI.init();
-		} );
-
 		it( 'passes toolbar config to the model', () => {
 			expect( editorUI.toolbar.model.config ).to.have.members( [ 'foo', 'bar' ] );
 		} );
-
-		it( 'passes the limiter element to the view constructor', () => {
-			expect( editorUI.toolbar.view.limiterElement ).to.equal( editorUI.view.element );
-		} );
 	} );
 } );