Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

hidden a div in preview mode

Avatar

Level 4

Hi,

i need to hidden a div when the user clicks on the lens (preview mode).

I can't use the WCMMode.EDIT variable why the page isn't refreshed.

It seems also that doesn't exist a particular class to add to the div.

How can i do?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

As @lokesh suggested add below code in your init.jsp

CQ.WCM.launchSidekick("<%= currentPage.getPath() %>", { propsDialog: "<%= dlgPath == null ? "" : dlgPath %>", locked: <%= currentPage.isLocked() %>, adminUrl: "/siteadmin", previewReload: "true" });

In Sightly:

<div data-sly-test="${wcmmode.edit}">Show this only in edit mode to the author</div>

In  JSTL- JSP

<% request.setAttribute("currentMode", WCMMode.fromRequest(request)); request.setAttribute("editMode", WCMMode.EDIT); %> <c:if test="${currentMode ne editMode}"> <c:set var ="style" value = "style=\"display:none\"" /> </c:if> <div ${style}> Here is you DIV </div>

View solution in original post

4 Replies

Avatar

Level 10

Refer [1] to reload the page when you switch the modes. After this change, as the page reloads, you can try adding your logic on preview mode.

[1] https://helpx.adobe.com/experience-manager/kb/ReloadOnWCMModeSwitch.html

Avatar

Correct answer by
Level 10

As @lokesh suggested add below code in your init.jsp

CQ.WCM.launchSidekick("<%= currentPage.getPath() %>", { propsDialog: "<%= dlgPath == null ? "" : dlgPath %>", locked: <%= currentPage.isLocked() %>, adminUrl: "/siteadmin", previewReload: "true" });

In Sightly:

<div data-sly-test="${wcmmode.edit}">Show this only in edit mode to the author</div>

In  JSTL- JSP

<% request.setAttribute("currentMode", WCMMode.fromRequest(request)); request.setAttribute("editMode", WCMMode.EDIT); %> <c:if test="${currentMode ne editMode}"> <c:set var ="style" value = "style=\"display:none\"" /> </c:if> <div ${style}> Here is you DIV </div>

Avatar

Level 4

Thanks, i have seen this document but i can't modify the libs.

I'm trying to solve this problem with js and the click function.

 

$(document).on ("click", ".cq-sidekick-preview", function (e) { e.stopImmediatePropagation(); alert("click1"); }); $(document).on ("click", ".x-tool-toggle", function (e) { e.stopImmediatePropagation(); alert("click2"); });

The first function works correctly and show the alert when the user click on the lens.

The second function doesn't work why the event is blocked from another function of cq5.

I'm trying to add a container to the  x-tool-toggle and add a function on it.

 

$(document).ready(function() {         alert("id"+$( ".x-tool-toggle" ).attr('id')); $( ".x-tool-toggle" ).wrap( "<div class='clickContainer'></div>" ); });

 

The id isn't defined so i'm trying the use the function load of jquery but:

 

$(document).load(function() { alert("function called"); });

I can't see the alert, why?

Avatar

Level 4

The document load doesn't work but works the window load.

The alert of the window load has an id undefined. How can i wait the loading of the popup?