Skip to content

Commit

Permalink
Merge branch 'stage' into promptcard-analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
TsayAdobe committed Sep 27, 2024
2 parents 849125d + 07a5da4 commit 212b0f9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 12 deletions.
6 changes: 3 additions & 3 deletions acrobat/blocks/prompt-card/prompt-card.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@
flex: 1 0 0;
flex-direction: column;
justify-content: space-between;
padding: 20px 20px 24px;
padding: 16px 16px 24px;
transition-delay: 3s;
transition-property: border;
max-width: 276px;
}

.prompt-blade:hover {
box-shadow: 3px 6px 6px 0 rgba(0, 0, 0, .16)
box-shadow: 0 3px 6px rgba(0, 0, 0, 16%)
}

.prompt-blade:active {
Expand Down Expand Up @@ -153,7 +153,7 @@
font-style: normal;
font-weight: 400;
line-height: 150%;
padding: 2px 8px
padding: 2px 16px
}

.prompt-copy-btn:after {
Expand Down
2 changes: 1 addition & 1 deletion acrobat/blocks/prompt-card/prompt-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function createBlocks(element, blockArray, templateCfg) {
}
element.remove();

if (templateCfg.rows && parentNode.classList.contains('section')) {
if (templateCfg?.rows && parentNode.classList.contains('section')) {
const resizeObserver = new ResizeObserver(() => {
const computedStyle = window.getComputedStyle(parentNode);
if (/^(\d+(\.\d+)?(px|fr|em|rem|%))( (\d+(\.\d+)?(px|fr|em|rem|%)))*$/.test(computedStyle.gridTemplateColumns)) {
Expand Down
59 changes: 54 additions & 5 deletions acrobat/blocks/verb-widget/verb-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,32 @@ import verbAnalytics from '../../scripts/alloy/verb-widget.js';
const miloLibs = setLibs('/libs');
const { createTag } = await import(`${miloLibs}/utils/utils.js`);

const fallBack = 'https://www.adobe.com/go/acrobat-overview';
const EOLBrowserPage = 'https://acrobat.adobe.com/home/index-browser-eol.html';

const verbRedirMap = {
createpdf: 'createpdf',
'crop-pages': 'crop',
'delete-pages': 'deletepages',
'extract-pages': 'extract',
'combine-pdf': 'combine',
'protect-pdf': 'protect',
'add-comment': 'addcomment',
'pdf-to-image': 'pdftoimage',
'reorder-pages': 'reorderpages',
sendforsignature: 'sendforsignature',
'rotate-pages': 'rotatepages',
fillsign: 'fillsign',
'split-pdf': 'split',
'insert-pdf': 'insert',
'compress-pdf': 'compress',
'png-to-pdf': 'jpgtopdf',
'number-pages': 'number',
'ocr-pdf': 'ocr',
'chat-pdf': 'chat',
'chat-pdf-student': 'study',
};

const setUser = () => {
localStorage.setItem('unity.user', 'true');
};
Expand Down Expand Up @@ -36,6 +60,19 @@ function initiatePrefetch(verb) {
}
}

function redDir(verb) {
const hostname = window?.location?.hostname;
const ENV = getEnv();
const VERB = verb;
let newLocation;
if (hostname !== 'www.adobe.com' && hostname !== 'sign.ing' && hostname !== 'edit.ing') {
newLocation = `https://www.adobe.com/go/acrobat-${verbRedirMap[VERB] || VERB.split('-').join('')}-${ENV}`;
} else {
newLocation = `https://www.adobe.com/go/acrobat-${verbRedirMap[VERB] || VERB.split('-').join('')}` || fallBack;
}
window.location.href = newLocation;
}

export default async function init(element) {
if (isOldBrowser()) {
window.location.href = EOLBrowserPage;
Expand Down Expand Up @@ -99,6 +136,21 @@ export default async function init(element) {

element.append(widget, footer);

// Redirect after IMS:Ready
window.addEventListener('IMS:Ready', () => {
console.log('IMS:Ready 😎');
if (window.adobeIMS.isSignedInUser()
&& window.adobeIMS.getAccountType() !== 'type1') {
redDir(VERB);
}
});
// Race Condition
if (window.adobeIMS?.isSignedInUser()
&& window.adobeIMS?.getAccountType() !== 'type1') {
console.log('Race Con ⏩');
redDir(VERB);
}

// Analytics
verbAnalytics('landing:shown', VERB);

Expand All @@ -110,6 +162,7 @@ export default async function init(element) {

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

Expand Down Expand Up @@ -139,7 +192,7 @@ export default async function init(element) {

window.addEventListener('unity:track-analytics', (e) => {
if (e.detail?.event === 'change') {
verbAnalytics('choose-file:open', VERB);
verbAnalytics('choose-file:open', VERB, e.detail?.data);
setUser();
}
// maybe new event name files-dropped?
Expand All @@ -148,10 +201,6 @@ export default async function init(element) {
setDraggingClass(widget, false);
setUser();
}
if (e.detail?.event === 'choose-file-clicked') {
verbAnalytics('dropzone:choose-file-clicked', VERB, e.detail?.data);
setUser();
}

if (e.detail?.event === 'uploading') {
verbAnalytics('job:uploading', VERB, e.detail?.data);
Expand Down
7 changes: 4 additions & 3 deletions test/scripts/scripts-preloads.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { expect } from '@esm-bundle/chai';
import { waitForElement } from '../helpers/waitfor.js';

describe('Test scripts.js configurable preloads', () => {
it('has preload metadata', async () => {
document.head.innerHTML = '<link rel="icon" href="data:,"><meta name="preloads" content="$MILOLIBS/blocks/marquee/marquee.js,$MILOLIBS/blocks/marquee/marquee.css,https://www.example.com/abc.js"/>';
document.body.innerHTML = '<main><div class="marquee"></main>';
await import('../../acrobat/scripts/scripts.js');
const js = document.querySelector('link[rel="preload"][href="https://main--milo--adobecom.hlx.page/libs/blocks/marquee/marquee.js"]');
const css = document.querySelector('link[rel="stylesheet"][href="https://main--milo--adobecom.hlx.page/libs/blocks/marquee/marquee.css"]');
const js = document.querySelector('link[rel="preload"][href="https://main--milo--adobecom.hlx.live/libs/blocks/marquee/marquee.js"]');
const css = document.querySelector('link[rel="stylesheet"][href="https://main--milo--adobecom.hlx.live/libs/blocks/marquee/marquee.css"]');
const other = document.querySelector('link[rel="preload"][href="https://www.example.com/abc.js"]');
const acrobatcss = document.querySelector('link[rel="stylesheet"][href="/acrobat/styles/styles.css"]');
const milocss = document.querySelector('link[rel="stylesheet"][href="https://main--milo--adobecom.hlx.page/libs/styles/styles.css"]');
const milocss = document.querySelector('link[rel="stylesheet"][href="https://main--milo--adobecom.hlx.live/libs/styles/styles.css"]');
expect(js).not.to.be.null;
expect(css).not.to.be.null;
expect(other).not.to.be.null;
Expand Down

0 comments on commit 212b0f9

Please sign in to comment.