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

MWPW-158599: Dynamic prefetch from anon on unity workflow #817

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Changes from 2 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
34 changes: 31 additions & 3 deletions acrobat/blocks/verb-widget/verb-widget.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import LIMITS from './limits.js';
import { setLibs, isOldBrowser } from '../../scripts/utils.js';
import { setLibs, getEnv, isOldBrowser } from '../../scripts/utils.js';
import verbAnalytics from '../../scripts/alloy/verb-widget.js';

const miloLibs = setLibs('/libs');
Expand Down Expand Up @@ -46,9 +45,29 @@ const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html';
// };

const setDraggingClass = (widget, shouldToggle) => {
shouldToggle ? widget.classList.add('dragging') : widget.classList.remove('dragging');
widget.classList.toggle('dragging', shouldToggle);
};
joaquinrivero marked this conversation as resolved.
Show resolved Hide resolved

function prefetchNextPage(verb) {
const ENV = getEnv();
joaquinrivero marked this conversation as resolved.
Show resolved Hide resolved
const isProd = ENV === 'prod';
const nextPageHost = isProd ? 'acrobat.adobe.com' : 'stage.acrobat.adobe.com';
const nextPageUrl = `https://${nextPageHost}/us/en/discover/${verb}`;
const link = document.createElement('link');
link.rel = 'prefetch';
link.href = nextPageUrl;
link.crossOrigin = 'anonymous';
link.as = 'document';
document.head.appendChild(link);
}

function initiatePrefetch(verb) {
if (!window.prefetchInitiated) {
prefetchNextPage(verb);
window.prefetchInitiated = true;
}
}

export default async function init(element) {
if (isOldBrowser()) {
window.location.href = EOLBrowserPage;
Expand Down Expand Up @@ -108,8 +127,11 @@ export default async function init(element) {

verbAnalytics('landing:shown', VERB);

window.prefetchInitiated = false;

button.addEventListener('click', () => {
verbAnalytics('dropzone:choose-file-clicked', VERB);
initiatePrefetch(VERB);
});

button.addEventListener('cancel', () => {
Expand All @@ -119,12 +141,18 @@ export default async function init(element) {
widget.addEventListener('dragover', (e) => {
e.preventDefault();
setDraggingClass(widget, true);
initiatePrefetch(VERB);
});

widget.addEventListener('dragleave', () => {
setDraggingClass(widget, false);
});

widget.addEventListener('drop', (e) => {
e.preventDefault();
initiatePrefetch(VERB);
});

errorCloseBtn.addEventListener('click', () => {
errorState.classList.remove('verb-error');
errorState.classList.add('hide');
Expand Down
Loading