mirror of
https://github.com/fluxscape/fluxscape.git
synced 2026-01-13 15:52:55 +01:00
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>
This commit is contained in:
48
packages/noodl-viewer-react/src/api/navigation.js
Normal file
48
packages/noodl-viewer-react/src/api/navigation.js
Normal file
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user