Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / filter / filter.es6.js
diff --git a/web/core/modules/filter/filter.es6.js b/web/core/modules/filter/filter.es6.js
new file mode 100644 (file)
index 0000000..97c5501
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * @file
+ * Attaches behavior for the Filter module.
+ */
+
+(function ($, Drupal) {
+  /**
+   * Displays the guidelines of the selected text format automatically.
+   *
+   * @type {Drupal~behavior}
+   *
+   * @prop {Drupal~behaviorAttach} attach
+   *   Attaches behavior for updating filter guidelines.
+   */
+  Drupal.behaviors.filterGuidelines = {
+    attach(context) {
+      function updateFilterGuidelines(event) {
+        const $this = $(event.target);
+        const value = $this.val();
+        $this.closest('.filter-wrapper')
+          .find('.filter-guidelines-item').hide()
+          .filter(`.filter-guidelines-${value}`).show();
+      }
+
+      $(context).find('.filter-guidelines').once('filter-guidelines')
+        .find(':header').hide()
+        .closest('.filter-wrapper').find('select.filter-list')
+        .on('change.filterGuidelines', updateFilterGuidelines)
+        // Need to trigger the namespaced event to avoid triggering formUpdated
+        // when initializing the select.
+        .trigger('change.filterGuidelines');
+    },
+  };
+}(jQuery, Drupal));