Ways to identify wcm mode in Javascript/Jquery

Avatar

Avatar

nehacms-0r3f0r

Avatar

nehacms-0r3f0r

nehacms-0r3f0r

16-02-2017

Hi,

We want to fetch wcmmode value in our custom Javascript file, based on mode some condition needs to be executed. Can you please let us know ways to fetch those.

We have tried using

if(!CQ || !CQ.WCM || !(CQ.WCM.isEditMode(true) || CQ.WCM.isDesignMode(true))){}

but it says CQ is null, though CQ object was there. Any other way we are looking for.

 

Thanks,

Neha

View Entire Topic

Avatar

Avatar

Gdubz-57m2mu

Avatar

Gdubz-57m2mu

Gdubz-57m2mu

16-02-2017

smacdonald2008 wrote...

See this community article -- https://edivad.wordpress.com/2013/10/23/whats-my-cq-run-mode/

 

If wordpress is blocked by anyone else's corporate proxy (like ours), here's the core of that article:

/* * EditMode.js * * Simple javascript object meant to be used within a CQ development to understand on a Javascript side which my Edit Mode is. * * USAGE: *      1) Drop the file in your clientlib *      2) Reference it in your js.txt * *      You can now use it as it will automatically create an "editmode" object *              (editmode.isEditMode())    ? "I'm Authoring"   : "" *              (editmode.isPreviewMode()) ? "I'm in Preview"  : "" *              (editmode.isDesignMode())  ? "I'm in Design"   : "" *              (editmode.isDisabled())    ? "I'm in Disabled" : "" */ function EditMode(){ this.isEditMode=function(){ return (CQ.WCM)?CQ.WCM.isEditMode(true):false; }; this.isPreviewMode=function(){ return (CQ.WCM)?CQ.WCM.isPreviewMode(true):false; }; this.isDesignMode=function(){ return (CQ.WCM)?CQ.WCM.isDesignMode(true):false; }; this.isDisabled=function(){ return (!CQ.WCM); } }; var editmode = new EditMode();

Source: https://github.com/davidegiannella/cq-misc/blob/master/EditMode.js