3
votes

Under certain circumstances, I want to prevent the Sidekick from being displayed on a page. I tried some things:

  • Removing the init.jsp include. This works, but it also prevents certain CQ javascript libraries from being loaded, and I need these libraries.
  • Adding a jquery onload event to hide the sidekick.

    $(function() {CQ.WCM.getSidekick().hide()});
    

    This doesnt work because the sidekick isnt loaded yet.

  • Adding a jquery onload event with a timeout.

    $(function() {
      setTimeout(function() {
        CQ.WCM.getSidekick().hide(); 
      }, 1)
    });
    

    But this is not reliable. Setting the timeout too low will have a high chance of failure. Setting it too high will cause it to appear then disappear, which is unacceptable.

Please help!

1

1 Answers

3
votes

There are various ways to achieve this.

If you want the sidekick to be unavailable in all the pages, just comment out the following piece of code available in the init.jsp

CQ.WCM.launchSidekick("<%= xssAPI.getValidHref(currentPage.getPath()) %>", {
    propsDialog: "<%= dlgPath == null ? "" : xssAPI.getValidHref(dlgPath) %>",
    locked: <%= currentPage.isLocked() %>
});

In case, you want the sidekick to be unavailable only under specific conditions, you can listen to the sidekickready event fired by the CQ.WCM class as shown below, and then hide the sidekick.

CQ.Ext.onReady(function(){
    var top = CQ.WCM.getTopWindow();
    if (top.CQ.WCM.isSidekickReady()) {
        top.CQ.WCM.getSidekick().hide();
    } else {
        top.CQ.WCM.on("sidekickready", function(sidekick) {
            sidekick.hide();
        });
    }
});

EDIT - Explaining the lengthy code

The above script is written to work in any component without issues, not just the init.jsp.

The CQ.Ext.onReady is to execute our code after the DOM is ready. CQ.WCM.getTopWindow() fetches the top most window. In case our script is executed after the sidekick is ready, then the sidekickready event would have been fired already and hence our code might not execute.

Hence we first check if the sidekick is already available using top.CQ.WCM.isSidekickReady() and in case it isn't, we attach a listener to the sidekickready event, so that we are notified when it is ready.

Hope this helps.