[JSFIELD-4] Make the module agnostic to magnolia's contextPath Created: 17/Jan/22 Updated: 28/Jan/22 Resolved: 28/Jan/22 |
|
| Status: | Closed |
| Project: | Java Script UI (App and Dialog Fields) |
| Component/s: | None |
| Affects Version/s: | 1.1.6 |
| Fix Version/s: | 1.1.7 |
| Type: | Improvement | Priority: | Neutral |
| Reporter: | Markus Schwarz | Assignee: | Adrien Manzoni |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Template: |
|
| Acceptance criteria: |
Empty
|
| Description |
|
Currently the JavaScript Dialog Fields module doesn't load the fieldScript
form:
implementationClass: info.magnolia.ui.javascript.form.FormViewWithChangeListener
properties:
imagesForUpload:
$type: javascriptField
fieldScript: /multi-assets-upload/webresources/upload.html
supplied in the yaml, when magnolia runs on a contextPath different to '/' (e.g. '/magnoliaAuthor'). Users may also encounter problems referencing their own css/js files (hosted in the modules webresources directory) as there is currently no way to inject the contextPath into the fieldScript. Both issues are now resolved by using info.magnolia.init.MagnoliaInitPaths. If users want to resolve the contextPath to load their JS/CSS, the following JavaScript could be used in the fieldScript.
let contextPath;
function loadStyle(href){
const link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = href;
document.head.appendChild(link);
}
function loadScript(href){
const script = document.createElement("script");
script.type = "text/javascript";
script.src = href;
document.head.appendChild(script);
}
window.addEventListener(
'message',
function (event) {
if (event.data.action === 'contextPath') {
contextPath = event.data.contextPath
loadStyle(contextPath + "/.resources/multi-assets-upload/webresources/css/dropzone_5.min.css");
loadStyle(contextPath + "/VAADIN/themes/resurface-admincentral/styles.css?v=8.13.1");
loadScript(contextPath + "/.resources/multi-assets-upload/webresources/js/dropzone_5.9.3.min.js");
}
},
false
);
|