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

Tests: Updated FramedEditableUIView so it is a child of FramedEditableUIIframeView and extends EditableUIView.

Aleksander Nowodzinski 9 лет назад
Родитель
Сommit
9fa18276e8

+ 1 - 1
tests/_utils/ui/editableui/framed/framededitableui.js → tests/_utils/ui/editableui/framed/framededitableuiiframe.js

@@ -7,7 +7,7 @@
 
 import EditableUI from '/ckeditor5/ui/editableui/editableui.js';
 
-export default class FramedEditableUI extends EditableUI {
+export default class FramedEditableUIIframe extends EditableUI {
 	constructor( editor, editableModel ) {
 		super( editor, editableModel );
 

+ 77 - 0
tests/_utils/ui/editableui/framed/framededitableuiiframeview.js

@@ -0,0 +1,77 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+// import EditableUIView from '/ckeditor5/ui/editableui/editableuiview.js';
+import View from '/ckeditor5/ui/view.js';
+import FramedEditableUIView from './framededitableuiview.js';
+
+export default class FramedEditableUIIframeView extends View {
+	constructor( model, locale ) {
+		super( model, locale );
+
+		const bind = this.attributeBinder;
+
+		// Here's the tricky part - we must return the promise from init()
+		// because iframe loading may be asynchronous. However, we can't start
+		// listening to 'load' in init(), because at this point the element is already in the DOM
+		// and the 'load' event might already be fired.
+		// So here we store both - the promise and the deferred object so we're able to resolve
+		// the promise in _iframeLoaded.
+		this._iframePromise = new Promise( ( resolve, reject ) => {
+			this._iframeDeferred = { resolve, reject };
+		} );
+
+		this.template = {
+			tag: 'iframe',
+			attributes: {
+				class: [ 'ck-framededitable ck-reset-all' ],
+				// It seems that we need to allow scripts in order to be able to listen to events.
+				// TODO: Research that. Perhaps the src must be set?
+				sandbox: 'allow-same-origin allow-scripts',
+				width: bind.to( 'width' ),
+				height: bind.to( 'height' )
+			},
+			on: {
+				load: 'loaded'
+			}
+		};
+
+		this.on( 'loaded', this._iframeLoaded, this );
+	}
+
+	init() {
+		super.init();
+
+		return this._iframePromise;
+	}
+
+	/**
+	 * This getter exposes the {@link ui.editable.EditableUIView#editableElement}. It points to the
+	 * `<body>` inside the `<iframe>` document, which is provided by `FramedEditableUIView`.
+	 */
+	get editableElement() {
+		return this.editableUIView.editableElement;
+	}
+
+	_iframeLoaded() {
+		this.editableUIView = new FramedEditableUIView(
+			this.model,
+			this.locale,
+			this.element.contentDocument.body
+		);
+
+		this.editableUIView.init();
+
+		this._iframeDeferred.resolve();
+	}
+
+	destroy() {
+		super.destroy();
+
+		return this.editableUIView.destroy();
+	}
+}

+ 3 - 42
tests/_utils/ui/editableui/framed/framededitableuiview.js

@@ -8,48 +8,9 @@
 import EditableUIView from '/ckeditor5/ui/editableui/editableuiview.js';
 
 export default class FramedEditableUIView extends EditableUIView {
-	constructor( model, locale ) {
-		super( model, locale );
+	constructor( model, locale, editableElement ) {
+		super( model, locale, editableElement );
 
-		const bind = this.attributeBinder;
-
-		// Here's the tricky part - we must return the promise from init()
-		// because iframe loading may be asynchronous. However, we can't start
-		// listening to 'load' in init(), because at this point the element is already in the DOM
-		// and the 'load' event might already be fired.
-		// So here we store both - the promise and the deferred object so we're able to resolve
-		// the promise in _iframeLoaded.
-		this._iframePromise = new Promise( ( resolve, reject ) => {
-			this._iframeDeferred = { resolve, reject };
-		} );
-
-		this.template = {
-			tag: 'iframe',
-			attributes: {
-				class: [ 'ck-framededitable ck-reset-all' ],
-				// It seems that we need to allow scripts in order to be able to listen to events.
-				// TODO: Research that. Perhaps the src must be set?
-				sandbox: 'allow-same-origin allow-scripts',
-				width: bind.to( 'width' ),
-				height: bind.to( 'height' )
-			},
-			on: {
-				load: 'loaded'
-			}
-		};
-
-		this.on( 'loaded', this._iframeLoaded, this );
-	}
-
-	init() {
-		super.init();
-
-		return this._iframePromise;
-	}
-
-	_iframeLoaded() {
-		this.setEditableElement( this.element.contentDocument.body );
-
-		this._iframeDeferred.resolve();
+		this.template.attributes.class.push( 'ck-editor__editable_framed' );
 	}
 }