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

Fix: Improved destroying of FileDialogButtonView.

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

+ 10 - 5
packages/ckeditor5-upload/src/ui/filedialogbuttonview.js

@@ -32,6 +32,7 @@ export default class FileDialogButtonView extends ButtonView {
 		 * @member {module:upload/ui/filedialogbuttonview~FileInputView}
 		 */
 		this.fileInputView = new FileInputView( locale );
+		this.addChildren( this.fileInputView );
 
 		/**
 		 * Accepted file types. Can be provided in form of file extensions, media type or one of:
@@ -42,7 +43,7 @@ export default class FileDialogButtonView extends ButtonView {
 		 * @observable
 		 * @member {String} #acceptedType
 		 */
-		this.fileInputView.bind( 'acceptedType' ).to( this, 'acceptedType' );
+		this.fileInputView.bind( 'acceptedType' ).to( this );
 
 		/**
 		 * Indicates if multiple files can be selected. Defaults to `true`.
@@ -50,8 +51,7 @@ export default class FileDialogButtonView extends ButtonView {
 		 * @observable
 		 * @member {Boolean} #allowMultipleFiles
 		 */
-		this.set( 'allowMultipleFiles', false );
-		this.fileInputView.bind( 'allowMultipleFiles' ).to( this, 'allowMultipleFiles' );
+		this.fileInputView.bind( 'allowMultipleFiles' ).to( this );
 
 		/**
 		 * Fired when file dialog is closed with file selected.
@@ -70,7 +70,13 @@ export default class FileDialogButtonView extends ButtonView {
 		this.on( 'execute', () => {
 			this.fileInputView.open();
 		} );
+	}
 
+	/**
+	 * @inheritDoc
+	 */
+	init() {
+		super.init();
 		document.body.appendChild( this.fileInputView.element );
 	}
 
@@ -78,9 +84,8 @@ export default class FileDialogButtonView extends ButtonView {
 	 * @inheritDoc
 	 */
 	destroy() {
-		document.body.removeChild( this.fileInputView.element );
-
 		super.destroy();
+		this.fileInputView.element.remove();
 	}
 }
 

+ 6 - 13
packages/ckeditor5-upload/tests/ui/filedialogbuttonview.js

@@ -5,33 +5,26 @@
 
 /* globals document */
 
-import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
 import FileDialogButtonView from '../../src/ui/filedialogbuttonview';
 
 describe( 'FileDialogButtonView', () => {
-	let view, editor;
+	let view, localeMock;
 
 	beforeEach( () => {
-		const editorElement = document.createElement( 'div' );
-		document.body.appendChild( editorElement );
+		localeMock = { t: val => val };
+		view = new FileDialogButtonView( localeMock );
 
-		return ClassicEditor
-			.create( editorElement )
-			.then( newEditor => {
-				editor = newEditor;
-
-				view = new FileDialogButtonView( editor.locale );
-			} );
+		return view.init();
 	} );
 
 	it( 'should append input view to document body', () => {
-		expect( view.fileInputView.element.parentNode ).to.equal( document.body );
+		expect( document.body.contains( view.fileInputView.element ) ).to.true;
 	} );
 
 	it( 'should remove input view from body after destroy', () => {
 		view.destroy();
 
-		expect( view.fileInputView.element.parentNode ).to.be.null;
+		expect( document.body.contains( view.fileInputView.element ) ).to.false;
 	} );
 
 	it( 'should open file dialog on execute', () => {