-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline_script_2.js
More file actions
239 lines (104 loc) · 4.65 KB
/
inline_script_2.js
File metadata and controls
239 lines (104 loc) · 4.65 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
document.addEventListener('DOMContentLoaded', function() {
const mainIcon = document.getElementById('mainIcon');
const verticalIcons = document.getElementById('verticalIcons');
let hoverTimeout;
let currentPopup = null;
// Icon Hover Handling
function showIcons() {
clearTimeout(hoverTimeout);
verticalIcons.style.display = 'flex';
mainIcon.innerHTML = '<i class="fas fa-times"></i>';
}
function hideIcons() {
hoverTimeout = setTimeout(() => {
verticalIcons.style.display = 'none';
mainIcon.innerHTML = '<i class="fas fa-plus"></i>';
}, 300);
}
mainIcon.addEventListener('mouseenter', showIcons);
mainIcon.addEventListener('mouseleave', hideIcons);
verticalIcons.addEventListener('mouseenter', showIcons);
verticalIcons.addEventListener('mouseleave', hideIcons);
// Function to open popup
function openPopup(popupId, updateHash = true) {
if(currentPopup) currentPopup.style.display = 'none';
currentPopup = document.getElementById(popupId);
currentPopup.style.display = 'flex';
// Update URL hash without scrolling
if (updateHash) {
try {
const newUrl = window.location.href.split('#')[0] + '#' + popupId;
window.history.replaceState(null, null, newUrl);
} catch (e) {
console.log("Hash update failed:", e);
}
}
if(popupId === 'cart-popup' && !document.querySelector('#rzpScript')) {
const script = document.createElement('script');
script.id = 'rzpScript';
script.src = 'https://checkout.razorpay.com/v1/payment-button.js';
script.dataset.payment_button_id = 'pl_PsXVCue2RE0NI5';
script.async = true;
document.getElementById('rzpForm').appendChild(script);
}
}
// Function to close popup
function closePopup() {
if(currentPopup) {
currentPopup.style.display = 'none';
currentPopup = null;
// Remove hash from URL without scrolling
try {
const newUrl = window.location.href.split('#')[0];
window.history.replaceState(null, null, newUrl);
} catch (e) {
console.log("Hash removal failed:", e);
}
}
}
// Popup Handling with hash support
document.querySelectorAll('.icon-item').forEach(icon => {
icon.addEventListener('click', function() {
const popupId = this.dataset.popup;
openPopup(popupId, true);
});
});
// Close Handling
document.querySelectorAll('.close-btn').forEach(btn => {
btn.addEventListener('click', closePopup);
});
// Close on Outside Click
window.addEventListener('click', (e) => {
if(e.target.classList.contains('popup')) {
closePopup();
}
});
// Notes Placeholder Handling
const editable = document.querySelector('.content-editable');
if (editable) {
editable.addEventListener('focus', function() {
if(this.textContent === 'Start typing here...') this.textContent = '';
});
editable.addEventListener('blur', function() {
if(!this.textContent.trim()) this.textContent = 'Start typing here...';
});
}
// Handle URL hash on page load for popups
function handlePopupHash() {
const hash = window.location.hash.substring(1);
if (hash) {
const popupExists = document.getElementById(hash);
if (popupExists && popupExists.classList.contains('popup')) {
// Open the popup but don't update hash again
openPopup(hash, false);
}
}
}
// Listen for hash changes
window.addEventListener('hashchange', handlePopupHash);
// Initial popup setup based on URL hash
handlePopupHash();
});
function openModal() {
alert('Terms & Conditions content here');
}