Jelajahi Sumber

Implemented basic IconManager class.

Aleksander Nowodzinski 9 tahun lalu
induk
melakukan
5acfdb2d55

+ 21 - 0
packages/ckeditor5-ui/src/editorui/editorui.js

@@ -9,6 +9,7 @@ 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 utils from '../../utils/utils.js';
 
 /**
@@ -51,6 +52,26 @@ export default class EditorUI extends Controller {
 
 		this.collections.add( new ControllerCollection( 'body' ) );
 	}
+
+	/**
+	 * Initializes EditorUI instance.
+	 *
+	 * @returns {Promise}
+	 */
+	init() {
+		return super.init().then( () => {
+			this._addIconManager();
+		} );
+	}
+
+	/**
+	 * Adds IconManager into DOM.
+	 *
+	 * @protected
+	 */
+	_addIconManager() {
+		this.collections.get( 'body' ).add( new IconManager( this.editor ) );
+	}
 }
 
 utils.mix( EditorUI, ObservableMixin );

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

@@ -0,0 +1,35 @@
+/**
+ * @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;
+	}
+}
+

+ 39 - 0
packages/ckeditor5-ui/src/iconmanager/iconmanagerview.js

@@ -0,0 +1,39 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+import View from '../view.js';
+import IconsSprite from '../../../theme/icons.js';
+
+/**
+ * Base class for the editor main views.
+ *
+ * @memberOf ui.iconManager
+ * @extends ui.View
+ */
+
+export default class IconManagerView extends View {
+	constructor( model, locale ) {
+		super( model, locale );
+
+		this.template = {
+			tag: 'div',
+			attributes: {
+				class: 'ck-icon-manager'
+			}
+		};
+	}
+
+	init() {
+		// 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>`;
+	}
+}