X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fblock%2Fjs%2Fblock.admin.es6.js;h=ff4d8eb20df24b7bb589b5473b55131371eebd4c;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=780ea12e2e70c9e3f07eccbfe86959f46a54f1f5;hpb=af6d1fb995500ae68849458ee10d66abbdcfb252;p=yaffs-website diff --git a/web/core/modules/block/js/block.admin.es6.js b/web/core/modules/block/js/block.admin.es6.js index 780ea12e2..ff4d8eb20 100644 --- a/web/core/modules/block/js/block.admin.es6.js +++ b/web/core/modules/block/js/block.admin.es6.js @@ -3,7 +3,7 @@ * Block admin behaviors. */ -(function ($, Drupal, debounce) { +(function($, Drupal, debounce) { /** * Filters the block list by a text input search string. * @@ -33,7 +33,9 @@ * The jQuery event for the keyup event that triggered the filter. */ function filterBlockList(e) { - const query = $(e.target).val().toLowerCase(); + const query = $(e.target) + .val() + .toLowerCase(); /** * Shows or hides the block entry based on the query. @@ -46,7 +48,11 @@ function toggleBlockEntry(index, label) { const $label = $(label); const $row = $label.parent().parent(); - const textMatch = $label.text().toLowerCase().indexOf(query) !== -1; + const textMatch = + $label + .text() + .toLowerCase() + .indexOf(query) !== -1; $row.toggle(textMatch); } @@ -60,10 +66,12 @@ '@count blocks are available in the modified list.', ), ); - } - else { - $filterRows.each(function (index) { - $(this).parent().parent().show(); + } else { + $filterRows.each(function(index) { + $(this) + .parent() + .parent() + .show(); }); } } @@ -85,16 +93,26 @@ */ Drupal.behaviors.blockHighlightPlacement = { attach(context, settings) { - if (settings.blockPlacement) { - $(context).find('[data-drupal-selector="edit-blocks"]').once('block-highlight').each(function () { - const $container = $(this); - // Just scrolling the document.body will not work in Firefox. The html - // element is needed as well. - $('html, body').animate({ - scrollTop: ($('.js-block-placed').offset().top - $container.offset().top) + $container.scrollTop(), - }, 500); - }); + // Ensure that the block we are attempting to scroll to actually exists. + if (settings.blockPlacement && $('.js-block-placed').length) { + $(context) + .find('[data-drupal-selector="edit-blocks"]') + .once('block-highlight') + .each(function() { + const $container = $(this); + // Just scrolling the document.body will not work in Firefox. The html + // element is needed as well. + $('html, body').animate( + { + scrollTop: + $('.js-block-placed').offset().top - + $container.offset().top + + $container.scrollTop(), + }, + 500, + ); + }); } }, }; -}(jQuery, Drupal, Drupal.debounce)); +})(jQuery, Drupal, Drupal.debounce);