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

Restart #284

Closed
wants to merge 6 commits 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
71 changes: 71 additions & 0 deletions acrobat/blocks/dc-converter-widget/dc-converter-widget.css
Original file line number Diff line number Diff line change
@@ -1 +1,72 @@
.dc-converter-widget > div:first-of-type {
display: none;
}

.widget-heading {
font-size: 36px;
margin: 40px 10px;
text-align: center;
}

.widget-copy {
font-size: 16px;
text-align: center;
margin: 0 10px;
}

.widget-center {
justify-content: center;
flex: 1 1 auto;
display: flex;
flex-direction: column;
}

.widget-legal {
font-size: 16px;
text-align: center;
margin: 0 10px;
}

.widget-wrapper {
border: 1px #e1e1e1 solid;
margin: 5px;
border-radius: 8px;
background-color: white;
}

.widget-button {
border-radius: 24px;
width: 252px;
padding: 10px;
background: grey;
margin: 0 auto;
text-align: center;
}

@media (max-width: 600px) {
.dc-converter-widget,
.widget-wrapper {
height: calc(100vh - 110px) !important;

display: flex;
height: 100%;
width: 100%;

display: flex;
flex: 1 1 auto;
flex-direction: column;

/* justify-content: center; */
}

.fs > div > div {
height: calc(100vh - 110px);
}
}

/*
@media (max-width: 600px) {
[lang="en-US"] .wapper-pdf-to-ppt > div > div {
height: calc(100vh - 120px);
}
} */
218 changes: 44 additions & 174 deletions acrobat/blocks/dc-converter-widget/dc-converter-widget.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {createTag} from "../../scripts/miloUtils.js";



// Could use webpack/rollup. Just manually inline these structures, for now.
const localeMap = {
'': 'en-us',
Expand Down Expand Up @@ -117,180 +121,46 @@ let langFromPath = url.pathname.split('/')[1];
const pageLang = localeMap[langFromPath] || 'en-us';

export default function init(element) {
const widget = element;
const DC_WIDGET_VERSION_FALLBACK = '2.40.0_1.172.1';
const DC_GENERATE_CACHE_VERSION_FALLBACK = '1.172.1';
const STG_DC_WIDGET_VERSION = document.querySelector('meta[name="stg-dc-widget-version"]')?.getAttribute('content');
const STG_DC_GENERATE_CACHE_VERSION = document.querySelector('meta[name="stg-dc-generate-cache-version"]')?.getAttribute('content');

let DC_DOMAIN = 'https://dev.acrobat.adobe.com';
let DC_WIDGET_VERSION = document.querySelector('meta[name="dc-widget-version"]')?.getAttribute('content');
let DC_GENERATE_CACHE_VERSION = document.querySelector('meta[name="dc-generate-cache-version"]')?.getAttribute('content');
const lanaOptions = {
sampleRate: 1,
tags: 'Cat=DxDC_Frictionless,origin=milo',
};
if (!DC_WIDGET_VERSION) {
DC_WIDGET_VERSION = DC_WIDGET_VERSION_FALLBACK;
window.lana?.log(`DC WIDGET VERSION IS NOT SET, USING FALLBACK VERSION: ${DC_WIDGET_VERSION_FALLBACK}`, lanaOptions);
}
if (!DC_GENERATE_CACHE_VERSION) {
DC_GENERATE_CACHE_VERSION = DC_GENERATE_CACHE_VERSION_FALLBACK;
window.lana?.log(`DC GENERATE CACHE VERSION IS NOT SET, USING FALLBACK VERSION: ${DC_GENERATE_CACHE_VERSION_FALLBACK}`, lanaOptions);
}
let WIDGET_ENV = `https://dev.acrobat.adobe.com/dc-hosted/${DC_WIDGET_VERSION}/dc-app-launcher.js`;
let ENV = 'dev';
let REDIRECT_URL = '';
let DC_GENERATE_CACHE_URL = '';

if (window.location.hostname === 'www.adobe.com') {
WIDGET_ENV = `https://acrobat.adobe.com/dc-hosted/${DC_WIDGET_VERSION}/dc-app-launcher.js`;
DC_DOMAIN = 'https://acrobat.adobe.com';
ENV = 'prod';
}

if (window.location.hostname === 'stage--dc--adobecom.hlx.page'
|| window.location.hostname === 'main--dc--adobecom.hlx.page'
|| window.location.hostname === 'stage--dc--adobecom.hlx.live'
|| window.location.hostname === 'main--dc--adobecom.hlx.live'
|| window.location.hostname === 'www.stage.adobe.com') {
WIDGET_ENV = `https://stage.acrobat.adobe.com/dc-hosted/${STG_DC_WIDGET_VERSION}/dc-app-launcher.js`;
DC_DOMAIN = 'https://stage.acrobat.adobe.com';
DC_GENERATE_CACHE_VERSION = STG_DC_GENERATE_CACHE_VERSION;
ENV = 'stage';
}

widget.querySelector('div').id = 'VERB';
const VERB = widget.querySelector('div').textContent.trim().toLowerCase();

// Redir URL
const REDIRECT_URL_DIV = widget.querySelectorAll('div')[2];
if (REDIRECT_URL_DIV) {
// REDIRECT_URL_DIV.id = 'REDIRECT_URL';
REDIRECT_URL = REDIRECT_URL_DIV.textContent.trim();
REDIRECT_URL_DIV.remove();
}


// Generate cache url
const GENERATE_CACHE_URL_DIV = widget.querySelectorAll('div')[4];
if (GENERATE_CACHE_URL_DIV) {
// GENERATE_CACHE_URL_DIV.id = 'GENERATE_CACHE_URL';
DC_GENERATE_CACHE_URL = GENERATE_CACHE_URL_DIV.textContent.trim();
GENERATE_CACHE_URL_DIV.remove();
}

// Redirect
const fallBack = 'https://www.adobe.com/go/acrobat-overview';
const redDir = () => {
if (window.location.hostname != 'main--dc--adobecom.hlx.live'
&& window.location.hostname != 'www.adobe.com' ) {
window.location = `https://www.adobe.com/go/acrobat-${verbRedirMap[VERB] || VERB.split('-').join('')}-${ENV}`|| REDIRECT_URL;
} else {
window.location = REDIRECT_URL || `https://www.adobe.com/go/acrobat-${verbRedirMap[VERB] || VERB.split('-').join('')}` || fallBack;
}
};

const widgetContainer = document.createElement('div');
widgetContainer.id = 'CID';
widgetContainer.className = `wapper-${VERB}`;
widget.appendChild(widgetContainer);

const isReturningUser = window.localStorage.getItem('pdfnow.auth');
const isRedirection = /redirect_(?:conversion|files)=true/.test(window.location.search);
const preRenderDropZone = !isReturningUser && !isRedirection;
if (preRenderDropZone) {
(async () => {
// TODO: Make dynamic
const response = await fetch(DC_GENERATE_CACHE_URL || `${DC_DOMAIN}/dc-generate-cache/dc-hosted-${DC_GENERATE_CACHE_VERSION}/${VERB}-${pageLang}.html`);
switch (response.status) {
case 200: {
const template = await response.text();
if (!("rendered" in widgetContainer.dataset)) {
widgetContainer.dataset.rendered = "true";
const doc = new DOMParser().parseFromString(template, 'text/html');
document.head.appendChild(doc.head.getElementsByTagName('Style')[0]);
widgetContainer.appendChild(doc.body.firstElementChild);
performance.mark("milo-insert-snippet");
}
break;
}
default:
break;
}
})();
}

window.addEventListener('IMS:Ready', async () => {
// Redirect Usage
if (window.adobeIMS.isSignedInUser()) {
redDir();
return;
}

const { default: frictionless } = await import('../../scripts/frictionless.js');
frictionless(VERB);
});

const dcScript = document.createElement('script');
dcScript.id = 'adobe_dc_sdk_launcher';
dcScript.setAttribute('src', WIDGET_ENV);
dcScript.dataset.dropzone_id = 'CID';
dcScript.dataset.locale = pageLang;
dcScript.dataset.server_env = ENV;
dcScript.dataset.verb = VERB;
dcScript.dataset.load_typekit = 'false';
dcScript.dataset.load_imslib = 'false';
dcScript.dataset.enable_unload_prompt = 'true';
if (preRenderDropZone) {
dcScript.dataset.pre_rendered = 'true'; // TODO: remove this line
}

window.addEventListener('Bowser:Ready', async () => {
// EOL Redirect
const { redirectLegacyBrowsers } = await import('../../scripts/legacyBrowser.js');
redirectLegacyBrowsers();
})

widget.appendChild(dcScript);

window.addEventListener('IMS:Ready', () => {
let evt;
evt = new CustomEvent('dc.imslib.ready', { detail: { instance: window.adobeIMS }});
evt.initEvent('dc.imslib.ready', true, true);
document.dispatchEvent(evt);
// window.adobe_dc_sdk.imsReady = true;
})

// DC Personalization
window.addEventListener('DC_Hosted:Ready', () => {
const DATA = window.dc_hosted.getUserLimits();
DATA.then((val) => {
const doccloudPersonalization = val;
// if limit for 300 uploads is reached, limit is shared across all verbs,
// upsell is shown for all verbs
const canNotUpload = val.upload && !val.upload.can_upload;
doccloudPersonalization.isUpsellDisplayed = {
// L2 VERBS
// convert-pdf, word-pdf, excel-pdf, jpg-pdf, ppt-pdf
createPDF: canNotUpload || (val.create_pdf && !val.create_pdf.can_process),
// pdf-word, pdf-excel, pdf-ppt, pdf-jpg (2 conversion allowed, limit is shared across them)
exportPDF: canNotUpload || (val.export_pdf && !val.export_pdf.can_process),
// compress-pdf
compressPDF: canNotUpload || (val.compress_pdf && !val.compress_pdf.can_process),
// password-protect
passwordProtectPDF: canNotUpload || (val.protect_pdf && !val.protect_pdf.can_process),
// merge-pdf
mergePDF: canNotUpload || (val.combine_pdf && !val.combine_pdf.can_process),
// L1 VERBS (all of them: request signature, pdf editor, delete pdf pages,
// rotate pdf, rearrange pdf, split pdf, add pages to pdf, sign pdf, export pdf)
l1Verbs: canNotUpload,
};
window.doccloudPersonalization = doccloudPersonalization;
// Personalization Ready Event
const personalizationIsReady = new CustomEvent('Personalization:Ready');

window.dispatchEvent(personalizationIsReady);
const HEADING = 'Convert PDF to PowerPoint';
const COPY = 'Select a PDF file to convert it into a Microsoft PowerPoint presentation.';
const LEGAL = 'Your file will be securely handled by Adobe servers and deleted unless you sign in to save it. By using this service, you agree to the Adobe Terms of Use and Privacy Policy.'
const BTN = 'Upload a File'

//Create Fake Widget
createTag.then((tag) => {
const wrapper = tag('div', {id: 'CID', class: 'widget-wrapper' });
const heading = tag('h1', { class: 'widget-heading' }, HEADING);

const center = tag('div', { class: 'widget-center' });
const copy = tag('div', { class: 'widget-copy' }, COPY);
const legal = tag('div', { class: 'widget-legal' }, LEGAL);
const button = tag('div', { class: 'widget-button' }, BTN);
element.append(wrapper);
wrapper.append(heading);
wrapper.append(center)
center.append(copy);
center.append(button);
wrapper.append(legal);

let WIDGET_ENV = `https://dev.acrobat.adobe.com/dc-hosted/2.40.0_1.172.1/dc-app-launcher.js`;

const dcWidgetScript = tag('script', {
id: 'adobe_dc_sdk_launcher',
src: WIDGET_ENV,
'data-dropzone_id': 'CID',
'data-locale': pageLang,
'data-server_env': 'STAGE',
'data-verb': 'pdf-to-ppt',
'data-load_typekit': 'false',
'data-load_imslib': 'false',
'data-enable_unload_prompt': 'true',
});

document.addEventListener('milo:deferred', ()=> {
wrapper.classList.add('fs');
element.append(dcWidgetScript);
})
});


}
1 change: 1 addition & 0 deletions acrobat/scripts/dcLana.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function lanaLogging() {
});
});

console.log('test');
setTimeout(() => {
if (fricPage && !window.dc_hosted) {
lanaOptions.tags = 'Cat=DxDC_Frictionless,origin=milo';
Expand Down
Loading