Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Fix "reference docs" not working in Office Online.
Browse files Browse the repository at this point in the history
Issue was that some of the ref docs (e.g., for PPT) were on a site that doesn't allow embedding.
Fixed by having it launch a standalone window instead.
OfficeDev/script-lab#807
  • Loading branch information
Zlatkovsky committed May 16, 2018
1 parent 8438d94 commit f752dc7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .vscode/cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
"LOCALSTORAGE",
"minified",
"officejs",
"onenote",
"parameterized",
"polyfills",
"powepoint",
"Prereq",
"Proxying",
"repo",
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

"spellright.notificationClass": "warning",
"spellright.ignoreFiles": ["**/.gitignore", "**/.spellignore"],
"cSpell.words": ["bornholm"],
"cSpell.words": [
"bornholm",
"onenote",
"powepoint"
],
"editor.formatOnSave": true
}
34 changes: 23 additions & 11 deletions src/client/public/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { safeExternalUrls } = PLAYGROUND;
const tutorialUrl = `${window.location.origin}/tutorial.html`;
const codeUrl = `${window.location.origin}/?mode=${Utilities.host}`;

const launchInDialog = (url: string, event?: any, options?: { width?: number, height?: number, displayInIframe?: boolean }) => {
function launchInDialog(url: string, event?: any, options?: { width?: number, height?: number, displayInIframe?: boolean }): void {
options = options || {};
options.width = options.width || 60;
options.height = options.height || 60;
Expand All @@ -29,41 +29,53 @@ const launchInDialog = (url: string, event?: any, options?: { width?: number, he
}
};

const launchDialogNavigation = (url: string, event: any, options?: { width?: number, height?: number, displayInIframe?: boolean }) => {
function launchDialogNavigation(url: string, event: any, options?: { width?: number, height?: number, displayInIframe?: boolean }): void {
launchInDialog(`${window.location.origin}/external-page.html?destination=${encodeURIComponent(url)}`, event, options);
};

function launchInStandaloneWindow(url: string, event: any): void {
// At least on desktop, it looks like you can't do "window.open" out of the invisible runner.
// Thus, on desktop, still use a dialog API
// As for Office Online, set displayInIframe as false, so that it prompts a window to
// have you open a dialog. If we did "window.open" directly,
// popup blockers would prevent the window from showing.
// And conversely, if had "displayInIframe: true" instead, the docs.microsoft.com
// site doesn't allow embedding, and get an error. So it has to be a standalone window,
// but created via the Dialog API
launchDialogNavigation(url, event, { displayInIframe: false });
}

(window as any).commandExecutor = {
launchCode: (event) => launchInDialog(codeUrl, event, { width: 75, height: 75, displayInIframe: false }),

launchTutorial: (event) => launchInDialog(tutorialUrl, event, { width: 35, height: 45 }),

launchHelp: (event) => launchDialogNavigation(safeExternalUrls.playground_help, event, { displayInIframe: false }),
launchHelp: (event) => launchInStandaloneWindow(safeExternalUrls.playground_help, event),

launchAsk: (event) => launchDialogNavigation(safeExternalUrls.ask, event, { displayInIframe: false }),
launchAsk: (event) => launchInStandaloneWindow(safeExternalUrls.ask, event),

launchApiDocs: (event) => {
if (Office.context.requirements.isSetSupported('ExcelApi')) {
return launchDialogNavigation(safeExternalUrls.excel_api, event);
return launchInStandaloneWindow(safeExternalUrls.excel_api, event);
}
else if (Office.context.requirements.isSetSupported('WordApi')) {
return launchDialogNavigation(safeExternalUrls.word_api, event);
return launchInStandaloneWindow(safeExternalUrls.word_api, event);
}
else if (Office.context.requirements.isSetSupported('OneNoteApi')) {
return launchDialogNavigation(safeExternalUrls.onenote_api, event);
return launchInStandaloneWindow(safeExternalUrls.onenote_api, event);
}
else {
if (Utilities.host === HostType.POWERPOINT) {
return launchDialogNavigation(safeExternalUrls.powepoint_api, event);
return launchInStandaloneWindow(safeExternalUrls.powepoint_api, event);
}
else if (Utilities.host === HostType.PROJECT) {
return launchDialogNavigation(safeExternalUrls.project_api, event);
return launchInStandaloneWindow(safeExternalUrls.project_api, event);
}
else if (Utilities.host === HostType.OUTLOOK) {
return launchDialogNavigation(safeExternalUrls.outlook_api, event);
return launchInStandaloneWindow(safeExternalUrls.outlook_api, event);
}
else {
return launchDialogNavigation(safeExternalUrls.generic_api, event);
return launchInStandaloneWindow(safeExternalUrls.generic_api, event);
}
}
}
Expand Down

0 comments on commit f752dc7

Please sign in to comment.