-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanding.js
More file actions
132 lines (110 loc) · 5.51 KB
/
Copy pathlanding.js
File metadata and controls
132 lines (110 loc) · 5.51 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
121
122
123
124
125
126
127
128
129
130
131
132
document.addEventListener('DOMContentLoaded', () => {
// 1. Try Live Demo Button
const tryLiveBtn = document.getElementById('try-live-btn');
if (tryLiveBtn) {
tryLiveBtn.addEventListener('click', () => {
const widgetContainer = document.getElementById('accesswidget-container');
if (widgetContainer && widgetContainer.shadowRoot) {
const trigger = widgetContainer.shadowRoot.querySelector('.aw-trigger');
if (trigger) {
trigger.click();
trigger.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}
});
}
// 2. Embed Code Generator
const posSelect = document.getElementById('pos-select');
const colorPicker = document.getElementById('color-picker');
const colorHex = document.getElementById('color-hex');
const codeSnippet = document.getElementById('code-snippet');
const resetBtn = document.getElementById('reset-config-btn');
const copyBtn = document.getElementById('copy-btn');
const demoScript = document.getElementById('demo-script'); // The actual live widget tag on the page
const defaultPos = 'bottom-right';
const defaultColor = '#4f46e5';
const baseUrl = 'https://accessibility.dippan.com.np/accessibility.js';
function updateSnippet() {
const pos = posSelect.value;
const color = colorPicker.value;
colorHex.textContent = color;
let snippetHtml = `<span class="token-punct"><</span><span class="token-tag">script</span> <span class="token-attr">src</span><span class="token-punct">=</span><span class="token-string">"${baseUrl}"</span>`;
// Only append attributes if they differ from defaults to keep it clean
if (pos !== defaultPos) {
snippetHtml += ` <span class="token-attr">data-position</span><span class="token-punct">=</span><span class="token-string">"${pos}"</span>`;
}
if (color !== defaultColor) {
snippetHtml += ` <span class="token-attr">data-color</span><span class="token-punct">=</span><span class="token-string">"${color}"</span>`;
}
snippetHtml += ` <span class="token-attr">defer</span><span class="token-punct">></</span><span class="token-tag">script</span><span class="token-punct">></span>`;
codeSnippet.innerHTML = snippetHtml;
// Also update the live widget if possible (requires removing and re-adding, or just updating CSS vars for color, but position is harder)
updateLiveDemo(pos, color);
}
function updateLiveDemo(pos, color) {
const widgetContainer = document.getElementById('accesswidget-container');
if (widgetContainer && widgetContainer.shadowRoot) {
// Update color
widgetContainer.shadowRoot.host.style.setProperty('--primary', color);
// Update position
widgetContainer.style.top = '';
widgetContainer.style.bottom = '';
widgetContainer.style.left = '';
widgetContainer.style.right = '';
if (pos.includes('bottom')) widgetContainer.style.bottom = '20px';
else widgetContainer.style.top = '20px';
if (pos.includes('right')) widgetContainer.style.right = '20px';
else widgetContainer.style.left = '20px';
// Update flex direction
widgetContainer.shadowRoot.host.style.flexDirection = pos.includes('bottom') ? 'column-reverse' : 'column';
widgetContainer.shadowRoot.host.style.alignItems = pos.includes('right') ? 'flex-end' : 'flex-start';
}
}
posSelect.addEventListener('change', updateSnippet);
colorPicker.addEventListener('input', updateSnippet);
resetBtn.addEventListener('click', () => {
posSelect.value = defaultPos;
colorPicker.value = defaultColor;
updateSnippet();
});
copyBtn.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(codeSnippet.textContent);
const originalHTML = copyBtn.innerHTML;
copyBtn.innerHTML = '<span style="color:#10b981;font-size:0.85rem;font-weight:500;">Copied!</span>';
copyBtn.classList.add('copied');
setTimeout(() => {
copyBtn.innerHTML = originalHTML;
copyBtn.classList.remove('copied');
}, 2000);
} catch (err) {
console.error('Failed to copy text: ', err);
}
});
// 3. Scroll Animations (Intersection Observer)
const observerOptions = {
root: null,
rootMargin: '0px',
threshold: 0.15
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
// Optional: stop observing once it's visible if we only want it to animate once
// observer.unobserve(entry.target);
}
});
}, observerOptions);
const animatedElements = document.querySelectorAll('.fade-in');
animatedElements.forEach(el => observer.observe(el));
// 4. Sticky Navbar Styling
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
});