Răsfoiți Sursa

Added isPanelInStack method to the ContextualBalloon interface.

Oskar Wróbel 8 ani în urmă
părinte
comite
2db5e75466

+ 10 - 0
packages/ckeditor5-ui/src/contextualballoon.js

@@ -48,6 +48,16 @@ export default class ContextualBalloon {
 		return this._stack.get( this.view.content.get( 0 ) ) || null;
 	}
 
+	/**
+	 * Returns `true` when panel of given view is in the stack otherwise returns `false`.
+	 *
+	 * @param {module:ui:view~View} view
+	 * @returns {Boolean}
+	 */
+	isPanelInStack( view ) {
+		return this._stack.has( view );
+	}
+
 	/**
 	 * Adds panel to the stack and makes this panel visible.
 	 *

+ 30 - 0
packages/ckeditor5-ui/tests/contextualballoon.js

@@ -27,6 +27,36 @@ describe( 'ContextualBalloon', () => {
 		balloon.view.attachTo.restore();
 	} );
 
+	describe( 'isPanelInStack()', () => {
+		it( 'should return true when panel of given view is in stack', () => {
+			balloon.add( {
+				view: viewA,
+				position: { target: 'fake' }
+			} );
+
+			expect( balloon.isPanelInStack( viewA ) ).to.true;
+		} );
+
+		it( 'should return true when panel of given view is in stack but is not visible', () => {
+			balloon.add( {
+				view: viewA,
+				position: { target: 'fake' }
+			} );
+
+			balloon.add( {
+				view: viewB,
+				position: { target: 'fake' }
+			} );
+
+			expect( balloon.visible.view === viewB ).to.true;
+			expect( balloon.isPanelInStack( viewA ) ).to.true;
+		} );
+
+		it( 'should return false when panel of given view is not in stack', () => {
+			expect( balloon.isPanelInStack( viewA ) ).to.false;
+		} );
+	} );
+
 	describe( 'add()', () => {
 		it( 'should add panel to the stack and display in balloon', () => {
 			balloon.add( {