UpcastWriter (engine/view)
@ckeditor/ckeditor5-engine/src/view/upcastwriter
View upcast writer class. Provides set of methods used to properly manipulate nodes attached to view instance. It should be only used to manipulate non-semantic view (view created from HTML string). For view which was downcasted from the model see writer.
Filtering
Methods
-
addClass( className, element )
Adds specified class to the element.
writer.addClass( linkElement, 'foo' ); writer.addClass( linkElement, [ 'foo', 'bar' ] );
Parameters
className : Array.<String> | String
Single class name or array of class names which will be added.
element : Element
Element for which class will be added.
-
appendChild( items, element ) → Number
Appends a child node or a list of child nodes at the end of this node and sets the parent of these nodes to this element.
Parameters
items : Item | Iterable.<Item>
Items to be inserted.
element : Element | DocumentFragment
Element to which items will be appended.
Returns
Number
Number of appended nodes.
Fires
-
insertChild( index, items, element ) → Number
Inserts a child node or a list of child nodes on the given index and sets the parent of these nodes to this element.
Parameters
index : Number
Offset at which nodes should be inserted.
items : Item | Iterable.<Item>
Items to be inserted.
element : Element | DocumentFragment
Element to which items will be inserted.
Returns
Number
Number of inserted nodes.
Fires
-
removeAttribute( key, element )
Removes attribute from the element.
writer.removeAttribute( linkElement, 'href' );
Parameters
key : String
Attribute key.
element : Element
Element from which attribute will be removed.
-
removeChildren( index, howMany, element ) → Array.<Node>
Removes number of child nodes starting at the given index and set the parent of these nodes to
null
.Parameters
index : Number
Offset from which nodes will be removed.
howMany : Number
Number of nodes to remove.
element : Element | DocumentFragment
Element which children will be removed.
Returns
Array.<Node>
The array containing removed nodes.
Fires
-
removeClass( className, element )
Removes specified class from the element.
writer.removeClass( linkElement, 'foo' ); writer.removeClass( linkElement, [ 'foo', 'bar' ] );
Parameters
className : Array.<String> | String
Single class name or array of class names which will be removed.
element : Element
Element from which class will be removed.
-
removeCustomProperty( key, element ) → Boolean
Removes a custom property stored under the given key.
Parameters
key : String | Symbol
Name/key of the custom property to be removed.
element : Element
Element from which the custom property will be removed.
Returns
Boolean
Returns true if property was removed.
-
removeStyle( property, element )
Removes specified style from the element.
writer.removeStyle( element, 'color' ); // Removes 'color' style. writer.removeStyle( element, [ 'color', 'border-top' ] ); // Removes both 'color' and 'border-top' styles.
Parameters
property : Array.<String> | String
Style property name or names to be removed.
element : Element
Element from which style will be removed.
-
Renames element by creating a copy of a given element but with its name changed and then moving contents of the old element to the new one.
Since this function creates a new element and removes the given one, the new element is returned to keep reference.
Parameters
newName : String
New element name.
element : Element
Element to be renamed.
Returns
Element | null
New element or null if the old element was not replaced (happens for detached elements).
-
replace( oldElement, newElement ) → Boolean
Replaces given element with the new one in the view structure. Will not have effect on detached elements.
-
setAttribute( key, value, element )
Adds or overwrites element's attribute with a specified key and value.
writer.setAttribute( linkElement, 'href', 'http://ckeditor.com' );
Parameters
key : String
Attribute key.
value : String
Attribute value.
element : Element
Element for which attribute will be set.
-
setCustomProperty( key, value, element )
Sets a custom property on element. Unlike attributes, custom properties are not rendered to the DOM, so they can be used to add special data to elements.
Parameters
key : String | Symbol
Custom property name/key.
value : *
Custom property value to be stored.
element : Element
Element for which custom property will be set.
-
setStyle( property, [ value ], element )
Adds style to the element.
writer.setStyle( element, 'color', 'red' ); writer.setStyle( element, { color: 'red', position: 'fixed' } );
Parameters
property : String | Object
Property name or object with key - value pairs.
[ value ] : String
Value to set. This parameter is ignored if object is provided as the first parameter.
element : Element
Element for which style will be added.