Skip to content

Commit

Permalink
Review autoInit and destroy on rtl CSS resource change
Browse files Browse the repository at this point in the history
  • Loading branch information
papegaill committed Apr 13, 2022
1 parent 71fbd72 commit 086d6df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/playground/ec/.storybook/manager-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@
);
}
}

// Re-initialize component in the preview frame when changing #ecl-rtl CSS resource checkbox.
window.onload = function (event) {
var inputRtlCss = document.getElementById('ecl-rtl');
inputRtlCss.addEventListener('change', function (event) {
setTimeout(() => {
const iframePreview = document.getElementById(
'storybook-preview-iframe'
).contentWindow;
if (iframePreview) {
iframePreview.ECL.autoInit().destroy();
iframePreview.ECL.autoInit();
}
}, 100);
});
};
</script>
<script
src="https://ec.europa.eu/wel/cookie-consent/consent.js"
Expand Down
2 changes: 1 addition & 1 deletion src/playground/ec/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ addParameters({
},
{
id: 'ecl-rtl',
code: `<link rel="stylesheet" type="text/css" href="./styles/optional/ecl-rtl.css" onload="ECL.autoInit().destroy(); ECL.autoInit();" />`,
code: `<link rel="stylesheet" type="text/css" href="./styles/optional/ecl-rtl.css" />`,
picked: false,
hideCode: true,
},
Expand Down
2 changes: 1 addition & 1 deletion src/playground/eu/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ addParameters({
},
{
id: 'ecl-rtl',
code: `<link rel="stylesheet" type="text/css" href="./styles/optional/ecl-rtl.css" onload="ECL.autoInit().destroy(); ECL.autoInit();" />`,
code: `<link rel="stylesheet" type="text/css" href="./styles/optional/ecl-rtl.css" />`,
picked: false,
hideCode: true,
},
Expand Down

0 comments on commit 086d6df

Please sign in to comment.