Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / filter / filter.es6.js
1 /**
2  * @file
3  * Attaches behavior for the Filter module.
4  */
5
6 (function ($, Drupal) {
7   /**
8    * Displays the guidelines of the selected text format automatically.
9    *
10    * @type {Drupal~behavior}
11    *
12    * @prop {Drupal~behaviorAttach} attach
13    *   Attaches behavior for updating filter guidelines.
14    */
15   Drupal.behaviors.filterGuidelines = {
16     attach(context) {
17       function updateFilterGuidelines(event) {
18         const $this = $(event.target);
19         const value = $this.val();
20         $this
21           .closest('.filter-wrapper')
22           .find('.filter-guidelines-item')
23           .hide()
24           .filter(`.filter-guidelines-${value}`)
25           .show();
26       }
27
28       $(context)
29         .find('.filter-guidelines')
30         .once('filter-guidelines')
31         .find(':header')
32         .hide()
33         .closest('.filter-wrapper')
34         .find('select.filter-list')
35         .on('change.filterGuidelines', updateFilterGuidelines)
36         // Need to trigger the namespaced event to avoid triggering formUpdated
37         // when initializing the select.
38         .trigger('change.filterGuidelines');
39     },
40   };
41 }(jQuery, Drupal));