Report an issue
Module

widget/utils

@ckeditor/ckeditor5-widget/src/utils

module

Filtering

Constants

  • WIDGET_CLASS_NAME : String

    static

    CSS class added to each widget element.

  • WIDGET_SELECTED_CLASS_NAME : String

    static

    CSS class added to currently selected widget element.

Functions

  • getLabel( element ) → String

    static

    Returns label for provided element.

    Parameters

    element : Element

    Returns

    String
  • isWidget( element ) → Boolean

    static

    Returns true if given Element is a widget.

    Parameters

    element : Element

    Returns

    Boolean
  • setHighlightHandling( element, writer, add, remove )

    static

    Sets highlight handling methods. Uses HighlightStack to properly determine which highlight descriptor should be used at given time.

    Parameters

    element : Element
    writer : Writer
    add : function
    remove : function
  • setLabel( element, labelOrCreator, writer )

    static

    Sets label for given element. It can be passed as a plain string or a function returning a string. Function will be called each time label is retrieved by getLabel.

    Parameters

    element : Element
    labelOrCreator : String | function
    writer : Writer
  • toWidget( element, writer, [ options ] = { [options.label], [options.hasSelectionHandler] } ) → Element

    static

    Converts given Element to widget in following way:

    • sets contenteditable attribute to "true",
    • adds custom getFillerOffset method returning null,
    • adds ck-widget CSS class,
    • adds custom property allowing to recognize widget elements by using isWidget,
    • implements addHighlight and removeHighlight custom properties to handle view highlight on widgets.

    Parameters

    element : Element
    writer : Writer
    [ options ] : Object
    Properties
    [ options.label ] : String | function

    Element's label provided to setLabel function. It can be passed as a plain string or a function returning a string.

    [ options.hasSelectionHandler ] : Boolean

    If true, the widget will have a selection handler added.

    Defaults to false

    Defaults to {}

    Returns

    Element

    Returns same element.

  • toWidgetEditable( editable, writer ) → EditableElement

    static

    Adds functionality to provided {module:engine/view/editableelement~EditableElement} to act as a widget's editable:

    • adds ck-editor__editable and ck-editor__nested-editable CSS classes,
    • sets contenteditable as true when {module:engine/view/editableelement~EditableElement#isReadOnly} is false otherwise set false,
    • adds ck-editor__nested-editable_focused CSS class when editable is focused and removes it when it's blurred.

    Parameters

    editable : EditableElement
    writer : Writer

    Returns

    EditableElement

    Returns same element that was provided in editable param.