瀏覽代碼

The end of today's audition.

Piotrek Koszuliński 9 年之前
父節點
當前提交
7ca5657202

+ 123 - 0
packages/ckeditor5-editor-classic/src/classic.js

@@ -0,0 +1,123 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+import StandardEditor from '../editor/standardeditor.js';
+
+import HtmlDataProcessor from '../engine/dataprocessor/htmldataprocessor.js';
+
+import BoxedEditorUI from '../ui/editorui/boxed/boxededitorui.js';
+import BoxedEditorUIView from '../ui/editorui/boxed/boxededitoruiview.js';
+
+import EditableUI from '../ui/editableui/editableui.js';
+import InlineEditableUIView from '../ui/editableui/inline/inlineeditableuiview.js';
+
+import Model from '../ui/model.js';
+import StickyToolbar from '../ui/bindings/stickytoolbar.js';
+import StickyToolbarView from '../ui/stickytoolbar/stickytoolbarview.js';
+
+import ElementReplacer from '../utils/elementreplacer.js';
+
+/**
+ * Classic editor creator using inline editable and sticky toolbar, all
+ * enclosed in a boxed UI.
+ *
+ * @memberOf editor-classic
+ * @extends ckeditor5.editor.StandardEditor
+ */
+export default class ClassicEditor extends StandardEditor {
+	/**
+	 * Creates an instance of the classic creator.
+	 *
+	 * @param {ckeditor5.Editor} The editor instance.
+	 */
+	constructor( element, config ) {
+		super( element, config );
+
+		this.document.createRoot();
+
+		this.editing.createRoot( 'div' );
+
+		this.data.processor = new HtmlDataProcessor();
+
+		this._elementReplacer = new ElementReplacer();
+	}
+
+	/**
+	 * Updates the original editor element with data and destroys
+	 * the UI.
+	 *
+	 * @returns {Promise}
+	 */
+	destroy() {
+		this.updateEditorElement();
+		this._elementReplacer.restore();
+
+		return this.ui.destroy()
+			.then( () => super.destroy() );
+	}
+
+	_createUI() {
+		const editorUI = new BoxedEditorUI( this );
+		const editorUIView = new BoxedEditorUIView( editorUI.viewModel, this.locale );
+
+		editorUI.view = editorUIView;
+
+		this.ui = editorUI;
+
+		this._createToolbar();
+		this._createEditableUI();
+
+		this._elementReplacer.replace( this.element, this.ui.view.element );
+
+		return Promise.resolve();
+	}
+
+	_initUI() {
+		this._toolbar.addButtons( this.config.toolbar );
+
+		return this.ui.init()
+			.then( () => this.editing.view.attachDomRoot( this._editableUI.view.element ) );
+	}
+
+	static create( element, config ) {
+		const editor = new ClassicEditor( element, config );
+
+		return editor._createUI()
+			.then( () => editor.initPlugins() )
+			.then( () => editor._initUI() )
+			.then( () => editor.loadDataFromEditorElement() )
+			.then( () => editor );
+	}
+
+	/**
+	 * Creates editor sticky toolbar and fills it with children using the configuration.
+	 *
+	 * @protected
+	 */
+	_createToolbar() {
+		// Note: StickyToolbar and StickyToolbarView share the same model. It may change in the future.
+		const toolbarModel = new Model();
+		const toolbarView = new StickyToolbarView( toolbarModel, this.locale );
+		const toolbar = new StickyToolbar( toolbarModel, toolbarView, this );
+
+		this.ui.add( 'top', toolbar );
+
+		this._toolbar = toolbar;
+	}
+
+	_createEditableUI() {
+		const editable = this.editing.view.getRoot();
+		const editableUI = new EditableUI( this, editable );
+		const editableUIView = new InlineEditableUIView( editableUI.viewModel, this.locale );
+
+		editableUI.view = editableUIView;
+
+		this.ui.add( 'main', editableUI );
+
+		this._editableUI = editableUI;
+	}
+}

+ 0 - 102
packages/ckeditor5-editor-classic/src/classiccreator.js

@@ -1,102 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-'use strict';
-
-import StandardCreator from '../creator/standardcreator.js';
-
-import { createEditableUI, createEditorUI } from '../ui/creator-utils.js';
-
-import BoxedEditorUI from '../ui/editorui/boxed/boxededitorui.js';
-import BoxedEditorUIView from '../ui/editorui/boxed/boxededitoruiview.js';
-
-import EditableUI from '../ui/editableui/editableui.js';
-import InlineEditableUIView from '../ui/editableui/inline/inlineeditableuiview.js';
-
-import Model from '../ui/model.js';
-import StickyToolbar from '../ui/bindings/stickytoolbar.js';
-import StickyToolbarView from '../ui/stickytoolbar/stickytoolbarview.js';
-
-/**
- * Classic editor creator using inline editable and sticky toolbar, all
- * enclosed in a boxed UI.
- *
- * @memberOf creator-classic
- * @extends ckeditor5.creator.StandardCreator
- */
-export default class ClassicCreator extends StandardCreator {
-	/**
-	 * Creates an instance of the classic creator.
-	 *
-	 * @param {ckeditor5.Editor} The editor instance.
-	 */
-	constructor( editor ) {
-		super( editor );
-
-		editor.document.createRoot();
-		editor.editing.createRoot( 'div' );
-
-		// UI.
-		createEditorUI( editor, BoxedEditorUI, BoxedEditorUIView );
-	}
-
-	/**
-	 * Creates editor UI and loads startup data into the editor.
-	 *
-	 * @returns {Promise}
-	 */
-	create() {
-		const editor = this.editor;
-		const editorElement = editor.firstElement;
-
-		// UI.
-		this._replaceElement( editorElement, editor.ui.view.element );
-		this._createToolbar();
-
-		const editableUI = createEditableUI( editor, EditableUI, InlineEditableUIView );
-
-		editor.ui.add( 'main', editableUI );
-
-		// Init.
-		return super.create()
-			.then( () => editor.ui.init() )
-			.then( () => editor.editing.view.attachDomRoot( editableUI.view.element ) )
-			// We'll be able to do that much earlier once the loading will be done to the document model,
-			// rather than straight to the editable.
-			.then( () => this.loadDataFromEditorElement() );
-	}
-
-	/**
-	 * Updates the original editor element with data and destroys
-	 * the UI.
-	 *
-	 * @returns {Promise}
-	 */
-	destroy() {
-		this.updateEditorElement();
-
-		super.destroy();
-
-		return this.editor.ui.destroy();
-	}
-
-	/**
-	 * Creates editor sticky toolbar and fills it with children using the configuration.
-	 *
-	 * @protected
-	 */
-	_createToolbar() {
-		const editor = this.editor;
-
-		// Note: StickyToolbar and StickyToolbarView share the same model. It may change in the future.
-		const toolbarModel = new Model();
-		const toolbarView = new StickyToolbarView( toolbarModel, editor.locale );
-		const toolbar = new StickyToolbar( toolbarModel, toolbarView, editor );
-
-		toolbar.addButtons( editor.config.toolbar );
-
-		this.editor.ui.add( 'top', toolbar );
-	}
-}

packages/ckeditor5-editor-classic/tests/manual/classiccreator.html → packages/ckeditor5-editor-classic/tests/manual/classic.html


+ 2 - 4
packages/ckeditor5-editor-classic/tests/manual/classiccreator.js

@@ -7,15 +7,13 @@
 
 'use strict';
 
-import CKEDITOR from '/ckeditor.js';
-import ClassicCreator from '/ckeditor5/creator-classic/classiccreator.js';
+import ClassicEditor from '/ckeditor5/creator-classic/classic.js';
 import testUtils from '/tests/utils/_utils/utils.js';
 
 let editor, editable, observer;
 
 function initEditor() {
-	CKEDITOR.create( '#editor', {
-		creator: ClassicCreator,
+	ClassicEditor.create( document.querySelector( '#editor' ), {
 		features: [ 'delete', 'enter', 'typing', 'paragraph', 'undo', 'basic-styles/bold', 'basic-styles/italic' ],
 		toolbar: [ 'bold', 'italic', 'undo', 'redo' ]
 	} )

packages/ckeditor5-editor-classic/tests/manual/classiccreator.md → packages/ckeditor5-editor-classic/tests/manual/classic.md