Skip to content
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

feat: MWPW-143356 | add floating-button block #39

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
Empty file.
35 changes: 35 additions & 0 deletions express/blocks/floating-button/floating-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { addTempWrapperDeprecated } from '../../scripts/utils/decorate.js';
import {
createFloatingButton,
collectFloatingButtonData,
} from '../../scripts/widgets/floating-cta.js';
import { formatDynamicCartLink } from '../../scripts/utils/pricing.js';

export default function decorate(block) {
addTempWrapperDeprecated(block, 'floating-button');
if (!block.classList.contains('metadata-powered')) {
block.parentElement?.remove();
return;
}

const audience = block.querySelector(':scope > div').textContent.trim();
if (audience === 'mobile') {
block.closest('.section')?.remove();
}

const parentSection = block.closest('.section');
const data = collectFloatingButtonData(block);

const blockWrapper = createFloatingButton(
block,
parentSection ? audience : null,
data,
);

const blockLinks = blockWrapper.querySelectorAll('a');
if (blockLinks && blockLinks.length > 0) {
formatDynamicCartLink(blockLinks[0]);
const linksPopulated = new CustomEvent('linkspopulated', { detail: blockLinks });
document.dispatchEvent(linksPopulated);
}
}
19 changes: 19 additions & 0 deletions express/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,22 @@ export function decorateArea(area = document) {
transpileMarquee(area);
overrideMiloColumns(area);
}

export function getMobileOperatingSystem() {
const userAgent = navigator.userAgent || navigator.vendor || window.opera;

// Windows Phone must come first because its UA also contains "Android"
if (/windows phone/i.test(userAgent)) {
return 'Windows Phone';
}

if (/android/i.test(userAgent)) {
return 'Android';
}

if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
return 'iOS';
}

return 'unknown';
}
Loading
Loading