Skip to content

Commit c9434d2

Browse files
authored
Handle short Click to Load placeholders more consistently (#360)
When Click to Load placeholders are displayed inside a short parent element, we take care to make the placeholder shorter and display an extra button in the header. There were two code-paths for this, let's combine them and also take care to check that placeholder.parentElement exists.
1 parent 8790400 commit c9434d2

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

src/features/click-to-load.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -402,24 +402,7 @@ async function createPlaceholderElementAndReplace (widget, trackingElement) {
402402
replaceTrackingElement(
403403
widget, trackingElement, contentBlock
404404
)
405-
406-
// Show the extra unblock link in the header if the placeholder or
407-
// its parent is too short for the normal unblock button to be visible.
408-
// Note: This does not take into account the placeholder's vertical
409-
// position in the parent element.
410-
const { height: placeholderHeight } = window.getComputedStyle(contentBlock)
411-
const { height: parentHeight } = window.getComputedStyle(contentBlock.parentElement)
412-
if (parseInt(placeholderHeight, 10) <= 200 || parseInt(parentHeight, 10) <= 200) {
413-
const titleRowTextButton = shadowRoot.querySelector(`#${titleID + 'TextButton'}`)
414-
titleRowTextButton.style.display = 'block'
415-
416-
// Avoid the placeholder being taller than the containing element
417-
// and overflowing.
418-
const innerDiv = shadowRoot.querySelector('.DuckDuckGoSocialContainer')
419-
innerDiv.style.minHeight = ''
420-
innerDiv.style.maxHeight = parentHeight
421-
innerDiv.style.overflow = 'hidden'
422-
}
405+
showExtraUnblockIfShortPlaceholder(shadowRoot, contentBlock)
423406
}
424407

425408
/** YouTube CTL */
@@ -475,19 +458,30 @@ async function replaceYouTubeCTL (trackingElement, widget, togglePlaceholder = f
475458
}
476459

477460
/**
478-
/* Show the extra unblock link in the header if the placeholder or
479-
/* its parent is too short for the normal unblock button to be visible.
480-
/* Note: This does not take into account the placeholder's vertical
481-
/* position in the parent element.
482-
* @param {Element} shadowRoot
483-
* @param {Element} placeholder Placeholder for tracking element
484-
*/
461+
* Show the extra unblock link in the header if the placeholder or
462+
* its parent is too short for the normal unblock button to be visible.
463+
* Note: This does not take into account the placeholder's vertical
464+
* position in the parent element.
465+
* @param {Element} shadowRoot
466+
* @param {Element} placeholder Placeholder for tracking element
467+
*/
485468
function showExtraUnblockIfShortPlaceholder (shadowRoot, placeholder) {
469+
if (!placeholder.parentElement) {
470+
return
471+
}
472+
486473
const { height: placeholderHeight } = window.getComputedStyle(placeholder)
487474
const { height: parentHeight } = window.getComputedStyle(placeholder.parentElement)
488475
if (parseInt(placeholderHeight, 10) <= 200 || parseInt(parentHeight, 10) <= 200) {
489476
const titleRowTextButton = shadowRoot.querySelector(`#${titleID + 'TextButton'}`)
490477
titleRowTextButton.style.display = 'block'
478+
479+
// Avoid the placeholder being taller than the containing element
480+
// and overflowing.
481+
const innerDiv = shadowRoot.querySelector('.DuckDuckGoSocialContainer')
482+
innerDiv.style.minHeight = ''
483+
innerDiv.style.maxHeight = parentHeight
484+
innerDiv.style.overflow = 'hidden'
491485
}
492486
}
493487

0 commit comments

Comments
 (0)