ckeditor_taxonomy_glossary-1.0.0-alpha1/js/ckeditor5_plugins/glossaryLink/src/glossarylinkediting.js

js/ckeditor5_plugins/glossaryLink/src/glossarylinkediting.js
/**
 * @file
 * The glossary link editing functionality.
 */

import { Plugin } from 'ckeditor5/src/core';
import GlossaryLinkCommand from './glossarylinkcommand';

/**
 * The glossary link editing plugin.
 */
export default class GlossaryLinkEditing extends Plugin {
  /**
   * @inheritdoc
   */
  static get pluginName() {
    return 'GlossaryLinkEditing';
  }

  /**
   * @inheritdoc
   */
  init() {
    this._defineSchema();
    this._defineConverters();
    this._defineCommands();
  }

  /**
   * Defines the schema for glossary links.
   */
  _defineSchema() {
    const schema = this.editor.model.schema;

    // Allow glossary-link attribute on text nodes
    schema.extend('$text', {
      allowAttributes: ['glossaryLink']
    });
  }

  /**
   * Defines the converters for glossary links.
   */
  _defineConverters() {
    const editor = this.editor;
    const conversion = editor.conversion;

    // Model to view (editing and data)
    conversion.for('downcast').attributeToElement({
      model: 'glossaryLink',
      view: (modelAttributeValue, { writer }) => {
        return writer.createAttributeElement('a', {
          'class': 'glossary-link',
          'data-glossary-id': modelAttributeValue
        }, { priority: 5 });
      }
    });

    // View to model
    conversion.for('upcast').elementToAttribute({
      view: {
        name: 'a',
        classes: 'glossary-link',
        attributes: {
          'data-glossary-id': true
        }
      },
      model: {
        key: 'glossaryLink',
        value: viewElement => viewElement.getAttribute('data-glossary-id')
      }
    });
  }

  /**
   * Defines the commands.
   */
  _defineCommands() {
    this.editor.commands.add('glossaryLink', new GlossaryLinkCommand(this.editor));
  }
} 

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc