feat: multiple layouts
This commit is contained in:
@@ -13,11 +13,14 @@ const searchToggle = document.getElementById('searchToggle');
|
|||||||
const searchWrapper = document.getElementById('searchWrapper');
|
const searchWrapper = document.getElementById('searchWrapper');
|
||||||
const addLinkToggle = document.getElementById('addLinkToggle');
|
const addLinkToggle = document.getElementById('addLinkToggle');
|
||||||
const addLinkWrapper = document.getElementById('addLinkWrapper');
|
const addLinkWrapper = document.getElementById('addLinkWrapper');
|
||||||
|
const layoutToggle = document.getElementById('layoutToggle');
|
||||||
|
const layoutDropdown = document.getElementById('layoutDropdown');
|
||||||
|
|
||||||
// State
|
// State
|
||||||
let allLinks = [];
|
let allLinks = [];
|
||||||
let searchTimeout = null;
|
let searchTimeout = null;
|
||||||
let showArchived = false;
|
let showArchived = false;
|
||||||
|
let currentLayout = 'masonry'; // Default layout
|
||||||
|
|
||||||
// Initialize app
|
// Initialize app
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
@@ -26,6 +29,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
setupScrollToTop();
|
setupScrollToTop();
|
||||||
setupMobileSearch();
|
setupMobileSearch();
|
||||||
setupMobileAddLink();
|
setupMobileAddLink();
|
||||||
|
setupLayoutToggle();
|
||||||
|
applyLayout(currentLayout);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Event listeners
|
// Event listeners
|
||||||
@@ -109,6 +114,48 @@ function setupMobileAddLink() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup layout toggle
|
||||||
|
function setupLayoutToggle() {
|
||||||
|
if (!layoutToggle || !layoutDropdown) return;
|
||||||
|
|
||||||
|
// Toggle dropdown on button click
|
||||||
|
layoutToggle.addEventListener('click', (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
layoutDropdown.classList.toggle('show');
|
||||||
|
layoutToggle.classList.toggle('active');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Close dropdown when clicking outside
|
||||||
|
document.addEventListener('click', (e) => {
|
||||||
|
if (!layoutToggle.contains(e.target) && !layoutDropdown.contains(e.target)) {
|
||||||
|
layoutDropdown.classList.remove('show');
|
||||||
|
layoutToggle.classList.remove('active');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle layout option clicks
|
||||||
|
layoutDropdown.querySelectorAll('.layout-option').forEach(option => {
|
||||||
|
option.addEventListener('click', () => {
|
||||||
|
const layout = option.dataset.layout;
|
||||||
|
applyLayout(layout);
|
||||||
|
layoutDropdown.classList.remove('show');
|
||||||
|
layoutToggle.classList.remove('active');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply layout
|
||||||
|
function applyLayout(layout) {
|
||||||
|
currentLayout = layout;
|
||||||
|
linksContainer.className = 'links-container';
|
||||||
|
linksContainer.classList.add(`layout-${layout}`);
|
||||||
|
|
||||||
|
// Update active state in dropdown
|
||||||
|
layoutDropdown.querySelectorAll('.layout-option').forEach(option => {
|
||||||
|
option.classList.toggle('active', option.dataset.layout === layout);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Setup scroll to top button
|
// Setup scroll to top button
|
||||||
function setupScrollToTop() {
|
function setupScrollToTop() {
|
||||||
// Show/hide button based on scroll position
|
// Show/hide button based on scroll position
|
||||||
@@ -267,6 +314,7 @@ function displayLinks(links) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
linksContainer.innerHTML = links.map(link => createLinkCard(link)).join('');
|
linksContainer.innerHTML = links.map(link => createLinkCard(link)).join('');
|
||||||
|
applyLayout(currentLayout);
|
||||||
|
|
||||||
// Add delete event listeners
|
// Add delete event listeners
|
||||||
document.querySelectorAll('.delete-btn').forEach(btn => {
|
document.querySelectorAll('.delete-btn').forEach(btn => {
|
||||||
@@ -301,7 +349,9 @@ function createLinkCard(link) {
|
|||||||
return `
|
return `
|
||||||
<div class="link-card" data-id="${link.id}">
|
<div class="link-card" data-id="${link.id}">
|
||||||
<div class="link-image">
|
<div class="link-image">
|
||||||
${imageHtml}
|
<a href="${escapeHtml(link.url)}" target="_blank" rel="noopener noreferrer" class="link-image-link">
|
||||||
|
${imageHtml}
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="link-content">
|
<div class="link-content">
|
||||||
<h3 class="link-title">${escapeHtml(link.title)}</h3>
|
<h3 class="link-title">${escapeHtml(link.title)}</h3>
|
||||||
|
|||||||
@@ -29,6 +29,36 @@
|
|||||||
<line x1="12" y1="22.08" x2="12" y2="12"/>
|
<line x1="12" y1="22.08" x2="12" y2="12"/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
<div class="layout-toggle-wrapper">
|
||||||
|
<button id="layoutToggle" class="layout-toggle-btn" title="Change layout">
|
||||||
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<rect x="3" y="3" width="7" height="7"></rect>
|
||||||
|
<rect x="14" y="3" width="7" height="7"></rect>
|
||||||
|
<rect x="14" y="14" width="7" height="7"></rect>
|
||||||
|
<rect x="3" y="14" width="7" height="7"></rect>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<div class="layout-dropdown" id="layoutDropdown">
|
||||||
|
<button class="layout-option" data-layout="masonry">
|
||||||
|
<span>Masonry</span>
|
||||||
|
<svg class="check-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<polyline points="20 6 9 17 4 12"></polyline>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button class="layout-option" data-layout="detail">
|
||||||
|
<span>Detail</span>
|
||||||
|
<svg class="check-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<polyline points="20 6 9 17 4 12"></polyline>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button class="layout-option" data-layout="list">
|
||||||
|
<span>List</span>
|
||||||
|
<svg class="check-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
|
<polyline points="20 6 9 17 4 12"></polyline>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<button id="searchToggle" class="search-toggle-btn" title="Toggle search">
|
<button id="searchToggle" class="search-toggle-btn" title="Toggle search">
|
||||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
<circle cx="11" cy="11" r="8"></circle>
|
<circle cx="11" cy="11" r="8"></circle>
|
||||||
|
|||||||
@@ -144,6 +144,103 @@ body {
|
|||||||
height: 20px;
|
height: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Layout Toggle Button */
|
||||||
|
.layout-toggle-wrapper {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-toggle-btn {
|
||||||
|
background: transparent;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
padding: 0.5rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-toggle-btn:hover {
|
||||||
|
background: var(--surface-light);
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-toggle-btn.active {
|
||||||
|
background: rgba(99, 102, 241, 0.1);
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-toggle-btn svg {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Layout Dropdown */
|
||||||
|
.layout-dropdown {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% + 0.5rem);
|
||||||
|
right: 0;
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 8px 24px var(--shadow-lg);
|
||||||
|
min-width: 140px;
|
||||||
|
opacity: 0;
|
||||||
|
visibility: hidden;
|
||||||
|
transform: translateY(-10px);
|
||||||
|
transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
|
||||||
|
z-index: 1000;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-dropdown.show {
|
||||||
|
opacity: 1;
|
||||||
|
visibility: visible;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-option {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0.625rem 0.875rem;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
color: var(--text-primary);
|
||||||
|
font-size: 0.875rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.2s ease;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-option:hover {
|
||||||
|
background: var(--surface-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-option.active {
|
||||||
|
background: rgba(99, 102, 241, 0.1);
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-option .check-icon {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-option.active .check-icon {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 1.5rem 1rem;
|
padding: 1.5rem 1rem;
|
||||||
@@ -546,6 +643,128 @@ body {
|
|||||||
animation: fadeIn 1s ease-out;
|
animation: fadeIn 1s ease-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Layout: Masonry */
|
||||||
|
.links-container.layout-masonry {
|
||||||
|
display: block;
|
||||||
|
column-count: auto;
|
||||||
|
column-width: 280px;
|
||||||
|
column-gap: 1.5rem;
|
||||||
|
animation: fadeIn 1s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-masonry .link-card {
|
||||||
|
display: inline-block;
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
break-inside: avoid;
|
||||||
|
page-break-inside: avoid;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-masonry .link-image {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-masonry .link-image-link {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-masonry .link-image img {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
object-fit: contain;
|
||||||
|
max-height: 400px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-masonry .link-content {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
padding: 1rem 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-masonry .link-title {
|
||||||
|
font-size: 1.1rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-masonry .link-description {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-masonry .link-url {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-masonry .link-footer {
|
||||||
|
margin-top: auto;
|
||||||
|
padding-top: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-masonry .empty-state {
|
||||||
|
column-span: all;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Layout: Detail (default - current layout) */
|
||||||
|
.links-container.layout-detail {
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Layout: List */
|
||||||
|
.links-container.layout-list {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-list .link-card {
|
||||||
|
flex-direction: row;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-list .link-image {
|
||||||
|
width: 100px;
|
||||||
|
height: 100px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-list .link-content {
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-list .link-title {
|
||||||
|
font-size: 1rem;
|
||||||
|
margin-bottom: 0.375rem;
|
||||||
|
-webkit-line-clamp: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-list .link-description {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
-webkit-line-clamp: 1;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-list .link-url {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-list .link-footer {
|
||||||
|
padding-top: 0.5rem;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.links-container.layout-list .link-date {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
.empty-state {
|
.empty-state {
|
||||||
grid-column: 1 / -1;
|
grid-column: 1 / -1;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -582,12 +801,25 @@ body {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-image-link {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-decoration: none;
|
||||||
|
color: inherit;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link-image img {
|
.link-image img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link-content {
|
.link-content {
|
||||||
@@ -816,6 +1048,14 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.layout-toggle-wrapper {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout-dropdown {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.add-link-wrapper {
|
.add-link-wrapper {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user