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

Updated panel position on resize.

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

+ 5 - 1
packages/ckeditor5-ui/src/panel/balloon/balloonpanelview.js

@@ -7,7 +7,7 @@
  * @module ui/panel/balloon/balloonpanelview
  */
 
-/* globals document */
+/* globals document, window */
 
 import View from '../../view';
 import Template from '../../template';
@@ -185,9 +185,13 @@ export default class BalloonPanelView extends View {
 			}
 		}, { useCapture: true } );
 
+		// We need to listen on window resize event and update position.
+		this.listenTo( window, 'resize', () => this.attachTo( options ) );
+
 		// After all we need to clean up the listener.
 		this.once( 'change:isVisible', () => {
 			this.stopListening( document, 'scroll' );
+			this.stopListening( window, 'resize' );
 		} );
 	}
 }

+ 25 - 0
packages/ckeditor5-ui/tests/panel/balloon/balloonpanelview.js

@@ -464,6 +464,31 @@ describe( 'BalloonPanelView', () => {
 			// Still once.
 			expect( attachToSpy.calledOnce ).to.true;
 		} );
+
+		it( 'should attach balloon to the target constantly when browser window is resized', () => {
+			view.keepAttachedTo( { target, limiter } );
+
+			expect( attachToSpy.calledOnce ).to.true;
+			expect( attachToSpy.lastCall.args[ 0 ] ).to.deep.equal( { target, limiter } );
+
+			window.dispatchEvent( new Event( 'resize' ) );
+
+			expect( attachToSpy.calledTwice ).to.true;
+			expect( attachToSpy.lastCall.args[ 0 ] ).to.deep.equal( { target, limiter } );
+		} );
+
+		it( 'should stop attach when balloon is hidden', () => {
+			view.keepAttachedTo( { target, limiter } );
+
+			expect( attachToSpy.calledOnce ).to.true;
+
+			view.hide();
+
+			window.dispatchEvent( new Event( 'resize' ) );
+
+			// Still once.
+			expect( attachToSpy.calledOnce ).to.true;
+		} );
 	} );
 } );