Sha256: 8e217c9deb175b8fbeeff30e6a78dd91def2754e13c86e639970b6531dde061d

Contents?: true

Size: 1.09 KB

Versions: 13

Compression:

Stored size: 1.09 KB

Contents

//= require ./app_bridge_redirect.js

(function () {
  function redirect() {
    var redirectTargetElement = document.getElementById("redirection-target");

    if (!redirectTargetElement) {
      return;
    }

    var targetInfo = JSON.parse(redirectTargetElement.dataset.target);

    if (window.top == window.self) {
      // If the current window is the 'parent', change the URL by setting location.href
      window.top.location.href = targetInfo.url;
    } else {
      // If the current window is the 'child' or embedded, change the parent's URL with
      // App Bridge redirect. This case can happen when an app updates its access scopes,
      // or the unlikely scenario where the shop thinks the app is installed, but the
      // app does not have an record for the shop.
      window.appBridgeRedirect(targetInfo.url);
    }
  }

  document.addEventListener("DOMContentLoaded", redirect);

  // In the turbolinks context, neither DOMContentLoaded nor turbolinks:load
  // consistently fires. This ensures that we at least attempt to fire in the
  // turbolinks situation as well.
  redirect();
})();

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
ruby_shopify_app-1.3.0 app/assets/javascripts/shopify_app/redirect.js
ruby_shopify_app-1.2.0 app/assets/javascripts/shopify_app/redirect.js
ruby_shopify_app-1.1.0 app/assets/javascripts/shopify_app/redirect.js
ruby_shopify_app-1.0.0 app/assets/javascripts/shopify_app/redirect.js
shopify_app-19.1.0 app/assets/javascripts/shopify_app/redirect.js
shopify_app-18.1.3 app/assets/javascripts/shopify_app/redirect.js
shopify_app-19.0.2 app/assets/javascripts/shopify_app/redirect.js
shopify_app-19.0.1 app/assets/javascripts/shopify_app/redirect.js
shopify_app-19.0.0 app/assets/javascripts/shopify_app/redirect.js
shopify_app-18.1.2 app/assets/javascripts/shopify_app/redirect.js
shopify_app-18.1.1 app/assets/javascripts/shopify_app/redirect.js
shopify_app-18.1.0 app/assets/javascripts/shopify_app/redirect.js
shopify_app-18.0.4 app/assets/javascripts/shopify_app/redirect.js