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

Renamed and simplified visible getter.

Oskar Wróbel 8 лет назад
Родитель
Сommit
0ba937ec25

+ 9 - 7
packages/ckeditor5-ui/src/contextualballoon.js

@@ -58,13 +58,15 @@ export default class ContextualBalloon extends Plugin {
 	}
 
 	/**
-	 * Returns configuration of the currently visible view or `null` when there are no
+	 * Returns the currently visible view or `null` when there are no
 	 * views in the stack.
 	 *
-	 * @returns {module:ui/contextualballoon~ViewConfig|null}
+	 * @returns {module:ui/view~View|null}
 	 */
-	get visible() {
-		return this._stack.get( this.view.content.get( 0 ) ) || null;
+	get visibleView() {
+		const item = this._stack.get( this.view.content.get( 0 ) );
+
+		return item ? item.view : null;
 	}
 
 	/**
@@ -93,9 +95,9 @@ export default class ContextualBalloon extends Plugin {
 		}
 
 		// When adding view to the not empty balloon.
-		if ( this.visible ) {
+		if ( this.visibleView ) {
 			// Remove displayed content from the view.
-			this.view.content.remove( this.visible.view );
+			this.view.content.remove( this.visibleView );
 		}
 
 		// Add new view to the stack.
@@ -122,7 +124,7 @@ export default class ContextualBalloon extends Plugin {
 		}
 
 		// When visible view is being removed.
-		if ( this.visible.view === view ) {
+		if ( this.visibleView === view ) {
 			// We need to remove it from the view content.
 			this.view.content.remove( view );
 

+ 9 - 24
packages/ckeditor5-ui/tests/contextualballoon.js

@@ -80,7 +80,7 @@ describe( 'ContextualBalloon', () => {
 				position: { target: 'fake' }
 			} );
 
-			expect( balloon.visible.view === viewB ).to.true;
+			expect( balloon.visibleView ).to.equal( viewB );
 			expect( balloon.hasView( viewA ) ).to.true;
 		} );
 
@@ -156,17 +156,14 @@ describe( 'ContextualBalloon', () => {
 		} );
 	} );
 
-	describe( 'visible', () => {
+	describe( 'visibleView', () => {
 		it( 'should return data of currently visible view', () => {
 			balloon.add( {
 				view: viewA,
 				position: { target: 'fake' }
 			} );
 
-			expect( balloon.visible ).to.deep.equal( {
-				view: viewA,
-				position: { target: 'fake' }
-			} );
+			expect( balloon.visibleView ).to.equal( viewA );
 		} );
 
 		it( 'should return data of currently visible view when there is more than one in the stack', () => {
@@ -180,14 +177,11 @@ describe( 'ContextualBalloon', () => {
 				position: { target: 'fake' }
 			} );
 
-			expect( balloon.visible ).to.deep.equal( {
-				view: viewB,
-				position: { target: 'fake' }
-			} );
+			expect( balloon.visibleView ).to.equal( viewB );
 		} );
 
 		it( 'should return `null` when the stack is empty', () => {
-			expect( balloon.visible ).to.null;
+			expect( balloon.visibleView ).to.null;
 		} );
 	} );
 
@@ -200,7 +194,7 @@ describe( 'ContextualBalloon', () => {
 
 			balloon.remove( viewA );
 
-			expect( balloon.visible ).to.null;
+			expect( balloon.visibleView ).to.null;
 		} );
 
 		it( 'should remove given view and set previous in the stack as visible when removed view was visible', () => {
@@ -216,10 +210,7 @@ describe( 'ContextualBalloon', () => {
 
 			balloon.remove( viewB );
 
-			expect( balloon.visible ).to.deep.equal( {
-				view: viewA,
-				position: { target: 'fake' }
-			} );
+			expect( balloon.visibleView ).to.equal( viewA );
 		} );
 
 		it( 'should remove given view from the stack when view is not visible', () => {
@@ -235,10 +226,7 @@ describe( 'ContextualBalloon', () => {
 
 			balloon.remove( viewA );
 
-			expect( balloon.visible ).to.deep.equal( {
-				view: viewB,
-				position: { target: 'fake' }
-			} );
+			expect( balloon.visibleView ).to.equal( viewB );
 		} );
 
 		it( 'should throw an error when there is no given view in the stack', () => {
@@ -304,10 +292,7 @@ describe( 'ContextualBalloon', () => {
 
 			balloon.remove( viewA );
 
-			expect( balloon.visible ).to.deep.equal( {
-				view: viewB,
-				position: { target: 'fake' }
-			} );
+			expect( balloon.visibleView ).to.equal( viewB );
 		} );
 
 		it( 'should throw an error when there is no given view in the stack', () => {

+ 1 - 1
packages/ckeditor5-ui/tests/manual/contextualballoon/contextualballoon.js

@@ -142,7 +142,7 @@ class PluginGeneric extends Plugin {
 	}
 
 	get _isVisible() {
-		return this._balloon.visible && this._balloon.visible.view === this.view;
+		return this._balloon.visibleView === this.view;
 	}
 
 	afterInit() {