Skip to content

Commit

Permalink
Force load of Vlibras in Storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Apr 3, 2024
1 parent 4c44ad3 commit ba0ac62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/volto-vlibras/src/components/Libras.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ const widgetSrc = 'https://vlibras.gov.br/app';
const scriptId = 'VLibras';
const scriptSrc = `https://vlibras.gov.br/app/vlibras-plugin.js`;

const loadVLibras = (callback) => {
const loadVLibras = (callback, force) => {
const existingScript = document.getElementById(scriptId);
if (existingScript && callback) {
callback(true);
if (force) {
window.onload();
}
} else {
if (callback) callback(false);
const script = document.createElement('script');
Expand All @@ -20,6 +23,9 @@ const loadVLibras = (callback) => {
if (callback) callback(true);
if (typeof window !== 'undefined') {
new window.VLibras.Widget(widgetSrc);
if (force) {
window.onload();
}
}
};
}
Expand All @@ -28,12 +34,12 @@ const loadVLibras = (callback) => {
const Libras = (props) => {
const [loaded, setLoaded] = useState(false);
const [status, setStatus] = useState('enabled');
const { location } = props;
const { location, force } = props;
const pathName = location.pathname;

useEffect(() => {
loadVLibras(setLoaded);
}, [loaded]);
loadVLibras(setLoaded, force);
}, [loaded, force]);

useEffect(() => {
// Disable widget on non content routes
Expand Down
1 change: 1 addition & 0 deletions packages/volto-vlibras/src/components/Libras.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {
location: {
pathname: '/',
},
force: true,
},
};

Expand Down

0 comments on commit ba0ac62

Please sign in to comment.