-
-
Save Phoen1x84/5c57cebdd7327202b50fb043971dd9de to your computer and use it in GitHub Desktop.
Sitecore Detect Page Editor JavaScript
This file contains 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
// 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