|
|
@@ -3,23 +3,51 @@
|
|
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
|
*/
|
|
|
|
|
|
-/* globals console, window, document */
|
|
|
+/* globals window, document */
|
|
|
|
|
|
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
|
|
|
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
|
|
|
import FontSize from '../../src/fontsize';
|
|
|
|
|
|
-ClassicEditor
|
|
|
- .create( document.querySelector( '#editor' ), {
|
|
|
+const restrictedModeButton = document.getElementById( 'mode-restricted-values' );
|
|
|
+const standardModeButton = document.getElementById( 'mode-disable-value-matching' );
|
|
|
+
|
|
|
+restrictedModeButton.addEventListener( 'change', handleModeChange );
|
|
|
+standardModeButton.addEventListener( 'change', handleModeChange );
|
|
|
+
|
|
|
+// When page loaded.
|
|
|
+startMode( document.querySelector( 'input[name="mode"]:checked' ).value );
|
|
|
+
|
|
|
+// When a user changed a mode.
|
|
|
+async function handleModeChange( evt ) {
|
|
|
+ await startMode( evt.target.value );
|
|
|
+}
|
|
|
+
|
|
|
+// Starts the editor.
|
|
|
+async function startMode( selectedMode ) {
|
|
|
+ if ( selectedMode === 'restricted-values' ) {
|
|
|
+ await reloadEditor();
|
|
|
+ } else {
|
|
|
+ await reloadEditor( { disableValueMatching: true } );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function reloadEditor( options = {} ) {
|
|
|
+ if ( window.editor ) {
|
|
|
+ await window.editor.destroy();
|
|
|
+ }
|
|
|
+
|
|
|
+ const config = {
|
|
|
plugins: [ ArticlePluginSet, FontSize ],
|
|
|
toolbar: [
|
|
|
'heading', '|', 'fontSize', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo'
|
|
|
],
|
|
|
fontSize: { options: [ 10, 12, 14, 'default', 18, 20, 22 ] }
|
|
|
- } )
|
|
|
- .then( editor => {
|
|
|
- window.editor = editor;
|
|
|
- } )
|
|
|
- .catch( err => {
|
|
|
- console.error( err.stack );
|
|
|
- } );
|
|
|
+ };
|
|
|
+
|
|
|
+ if ( options.disableValueMatching ) {
|
|
|
+ config.fontSize.disableValueMatching = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ window.editor = await ClassicEditor.create( document.querySelector( '#editor' ), config );
|
|
|
+}
|