Browse Source

Aligned link to the new BalloonPanelView API.

Aleksander Nowodzinski 9 years ago
parent
commit
a1e8d199db
2 changed files with 14 additions and 18 deletions
  1. 10 16
      packages/ckeditor5-link/src/link.js
  2. 4 2
      packages/ckeditor5-link/tests/link.js

+ 10 - 16
packages/ckeditor5-link/src/link.js

@@ -129,7 +129,6 @@ export default class Link extends Plugin {
 
 		// Create the balloon panel instance.
 		const balloonPanelView = new BalloonPanelView( editor.locale );
-
 		balloonPanelView.maxWidth = 300;
 
 		// Add balloonPanel.view#element to FocusTracker.
@@ -221,23 +220,18 @@ export default class Link extends Plugin {
 	 */
 	_attachPanelToElement( parentLink ) {
 		const viewDocument = this.editor.editing.view;
-		const domEditableElement = viewDocument.domConverter.getCorrespondingDomElement( viewDocument.selection.editableElement );
 		const targetLink = parentLink || getPositionParentLink( viewDocument.selection.getFirstPosition() );
 
-		// When selection is inside link element, then attach panel to this element.
-		if ( targetLink ) {
-			this.balloonPanelView.attachTo(
-				viewDocument.domConverter.getCorrespondingDomElement( targetLink ),
-				domEditableElement
-			);
-		}
-		// Otherwise attach panel to the selection.
-		else {
-			this.balloonPanelView.attachTo(
-				viewDocument.domConverter.viewRangeToDom( viewDocument.selection.getFirstRange() ),
-				domEditableElement
-			);
-		}
+		this.balloonPanelView.limiter = viewDocument.domConverter.getCorrespondingDomElement( viewDocument.selection.editableElement );
+
+		const target = targetLink ?
+				// When selection is inside link element, then attach panel to this element.
+				viewDocument.domConverter.getCorrespondingDomElement( targetLink )
+			:
+				// Otherwise attach panel to the selection.
+				viewDocument.domConverter.viewRangeToDom( viewDocument.selection.getFirstRange() );
+
+		this.balloonPanelView.attachTo( target );
 	}
 
 	/**

+ 4 - 2
packages/ckeditor5-link/tests/link.js

@@ -91,7 +91,8 @@ describe( 'Link', () => {
 
 			const linkElement = editorElement.querySelector( 'a' );
 
-			expect( attachToSpy.calledWithExactly( linkElement, editorElement ) ).to.true;
+			expect( balloonPanelView.limiter ).to.equal( editorElement );
+			expect( attachToSpy.calledWithExactly( linkElement ) ).to.true;
 		} );
 
 		it( 'should open panel attached to the selection, when there is non-collapsed selection', () => {
@@ -105,7 +106,8 @@ describe( 'Link', () => {
 
 			const selectedRange = editorElement.ownerDocument.getSelection().getRangeAt( 0 );
 
-			expect( attachToSpy.calledWithExactly( selectedRange, editorElement ) ).to.true;
+			expect( balloonPanelView.limiter ).to.equal( editorElement );
+			expect( attachToSpy.calledWithExactly( selectedRange ) ).to.true;
 		} );
 
 		it( 'should select panel input value when panel is opened', () => {