-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.js
50 lines (43 loc) · 1.89 KB
/
general.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Custom context menu
const contextMenuTrigger = document.querySelector(".context-menu-trigger");
const contextMenu = document.querySelector(".context-menu");
contextMenuTrigger.addEventListener("contextmenu", function (e) {
e.preventDefault();
// Show the context menu with a smooth opacity transition
contextMenu.style.visibility = "visible";
contextMenu.classList.add("cc-show");
});
document.body.addEventListener("click", function () {
// Delay the removal of the "cc-show" class
setTimeout(function () {
contextMenu.classList.remove("cc-show"); // Remove the class to hide the menu
// Wait for the opacity transition to finish before hiding the element
setTimeout(function () {
contextMenu.style.visibility = "hidden";
}, 400); // Match the duration of the opacity transition
}, 200); // Delay before removing the class
});
// Function to get a local storage item with expiry check
function getItemWithExpiry(key) {
const dataString = localStorage.getItem(key);
if (!dataString) {
return null; // No item found
}
const data = JSON.parse(dataString);
const currentTime = Date.now();
if (currentTime > data.expiry) {
localStorage.removeItem(key); // Remove expired item
return null; // Expired item
}
return data.value; // Return valid item
}
// Check the flag and toggle visibility of the Webflow migrate CTA
const visited = getItemWithExpiry('visitedWebflowMigrationPage');
if (visited) {
// User has visited the specific page
document.querySelector('#migrateWebflow').style.display = 'block'; // Show Webflow migrate CTA
document.querySelector('#migrateGeneral').style.display = 'none'; // Hide general migrate CTA
} else {
// User has NOT visited or the visit data has expired
document.querySelector('#migrateWebflow').style.display = 'none'; // Hide Webflow migrate CTA
}