Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views_ui / js / views_ui.listing.js
1 /**
2  * @file
3  * Views listing behaviors.
4  */
5
6 (function ($, Drupal) {
7
8   'use strict';
9
10   /**
11    * Filters the view listing tables by a text input search string.
12    *
13    * Text search input: input.views-filter-text
14    * Target table:      input.views-filter-text[data-table]
15    * Source text:       [data-drupal-selector="views-table-filter-text-source"]
16    *
17    * @type {Drupal~behavior}
18    *
19    * @prop {Drupal~behaviorAttach} attach
20    *   Attaches the filter functionality to the views admin text search field.
21    */
22   Drupal.behaviors.viewTableFilterByText = {
23     attach: function (context, settings) {
24       var $input = $('input.views-filter-text').once('views-filter-text');
25       var $table = $($input.attr('data-table'));
26       var $rows;
27
28       function filterViewList(e) {
29         var query = $(e.target).val().toLowerCase();
30
31         function showViewRow(index, row) {
32           var $row = $(row);
33           var $sources = $row.find('[data-drupal-selector="views-table-filter-text-source"]');
34           var textMatch = $sources.text().toLowerCase().indexOf(query) !== -1;
35           $row.closest('tr').toggle(textMatch);
36         }
37
38         // Filter if the length of the query is at least 2 characters.
39         if (query.length >= 2) {
40           $rows.each(showViewRow);
41         }
42         else {
43           $rows.show();
44         }
45       }
46
47       if ($table.length) {
48         $rows = $table.find('tbody tr');
49         $input.on('keyup', filterViewList);
50       }
51     }
52   };
53
54 }(jQuery, Drupal));