-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
804 lines (711 loc) · 23.3 KB
/
Copy pathscript.js
File metadata and controls
804 lines (711 loc) · 23.3 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
const LESSONS = [
{
title: "Headings & Paragraph Text",
desc: "HTML has 6 heading levels (h1–h6) and the <p> tag for paragraphs. Use <strong> for bold, <em> for italic. Edit the code and click Run!",
hint: "Try all 6 heading levels: <code><h1></code> through <code><h6></code>. Wrap text in <code><strong></code> for bold and <code><em></code> for italic.",
code: `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Georgia, serif; padding: 2rem; color: #222; }
</style>
</head>
<body>
<h1>This is a Heading 1</h1>
<h2>This is a Heading 2</h2>
<h3>Heading 3 is smaller</h3>
<p>This is a paragraph. HTML text lives inside the
<strong>p tag</strong>. You can make text <em>italic</em>
or <strong>bold</strong>.</p>
<p>Try changing the text or adding more tags below!</p>
</body>
</html>`
},
{
title: "Links & Images",
desc: "The <a> tag creates hyperlinks. The <img> tag embeds images using a src attribute. Both are essential building blocks.",
hint: "Links: <code><a href=\"url\">text</a></code>. Images: <code><img src=\"url\" alt=\"description\"></code>. Add <code>target=\"_blank\"</code> to open in a new tab.",
code: `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; padding: 2rem; }
a { color: #0066cc; }
img { max-width: 100%; border-radius: 8px; }
</style>
</head>
<body>
<h2>Links</h2>
<p>Visit <a href="https://developer.mozilla.org" target="_blank">
MDN Web Docs
</a> to learn more HTML.</p>
<h2>Images</h2>
<img src="https://picsum.photos/400/200?random=1"
alt="A random image" width="400">
<p>Try changing the URL or the width!</p>
</body>
</html>`
},
{
title: "Lists",
desc: "HTML has ordered lists <ol>, unordered lists <ul>, and definition lists <dl>. Each item goes in an <li> tag.",
hint: "Unordered: <code><ul><li>item</li></ul></code>. Ordered: <code><ol></code>. You can nest lists inside list items!",
code: `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; padding: 2rem; }
li { margin: 0.3rem 0; }
</style>
</head>
<body>
<h2>Shopping List (unordered)</h2>
<ul>
<li>Apples</li>
<li>Bread</li>
<li>Milk</li>
</ul>
<h2>Steps to make tea (ordered)</h2>
<ol>
<li>Boil water</li>
<li>Add tea bag to cup</li>
<li>Pour hot water</li>
<li>Wait 3 minutes</li>
<li>Enjoy!</li>
</ol>
</body>
</html>`
},
{
title: "Tables",
desc: "HTML tables use <table>, <tr> (row), <th> (header cell), and <td> (data cell). Great for displaying structured data.",
hint: "Use <code><thead></code> for the header row and <code><tbody></code> for data rows. Add <code>border-collapse: collapse</code> in CSS for clean borders.",
code: `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; padding: 2rem; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ccc; padding: 8px 12px; text-align: left; }
th { background: #f0f0f0; font-weight: bold; }
tr:nth-child(even) { background: #fafafa; }
</style>
</head>
<body>
<h2>Student Scores</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Subject</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<tr><td>Arjun</td><td>Math</td><td>92</td></tr>
<tr><td>Priya</td><td>Science</td><td>88</td></tr>
<tr><td>Rohan</td><td>English</td><td>95</td></tr>
</tbody>
</table>
</body>
</html>`
},
{
title: "Forms",
desc: "Forms collect user input using <input>, <textarea>, <select>, and <button> tags. The <label> tag links text to an input.",
hint: "Connect a label to an input with <code>for</code> and <code>id</code> attributes. Use <code>type=\"email\"</code> or <code>type=\"number\"</code> for automatic validation.",
code: `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; padding: 2rem; max-width: 400px; }
label { display: block; font-size: 0.9rem; margin-bottom: 0.3rem; color: #555; }
input, select, textarea {
width: 100%; padding: 0.5rem 0.7rem;
border: 1px solid #ccc; border-radius: 6px;
margin-bottom: 1rem; font-size: 1rem;
}
button {
background: #4a90e2; color: white; border: none;
padding: 0.6rem 1.5rem; border-radius: 6px;
font-size: 1rem; cursor: pointer;
}
button:hover { background: #357abd; }
</style>
</head>
<body>
<h2>Contact Form</h2>
<label for="name">Your Name</label>
<input type="text" id="name" placeholder="Arjun Sharma">
<label for="email">Email Address</label>
<input type="email" id="email" placeholder="you@example.com">
<label for="topic">Topic</label>
<select id="topic">
<option>General Question</option>
<option>Feedback</option>
<option>Bug Report</option>
</select>
<label for="msg">Message</label>
<textarea id="msg" rows="4" placeholder="Write your message..."></textarea>
<button type="button">Send Message</button>
</body>
</html>`
},
{
title: "Colors & Fonts",
desc: "CSS controls visual style. Change text color with 'color', background with 'background-color', and load custom fonts with Google Fonts.",
hint: "Colors can be hex (<code>#ff6b6b</code>), rgb (<code>rgb(255,107,107)</code>), or named (<code>tomato</code>). Google Fonts: add a link tag then use the font-family name.",
code: `<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css2?family=Pacifico&family=Open+Sans&display=swap" rel="stylesheet">
<style>
body {
background-color: #fff9f0;
font-family: 'Open Sans', sans-serif;
padding: 2rem;
}
h1 {
font-family: 'Pacifico', cursive;
color: #e85d4a;
font-size: 2.5rem;
}
.highlight {
background-color: #ffd166;
color: #333;
padding: 4px 8px;
border-radius: 4px;
}
.box {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
padding: 1.5rem;
border-radius: 12px;
margin-top: 1rem;
}
</style>
</head>
<body>
<h1>Hello, CSS Colors!</h1>
<p>This text uses <span class="highlight">highlighted</span> styling.</p>
<div class="box">
<p>This box uses a gradient background.</p>
<p>Try changing the colors!</p>
</div>
</body>
</html>`
},
{
title: "The Box Model",
desc: "Every HTML element is a box. The box model has content, padding (inner space), border, and margin (outer space). Understanding this is key to layout.",
hint: "Use browser DevTools to visualize the box model. <code>margin</code> pushes elements apart, <code>padding</code> creates internal space, <code>border</code> draws an outline.",
code: `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; background: #f5f5f5; padding: 2rem; }
.box {
width: 200px;
padding: 20px; /* inner space */
border: 4px solid #4a90e2; /* border */
margin: 20px; /* outer space */
background: white;
border-radius: 8px;
}
.tight {
padding: 5px;
margin: 5px;
border: 2px dashed #e85d4a;
}
.spacious {
padding: 40px;
margin: 30px;
border: 6px solid #27ae60;
}
</style>
</head>
<body>
<h2>Box Model Demo</h2>
<div class="box">
<p>Normal box: 20px padding, 20px margin</p>
</div>
<div class="box tight">
<p>Tight box: less padding & margin</p>
</div>
<div class="box spacious">
<p>Spacious box: lots of padding & margin</p>
</div>
</body>
</html>`
},
{
title: "Flexbox Layout",
desc: "Flexbox makes it easy to align and distribute elements in a row or column. Use 'display: flex' on the parent and control children with gap, justify-content, align-items.",
hint: "Key properties: <code>justify-content</code> (main axis), <code>align-items</code> (cross axis), <code>flex-wrap: wrap</code> (for responsive wrapping), <code>gap</code> for spacing.",
code: `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; padding: 2rem; }
.flex-row {
display: flex;
gap: 12px;
margin-bottom: 2rem;
}
.flex-center {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
background: #f0f4ff;
padding: 2rem;
border-radius: 10px;
}
.flex-space {
display: flex;
justify-content: space-between;
align-items: center;
background: #fff0f5;
padding: 1rem 1.5rem;
border-radius: 10px;
}
.card {
background: white;
border: 1px solid #e0e0e0;
padding: 1rem;
border-radius: 8px;
flex: 1;
text-align: center;
}
</style>
</head>
<body>
<h2>Row of Cards (flex)</h2>
<div class="flex-row">
<div class="card">🍕 Pizza</div>
<div class="card">🍜 Noodles</div>
<div class="card">🥗 Salad</div>
</div>
<h2>Centered Content</h2>
<div class="flex-center">
<div>⬅ Left</div>
<div>Center ✦</div>
<div>Right ➡</div>
</div>
<br>
<h2>Space Between</h2>
<div class="flex-space">
<span><strong>Logo</strong></span>
<span>Home About Contact</span>
</div>
</body>
</html>`
},
{
title: "CSS Grid Layout",
desc: "CSS Grid is perfect for two-dimensional layouts. Define rows and columns with grid-template-columns, then place elements into cells.",
hint: "Use <code>grid-template-columns: repeat(3, 1fr)</code> for 3 equal columns. <code>grid-column: span 2</code> makes an item stretch across 2 columns.",
code: `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; padding: 2rem; }
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 12px;
margin-bottom: 2rem;
}
.cell {
background: #e8f4fd;
border: 1px solid #b3d4f5;
padding: 1.5rem;
text-align: center;
border-radius: 8px;
font-weight: 600;
}
.wide { grid-column: span 2; background: #d4f5e8; border-color: #8fd4b4; }
.tall { grid-row: span 2; background: #fde8f4; border-color: #f4b3d4; }
.page-grid {
display: grid;
grid-template-columns: 1fr 3fr;
grid-template-rows: auto 1fr auto;
gap: 10px;
height: 200px;
}
.header { grid-column: 1 / -1; background: #333; color: white; padding: 0.6rem 1rem; border-radius: 6px; }
.sidebar { background: #f0f0f0; padding: 0.8rem; border-radius: 6px; }
.content { background: #fff; border: 1px solid #ddd; padding: 0.8rem; border-radius: 6px; }
.footer { grid-column: 1 / -1; background: #555; color: white; padding: 0.5rem 1rem; border-radius: 6px; text-align: center; }
</style>
</head>
<body>
<h2>Basic Grid</h2>
<div class="grid">
<div class="cell">1</div>
<div class="cell wide">2 (spans 2 cols)</div>
<div class="cell tall">3 (spans 2 rows)</div>
<div class="cell">4</div>
<div class="cell">5</div>
</div>
<h2>Page Layout with Grid</h2>
<div class="page-grid">
<div class="header">Header</div>
<div class="sidebar">Sidebar</div>
<div class="content">Main Content Area</div>
<div class="footer">Footer</div>
</div>
</body>
</html>`
},
{
title: "CSS Animations",
desc: "CSS can animate elements using @keyframes. Define the start and end states, then apply the animation with animation-name, duration, and timing.",
hint: "Use <code>animation: name duration timing infinite</code>. Combine with <code>transform: scale()</code> or <code>translateX()</code> for smooth motion.",
code: `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; padding: 2rem; }
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-20px); }
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
@keyframes pulse {
0%, 100% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.15); opacity: 0.7; }
}
@keyframes slide-in {
from { transform: translateX(-100px); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
.box { display: inline-block; width: 60px; height: 60px; border-radius: 10px; margin: 1rem; }
.bounce { background: #e85d4a; animation: bounce 1s ease infinite; }
.spin { background: #4a90e2; animation: spin 2s linear infinite; border-radius: 50%; }
.pulse { background: #27ae60; animation: pulse 1.5s ease infinite; }
.slide {
background: #f0f4ff;
border: 1px solid #b3c6f5;
padding: 1rem 1.5rem;
border-radius: 8px;
animation: slide-in 0.8s ease forwards;
margin-top: 1rem;
display: inline-block;
}
.hover-box {
background: #fff0d4;
border: 2px solid #ffd166;
padding: 1rem 2rem;
border-radius: 10px;
display: inline-block;
transition: transform 0.2s, box-shadow 0.2s;
cursor: pointer;
margin-top: 1rem;
}
.hover-box:hover {
transform: translateY(-4px);
box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}
</style>
</head>
<body>
<h2>Animated Elements</h2>
<div class="box bounce"></div>
<div class="box spin"></div>
<div class="box pulse"></div>
<h2>Slide In on Load</h2>
<div class="slide">I slid in when the page loaded!</div>
<h2>Hover Transition</h2>
<div class="hover-box">Hover over me!</div>
</body>
</html>`
},
{
title: "Profile Card",
desc: "Build a complete profile card using HTML structure and CSS styling — a classic mini project that uses flexbox, borders, and typography together.",
hint: "Structure: a card div containing an avatar, name, role, stats row, and a button. Use <code>border-radius: 50%</code> for circle avatars.",
code: `<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
<style>
body {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
font-family: 'Nunito', sans-serif;
}
.card {
background: white;
border-radius: 20px;
padding: 2rem;
width: 280px;
text-align: center;
box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.avatar {
width: 90px;
height: 90px;
border-radius: 50%;
background: linear-gradient(135deg, #f093fb, #f5576c);
display: flex;
align-items: center;
justify-content: center;
font-size: 2.2rem;
margin: 0 auto 1rem;
}
.name { font-size: 1.3rem; font-weight: 800; color: #222; }
.role { color: #888; font-size: 0.9rem; margin-top: 0.2rem; }
.stats {
display: flex;
justify-content: space-around;
margin: 1.5rem 0;
padding: 1rem 0;
border-top: 1px solid #f0f0f0;
border-bottom: 1px solid #f0f0f0;
}
.stat-num { font-size: 1.2rem; font-weight: 800; color: #333; }
.stat-label { font-size: 0.75rem; color: #aaa; margin-top: 2px; }
.follow-btn {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
border: none;
padding: 0.7rem 2rem;
border-radius: 25px;
font-size: 0.95rem;
font-weight: 700;
cursor: pointer;
width: 100%;
transition: opacity 0.2s;
}
.follow-btn:hover { opacity: 0.85; }
</style>
</head>
<body>
<div class="card">
<div class="avatar">✦</div>
<div class="name">Priya Sharma</div>
<div class="role">UI Designer & Developer</div>
<div class="stats">
<div><div class="stat-num">482</div><div class="stat-label">Posts</div></div>
<div><div class="stat-num">12.4K</div><div class="stat-label">Followers</div></div>
<div><div class="stat-num">318</div><div class="stat-label">Following</div></div>
</div>
<button class="follow-btn">Follow</button>
</div>
</body>
</html>`
},
{
title: "Navigation Bar",
desc: "Build a responsive navigation bar — a must-have for any website. Uses flexbox for layout, with a logo on the left and links on the right.",
hint: "Use <code>position: sticky; top: 0</code> to keep the nav visible while scrolling. Add <code>box-shadow</code> to make it appear elevated from the content.",
code: `<!DOCTYPE html>
<html>
<head>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: sans-serif; }
nav {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 2rem;
height: 64px;
background: white;
box-shadow: 0 2px 12px rgba(0,0,0,0.08);
position: sticky;
top: 0;
}
.logo {
font-size: 1.3rem;
font-weight: 700;
color: #4a90e2;
}
.nav-links {
display: flex;
list-style: none;
gap: 0.5rem;
}
.nav-links a {
text-decoration: none;
color: #555;
padding: 0.4rem 0.9rem;
border-radius: 7px;
font-size: 0.92rem;
transition: all 0.2s;
}
.nav-links a:hover { background: #f0f4ff; color: #4a90e2; }
.nav-links .active a { background: #4a90e2; color: white; }
.hero {
text-align: center;
padding: 4rem 2rem;
background: linear-gradient(135deg, #f5f7ff, #e8f0fe);
}
.hero h1 { font-size: 2rem; color: #333; margin-bottom: 0.5rem; }
.hero p { color: #777; }
</style>
</head>
<body>
<nav>
<div class="logo">MySite</div>
<ul class="nav-links">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Work</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<div class="hero">
<h1>Welcome to My Site</h1>
<p>Scroll down to see the sticky navigation in action!</p>
</div>
<div style="height: 600px; display:flex; align-items:center; justify-content:center; color:#aaa;">
More content here...
</div>
</body>
</html>`
},
{
title: "Button Styles",
desc: "CSS buttons can look dramatically different with borders, gradients, and hover effects. Practice creating a variety of button styles from scratch.",
hint: "Key properties: <code>cursor: pointer</code>, <code>transition</code> for smooth hover, <code>border-radius</code> for pill/square shapes, <code>:hover</code> and <code>:active</code> pseudo-classes.",
code: `<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; padding: 2rem; background: #f8f8f8; }
h3 { color: #555; font-size: 0.8rem; letter-spacing: 0.1em; text-transform: uppercase; margin: 1.5rem 0 0.7rem; }
.row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 0.5rem; }
button {
font-family: sans-serif;
font-size: 0.9rem;
padding: 0.55rem 1.3rem;
border-radius: 8px;
border: none;
cursor: pointer;
transition: all 0.2s;
}
.solid-blue { background: #4a90e2; color: white; }
.solid-blue:hover { background: #357abd; transform: translateY(-1px); }
.solid-green { background: #27ae60; color: white; }
.solid-green:hover { background: #1e8449; }
.solid-red { background: #e74c3c; color: white; }
.solid-red:hover { background: #c0392b; }
.outline { background: transparent; border: 2px solid #4a90e2; color: #4a90e2; }
.outline:hover { background: #4a90e2; color: white; }
.ghost { background: transparent; border: 1px solid #ddd; color: #555; }
.ghost:hover { background: #f0f0f0; }
.pill { border-radius: 50px; background: #764ba2; color: white; }
.pill:hover { background: #6a3d9f; }
.gradient { background: linear-gradient(135deg, #f093fb, #f5576c); color: white; border-radius: 10px; }
.gradient:hover { opacity: 0.85; transform: scale(1.03); }
.shadow { background: white; border: 1px solid #e0e0e0; color: #333; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.shadow:hover { box-shadow: 0 8px 20px rgba(0,0,0,0.15); transform: translateY(-2px); }
.disabled { background: #ccc; color: #999; cursor: not-allowed; }
</style>
</head>
<body>
<h2>Button Showcase</h2>
<h3>Solid</h3>
<div class="row">
<button class="solid-blue">Primary</button>
<button class="solid-green">Success</button>
<button class="solid-red">Danger</button>
</div>
<h3>Outline & Ghost</h3>
<div class="row">
<button class="outline">Outline</button>
<button class="ghost">Ghost</button>
</div>
<h3>Special Styles</h3>
<div class="row">
<button class="pill">Pill Shape</button>
<button class="gradient">Gradient</button>
<button class="shadow">Elevated</button>
</div>
<h3>States</h3>
<div class="row">
<button class="solid-blue">Hover me</button>
<button class="disabled" disabled>Disabled</button>
</div>
</body>
</html>`
}
];
let currentLesson = 0;
let completed = new Set();
let hintVisible = false;
function loadLesson(index, btn) {
currentLesson = index;
const lesson = LESSONS[index];
document.getElementById('lesson-title').textContent = lesson.title;
document.getElementById('lesson-desc').innerHTML = lesson.desc;
document.getElementById('code-editor').value = lesson.code;
document.getElementById('hint-text').innerHTML = lesson.hint;
document.getElementById('status-hint').textContent = 'Press ▶ Run to see your changes';
document.querySelectorAll('.lesson-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
if (hintVisible) { document.getElementById('hint-panel').classList.remove('visible'); hintVisible = false; }
runCode();
updateProgress();
}
function runCode() {
const code = document.getElementById('code-editor').value;
const frame = document.getElementById('preview-frame');
const doc = frame.contentDocument || frame.contentWindow.document;
doc.open();
doc.write(code);
doc.close();
completed.add(currentLesson);
updateProgress();
showNotif('Preview updated!', false);
}
function resetCode() {
document.getElementById('code-editor').value = LESSONS[currentLesson].code;
runCode();
}
function toggleHint() {
hintVisible = !hintVisible;
document.getElementById('hint-panel').classList.toggle('visible', hintVisible);
}
function showNotif(msg, isError) {
const n = document.getElementById('notif');
n.textContent = msg;
n.className = 'notif' + (isError ? ' error' : '') + ' show';
clearTimeout(n._t);
n._t = setTimeout(() => n.classList.remove('show'), 1800);
}
function updateProgress() {
const track = document.getElementById('progress-track');
track.innerHTML = LESSONS.map((_, i) => {
let cls = 'progress-pip';
if (i === currentLesson) cls += ' active';
else if (completed.has(i)) cls += ' done';
return `<div class="${cls}"></div>`;
}).join('');
}
function setTab(el, tab) {
document.querySelectorAll('nav a').forEach(a => a.classList.remove('active'));
el.classList.add('active');
}
// Keyboard shortcut: Ctrl+Enter / Cmd+Enter to run
document.getElementById('code-editor').addEventListener('keydown', e => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { e.preventDefault(); runCode(); }
if (e.key === 'Tab') {
e.preventDefault();
const ta = e.target;
const s = ta.selectionStart;
ta.value = ta.value.substring(0, s) + ' ' + ta.value.substring(ta.selectionEnd);
ta.selectionStart = ta.selectionEnd = s + 2;
}
});
// Init
loadLesson(0, document.querySelector('.lesson-btn'));