Files
fluxscape/packages/noodl-viewer-react/src/api/navigation.js
Michael Cartner b9c60b07dc Initial commit
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com>
Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com>
Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com>
Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com>
Co-Authored-By: Johan  <4934465+joolsus@users.noreply.github.com>
Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com>
Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
2024-01-26 11:52:55 +01:00

49 lines
1.4 KiB
JavaScript

const { RouterHandler } = require('../nodes/navigation/router-handler');
const NoodlRuntime = require('@noodl/runtime');
const navigation = {
async showPopup(componentPath, params) {
return new Promise((resolve) => {
navigation._noodlRuntime.context.showPopup(componentPath, params, {
onClosePopup: (action, results) => {
resolve({
action: action.replace('closeAction-', ''),
parameters: results
});
}
});
});
},
navigate(routerName, targetPageName, params) {
RouterHandler.instance.navigate(routerName, {
target: targetPageName,
params: params
});
},
navigateToPath(path, options) {
let hashPath, urlPath;
var navigationPathType = NoodlRuntime.instance.getProjectSettings()['navigationPathType'];
if (navigationPathType === undefined || navigationPathType === 'hash') hashPath = path;
else urlPath = path;
var query = [];
if (options && options.query !== undefined) {
for (let key in options.query) {
query.push(key + '=' + options.query[key]);
}
}
var compiledUrl =
(urlPath !== undefined ? urlPath : '') +
(query.length >= 1 ? '?' + query.join('&') : '') +
(hashPath !== undefined ? '#' + hashPath : '');
window.history.pushState({}, '', compiledUrl);
dispatchEvent(new PopStateEvent('popstate', {}));
}
};
module.exports = navigation;