34d8488dbda177e89d12cb7fd69d6a89e230528a
[yaffs-website] / js / modules / filter / filter.js
1 /**
2  * @file
3  * Attaches behavior for the Filter module.
4  */
5
6 (function ($) {
7   'use strict';
8
9   function updateFilterHelpLink () {
10     var $link = $(this).parents('.filter-wrapper').find('.filter-help > a');
11     var originalLink = $link.data('originalLink');
12     if (!originalLink) {
13       originalLink = $link.attr('href');
14       $link.data('originalLink', originalLink);
15     }
16     $link.attr('href', originalLink + '/' + $(this).find(':selected').val());
17   }
18
19   $(document).on('change', '.filter-wrapper select.filter-list', updateFilterHelpLink);
20
21   /**
22    * Displays the guidelines of the selected text format automatically.
23    *
24    * @type {Drupal~behavior}
25    *
26    * @prop {Drupal~behaviorAttach} attach
27    *   Attaches behavior for updating filter guidelines.
28    */
29   Drupal.behaviors.filterGuidelines = {
30     attach: function (context) {
31       $(context).find('.filter-wrapper select.filter-list').once('filter-list').each(updateFilterHelpLink);
32     }
33   };
34
35 })(jQuery);