Skip to content

Handle short Click to Load placeholders more consistently #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions src/features/click-to-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,24 +402,7 @@ async function createPlaceholderElementAndReplace (widget, trackingElement) {
replaceTrackingElement(
widget, trackingElement, contentBlock
)

// Show the extra unblock link in the header if the placeholder or
// its parent is too short for the normal unblock button to be visible.
// Note: This does not take into account the placeholder's vertical
// position in the parent element.
const { height: placeholderHeight } = window.getComputedStyle(contentBlock)
const { height: parentHeight } = window.getComputedStyle(contentBlock.parentElement)
if (parseInt(placeholderHeight, 10) <= 200 || parseInt(parentHeight, 10) <= 200) {
const titleRowTextButton = shadowRoot.querySelector(`#${titleID + 'TextButton'}`)
titleRowTextButton.style.display = 'block'

// Avoid the placeholder being taller than the containing element
// and overflowing.
const innerDiv = shadowRoot.querySelector('.DuckDuckGoSocialContainer')
innerDiv.style.minHeight = ''
innerDiv.style.maxHeight = parentHeight
innerDiv.style.overflow = 'hidden'
}
showExtraUnblockIfShortPlaceholder(shadowRoot, contentBlock)
}

/** YouTube CTL */
Expand Down Expand Up @@ -475,19 +458,30 @@ async function replaceYouTubeCTL (trackingElement, widget, togglePlaceholder = f
}

/**
/* Show the extra unblock link in the header if the placeholder or
/* its parent is too short for the normal unblock button to be visible.
/* Note: This does not take into account the placeholder's vertical
/* position in the parent element.
* @param {Element} shadowRoot
* @param {Element} placeholder Placeholder for tracking element
*/
* Show the extra unblock link in the header if the placeholder or
* its parent is too short for the normal unblock button to be visible.
* Note: This does not take into account the placeholder's vertical
* position in the parent element.
* @param {Element} shadowRoot
* @param {Element} placeholder Placeholder for tracking element
*/
function showExtraUnblockIfShortPlaceholder (shadowRoot, placeholder) {
if (!placeholder.parentElement) {
return
}

const { height: placeholderHeight } = window.getComputedStyle(placeholder)
const { height: parentHeight } = window.getComputedStyle(placeholder.parentElement)
if (parseInt(placeholderHeight, 10) <= 200 || parseInt(parentHeight, 10) <= 200) {
const titleRowTextButton = shadowRoot.querySelector(`#${titleID + 'TextButton'}`)
titleRowTextButton.style.display = 'block'

// Avoid the placeholder being taller than the containing element
// and overflowing.
const innerDiv = shadowRoot.querySelector('.DuckDuckGoSocialContainer')
innerDiv.style.minHeight = ''
innerDiv.style.maxHeight = parentHeight
innerDiv.style.overflow = 'hidden'
}
}

Expand Down