AEM : Access to global values from dialog-clientlib

Avatar

Avatar

infinityskyline

Avatar

infinityskyline

infinityskyline

08-01-2021

Currently, I am storing certain value as in data-attributes in customheaderlibs.html

<div data-sly-use.myjava="MyJava"
     data-score="${myjava.getScore}"
     data-team="${myjava.getTeam}"></div>

and were reading these values by

const iframeContents = document.querySelector('iframe').contentWindow.document.body;
        const configElement = iframeContents.querySelector('div[data-score]');

 

This works fine for certain resolution of a screen. But in smaller viewport such as in iPad where cq dialog opens as a full screen and not as a dialog box, customheaderlibs.html seems to be absent from the DOM. Hence, these data cannot be accessed from javascript on dialog-ready. Is there any way these data can be accessed, may be if passed as query parameter to the granite dialog path? But not sure how to achieve this. 

View Entire Topic

Avatar

Avatar

BrianKasingli

MVP

Avatar

BrianKasingli

MVP

BrianKasingli
MVP

08-01-2021

@infinityskyline, maybe you can create a servlet that would be called by your cq.authoring.editor.hook client library. Right, and reviewing your custom JavaScript code, when writing custom logic for cq.authoring.editor.hook, and you should tick to ES5 syntax, as ES6 syntax is not yet supported by browsers like IE11. 

 

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="cq:ClientLibraryFolder"
    allowProxy="{Boolean}true"
    categories="[cq.authoring.editor.hook]"
    dependencies="[cq.authoring.editor.core]"/>

 

 // the client library js file

 

$.get( "/bin/mycustomservlet", function( response ) {
    // do something with the response
});