AEM CQ 56 - Get Sidekick instance and disable components panel

Goal


In your javascript code of a component, get the sidekick (CQ.wcm.Sidekick) instance and disable components panel

Often situations arise where you need to play with the sidekick of AEM (CQ5) instance and do some customization. This is not Adobe recommended or suggested approach. It's just a way to get the sidekick and do operations on sidekick components.

Tested on 


Adobe Experience Manager ( AEM 561 )

Solution - 1


1) Login to CRXDE Lite (http://localhost:4502/crx/de) and create folder /apps/sk-comp-panel-disabled

2) Create node /apps/sk-comp-panel-disabled/clientlib of type cq:ClientLibraryFolder and add a String property categories with value cq.widgets

3) Create file (nt:file) /apps/sk-comp-panel-disabled/clientlib/js.txt and add

                       disabled.js

4) Create file (nt:file) /apps/sk-comp-panel-disabled/clientlib/disabled.js and add the following code

(function(){
    if( ( window.location.pathname == "/cf" ) || ( window.location.pathname.indexOf("/content") == 0)){
        CQ.WCM.on("sidekickready", function(sk){
            sk.on("loadcontent", function(){
                var compTab = sk.panels["COMPONENTS"];

                if (compTab) {
                    compTab.setDisabled(true);
                }
            });
        });
    }
})();

Solution - 2


In your component jsp add the following script

<script type="text/javascript">
    window.MyComponent = window.MyComponent || {};

    MyComponent.HideComponentsPanel = {
        IN_ID : '',

        disableFn: function(){
            try{
                var sk = CQ.WCM.getSidekick();

                if(!sk){
                    return;
                }

                var compTab = sk.panels["COMPONENTS"];

                if (compTab) {
                    compTab.setDisabled(true);
                    clearInterval(MyComponent.HideComponentsPanel.IN_ID);
                }
            }catch(err){
                console.log("Error:--" + err);
            }
        }
    }

    CQ.Ext.onReady(function(){
        var h = MyComponent.HideComponentsPanel;
        h.IN_ID = setInterval(h.disableFn, 500);
    });
</script>


8 comments: