Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentFactory.add( 'alignment', locale => {
const dropdownView = createDropdown( locale );
// Add existing alignment buttons to dropdown's toolbar.
const buttons = options.map( option => componentFactory.create( `alignment:${ option }` ) );
addToolbarToDropdown( dropdownView, buttons );
// Configure dropdown properties an behavior.
dropdownView.buttonView.set( {
label: t( 'Text alignment' ),
tooltip: true
} );
dropdownView.toolbarView.isVertical = true;
dropdownView.toolbarView.ariaLabel = t( 'Text alignment toolbar' );
dropdownView.extendTemplate( {
attributes: {
editor.ui.componentFactory.add( 'insertTable', locale => {
const command = editor.commands.get( 'insertTable' );
const dropdownView = createDropdown( locale );
dropdownView.bind( 'isEnabled' ).to( command );
// Decorate dropdown's button.
dropdownView.buttonView.set( {
icon: tableIcon,
label: t( 'Insert table' ),
tooltip: true
} );
// Prepare custom view for dropdown's panel.
const insertTableView = new InsertTableView( locale );
dropdownView.panelView.children.add( insertTableView );
insertTableView.delegate( 'execute' ).to( dropdownView );
editor.ui.componentFactory.add( FONT_SIZE, locale => {
const dropdownView = createDropdown( locale );
addListToDropdown( dropdownView, _prepareListOptions( options, command ) );
// Create dropdown model.
dropdownView.buttonView.set( {
label: t( 'Font Size' ),
icon: fontSizeIcon,
tooltip: true
} );
dropdownView.extendTemplate( {
attributes: {
class: [
'ck-font-size-dropdown'
]
}
} );
componentFactory.add( 'highlight', locale => {
const command = editor.commands.get( 'highlight' );
const dropdownView = createDropdown( locale, SplitButtonView );
const splitButtonView = dropdownView.buttonView;
splitButtonView.set( {
tooltip: t( 'Highlight' ),
// Holds last executed highlighter.
lastExecuted: startingHighlighter.model,
// Holds current highlighter to execute (might be different then last used).
commandValue: startingHighlighter.model,
isToggleable: true
} );
// Dropdown button changes to selection (command.value):
// - If selection is in highlight it get active highlight appearance (icon, color) and is activated.
// - Otherwise it gets appearance (icon, color) of last executed highlight.
splitButtonView.bind( 'icon' ).to( command, 'value', value => getIconForType( getActiveOption( value, 'type' ) ) );
splitButtonView.bind( 'color' ).to( command, 'value', value => getActiveOption( value, 'color' ) );
_prepareDropdown( label, icon, options, locale ) {
const editor = this.editor;
const dropdownView = createDropdown( locale );
const commands = [];
// Prepare dropdown list items for list dropdown.
const itemDefinitions = new Collection();
for ( const option of options ) {
addListOption( option, editor, commands, itemDefinitions );
}
addListToDropdown( dropdownView, itemDefinitions );
// Decorate dropdown's button.
dropdownView.buttonView.set( {
label,
icon,
tooltip: true
it( 'should create dropdown with color table', () => {
const dropdown = createDropdown();
dropdown.render();
addColorTableToDropdown( {
dropdownView: dropdown,
colors: [
{
label: 'Black',
color: '#000',
options: {
hasBorder: false
}
},
{
label: 'White',
color: '#FFFFFF',
options: {
this.editor.ui.componentFactory.add('internalLink', (locale) => {
const dropdownButton = createDropdown(locale);
const list = new ListView(locale);
dropdownButton.bind('isEnabled').to(
this.editor.commands.get('internalLink'),
'buttonEnabled',
this.editor.commands.get('externalLink'),
'buttonEnabled',
(internalLinkEnabled, externalLinkEnabled) => internalLinkEnabled && externalLinkEnabled
);
dropdownButton.buttonView.set({icon: linkIcon});
internalLinkTypeRegistry.getKeys().forEach((key) => {
const button = new ButtonView(locale);
button.set({
class: 'ck-link-button',
label: internalLinkTypeRegistry.getTitle(key),
editor.ui.componentFactory.add( FONT_FAMILY, locale => {
const dropdownView = createDropdown( locale );
addListToDropdown( dropdownView, _prepareListOptions( options, command ) );
dropdownView.buttonView.set( {
label: t( 'Font Family' ),
icon: fontFamilyIcon,
tooltip: true
} );
dropdownView.extendTemplate( {
attributes: {
class: 'ck-font-family-dropdown'
}
} );
dropdownView.bind( 'isEnabled' ).to( command );
editor.ui.componentFactory.add( this.componentName, locale => {
const dropdownView = createDropdown( locale );
this.colorTableView = addColorTableToDropdown( {
dropdownView,
colors: localizedColors.map( option => ( {
label: option.label,
color: option.model,
options: {
hasBorder: option.hasBorder
}
} ) ),
columns: this.columns,
removeButtonLabel: t( 'Remove color' ),
documentColorsLabel: documentColorsCount !== 0 ? t( 'Document colors' ) : undefined,
documentColorsCount: documentColorsCount === undefined ? this.columns : documentColorsCount
} );
this.colorTableView.bind( 'selectedColor' ).to( command, 'value' );
editor.ui.componentFactory.add( 'mediaEmbed', locale => {
const dropdown = createDropdown( locale );
this._setUpDropdown( dropdown, this.form, command, editor );
this._setUpForm( this.form, dropdown, command );
return dropdown;
} );
}