Skip to content

Commit

Permalink
change loader to allow keeping parent origin in config when embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
atoa committed Jan 12, 2018
1 parent 7636bac commit 245ac70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/lex-web-ui-loader/js/defaults/loader.js
Expand Up @@ -31,6 +31,7 @@ export const options = {

// controls whether the local config should be ignored when running
// embedded (e.g. iframe) in which case the parent page will pass the config
// Only the parentOrigin config field is kept when set to true
shouldIgnoreConfigWhenEmbedded: true,

// controls whether the config should be obtained using events
Expand Down
28 changes: 19 additions & 9 deletions src/lex-web-ui-loader/js/lib/config-loader.js
Expand Up @@ -42,15 +42,6 @@ export class ConfigLoader {
* Returns a promise that resolves to the merged config
*/
load(configParam = {}) {
const url = window.location.href;
// no need for config if running embedded
// since the parent passes the config down to the iframe
if (this.options.shouldIgnoreConfigWhenEmbedded &&
url.includes('lexWebUiEmbed=true')
) {
return Promise.resolve({});
}

return Promise.resolve()
// json file
.then(() => (
Expand All @@ -73,6 +64,10 @@ export class ConfigLoader {
) :
Promise.resolve(configMobileHub)
))
// filter config when running embedded
.then(mergedConfigFromEvent => (
this.filterConfigWhenEmedded(mergedConfigFromEvent)
))
// parameter
.then(config => (ConfigLoader.mergeConfig(config, configParam)));
}
Expand Down Expand Up @@ -196,6 +191,21 @@ export class ConfigLoader {
});
}

/**
* Ignores most fields when running embeded and the
* shouldIgnoreConfigWhenEmbedded is set to true
*/
filterConfigWhenEmedded(config) {
const url = window.location.href;
// when shouldIgnoreConfigEmbedded is true
// ignore most of the config with the exception of the parentOrigin
const parentOrigin = config.ui && config.ui.parentOrigin;
return (this.options &&
this.options.shouldIgnoreConfigWhenEmbedded &&
url.includes('lexWebUiEmbed=true')) ?
{ ui: { parentOrigin } } : config;
}

/**
* Merges config objects. The initial set of keys to merge are driven by
* the baseConfig. The srcConfig values override the baseConfig ones
Expand Down

0 comments on commit 245ac70

Please sign in to comment.