Przeglądaj źródła

View writer.createUIElement() method can now initialize rendering method.

Szymon Kupś 7 lat temu
rodzic
commit
80325bbc16
1 zmienionych plików z 20 dodań i 4 usunięć
  1. 20 4
      packages/ckeditor5-engine/src/view/writer.js

+ 20 - 4
packages/ckeditor5-engine/src/view/writer.js

@@ -177,15 +177,31 @@ export default class Writer {
 	/**
 	 * Creates new {@link module:engine/view/uielement~UIElement}.
 	 *
-	 *		writer.createUIElement( 'paragraph' );
-	 *		writer.createUIElement( 'paragraph', { 'alignment': 'center' } );
+	 *		writer.createUIElement( 'span' );
+	 *		writer.createUIElement( 'span', { 'alignment': 'center' } );
+	 *
+	 * Custom render function can be provided as third parameter:
+	 *
+	 *		writer.createUIElement( 'span', null, function( domDocument ) {
+	 *			const domElement = this.toDomElement( domDocument );
+	 *			domElement.innerHTML = '<b>this is ui element</b>';
+	 *
+	 *			return domElement;
+	 *		} );
 	 *
 	 * @param {String} name Name of the element.
 	 * @param {Object} [attributes] Elements attributes.
+	 * @param {Function} [renderFunction] Custom render function.
 	 * @returns {module:engine/view/uielement~UIElement} Created element.
 	 */
-	createUIElement( name, attributes ) {
-		return new UIElement( name, attributes );
+	createUIElement( name, attributes, renderFunction ) {
+		const uiElement = new UIElement( name, attributes );
+
+		if ( renderFunction ) {
+			uiElement.render = renderFunction;
+		}
+
+		return uiElement;
 	}
 
 	setAttribute( key, value, element ) {