' );
+ } );
+ } );
+
+ it( 'editor.element should be equal to editor.ui.view.element when data is passed', () => {
+ return ClassicEditor.create( '
Hello world!
', {
+ plugins: [ Paragraph ]
+ } ).then( editor => {
+ expect( editor.element ).to.equal( editor.ui.view.element );
+ } );
+ } );
+
describe( 'ui', () => {
it( 'creates the UI using BoxedEditorUI classes', () => {
expect( editor.ui ).to.be.instanceof( ClassicEditorUI );
From 633b5d388e06f5d2ab96156286d53ce06717422a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Szymon=20Kup=C5=9B?=
Date: Tue, 15 May 2018 17:12:19 +0200
Subject: [PATCH 03/13] Improved documentation.
---
src/classiceditor.js | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/classiceditor.js b/src/classiceditor.js
index cca0a7b..6d41f39 100644
--- a/src/classiceditor.js
+++ b/src/classiceditor.js
@@ -54,8 +54,10 @@ export default class ClassicEditor extends Editor {
* {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`} method instead.
*
* @protected
- * @param {HTMLElement} element The DOM element that will be the source for the created editor.
- * The data will be loaded from it and loaded back to it once the editor is destroyed.
+ * @param {HTMLElement} elementOrData The DOM element that will be the source for the created editor.
+ * The data will be loaded from it and loaded back to it once the editor is destroyed. If data is provided, `editor.element`
+ * should be added manually to the DOM after the editor is initialized. For more information see
+ * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}.
* @param {module:core/editor/editorconfig~EditorConfig} config The editor configuration.
*/
constructor( elementOrData, config ) {
@@ -131,6 +133,29 @@ export default class ClassicEditor extends Editor {
* console.error( err.stack );
* } );
*
+ * Creating instance when using initial data instead of DOM element:
+ *
+ * import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
+ * import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
+ * import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
+ * import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
+ * import ...
+ *
+ * ClassicEditor
+ * .create( '
Hello world!
', {
+ * plugins: [ Essentials, Bold, Italic, ... ],
+ * toolbar: [ 'bold', 'italic', ... ]
+ * } )
+ * .then( editor => {
+ * console.log( 'Editor was initialized', editor );
+ *
+ * // Initial data was provided so `editor.element` needs to be added manually to the DOM.
+ * document.body.appendChild( editor.element );
+ * } )
+ * .catch( err => {
+ * console.error( err.stack );
+ * } );
+ *
* @param {HTMLElement} element The DOM element that will be the source for the created editor.
* The data will be loaded from it and loaded back to it once the editor is destroyed.
* @param {module:core/editor/editorconfig~EditorConfig} config The editor configuration.
From f38aec793645d0d282935547b9366d2f29d9bf99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Szymon=20Kup=C5=9B?=
Date: Tue, 15 May 2018 18:49:46 +0200
Subject: [PATCH 04/13] Improved manual test with data initialization.
---
tests/manual/classiceditor-data.js | 34 +++++++++---------------------
tests/manual/classiceditor-data.md | 19 ++---------------
2 files changed, 12 insertions(+), 41 deletions(-)
diff --git a/tests/manual/classiceditor-data.js b/tests/manual/classiceditor-data.js
index e0f00fc..018dfc4 100644
--- a/tests/manual/classiceditor-data.js
+++ b/tests/manual/classiceditor-data.js
@@ -13,28 +13,19 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Undo from '@ckeditor/ckeditor5-undo/src/undo';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
-import testUtils from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
-
-let editor, editable, observer;
const data = '
Hello world!
This is an editor instance.
';
+window.editors = [];
+
function initEditor() {
ClassicEditor
.create( data, {
plugins: [ Enter, Typing, Paragraph, Undo, Heading, Bold, Italic ],
toolbar: [ 'heading', '|', 'bold', 'italic', 'undo', 'redo' ]
} )
- .then( newEditor => {
- console.log( 'Editor was initialized', newEditor );
- console.log( 'You can now play with it using global `editor` and `editable` variables.' );
-
- window.editor = editor = newEditor;
- window.editable = editable = editor.editing.view.document.getRoot();
-
- observer = testUtils.createObserver();
- observer.observe( 'Editable', editable, [ 'isFocused' ] );
-
+ .then( editor => {
+ window.editors.push( editor );
document.body.appendChild( editor.element );
} )
.catch( err => {
@@ -43,17 +34,12 @@ function initEditor() {
}
function destroyEditor() {
- editor.destroy()
- .then( () => {
- editor.element.remove();
-
- window.editor = editor = null;
- window.editable = editable = null;
-
- observer.stopListening();
- observer = null;
- console.log( 'Editor was destroyed' );
- } );
+ window.editors.forEach( editor => {
+ editor.destroy()
+ .then( () => {
+ editor.element.remove();
+ } );
+ } );
}
document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
diff --git a/tests/manual/classiceditor-data.md b/tests/manual/classiceditor-data.md
index 0831642..eeffc09 100644
--- a/tests/manual/classiceditor-data.md
+++ b/tests/manual/classiceditor-data.md
@@ -1,18 +1,3 @@
1. Click "Init editor".
-2. Expected:
- * Framed editor should be created.
- * Original element should disappear.
- * There should be a toolbar with "Bold", "Italic", "Undo" and "Redo" buttons.
-3. Click "Destroy editor".
-4. Expected:
- * Editor should be destroyed.
- * Original element should be visible.
- * The element should contain its data (updated).
- * The 'ck-body region' should be removed.
-
-## Notes:
-
-* You can play with:
- * `editable.isReadOnly`,
-* Changes to `editable.isFocused` should be logged to the console.
-* Features should work.
+2. New editor instance should be appended to the document with initial data in it.
+3. After clicking "Destroy editor" all editors should be removed from the document.
From 3232bfbbdd0eb68cf99a60017bf0a5195e336444 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Szymon=20Kup=C5=9B?=
Date: Tue, 15 May 2018 18:51:20 +0200
Subject: [PATCH 05/13] Removed unused CSS class.
---
tests/manual/classiceditor-data.html | 7 -------
1 file changed, 7 deletions(-)
diff --git a/tests/manual/classiceditor-data.html b/tests/manual/classiceditor-data.html
index 168f3a1..7bf3aa6 100644
--- a/tests/manual/classiceditor-data.html
+++ b/tests/manual/classiceditor-data.html
@@ -8,11 +8,4 @@
width: 10000px;
height: 10000px;
}
-
- .ck-editor {
- margin-top: 200px;
- margin-left: 100px;
- margin-bottom: 200px;
- width: 450px;
- }
From 8a7ea542ec9f677b6c55571c5286361269f939be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Szymon=20Kup=C5=9B?=
Date: Tue, 15 May 2018 18:55:24 +0200
Subject: [PATCH 06/13] Appending editor to the container in data
initialization manual test.
---
tests/manual/classiceditor-data.html | 7 +++++++
tests/manual/classiceditor-data.js | 4 +++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/tests/manual/classiceditor-data.html b/tests/manual/classiceditor-data.html
index 7bf3aa6..5e2ef53 100644
--- a/tests/manual/classiceditor-data.html
+++ b/tests/manual/classiceditor-data.html
@@ -3,9 +3,16 @@
`, {
plugins: [ Enter, Typing, Paragraph, Undo, Heading, Bold, Italic ],
toolbar: [ 'heading', '|', 'bold', 'italic', 'undo', 'redo' ]
} )
.then( editor => {
+ counter += 1;
window.editors.push( editor );
container.appendChild( editor.element );
} )
@@ -35,14 +35,16 @@ function initEditor() {
} );
}
-function destroyEditor() {
+function destroyEditors() {
window.editors.forEach( editor => {
editor.destroy()
.then( () => {
editor.element.remove();
} );
} );
+ window.editors = [];
+ counter = 1;
}
document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
-document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );
+document.getElementById( 'destroyEditors' ).addEventListener( 'click', destroyEditors );
diff --git a/tests/manual/classiceditor-data.md b/tests/manual/classiceditor-data.md
index eeffc09..b7c1b95 100644
--- a/tests/manual/classiceditor-data.md
+++ b/tests/manual/classiceditor-data.md
@@ -1,3 +1,3 @@
1. Click "Init editor".
-2. New editor instance should be appended to the document with initial data in it.
+2. New editor instance should be appended to the document with initial data in it. You can create more than one editor.
3. After clicking "Destroy editor" all editors should be removed from the document.
From a9497d212ea1df85187c9facaa30079f661b70a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?=
Date: Wed, 6 Jun 2018 13:54:50 +0200
Subject: [PATCH 08/13] Docs: Improved API docs for the create() method.
---
src/classiceditor.js | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/classiceditor.js b/src/classiceditor.js
index 6d41f39..3c27440 100644
--- a/src/classiceditor.js
+++ b/src/classiceditor.js
@@ -54,9 +54,8 @@ export default class ClassicEditor extends Editor {
* {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`} method instead.
*
* @protected
- * @param {HTMLElement} elementOrData The DOM element that will be the source for the created editor.
- * The data will be loaded from it and loaded back to it once the editor is destroyed. If data is provided, `editor.element`
- * should be added manually to the DOM after the editor is initialized. For more information see
+ * @param {HTMLElement|String} elementOrData The DOM element that will be the source for the created editor
+ * or editor's initial data. For more information see
* {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}.
* @param {module:core/editor/editorconfig~EditorConfig} config The editor configuration.
*/
@@ -133,7 +132,7 @@ export default class ClassicEditor extends Editor {
* console.error( err.stack );
* } );
*
- * Creating instance when using initial data instead of DOM element:
+ * Creating instance when using initial data instead of a DOM element:
*
* import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
* import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials';
@@ -156,8 +155,22 @@ export default class ClassicEditor extends Editor {
* console.error( err.stack );
* } );
*
- * @param {HTMLElement} element The DOM element that will be the source for the created editor.
- * The data will be loaded from it and loaded back to it once the editor is destroyed.
+ * @param {HTMLElement|String} elementOrData The DOM element that will be the source for the created editor
+ * or editor's initial data.
+ *
+ * If an element is passed, then it contents will be automatically
+ * {@link module:editor-classic/classiceditor~ClassicEditor#setData loaded} to the editor on startup
+ * and the editor element will replace the passed element in the DOM (the original one will be hidden and editor
+ * will be injected next to it).
+ *
+ * Moreover, the data will be set back to the original element once the editor is destroyed and
+ * (if the element is a `