Skip to content

Instantly share code, notes, and snippets.

@duracell80
Created September 28, 2021 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duracell80/f1d4b31712cd56bf24bc8d36cf7da74b to your computer and use it in GitHub Desktop.
Save duracell80/f1d4b31712cd56bf24bc8d36cf7da74b to your computer and use it in GitHub Desktop.
Liferay Content Page Edit Mode Detection
<script>
$( document ).ready(function() {
/* DON'T DO THIS IN EDIT MODE */
if (!$('body').hasClass('has-edit-mode-menu')) {
console.log("You're in Page View Mode");
} else {
console.log("You're in Edit Mode");
alert("You're in Edit Mode");
}
});
</script>
<style>
.fragment_${fragmentEntryLinkNamespace} .editmode {
display : none;
}
/* When has-edit-mode-menu is present in body tag, show the content */
body.has-edit-mode-menu .fragment_${fragmentEntryLinkNamespace} .editmode {
display : block !important;
}
.fragment_${fragmentEntryLinkNamespace} {
padding : 2rem;
border : 1px solid #ff0000;
}
</style>
<div class="fragment_2601 fragment_${fragmentEntryLinkNamespace}">
<p class="editmode">This will only show in edit mode</p>
<p>This will be visible all the time</p>
<button class="editmode">This will only show in edit mode</button>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment