Skip to content

Instantly share code, notes, and snippets.

@Phoen1x84
Created November 28, 2016 22:53
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 Phoen1x84/5c57cebdd7327202b50fb043971dd9de to your computer and use it in GitHub Desktop.
Save Phoen1x84/5c57cebdd7327202b50fb043971dd9de to your computer and use it in GitHub Desktop.
Sitecore Detect Page Editor JavaScript
 // noConflict mode
jQuery.noConflict();
var app = app || {};
var pageEditorMode = function() {
// Sitecore global name space in page editor or preview mode
return !!(Sitecore && Sitecore.PageModes && Sitecore.PageModes.PageEditor);
};
app = (function($, undefined) {
// do all the things
var init = function() {
if (pageEditorMode()) {
// add class to body to help override styles for experience editor mode
document.body.classList.add('page-editor');
console.log('Experience editor (or page editor if your old school)');
} else {
// js will run here when in page preview mode or normal viewing
console.log('no page editor');
}
};
return {
init: init
};
})(jQuery);
jQuery(document).ready(function() {
app.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment