-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
152 lines (129 loc) · 5.43 KB
/
Copy pathscript.js
File metadata and controls
152 lines (129 loc) · 5.43 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
$(document).ready(function() {
// Switch between tabs
$('.tab-link').click(function(e) {
e.preventDefault();
const targetTab = $(this).attr('href');
// Remove current class from all tab links and hide all tab contents
$('.tab-link').removeClass('current');
$('.tab-content').removeClass('active');
// Add current class to the clicked tab link and show the corresponding tab content
$(this).addClass('current');
$(targetTab).addClass('active');
});
// Change color of project links on click
$('.project a').click(function() {
$(this).css('color', '#ffca1e');
});
// Initialize default positions for projects
$('.project').each(function() {
$(this).data('defaultPos', $(this).index() + 1);
});
$.fn.resetProject = function() {
this.removeClass('focus');
this.find('.projectWrapper').removeClass('blur');
this.find('img').removeClass('right');
this.find('div.info').removeClass('blur-bg').removeAttr('style');
this.insertAfter(`div.project:nth-of-type(${this.data('defaultPos')})`);
};
$.fn.focusProject = function(pageX) {
const focusPos = Math.floor((this.data('defaultPos') - 1) / 4) * 4 + 1;
this.addClass('focus');
const img = this.find('img');
const info = this.find('div.info');
if (pageX > $(window).width() / 2) {
img.addClass('right');
info.css('left', '0');
}
info.addClass('blur-bg');
this.insertBefore(`div.project:nth-of-type(${focusPos})`);
};
$.fn.runFocus = function(pageX) {
if (window.matchMedia('(min-aspect-ratio: 2/3)').matches) {
if (this.hasClass('focus')) {
this.resetProject();
} else {
$('.project').each(function() {
$(this).resetProject();
});
this.focusProject(pageX);
}
const midPoint = this.find('img').offset().top - ($(window).height() / 2 - this.find('img').height() / 2);
$('html, body').animate({ scrollTop: midPoint }, 1);
}
};
$(window).resize(function() {
if (window.matchMedia('(max-aspect-ratio: 2/3)').matches) {
$('.project').each(function() {
$(this).resetProject();
});
}
});
$('.project img').on('click', function(e) {
$(this).parent().runFocus(e.pageX);
});
$('#search-input').on('input', function() {
const searchQuery = $(this).val().toLowerCase();
// Filter articles based on the search query and update the display
// (You'll need to implement this part based on your data structure)
});
$('.tag').click(function(e) {
e.preventDefault();
const selectedTag = $(this).text(); // Get the tag text
// Filter articles based on the selected tag and update the display
// (Again, customize this part according to your data)
});
// Handle form submission to Google Sheets
$('#contact-form').on('submit', function(event) {
event.preventDefault(); // Prevent the default form submission
const formData = new FormData(this);
const url = 'https://script.google.com/macros/s/AKfycbykioMhIKq-K3YF0H9p5GKU9z7q9DZkOKyg8mfG9WHGHPIcSghUX7Q9Xs4yxFbR5E7I/exec'; // Replace with your Web App URL
// Convert FormData to URLSearchParams
const urlParams = new URLSearchParams();
formData.forEach((value, key) => {
urlParams.append(key, value);
});
fetch(url, {
method: 'POST',
mode: 'cors', // Ensure CORS mode is set
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: urlParams.toString()
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
if (data.result === 'success') {
$('#response-message').removeClass('hidden');
$('#contact-form').trigger('reset');
} else {
alert('There was a problem with your submission: ' + data.error);
}
})
.catch(error => {
alert('There was an error: ' + error.message);
console.error('Fetch error:', error); // Log error details for debugging
});
});
});
// Function to detect mobile devices
function isMobileDevice() {
return window.matchMedia("(max-width: 767px)").matches;
}
window.addEventListener("orientationchange", function() {
if (isMobileDevice()) {
if (window.orientation === 90 || window.orientation === -90) {
// Landscape on mobile
document.body.style.display = "none";
document.getElementById("rotateMessage").style.display = "block";
} else {
// Portrait on mobile
document.body.style.display = "block";
document.getElementById("rotateMessage").style.display = "none";
}
}
});