Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
188 lines (162 loc) · 6.5 KB
/
Copy pathscript.js
File metadata and controls
188 lines (162 loc) · 6.5 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Text-based portfolio website JavaScript
document.addEventListener('DOMContentLoaded', function() {
// Smooth scrolling for navigation links
const navLinks = document.querySelectorAll('a[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
const headerHeight = document.querySelector('.header-main').offsetHeight;
const targetPosition = targetSection.offsetTop - headerHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Case filtering functionality for table rows
const filterButtons = document.querySelectorAll('.filter-btn');
const caseItems = document.querySelectorAll('.case-item');
filterButtons.forEach(button => {
button.addEventListener('click', function() {
// Remove active class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
this.classList.add('active');
const filterValue = this.getAttribute('data-filter');
caseItems.forEach(item => {
if (filterValue === 'all') {
item.style.display = 'table-row';
item.classList.remove('hidden');
} else {
const itemCategory = item.getAttribute('data-category');
if (itemCategory === filterValue) {
item.style.display = 'table-row';
item.classList.remove('hidden');
} else {
item.style.display = 'none';
item.classList.add('hidden');
}
}
});
});
});
// Mobile menu functionality
const mobileMenuToggle = document.getElementById('mobileMenuToggle');
const mobileMenu = document.getElementById('mobileMenu');
const mobileMenuClose = document.getElementById('mobileMenuClose');
const mobileNavLinks = document.querySelectorAll('.mobile-nav-link');
// Toggle mobile menu
if (mobileMenuToggle) {
mobileMenuToggle.addEventListener('click', function() {
mobileMenu.classList.add('active');
document.body.style.overflow = 'hidden';
});
}
// Close mobile menu
if (mobileMenuClose) {
mobileMenuClose.addEventListener('click', function() {
mobileMenu.classList.remove('active');
document.body.style.overflow = '';
});
}
// Close mobile menu when clicking on a link
mobileNavLinks.forEach(link => {
link.addEventListener('click', function() {
mobileMenu.classList.remove('active');
document.body.style.overflow = '';
});
});
// Close mobile menu when clicking outside
if (mobileMenu) {
mobileMenu.addEventListener('click', function(e) {
if (e.target === mobileMenu) {
mobileMenu.classList.remove('active');
document.body.style.overflow = '';
}
});
}
// Phone copy functionality
const phoneCopyElements = document.querySelectorAll('.phone-copy');
phoneCopyElements.forEach(element => {
element.addEventListener('click', function() {
const phoneNumber = this.getAttribute('data-phone');
// Try to copy to clipboard
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(phoneNumber).then(() => {
showCopyMessage(this);
}).catch(() => {
fallbackCopyTextToClipboard(phoneNumber, this);
});
} else {
fallbackCopyTextToClipboard(phoneNumber, this);
}
});
});
function fallbackCopyTextToClipboard(text, element) {
const textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed";
textArea.style.top = "0";
textArea.style.left = "0";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
showCopyMessage(element);
} catch (err) {
console.error('Could not copy text', err);
}
document.body.removeChild(textArea);
}
function showCopyMessage(element) {
element.classList.add('copied');
setTimeout(() => {
element.classList.remove('copied');
}, 2000);
}
// Simple table row hover effects
const tableRows = document.querySelectorAll('tbody tr');
tableRows.forEach(row => {
row.addEventListener('mouseenter', function() {
this.style.backgroundColor = '#f0f0f0';
});
row.addEventListener('mouseleave', function() {
this.style.backgroundColor = '';
});
});
// Button click effects
const buttons = document.querySelectorAll('.btn');
buttons.forEach(button => {
button.addEventListener('click', function(e) {
// Simple scale effect
this.style.transform = 'scale(0.95)';
setTimeout(() => {
this.style.transform = 'scale(1)';
}, 150);
});
});
// Header style changes on scroll
const header = document.querySelector('.header-main');
if (header) {
window.addEventListener('scroll', function() {
if (window.scrollY > 50) {
header.style.borderBottomWidth = '3px';
} else {
header.style.borderBottomWidth = '2px';
}
});
}
// Print functionality helper
window.addEventListener('beforeprint', function() {
// Show all case items when printing
caseItems.forEach(item => {
item.style.display = 'table-row';
});
});
console.log('Text-based design loaded successfully');
});