Notes/src/utils.js
Mateusz Zagórski 302a0dc2ef Initial commit.
2022-03-04 13:39:39 +01:00

28 lines
784 B
JavaScript

/**
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module mermaid/utils
*/
/**
* Helper function for setting the `isOn` state of buttons.
*
* @private
* @param {module:core/editor/editor~Editor} editor
* @param {String} commandName Short name of the command.
* @returns {Boolean}
*/
export function checkIsOn( editor, commandName ) {
const selection = editor.model.document.selection;
const mermaidItem = selection.getSelectedElement() || selection.getLastPosition().parent;
if ( mermaidItem && mermaidItem.is( 'element', 'mermaid' ) && mermaidItem.getAttribute( 'displayMode' ) === commandName ) {
return true;
}
return false;
}