menu_book Documentation expand_more

using javascript

Sometimes custom Javascript can clash with the Sitecake editor in edit mode. The solution is to detect edit mode and exclude the conflicting script.

Summary

Use the sitecakeGlobals.editMode boolean to detect when the Sitecake editor is active. Turn off your custom script when it is.

Example

Put this script in the <head> of your page:

<script type="text/javascript">
  // Only run your script when NOT in edit mode
  if ( !window.sitecakeGlobals || sitecakeGlobals.editMode !== true ) {
    var s = document.createElement('script');
    s.src = 'js/yourscript.js';
    document.head.appendChild(s);
  }
</script>

No jQuery required — sitecakeGlobals is a plain JavaScript object Sitecake injects into every page while you’re editing.