In Sightly,
<div data-sly-test.author="${wcmmode.edit || wcmmode.design || wcmmode.preview}">
In Sightly Java code that extends WCMUse ,
getWcmMode().isEdit(), getWcmMode().isDesign() or getWcmMode().isPreview()
But, finding this in Jquery or Javascript is not straight forward. We need to make use of the cookies like
if($.cookie('cq-editor-layer') == "Preview") {
console.log("Preview Mode");
}else if ($.cookie('cq-editor-layer') == "Edit") {
console.log("Edit Mode");
}
or
if($.cookie('wcmmode') == "preview") {
console.log("Preview Mode");
}else if ($.cookie('wcmmode') == "edit") {
console.log("Edit Mode");
}
Also, you can find the AuthoringUIMode is touch or classic with the cookie
if($.cookie('cq-authoring-mode') == "Touch") {
console.log("Touch UI");
}else if($.cookie('cq-authoring-mode') == "Classic") {
console.log("Classic UI");
}
This comment has been removed by the author.
ReplyDeleteWhat if page published? I'm not able check this condition once after page published.
ReplyDeleteI tried using if($.cookie('wcmmode') == "Disabled"), also not working.
Please do suggest.
In Publish environment you don't find the WCMMode cookie and there by it returns false.
ReplyDeleteThere is also a class aem-AuthorLayer-Preview at the html tag which is replaced by aem-AuthorLayer-Edit in edit mode. This can be used to distinguish both modes both in Javascript and CSS.
ReplyDelete