Created
September 28, 2021 15:18
-
-
Save duracell80/f1d4b31712cd56bf24bc8d36cf7da74b to your computer and use it in GitHub Desktop.
Liferay Content Page Edit Mode Detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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