-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #617 from Shopify/top-level-partitioning-for-safar…
…i-12 Top level partitioning for safari 12
- Loading branch information
Showing
11 changed files
with
642 additions
and
44 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(function() { | ||
function setCookieAndRedirect() { | ||
document.cookie = "shopify.cookies_persist=true"; | ||
window.location.href = window.shopOrigin + "/admin/apps/" + window.apiKey; | ||
} | ||
|
||
function shouldDisplayPrompt() { | ||
if (navigator.userAgent.indexOf('com.jadedpixel.pos') !== -1) { | ||
return false; | ||
} | ||
|
||
if (navigator.userAgent.indexOf('Shopify Mobile/iOS') !== -1) { | ||
return false; | ||
} | ||
|
||
return Boolean(document.hasStorageAccess); | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", function() { | ||
if (shouldDisplayPrompt()) { | ||
var itpContent = document.querySelector('#CookiePartitionPrompt'); | ||
itpContent.style.display = 'block'; | ||
|
||
var button = document.querySelector('#AcceptCookies'); | ||
button.addEventListener('click', setCookieAndRedirect); | ||
} else { | ||
setCookieAndRedirect(); | ||
} | ||
}); | ||
})(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
document.addEventListener("DOMContentLoaded", function() { | ||
var redirectTargetElement = document.getElementById("redirection-target"); | ||
var targetInfo = JSON.parse(redirectTargetElement.dataset.target) | ||
(function() { | ||
function redirect() { | ||
var redirectTargetElement = document.getElementById("redirection-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', change the parent's URL with postMessage | ||
normalizedLink = document.createElement('a'); | ||
normalizedLink.href = targetInfo.url; | ||
if (!redirectTargetElement) { | ||
return; | ||
} | ||
|
||
data = JSON.stringify({ | ||
message: 'Shopify.API.remoteRedirect', | ||
data: { location: normalizedLink.href } | ||
}); | ||
window.parent.postMessage(data, targetInfo.myshopifyUrl); | ||
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', change the parent's URL with postMessage | ||
normalizedLink = document.createElement('a'); | ||
normalizedLink.href = targetInfo.url; | ||
|
||
data = JSON.stringify({ | ||
message: 'Shopify.API.remoteRedirect', | ||
data: {location: normalizedLink.href} | ||
}); | ||
window.parent.postMessage(data, targetInfo.myshopifyUrl); | ||
} | ||
} | ||
}); | ||
|
||
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(); | ||
})(); |
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
Oops, something went wrong.