comparison core/modules/block/js/block.admin.es6.js @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
1 /** 1 /**
2 * @file 2 * @file
3 * Block admin behaviors. 3 * Block admin behaviors.
4 */ 4 */
5 5
6 (function ($, Drupal, debounce) { 6 (function($, Drupal, debounce) {
7 /** 7 /**
8 * Filters the block list by a text input search string. 8 * Filters the block list by a text input search string.
9 * 9 *
10 * The text input will have the selector `input.block-filter-text`. 10 * The text input will have the selector `input.block-filter-text`.
11 * 11 *
31 * 31 *
32 * @param {jQuery.Event} e 32 * @param {jQuery.Event} e
33 * The jQuery event for the keyup event that triggered the filter. 33 * The jQuery event for the keyup event that triggered the filter.
34 */ 34 */
35 function filterBlockList(e) { 35 function filterBlockList(e) {
36 const query = $(e.target).val().toLowerCase(); 36 const query = $(e.target)
37 .val()
38 .toLowerCase();
37 39
38 /** 40 /**
39 * Shows or hides the block entry based on the query. 41 * Shows or hides the block entry based on the query.
40 * 42 *
41 * @param {number} index 43 * @param {number} index
44 * The label of the block. 46 * The label of the block.
45 */ 47 */
46 function toggleBlockEntry(index, label) { 48 function toggleBlockEntry(index, label) {
47 const $label = $(label); 49 const $label = $(label);
48 const $row = $label.parent().parent(); 50 const $row = $label.parent().parent();
49 const textMatch = $label.text().toLowerCase().indexOf(query) !== -1; 51 const textMatch =
52 $label
53 .text()
54 .toLowerCase()
55 .indexOf(query) !== -1;
50 $row.toggle(textMatch); 56 $row.toggle(textMatch);
51 } 57 }
52 58
53 // Filter if the length of the query is at least 2 characters. 59 // Filter if the length of the query is at least 2 characters.
54 if (query.length >= 2) { 60 if (query.length >= 2) {
58 $table.find('tr:visible').length - 1, 64 $table.find('tr:visible').length - 1,
59 '1 block is available in the modified list.', 65 '1 block is available in the modified list.',
60 '@count blocks are available in the modified list.', 66 '@count blocks are available in the modified list.',
61 ), 67 ),
62 ); 68 );
63 } 69 } else {
64 else { 70 $filterRows.each(function(index) {
65 $filterRows.each(function (index) { 71 $(this)
66 $(this).parent().parent().show(); 72 .parent()
73 .parent()
74 .show();
67 }); 75 });
68 } 76 }
69 } 77 }
70 78
71 if ($table.length) { 79 if ($table.length) {
83 * @prop {Drupal~behaviorAttach} attach 91 * @prop {Drupal~behaviorAttach} attach
84 * Attaches the behavior for the block placement highlighting. 92 * Attaches the behavior for the block placement highlighting.
85 */ 93 */
86 Drupal.behaviors.blockHighlightPlacement = { 94 Drupal.behaviors.blockHighlightPlacement = {
87 attach(context, settings) { 95 attach(context, settings) {
88 if (settings.blockPlacement) { 96 // Ensure that the block we are attempting to scroll to actually exists.
89 $(context).find('[data-drupal-selector="edit-blocks"]').once('block-highlight').each(function () { 97 if (settings.blockPlacement && $('.js-block-placed').length) {
90 const $container = $(this); 98 $(context)
91 // Just scrolling the document.body will not work in Firefox. The html 99 .find('[data-drupal-selector="edit-blocks"]')
92 // element is needed as well. 100 .once('block-highlight')
93 $('html, body').animate({ 101 .each(function() {
94 scrollTop: ($('.js-block-placed').offset().top - $container.offset().top) + $container.scrollTop(), 102 const $container = $(this);
95 }, 500); 103 // Just scrolling the document.body will not work in Firefox. The html
96 }); 104 // element is needed as well.
105 $('html, body').animate(
106 {
107 scrollTop:
108 $('.js-block-placed').offset().top -
109 $container.offset().top +
110 $container.scrollTop(),
111 },
112 500,
113 );
114 });
97 } 115 }
98 }, 116 },
99 }; 117 };
100 }(jQuery, Drupal, Drupal.debounce)); 118 })(jQuery, Drupal, Drupal.debounce);