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

    var embedded_styles_active = $('body.off-canvas').hasClass('embedded');

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

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

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

: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
  );

Fix embedded shops failing javascript because jQuery is try to be accessed before being loaded Show we check for $.ready when jQuery is not downloaded yet in the browser. The solution is to check if document is ready with plain DOM javascript event `DOMContentLoaded`
Fix embedded shops failing javascript because jQuery is try to be
accessed before being loaded
Show we check for $.ready when jQuery is not downloaded yet in the
browser. The solution is to check if document is ready with plain DOM
javascript event `DOMContentLoaded`
