Skip to content

Commit

Permalink
feat(SHS-5955): Prevent modal from scrolling when adding new social l…
Browse files Browse the repository at this point in the history
…inks
  • Loading branch information
codechefmarc committed Jan 4, 2025
1 parent a12f965 commit 9440593
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docroot/modules/humsci/hs_blocks/hs_blocks.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ back_to_top:
css/hs_blocks.back_to_top.css: {}
js:
js/hs_blocks.back_to_top.js: {}
prevent_modal_scroll:
js:
js/hs_blocks.prevent_modal_scroll.js: {}
dependencies:
- core/jquery
- core/drupal
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(function (Drupal, once, jQuery) {
Drupal.behaviors.preventScroll = {
attach: function (context) {
once('preventScroll', 'input[name="links_add_more"]', context).forEach((input) => {
jQuery(input).on('click', function () {

// Wait for the AJAX update to complete - due to block_class module?
setTimeout(() => {
const modal = jQuery('#drupal-modal');
const table = modal.find('table[id^="links-values"]');
const lastRow = table.find('tr:last');

if (modal.length && lastRow.length) {
const lastRowOffsetTop = lastRow[0].offsetTop - modal[0].offsetTop;
modal.scrollTop(lastRowOffsetTop);
}
}, 400);
});
});
},
};
})(Drupal, once, jQuery);
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ public function blockForm($form, FormStateInterface $form_state): array {
'callback' => [get_class($this), 'addMoreAjax'],
'wrapper' => 'links-wrapper',
'effect' => 'fade',
'event' => 'click',
'progress' => [
'type' => 'throbber',
'message' => NULL,
],
],
'#attached' => [
'library' => [
'hs_blocks/prevent_modal_scroll',
],
],
];

Expand Down

0 comments on commit 9440593

Please sign in to comment.