:javascript
  var isInIframe = function(){
    try {
      return window.self !== window.top;
    } catch (e) {
      return true;
    }
  };

  document.addEventListener(
    'DOMContentLoaded',
    function() {
      var inIframe = isInIframe();
      var embedded_styles_active = $('body.off-canvas').hasClass('embedded');

      var set_shopfront_styles = function (state) {
        $.ajax({
          url: '/embedded_shopfront/' + state,
          type: 'POST'
        });
      };

      if (inIframe && !embedded_styles_active){
        $('body.off-canvas').addClass('embedded');
        set_shopfront_styles('enable');
      }

      if (!inIframe && embedded_styles_active) {
        $('body.off-canvas').removeClass('embedded');
        set_shopfront_styles('disable');
      }
    },
    false
  );
