-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgallery.js
More file actions
228 lines (196 loc) · 9.83 KB
/
Copy pathgallery.js
File metadata and controls
228 lines (196 loc) · 9.83 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Gallery functionality
document.addEventListener('DOMContentLoaded', function() {
const gallerySection = document.getElementById('gallery-section');
const galleryContainer = document.getElementById('gallery-container');
const galleryBtn = document.getElementById('gallery-btn');
const closeGalleryBtn = document.getElementById('close-gallery-btn');
if (!gallerySection || !galleryContainer || !galleryBtn || !closeGalleryBtn) {
console.error('Required gallery elements not found');
return;
}
// Create category navigation menu
const categoryNav = document.createElement('div');
categoryNav.className = 'category-nav';
const categoryMenu = document.createElement('div');
categoryMenu.className = 'category-menu';
categoryNav.appendChild(categoryMenu);
gallerySection.insertBefore(categoryNav, galleryContainer);
// Initialize back to top button
const backToTopBtn = initializeBackToTopButton(gallerySection);
// Function to handle scroll event
function handleScroll() {
const categoryNav = document.querySelector('.category-nav');
const scrollPosition = gallerySection.scrollTop;
// Show/hide category nav
if (scrollPosition > 300) {
categoryNav.classList.add('hidden');
} else {
categoryNav.classList.remove('hidden');
}
// Update active category
updateActiveCategory();
}
// Add scroll event listener to gallery section
gallerySection.addEventListener('scroll', handleScroll);
// Define the order of categories
const categoryOrder = [
"Short-read centered",
"Long-read focused",
"Dual",
"Hybrid",
"Web-based",
"Special"
];
// Function to map pipeline categories to display categories
function mapCategoryToDisplay(category) {
// Since we're using the exact categories from pipelineObjects.js, no mapping is needed
return category;
}
// Function to create category navigation
function createCategoryNav() {
categoryMenu.innerHTML = ''; // Clear existing content
// Create menu items for each category
categoryOrder.forEach(category => {
const menuItem = document.createElement('a');
menuItem.href = `#${category.toLowerCase().replace(/\s+/g, '-')}`;
menuItem.textContent = category;
menuItem.addEventListener('click', (e) => {
e.preventDefault();
const targetCategory = document.querySelector(`.gallery-category-header[data-category="${category}"]`);
if (targetCategory) {
targetCategory.scrollIntoView({ behavior: 'smooth' });
// Update active state
categoryMenu.querySelectorAll('a').forEach(link => link.classList.remove('active'));
menuItem.classList.add('active');
}
});
categoryMenu.appendChild(menuItem);
});
}
// Function to update active category based on scroll position
function updateActiveCategory() {
const categoryHeaders = document.querySelectorAll('.gallery-category-header');
const scrollPosition = gallerySection.scrollTop;
categoryHeaders.forEach(header => {
const category = header.dataset.category;
const headerTop = header.offsetTop - categoryNav.offsetHeight;
const headerBottom = headerTop + header.offsetHeight;
if (scrollPosition >= headerTop && scrollPosition < headerBottom) {
const menuItem = categoryMenu.querySelector(`a[href="#${category.toLowerCase().replace(/\s+/g, '-')}"]`);
if (menuItem) {
categoryMenu.querySelectorAll('a').forEach(link => link.classList.remove('active'));
menuItem.classList.add('active');
}
}
});
}
// Add scroll event listener for active category
gallerySection.addEventListener('scroll', updateActiveCategory);
// Function to create gallery items
function createGalleryItems() {
const galleryContainer = document.getElementById('gallery-container');
galleryContainer.innerHTML = ''; // Clear existing content
// Group pipelines by category
const pipelinesByCategory = {};
// Sort alphabetically by name first
const sorted = [...preLoadedObjects].sort((a, b) => a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }));
sorted.forEach(pipeline => {
const category = pipeline.category || 'Uncategorized';
if (!pipelinesByCategory[category]) {
pipelinesByCategory[category] = [];
}
pipelinesByCategory[category].push(pipeline);
});
// Create gallery items based on category order
categoryOrder.forEach(category => {
if (pipelinesByCategory[category] && pipelinesByCategory[category].length > 0) {
// Create category header
const categoryHeader = document.createElement('div');
categoryHeader.className = 'gallery-category-header';
categoryHeader.dataset.category = category;
categoryHeader.innerHTML = `<h3>${category}</h3>`;
galleryContainer.appendChild(categoryHeader);
// Create gallery items for this category (already sorted by name)
pipelinesByCategory[category].forEach(pipeline => {
const galleryItem = document.createElement('div');
galleryItem.className = 'gallery-item';
galleryItem.innerHTML = `
<div class="gallery-card" data-pipeline-id="${pipeline.id}" data-pipeline-name="I want to know more about ${pipeline.name}" style="cursor: pointer;">
<img src="assets/${pipeline.id}.png" alt="${pipeline.name}" class="gallery-image" onerror="this.src='images/default-pipeline.png'">
<div class="gallery-content">
<h3>${pipeline.name}</h3>
<p>${pipeline.description}</p>
</div>
</div>
`;
galleryContainer.appendChild(galleryItem);
// Add click event listener to the entire card
const card = galleryItem.querySelector('.gallery-card');
card.addEventListener('click', () => {
showWorkflowForPipeline(pipeline.id);
});
});
}
});
// Handle uncategorized pipelines if any
if (pipelinesByCategory['Uncategorized'] && pipelinesByCategory['Uncategorized'].length > 0) {
const categoryHeader = document.createElement('div');
categoryHeader.className = 'gallery-category-header';
categoryHeader.innerHTML = '<h3>Uncategorized Pipelines</h3>';
galleryContainer.appendChild(categoryHeader);
pipelinesByCategory['Uncategorized'].forEach(pipeline => {
const galleryItem = document.createElement('div');
galleryItem.className = 'gallery-item';
galleryItem.innerHTML = `
<div class="gallery-card" data-pipeline-id="${pipeline.id}" data-pipeline-name="I want to know more about '${pipeline.name}'" style="cursor: pointer;">
<img src="images/${pipeline.id}.png" alt="${pipeline.name}" class="gallery-image" onerror="this.src='images/default-pipeline.png'">
<div class="gallery-content">
<h3>${pipeline.name}</h3>
<p>${pipeline.description}</p>
</div>
</div>
`;
galleryContainer.appendChild(galleryItem);
// Add click event listener to the entire card
const card = galleryItem.querySelector('.gallery-card');
card.addEventListener('click', () => {
showWorkflowForPipeline(pipeline.id);
});
});
}
}
// Function to show workflow for a specific pipeline
function showWorkflowForPipeline(pipelineId) {
// Hide gallery
hideGallery();
// Show workflow section
const workflowSection = document.getElementById('workflow-section');
workflowSection.style.display = 'block';
// Select the pipeline in the dropdown
const pipelineSelect = document.getElementById('pipeline-select');
pipelineSelect.value = pipelineId;
// Trigger the change event to display the workflow
const event = new Event('change');
pipelineSelect.dispatchEvent(event);
}
// Function to show gallery
function showGallery() {
gallerySection.style.display = 'block';
document.body.style.overflow = 'hidden'; // Prevent scrolling when gallery is open
createGalleryItems(); // Refresh gallery items when showing
}
// Function to hide gallery
function hideGallery() {
gallerySection.style.display = 'none';
document.body.style.overflow = 'auto'; // Re-enable scrolling
}
// Event listeners
galleryBtn.addEventListener('click', showGallery);
closeGalleryBtn.addEventListener('click', hideGallery);
// Initialize gallery
createCategoryNav();
createGalleryItems();
// Make functions globally available
window.showGallery = showGallery;
window.hideGallery = hideGallery;
});