utils.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module alignment/utils
  7. */
  8. /**
  9. * The list of supported alignment options:
  10. *
  11. * * `'left'`,
  12. * * `'right'`,
  13. * * `'center'`,
  14. * * `'justify'`
  15. */
  16. export const supportedOptions = [ 'left', 'right', 'center', 'justify' ];
  17. /**
  18. * Checks whether the passed option is supported by {@link module:alignment/alignmentediting~AlignmentEditing}.
  19. *
  20. * @param {String} option The option value to check.
  21. * @returns {Boolean}
  22. */
  23. export function isSupported( option ) {
  24. return supportedOptions.includes( option );
  25. }
  26. /**
  27. * Checks whether alignment is the default one considering the direction
  28. * of the editor content.
  29. *
  30. * @param {String} alignment The name of the alignment to check.
  31. * @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
  32. * @returns {Boolean}
  33. */
  34. export function isDefault( alignment, locale ) {
  35. // Right now only LTR is supported so the 'left' value is always the default one.
  36. if ( locale.contentLanguageDirection == 'rtl' ) {
  37. return alignment === 'right';
  38. } else {
  39. return alignment === 'left';
  40. }
  41. }