ckeditor.stylescombo.admin.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal, drupalSettings, _) {
  8. Drupal.behaviors.ckeditorStylesComboSettings = {
  9. attach: function attach(context) {
  10. var $context = $(context);
  11. var $ckeditorActiveToolbar = $context.find('.ckeditor-toolbar-configuration').find('.ckeditor-toolbar-active');
  12. var previousStylesSet = drupalSettings.ckeditor.hiddenCKEditorConfig.stylesSet;
  13. var that = this;
  14. $context.find('[name="editor[settings][plugins][stylescombo][styles]"]').on('blur.ckeditorStylesComboSettings', function () {
  15. var styles = $.trim($(this).val());
  16. var stylesSet = that._generateStylesSetSetting(styles);
  17. if (!_.isEqual(previousStylesSet, stylesSet)) {
  18. previousStylesSet = stylesSet;
  19. $ckeditorActiveToolbar.trigger('CKEditorPluginSettingsChanged', [{ stylesSet: stylesSet }]);
  20. }
  21. });
  22. },
  23. _generateStylesSetSetting: function _generateStylesSetSetting(styles) {
  24. var stylesSet = [];
  25. styles = styles.replace(/\r/g, '\n');
  26. var lines = styles.split('\n');
  27. for (var i = 0; i < lines.length; i++) {
  28. var style = $.trim(lines[i]);
  29. if (style.length === 0) {
  30. continue;
  31. }
  32. if (style.match(/^ *[a-zA-Z0-9]+ *(\.[a-zA-Z0-9_-]+ *)*\| *.+ *$/) === null) {
  33. continue;
  34. }
  35. var parts = style.split('|');
  36. var selector = parts[0];
  37. var label = parts[1];
  38. var classes = selector.split('.');
  39. var element = classes.shift();
  40. stylesSet.push({
  41. attributes: { class: classes.join(' ') },
  42. element: element,
  43. name: label
  44. });
  45. }
  46. return stylesSet;
  47. }
  48. };
  49. Drupal.behaviors.ckeditorStylesComboSettingsSummary = {
  50. attach: function attach() {
  51. $('[data-ckeditor-plugin-id="stylescombo"]').drupalSetSummary(function (context) {
  52. var styles = $.trim($('[data-drupal-selector="edit-editor-settings-plugins-stylescombo-styles"]').val());
  53. if (styles.length === 0) {
  54. return Drupal.t('No styles configured');
  55. }
  56. var count = $.trim(styles).split('\n').length;
  57. return Drupal.t('@count styles configured', { '@count': count });
  58. });
  59. }
  60. };
  61. })(jQuery, Drupal, drupalSettings, _);