8
0
Piotrek Koszuliński 9 лет назад
Родитель
Сommit
5c05c56b9b

+ 1 - 3
packages/ckeditor5-ui/src/button/buttonview.js

@@ -86,9 +86,7 @@ export default class ButtonView extends View {
 		this.set( 'withText', false );
 
 		/**
-		 * (Optional) The name of the icon of the button view.
-		 * See {@link module:ui/icon/iconview~IconView} and
-		 * {@link module:theme/iconmanagermodel~IconManagerModel}.
+		 * (Optional) Source of the icon. See {@link module:ui/icon/iconview~IconView#content}.
 		 *
 		 * @observable
 		 * @member {String} #icon

+ 0 - 14
packages/ckeditor5-ui/src/editorui/editoruiview.js

@@ -11,8 +11,6 @@
 
 import View from '../view';
 import Template from '../template';
-import IconManagerView from '../iconmanager/iconmanagerview';
-import iconManagerModel from 'ckeditor5-theme/src/iconmanagermodel';
 
 /**
  * The editor UI view class. Base class for the editor main views.
@@ -51,7 +49,6 @@ export default class EditorUIView extends View {
 	init() {
 		return Promise.resolve()
 			.then( () => this._renderBodyCollection() )
-			.then( () => this._setupIconManager() )
 			.then( () => super.init() );
 	}
 
@@ -64,17 +61,6 @@ export default class EditorUIView extends View {
 		return super.destroy();
 	}
 
-	/**
-	 * Injects the {@link module:ui/iconmanager/iconmanagerview~IconManagerView} into DOM.
-	 *
-	 * @protected
-	 */
-	_setupIconManager() {
-		this.iconManagerView = new IconManagerView( iconManagerModel.sprite, iconManagerModel.icons );
-
-		return this.body.add( this.iconManagerView );
-	}
-
 	/**
 	 * Creates and appends to `<body>` the {@link #body} collection container.
 	 *

+ 6 - 17
packages/ckeditor5-ui/src/icon/iconview.js

@@ -27,9 +27,7 @@ export default class IconView extends View {
 		const bind = this.bindTemplate;
 
 		/**
-		 * The inline SVG or in legacy mode the name of the icon
-		 * which corresponds with the name of the file in the
-		 * {@link module:theme/iconmanagermodel~IconManagerModel}.
+		 * The SVG source of the icon.
 		 *
 		 * @observable
 		 * @member {String} #content
@@ -57,22 +55,13 @@ export default class IconView extends View {
 
 		// This is a hack for lack of innerHTML binding.
 		// See: https://github.com/ckeditor/ckeditor5-ui/issues/99.
-		//
-		// Temporarily 2 types of icon content are supported:
-		//   * Inline SVG - content of svg file as plan text.
-		//   * Icon name (legacy) - name of icon corresponds with name of the
-		//     file in the {@link module:theme/iconmanagermodel~IconManagerModel}.
 		this.on( 'change:content', ( evt, name, value ) => {
-			if ( /</.test( value ) ) {
-				const svg = new DOMParser()
-					.parseFromString( value.trim(), 'image/svg+xml' )
-					.firstChild;
+			const svg = new DOMParser()
+				.parseFromString( value.trim(), 'image/svg+xml' )
+				.firstChild;
 
-				while ( svg.childNodes.length > 0 ) {
-					this.element.appendChild( svg.childNodes[ 0 ] );
-				}
-			} else {
-				this.element.innerHTML = `<use xlink:href="#ck-icon-${ value }"></use>`;
+			while ( svg.childNodes.length > 0 ) {
+				this.element.appendChild( svg.childNodes[ 0 ] );
 			}
 		} );
 	}

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

@@ -1,78 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module ui/iconmanager/iconmanagerview
- */
-
-/* globals document */
-
-import View from '../view';
-import Template from '../template';
-
-/**
- * The icon manager view class.
- *
- * @extends module:ui/view~View
- */
-export default class IconManagerView extends View {
-	/**
-	 * Creates an instance of the icon manager view.
-	 *
-	 * @param {String} sprite The SVG (HTML) string of the icons to be injected into DOM.
-	 * @param {Array.<String>} icons List of icon names available in the manager.
-	 */
-	constructor( sprite, icons ) {
-		super();
-
-		this.template = new Template( {
-			tag: 'svg',
-			ns: 'http://www.w3.org/2000/svg',
-			attributes: {
-				class: 'ck-icon-manager__sprite'
-			}
-		} );
-
-		/**
-		 * The actual SVG (HTML) of the icons to be injected in DOM.
-		 *
-		 * @member {String}
-		 */
-		this.sprite = sprite;
-
-		/**
-		 * List of icon names available in the manager.
-		 *
-		 * @readonly
-		 * @member {Array.<String>}
-		 */
-		this.icons = icons;
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	init() {
-		// Note: In MS Edge it's not enough to set:
-		//
-		//		this.element.innerHTML = this.sprite;
-		//
-		// because for some reason the browser won't parse the symbols string
-		// properly as svg content. Instead, an explicit parsing is needed (#55).
-		const tmp = document.createElement( 'div' );
-
-		tmp.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg">${ this.sprite }</svg>`;
-
-		const symbols = tmp.firstChild.childNodes;
-
-		// Pick symbols from the tmp and put them into icon manager.
-		// Note: MS Edge does not support forEach or Symbol.iterator for NodeList.
-		for ( let i = 0; i < symbols.length; ++i ) {
-			this.element.appendChild( document.importNode( symbols[ i ], true ) );
-		}
-
-		return super.init();
-	}
-}

+ 6 - 29
packages/ckeditor5-ui/tests/editorui/editoruiview.js

@@ -3,6 +3,8 @@
  * For licensing, see LICENSE.md.
  */
 
+/* global document */
+
 import testUtils from 'ckeditor5-core/tests/_utils/utils';
 import EditorUIView from 'ckeditor5-ui/src/editorui/editoruiview';
 import ViewCollection from 'ckeditor5-ui/src/viewcollection';
@@ -28,45 +30,20 @@ describe( 'EditorUIView', () => {
 		it( 'sets all the properties', () => {
 			expect( view.body ).to.be.instanceof( ViewCollection );
 		} );
+	} );
 
+	describe( 'init()', () => {
 		it( 'sets the right class set to the body region', () => {
 			const el = view._bodyCollectionContainer;
 
+			expect( el.parentNode ).to.equal( document.body );
 			expect( el.classList.contains( 'ck-body' ) ).to.be.true;
 			expect( el.classList.contains( 'ck-rounded-corners' ) ).to.be.true;
 			expect( el.classList.contains( 'ck-reset_all' ) ).to.be.true;
 		} );
 	} );
 
-	describe( 'init', () => {
-		it( 'calls view#_setupIconManager', () => {
-			view = new EditorUIView( locale );
-			const spy = testUtils.sinon.spy( view, '_setupIconManager' );
-
-			return view.init().then( () => {
-				expect( spy.calledOnce ).to.be.true;
-			} );
-		} );
-	} );
-
-	describe( 'view#_setupIconManager', () => {
-		it( 'injects the manager into DOM', () => {
-			view._setupIconManager().then( () => {
-				const iconManagerElement = view._bodyCollectionContainer.firstChild;
-
-				expect( iconManagerElement.classList.contains( 'ck-icon-manager__sprite' ) ).to.be.true;
-			} );
-		} );
-
-		it( 'sets view#icon property', () => {
-			view._setupIconManager().then( () => {
-				expect( view.icons ).to.be.an( 'array' );
-				expect( view.icons ).to.not.be.empty;
-			} );
-		} );
-	} );
-
-	describe( 'destroy', () => {
+	describe( 'destroy()', () => {
 		it( 'removes the body region container', () => {
 			const el = view._bodyCollectionContainer;
 

+ 0 - 15
packages/ckeditor5-ui/tests/icon/iconview.js

@@ -40,20 +40,5 @@ describe( 'IconView', () => {
 				expect( view.element.innerHTML = '<g id="test"></g>' );
 			} );
 		} );
-
-		describe( 'legacy xlink:href', () => {
-			it( 'reacts to changes in view#content', () => {
-				const svgHrefNs = 'http://www.w3.org/1999/xlink';
-				let svgUseElement;
-
-				view.content = 'foo';
-				svgUseElement = view.element.firstChild;
-				expect( svgUseElement.getAttributeNS( svgHrefNs, 'href' ) ).to.equal( '#ck-icon-foo' );
-
-				view.content = 'abc';
-				svgUseElement = view.element.firstChild;
-				expect( svgUseElement.getAttributeNS( svgHrefNs, 'href' ) ).to.equal( '#ck-icon-abc' );
-			} );
-		} );
 	} );
 } );

+ 0 - 41
packages/ckeditor5-ui/tests/iconmanager/iconmanagerview.js

@@ -1,41 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* bender-tags: ui, iconmanager */
-
-import testUtils from 'ckeditor5-core/tests/_utils/utils';
-import IconManagerView from 'ckeditor5-ui/src/iconmanager/iconmanagerview';
-
-testUtils.createSinonSandbox();
-
-describe( 'IconManagerView', () => {
-	let view, sprite, icons;
-
-	beforeEach( () => {
-		sprite = '<symbol><title>foo</title></symbol>';
-		icons = [ 'foo' ];
-		view = new IconManagerView( sprite, icons );
-
-		return view.init();
-	} );
-
-	describe( 'constructor()', () => {
-		it( 'sets initial view attribute values', () => {
-			expect( view.sprite ).to.equal( sprite );
-			expect( view.icons ).to.equal( icons );
-		} );
-
-		it( 'creates element from template', () => {
-			expect( view.element.tagName ).to.equal( 'svg' );
-			expect( view.element.getAttribute( 'class' ) ).to.equal( 'ck-icon-manager__sprite' );
-		} );
-	} );
-
-	describe( 'init', () => {
-		it( 'initializes the sprite', () => {
-			expect( view.element.innerHTML ).to.equal( '<symbol><title>foo</title></symbol>' );
-		} );
-	} );
-} );