This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Allow to pass initial data to the editor constructor #73
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3015814
Allow to pass data to the constructor instaead of element to replace.
szymonkups 5af49aa
Added tests checking data initialization.
szymonkups 633b5d3
Improved documentation.
szymonkups f38aec7
Improved manual test with data initialization.
szymonkups 3232bfb
Removed unused CSS class.
szymonkups 8a7ea54
Appending editor to the container in data initialization manual test.
szymonkups ffdede7
Minor improvements for the manual test.
216cd88
Merge branch 'master' into t/72
Reinmar a9497d2
Docs: Improved API docs for the create() method.
Reinmar 674c3b0
Renamed editor.element to editor.sourceElement and implemented the Ed…
51cdeee
Simplified the code and docs. Added more tests.
22b6f4f
Merge branch 'master' into t/72
4a13075
Merge branch 'master' into t/72
c210e56
Fixed broken promises chain (editor.data.init() returns a promise).
46d2f71
Used better variable name.
6df6ba9
More API docs polish.
Reinmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<p> | ||
<button id="destroyEditors">Destroy editors</button> | ||
<button id="initEditor">Init editor</button> | ||
</p> | ||
|
||
<div class="container"></div> | ||
|
||
<style> | ||
body { | ||
width: 10000px; | ||
height: 10000px; | ||
} | ||
|
||
.container { | ||
padding: 20px; | ||
width: 500px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* globals console:false, document, window */ | ||
|
||
import ClassicEditor from '../../src/classiceditor'; | ||
import Enter from '@ckeditor/ckeditor5-enter/src/enter'; | ||
import Typing from '@ckeditor/ckeditor5-typing/src/typing'; | ||
import Heading from '@ckeditor/ckeditor5-heading/src/heading'; | ||
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'; | ||
|
||
window.editors = []; | ||
let counter = 1; | ||
|
||
const container = document.querySelector( '.container' ); | ||
|
||
function initEditor() { | ||
ClassicEditor | ||
.create( `<h2>Hello world! #${ counter }</h2><p>This is an editor instance.</p>`, { | ||
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 ); | ||
} ) | ||
.catch( err => { | ||
console.error( err.stack ); | ||
} ); | ||
} | ||
|
||
function destroyEditors() { | ||
window.editors.forEach( editor => { | ||
editor.destroy() | ||
.then( () => { | ||
editor.element.remove(); | ||
} ); | ||
} ); | ||
window.editors = []; | ||
counter = 1; | ||
} | ||
|
||
document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor ); | ||
document.getElementById( 'destroyEditors' ).addEventListener( 'click', destroyEditors ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1. Click "Init editor". | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be easier to read if it was written like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is – what differs these two scenarios isn't how or whether you call
editor.data.init()
. It's how you retrieve this data and from where.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the code you committed isn't equal to what I proposed:
In this case, we lose the information what do we call
init()
with. It makes reading the code harder.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW,
editor.data.init()
may return a promise so this change breaks the promise chain – make sure to add a test for that.