Parcourir la source

Code refactoring. Simplified IconManagerView integration with EditorUI.

Aleksander Nowodzinski il y a 9 ans
Parent
commit
108c088daa

+ 23 - 6
packages/ckeditor5-ui/src/editorui/editorui.js

@@ -9,7 +9,8 @@ import Controller from '../controller.js';
 import ControllerCollection from '../controllercollection.js';
 import ComponentFactory from '../componentfactory.js';
 import ObservableMixin from '../../utils/observablemixin.js';
-import IconManager from '../iconmanager/iconmanager.js';
+import IconManagerView from '../iconmanagerview.js';
+import iconManagerModel from '../../../theme/iconmanagermodel.js';
 import utils from '../../utils/utils.js';
 
 /**
@@ -59,9 +60,9 @@ export default class EditorUI extends Controller {
 	 * @returns {Promise}
 	 */
 	init() {
-		return super.init().then( () => {
-			this._addIconManager();
-		} );
+		this._setupIconManager();
+
+		return super.init();
 	}
 
 	/**
@@ -69,8 +70,24 @@ export default class EditorUI extends Controller {
 	 *
 	 * @protected
 	 */
-	_addIconManager() {
-		this.collections.get( 'body' ).add( new IconManager( this.editor ) );
+	_setupIconManager() {
+		/**
+		 * A reference to IconManager controller.
+		 *
+		 * @readonly
+		 * @member {ui.Controller} ui.editorUI.EditorUI#iconManager
+		 */
+		this.iconManager = new Controller( iconManagerModel, new IconManagerView( iconManagerModel ) );
+
+		/**
+		 * Icons available in the UI.
+		 *
+		 * @readonly
+		 * @member {Array} ui.editorUI.EditorUI#icons
+		 */
+		this.icons = iconManagerModel.icons;
+
+		this.collections.get( 'body' ).add( this.iconManager );
 	}
 }
 

+ 0 - 35
packages/ckeditor5-ui/src/iconmanager/iconmanager.js

@@ -1,35 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-'use strict';
-
-import Controller from '../controller.js';
-import IconManagerView from './iconmanagerview.js';
-
-/**
- *
- * @memberOf ui.iconManager
- * @extends ui.Controller
- */
-
-export default class IconManager extends Controller {
-	/**
-	 * Creates IconManager instances.
-	 *
-	 * @param {ckeditor5.Editor} editor
-	 */
-	constructor( editor ) {
-		super();
-
-		this.view = new IconManagerView();
-
-		/**
-		 * @readonly
-		 * @member {ckeditor5.Editor} ui.iconManager.IconManager#editor
-		 */
-		this.editor = editor;
-	}
-}
-

+ 15 - 7
packages/ckeditor5-ui/src/iconmanager/iconmanagerview.js → packages/ckeditor5-ui/src/iconmanagerview.js

@@ -5,8 +5,7 @@
 
 'use strict';
 
-import View from '../view.js';
-import IconsSprite from '../../../theme/icons.js';
+import View from './view.js';
 
 /**
  * Base class for the editor main views.
@@ -28,12 +27,21 @@ export default class IconManagerView extends View {
 	}
 
 	init() {
+		this._setupSprite();
+
+		return super.init();
+	}
+
+	/**
+	 * Injects icon sprite into DOM.
+	 *
+	 * @protected
+	 */
+	_setupSprite() {
 		// Note: Creating SVG icons with with Template class is not possible
 		// because of CSS limitations of document.createEleentNS–created elements.
-		this.element.innerHTML = `<svg
-				xmlns="http://www.w3.org/2000/svg"
-				xmlns:xlink="http://www.w3.org/1999/xlink"
-				id="ck-sprite"
-			>${ IconsSprite }</svg>`;
+		this.element.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="ck-sprite">
+				${ this.model.sprite }
+			</svg>`;
 	}
 }