linkit.filter_html.admin.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @file
  3. * Send events to add or remove a tags to the filter_html allowed tags.
  4. */
  5. (function ($, Drupal, document) {
  6. 'use strict';
  7. /**
  8. * When enabling the linkit filter, also add linkit rules to filter_html.
  9. *
  10. * @type {Drupal~behavior}
  11. *
  12. * @prop {Drupal~behaviorAttach} attach
  13. * Attaches linkitFilterHtml behavior.
  14. */
  15. Drupal.behaviors.linkitFilterHtml = {
  16. attach: function (context) {
  17. var selector = '[data-drupal-selector="edit-filters-linkit-status"]';
  18. var feature = editorFeature();
  19. $(context).find(selector).once('filters-linkit-status').each(function () {
  20. $(this).on('click', function () {
  21. var eventName = $(this).is(':checked') ? 'drupalEditorFeatureAdded' : 'drupalEditorFeatureRemoved';
  22. $(document).trigger(eventName, feature);
  23. });
  24. });
  25. }
  26. };
  27. /**
  28. * Returns a editor feature.
  29. *
  30. * @return {Drupal.EditorFeature}
  31. * A editor feature with linkit specific tags and attributes.
  32. */
  33. function editorFeature() {
  34. var linkitFeature = new Drupal.EditorFeature('linkit');
  35. var rule = new Drupal.EditorFeatureHTMLRule();
  36. // Tags.
  37. rule.required.tags = ['a'];
  38. rule.allowed.tags = ['a'];
  39. // Attributes.
  40. rule.required.attributes = ['data-entity-substitution', 'data-entity-type', 'data-entity-uuid', 'title'];
  41. rule.allowed.attributes = ['data-entity-substitution', 'data-entity-type', 'data-entity-uuid', 'title'];
  42. linkitFeature.addHTMLRule(rule);
  43. return linkitFeature;
  44. }
  45. })(jQuery, Drupal, document);