ckeditor_taxonomy_glossary-1.0.0-alpha1/js/ckeditor5_plugins/glossaryLink/src/glossarylinkcommand.js
js/ckeditor5_plugins/glossaryLink/src/glossarylinkcommand.js
/**
* @file
* The glossary link command.
*/
import { Command } from 'ckeditor5/src/core';
/**
* The glossary link command.
*/
export default class GlossaryLinkCommand extends Command {
/**
* @inheritdoc
*/
execute(termId) {
const model = this.editor.model;
const selection = model.document.selection;
model.change(writer => {
const ranges = model.schema.getValidRanges(selection.getRanges(), 'glossaryLink');
for (const range of ranges) {
if (termId) {
writer.setAttribute('glossaryLink', termId, range);
} else {
writer.removeAttribute('glossaryLink', range);
}
}
});
}
/**
* @inheritdoc
*/
refresh() {
const model = this.editor.model;
const selection = model.document.selection;
this.isEnabled = model.schema.checkAttributeInSelection(selection, 'glossaryLink');
this.value = selection.getAttribute('glossaryLink') || null;
}
} 