瀏覽代碼

Merge pull request #76 from ckeditor/t/75

Aligned link to the new BalloonPanelView API.
Piotrek Koszuliński 9 年之前
父節點
當前提交
c1a5ebf109
共有 2 個文件被更改,包括 19 次插入18 次删除
  1. 11 16
      packages/ckeditor5-link/src/link.js
  2. 8 2
      packages/ckeditor5-link/tests/link.js

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

@@ -132,7 +132,6 @@ export default class Link extends Plugin {
 
 
 		// Create the balloon panel instance.
 		// Create the balloon panel instance.
 		const balloonPanelView = new BalloonPanelView( editor.locale );
 		const balloonPanelView = new BalloonPanelView( editor.locale );
-
 		balloonPanelView.maxWidth = 300;
 		balloonPanelView.maxWidth = 300;
 
 
 		// Add balloonPanel.view#element to FocusTracker.
 		// Add balloonPanel.view#element to FocusTracker.
@@ -224,23 +223,19 @@ export default class Link extends Plugin {
 	 */
 	 */
 	_attachPanelToElement( parentLink ) {
 	_attachPanelToElement( parentLink ) {
 		const viewDocument = this.editor.editing.view;
 		const viewDocument = this.editor.editing.view;
-		const domEditableElement = viewDocument.domConverter.getCorrespondingDomElement( viewDocument.selection.editableElement );
 		const targetLink = parentLink || getPositionParentLink( viewDocument.selection.getFirstPosition() );
 		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
-			);
-		}
+		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,
+			limiter: viewDocument.domConverter.getCorrespondingDomElement( viewDocument.selection.editableElement )
+		} );
 	}
 	}
 
 
 	/**
 	/**

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

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