-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
316 lines (294 loc) · 11.9 KB
/
index.html
File metadata and controls
316 lines (294 loc) · 11.9 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>moTimeline — Example</title>
<link rel="stylesheet" href="../src/moTimeline.css">
<style>
*, *::before, *::after { box-sizing: border-box; }
body {
font-family: system-ui, -apple-system, sans-serif;
background: #f3f4f6;
color: #1f2937;
margin: 0;
}
header {
background: #1e1b4b;
color: #fff;
padding: 2.5rem 1.5rem;
text-align: center;
}
header h1 { margin: 0 0 0.5rem; font-size: 2rem; letter-spacing: -0.5px; }
header p { margin: 0; opacity: 0.65; font-size: 0.95rem; }
main { max-width: 960px; margin: 2.5rem auto; padding: 0 1rem; }
.controls { display: flex; gap: 0.75rem; justify-content: center; margin: 1.5rem 0 1rem; flex-wrap: wrap; }
.cat-filters { display: flex; gap: 0.5rem; justify-content: center; margin: 0 0 2rem; flex-wrap: wrap; }
.cat-btn { background: #fff; border: 1.5px solid #e5e7eb; border-radius: 999px; color: #6b7280; cursor: pointer; font-size: 0.8rem; font-weight: 600; padding: 0.35rem 1rem; transition: background .15s, color .15s, border-color .15s; }
.cat-btn:hover { border-color: #4f46e5; color: #4f46e5; }
.cat-btn.active { background: #4f46e5; border-color: #4f46e5; color: #fff; }
button {
background: #4f46e5;
border: none;
border-radius: 7px;
color: #fff;
cursor: pointer;
font-size: 0.875rem;
font-weight: 600;
padding: 0.55rem 1.2rem;
}
button:hover { background: #4338ca; }
button.secondary {
background: #fff;
border: 1.5px solid #e5e7eb;
color: #374151;
}
button.secondary:hover { background: #f9fafb; }
/* ── Note about Bootstrap ──────────────────────────────────
Bootstrap is fully compatible: just wrap the <ul> inside a
Bootstrap .container / .row — no special library option needed.
moTimeline handles its own 50% column widths internally.
──────────────────────────────────────────────────────────── */
</style>
</head>
<body>
<header>
<h1>moTimeline</h1>
<p>Responsive two-column timeline — plain JavaScript, no dependencies · Bootstrap-compatible</p>
</header>
<main>
<div class="controls">
<button id="addBtn">+ Add item</button>
<button id="toggleThemeBtn" class="secondary">Toggle theme</button>
<button id="toggleBadgeBtn" class="secondary">Toggle badges</button>
<button id="toggleFullWidthBtn" class="secondary">Toggle random full-width</button>
<button id="insertRandomBtn" class="secondary">Insert at random pos</button>
<button id="insertAtBtn" class="secondary">Insert at pos 2</button>
<button id="toggleAnimateBtn" class="secondary">Toggle animate</button>
</div>
<div class="cat-filters">
<button class="cat-btn active" data-cat="all">All</button>
<button class="cat-btn" data-cat="frontend">Frontend</button>
<button class="cat-btn" data-cat="backend">Backend</button>
<button class="cat-btn" data-cat="devops">DevOps</button>
</div>
<!-- mo-theme is added/removed by JS via the theme option.
Card structure when using the theme:
<li>
<div class="mo-card">
<div class="mo-card-image"> (optional)
<img class="mo-banner" src="...">
<img class="mo-avatar" src="...">
</div>
<div class="mo-card-body">
<h3>Title</h3>
<p class="mo-meta">Date</p>
<p>Text</p>
</div>
</div>
</li>
-->
<ul id="timeline"></ul>
</main>
<script type="module">
import MoTimeline from '../src/moTimeline.js';
// ── Item data ───────────────────────────────────────────────────────────────
const ITEMS = [
{
title: 'Project kickoff',
meta: 'January 2024',
text: 'Started the moTimeline rewrite. Removed jQuery, migrated to plain JavaScript with a class-based API and zero dependencies.',
banner: '../images/banner1.svg',
avatar: '../images/ryan.jpg',
categories: ['frontend', 'backend'],
},
{
title: 'Vite build pipeline',
meta: 'February 2024',
text: 'Set up Vite in library mode. Ships ESM, CJS and UMD bundles so any project can import it — bundled or via a plain script tag.',
categories: ['devops'],
},
{
title: 'Two-column layout',
meta: 'March 2024',
text: 'Core algorithm places items left and right automatically, filling the shorter column first.',
banner: '../images/banner2.svg',
avatar: '../images/eva.jpg',
categories: ['frontend'],
},
{
title: 'Responsive design',
meta: 'April 2024',
text: 'Collapses to a single column on mobile. Breakpoints configurable per instance via the columnCount option.',
categories: ['frontend'],
},
{
title: 'Badge & arrow support',
meta: 'May 2024',
text: 'Numbered badges sit on the center line. Arrows point from each card toward the center — left or right automatically.',
banner: '../images/banner3.svg',
avatar: '../images/avatar.jpg',
categories: ['frontend'],
},
{
title: 'REST API',
meta: 'June 2024',
text: 'No framework option needed. Wrap the <ul> inside a Bootstrap .container for page layout — the library handles its own column widths.',
categories: ['backend'],
},
{
title: 'GitHub Pages',
meta: 'July 2024',
text: 'Published a live demo and documentation page. Set GH Pages source to /docs in repo settings.',
banner: '../images/banner4.svg',
avatar: '../images/ryan.jpg',
categories: ['devops'],
},
{
title: 'Theme system',
meta: 'August 2024',
text: 'Opt-in visual theme with card images, overlapping avatars, and styled badges. Enable with theme: true.',
categories: ['frontend'],
},
{
title: 'Dynamic items',
meta: 'September 2024',
text: 'Append new <li> elements at any time and call initNewItems() — the library picks them up and positions them correctly.',
banner: '../images/sample-1.jpg',
avatar: '../images/eva.jpg',
categories: ['backend'],
},
{
title: 'CSS custom properties',
meta: 'October 2024',
text: 'Override --mo-badge-bg, --mo-line-color, --mo-arrow-color and others to match your brand in one line of CSS.',
categories: ['frontend'],
},
{
title: 'CI/CD pipeline',
meta: 'November 2024',
text: 'Automated build, test, and release pipeline. Deploys to GitHub Pages on every push to main.',
banner: '../images/banner1.svg',
avatar: '../images/avatar.jpg',
categories: ['devops'],
},
{
title: 'v2.1.0 released',
meta: 'December 2024',
text: 'Badges, arrows, theme, CSS variables, zero dependencies, Vite build. The timeline library, done right.',
categories: ['frontend', 'backend', 'devops'],
},
];
// ── Build themed card HTML ──────────────────────────────────────────────────
function makeItem(d) {
const li = document.createElement('li');
if (d.banner) {
li.innerHTML = `
<div class="mo-card">
<div class="mo-card-image">
<img class="mo-banner" src="${d.banner}" alt="">
${d.avatar ? `<img class="mo-avatar" src="${d.avatar}" alt="">` : ''}
</div>
<div class="mo-card-body">
<h3>${d.title}</h3>
<p class="mo-meta">${d.meta}</p>
<p>${d.text}</p>
</div>
</div>`;
} else {
li.innerHTML = `
<div class="mo-card">
<div class="mo-card-body">
<h3>${d.title}</h3>
<p class="mo-meta">${d.meta}</p>
<p>${d.text}</p>
</div>
</div>`;
}
return li;
}
// ── Populate ────────────────────────────────────────────────────────────────
const tlEl = document.getElementById('timeline');
ITEMS.forEach(d => tlEl.appendChild(makeItem(d)));
// ── Initialize ──────────────────────────────────────────────────────────────
let tl = new MoTimeline(tlEl, {
showBadge: true,
showArrow: true,
theme: true,
animate: 'slide',
});
window.tl = tl; // expose for console debugging
// ── Controls ────────────────────────────────────────────────────────────────
let addCount = ITEMS.length + 1;
document.getElementById('addBtn').addEventListener('click', () => {
tlEl.appendChild(makeItem({
title: `New item ${addCount}`,
meta: 'Just now',
text: 'Dynamically appended item, picked up by initNewItems().',
}));
tl.initNewItems();
addCount++;
});
document.getElementById('toggleThemeBtn').addEventListener('click', () => {
tlEl.classList.toggle('mo-theme');
});
document.getElementById('toggleBadgeBtn').addEventListener('click', () => {
const badges = tlEl.querySelectorAll('.js-mo-badge');
badges.forEach(b => b.style.display = b.style.display === 'none' ? '' : 'none');
});
document.getElementById('toggleFullWidthBtn').addEventListener('click', () => {
const items = Array.from(tlEl.querySelectorAll('.js-mo-item'));
const anyFullWidth = items.some(i => i.classList.contains('mo-fullwidth'));
if (anyFullWidth) {
// Clear all full-width
items.forEach(i => i.classList.remove('mo-fullwidth', 'js-mo-fullwidth'));
} else {
// Randomly assign ~33% as full-width
items.forEach(i => {
if (Math.random() < 0.33) i.classList.add('mo-fullwidth', 'js-mo-fullwidth');
});
}
tl.refresh();
});
let insertCount = 1;
document.getElementById('insertRandomBtn').addEventListener('click', () => {
tl.insertItem({
title: `Inserted #${insertCount} (random)`,
meta: 'Just now',
text: 'This item was inserted at a random position.',
});
insertCount++;
});
document.getElementById('insertAtBtn').addEventListener('click', () => {
tl.insertItem({
title: `Inserted #${insertCount} (pos 2, full-width)`,
meta: 'Just now',
text: 'This item was inserted at index 2 as a full-width item.',
fullWidth: true,
}, 2);
insertCount++;
});
document.getElementById('toggleAnimateBtn').addEventListener('click', () => {
const hasAnimate = tlEl.classList.contains('mo-animate');
if (hasAnimate) {
tlEl.classList.remove('mo-animate', 'mo-animate-fade', 'mo-animate-slide');
tlEl.querySelectorAll('.mo-visible').forEach(i => i.classList.remove('mo-visible'));
} else {
tlEl.classList.add('mo-animate', 'mo-animate-slide');
// Re-observe all items that don't yet have mo-visible
tlEl.querySelectorAll('.js-mo-item').forEach(i => {
i.classList.remove('mo-visible');
tl._observer && tl._observer.observe(i);
});
}
});
document.querySelectorAll('.cat-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.cat-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
tl.filterByCategory(btn.dataset.cat);
});
});
</script>
</body>
</html>