LMS — Course Builder
A focused, three-pane course builder for an online learning platform. A reorderable module and lesson tree on the left drives a center lesson editor with title, type, a mock video uploader, content, and a free-preview toggle, while a right rail handles pricing, difficulty levels, category, and tags. Drag modules and lessons to reorder, check lessons off, watch live curriculum stats and a completion bar, then save or publish with friendly toasts and a draft-to-published status pill.
MCP
Code
:root {
--brand: #5b5bd6;
--brand-d: #4444c2;
--brand-50: #eeeefc;
--accent: #13b981;
--amber: #f59e0b;
--ink: #1a1a2e;
--ink-2: #44465f;
--muted: #6b6e87;
--bg: #f7f7fb;
--surface: #ffffff;
--line: rgba(26, 26, 46, 0.1);
--ok: #13b981;
--danger: #e05656;
--r-sm: 8px;
--r-md: 14px;
--r-lg: 20px;
--sh-sm: 0 1px 2px rgba(26, 26, 46, 0.06);
--sh-md: 0 6px 20px rgba(26, 26, 46, 0.08);
--sh-lg: 0 16px 40px rgba(26, 26, 46, 0.14);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
font-family: "Inter", system-ui, -apple-system, sans-serif;
background: var(--bg);
color: var(--ink);
line-height: 1.5;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
h1, h2, p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
.app { min-height: 100vh; display: flex; flex-direction: column; }
/* ============ TOPBAR ============ */
.topbar {
display: flex; align-items: center; justify-content: space-between;
gap: 16px; padding: 12px 20px;
background: var(--surface);
border-bottom: 1px solid var(--line);
position: sticky; top: 0; z-index: 30;
box-shadow: var(--sh-sm);
}
.topbar__left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo {
width: 38px; height: 38px; flex: none; display: grid; place-items: center;
background: linear-gradient(135deg, var(--brand), var(--brand-d));
color: #fff; border-radius: var(--r-md);
box-shadow: var(--sh-md);
}
.topbar__title { min-width: 0; }
.crumb { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.crumb span { margin: 0 5px; opacity: .5; }
.topbar__title h1 {
font-size: 16px; font-weight: 700; color: var(--ink);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw;
}
.status-pill {
font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
background: var(--amber); color: #4a3000; letter-spacing: .03em;
}
.status-pill[data-state="published"] { background: var(--accent); color: #003d2a; }
.topbar__right { display: flex; align-items: center; gap: 10px; }
.autosave { font-size: 12px; color: var(--muted); font-weight: 500; transition: color .2s; }
.autosave.is-saving { color: var(--brand); }
.btn {
display: inline-flex; align-items: center; gap: 6px;
border: 1px solid transparent; border-radius: var(--r-sm);
padding: 9px 14px; font-size: 13px; font-weight: 600;
transition: transform .08s, box-shadow .15s, background .15s, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn--sm { padding: 6px 10px; font-size: 12px; }
.btn--ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn--ghost:hover { background: var(--bg); color: var(--ink); }
.btn--ghost.danger { color: var(--danger); }
.btn--ghost.danger:hover { background: #fdeaea; border-color: #f3c4c4; }
.btn--soft { background: var(--brand-50); color: var(--brand-d); }
.btn--soft:hover { background: #e3e3fb; }
.btn--primary { background: linear-gradient(135deg, var(--brand), var(--brand-d)); color: #fff; box-shadow: var(--sh-md); }
.btn--primary:hover { box-shadow: var(--sh-lg); }
/* ============ LAYOUT ============ */
.layout {
flex: 1; display: grid;
grid-template-columns: 300px 1fr 308px;
gap: 16px; padding: 16px; max-width: 1500px; width: 100%; margin: 0 auto;
}
.panel {
background: var(--surface); border: 1px solid var(--line);
border-radius: var(--r-lg); box-shadow: var(--sh-sm);
display: flex; flex-direction: column; min-width: 0;
}
.panel__head {
display: flex; align-items: center; justify-content: space-between;
padding: 16px 18px 12px;
}
.panel__head h2 { font-size: 14px; font-weight: 700; }
.counter { font-size: 12px; color: var(--muted); font-weight: 600; }
/* ============ TREE ============ */
.tree { position: sticky; top: 78px; align-self: start; max-height: calc(100vh - 94px); }
.tree__progress { padding: 0 18px 14px; }
.tree__progress-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.tree__progress-row strong { color: var(--ink); }
.bar { height: 7px; background: var(--brand-50); border-radius: 999px; overflow: hidden; }
.bar__fill { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #0fa372); border-radius: 999px; transition: width .5s cubic-bezier(.4,0,.2,1); }
.tree__list { flex: 1; overflow-y: auto; padding: 4px 12px; }
.module {
border: 1px solid var(--line); border-radius: var(--r-md);
margin-bottom: 10px; background: #fcfcff; overflow: hidden;
}
.module.is-dragging { opacity: .45; }
.module.drag-over { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.module__head {
display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 6px;
}
.grip { color: var(--muted); cursor: grab; padding: 2px; line-height: 0; flex: none; }
.grip:active { cursor: grabbing; }
.module__toggle {
background: none; border: none; padding: 2px; color: var(--muted);
transition: transform .2s; line-height: 0; flex: none;
}
.module.collapsed .module__toggle { transform: rotate(-90deg); }
.module__name {
flex: 1; border: none; background: transparent; font-size: 13px; font-weight: 700;
color: var(--ink); padding: 4px 4px; border-radius: 6px; min-width: 0;
}
.module__name:focus { outline: 2px solid var(--brand-50); background: #fff; }
.module__count { font-size: 11px; color: var(--muted); font-weight: 600; flex: none; }
.icon-btn {
background: none; border: none; color: var(--muted); padding: 4px; border-radius: 6px; line-height: 0;
transition: background .15s, color .15s; flex: none;
}
.icon-btn:hover { background: #fdeaea; color: var(--danger); }
.lessons { padding: 2px 8px 8px; display: grid; gap: 4px; }
.module.collapsed .lessons { display: none; }
.lesson {
display: flex; align-items: center; gap: 8px; padding: 7px 8px;
border-radius: var(--r-sm); cursor: pointer; border: 1px solid transparent;
transition: background .12s, border-color .12s;
}
.lesson:hover { background: var(--brand-50); }
.lesson.is-active { background: var(--brand-50); border-color: #d6d6f6; }
.lesson.is-dragging { opacity: .45; }
.lesson.drag-over { box-shadow: 0 -2px 0 var(--brand); }
.lesson__check {
width: 18px; height: 18px; flex: none; border-radius: 50%;
border: 2px solid var(--line); display: grid; place-items: center;
color: #fff; font-size: 11px; transition: background .15s, border-color .15s;
}
.lesson.done .lesson__check { background: var(--accent); border-color: var(--accent); }
.lesson__type { font-size: 13px; flex: none; }
.lesson__title { flex: 1; font-size: 12.5px; font-weight: 600; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson.is-active .lesson__title { color: var(--brand-d); }
.lesson__min { font-size: 10.5px; color: var(--muted); font-weight: 600; flex: none; }
.add-lesson {
display: flex; align-items: center; gap: 6px; width: calc(100% - 4px); margin: 2px;
background: transparent; border: 1px dashed var(--line); border-radius: var(--r-sm);
padding: 7px; font-size: 12px; font-weight: 600; color: var(--muted);
transition: border-color .15s, color .15s, background .15s;
}
.add-lesson:hover { border-color: var(--brand); color: var(--brand-d); background: var(--brand-50); }
.add-module {
display: flex; align-items: center; justify-content: center; gap: 8px;
margin: 4px 14px 16px; padding: 11px;
background: var(--brand-50); color: var(--brand-d);
border: none; border-radius: var(--r-md); font-size: 13px; font-weight: 700;
transition: background .15s;
}
.add-module:hover { background: #e3e3fb; }
/* ============ EDITOR ============ */
.editor { padding: 0 22px 24px; gap: 18px; }
.editor__head {
display: flex; align-items: center; justify-content: space-between;
padding: 18px 0 4px; position: sticky; top: 78px; background: var(--surface); z-index: 5;
}
.editor__crumb { font-size: 12px; font-weight: 700; color: var(--brand-d); background: var(--brand-50); padding: 5px 11px; border-radius: 999px; }
.editor__actions { display: flex; gap: 8px; }
.field { display: grid; gap: 7px; }
.field__label { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.field__input {
width: 100%; border: 1px solid var(--line); border-radius: var(--r-sm);
padding: 11px 13px; font-size: 14px; color: var(--ink); background: var(--surface);
transition: border-color .15s, box-shadow .15s;
}
.field__input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.field__input--lg { font-size: 19px; font-weight: 700; padding: 13px 14px; }
.field__textarea { resize: vertical; line-height: 1.6; min-height: 120px; }
select.field__input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b6e87' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field__suffix, .field__prefix { display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.field__suffix:focus-within, .field__prefix:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.field__suffix .field__input, .field__prefix .field__input { border: none; box-shadow: none; }
.field__suffix span, .field__prefix span { padding: 0 12px; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--bg); align-self: stretch; display: grid; place-items: center; }
.field__prefix span { border-right: 1px solid var(--line); }
.field__suffix span { border-left: 1px solid var(--line); }
.uploader {
border: 2px dashed var(--line); border-radius: var(--r-md); padding: 4px;
transition: border-color .15s, background .15s; min-height: 96px; display: grid;
}
.uploader:hover, .uploader:focus { outline: none; border-color: var(--brand); background: var(--brand-50); }
.uploader.is-dragover { border-color: var(--brand); background: var(--brand-50); }
.uploader__empty { display: grid; place-items: center; gap: 4px; text-align: center; color: var(--muted); padding: 18px; }
.uploader__empty svg { color: var(--brand); }
.uploader__empty p { font-size: 13px; color: var(--ink-2); }
.uploader__empty span { font-size: 11.5px; }
.uploader__file { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 14px; width: 100%; }
.uploader__thumb { width: 52px; height: 52px; border-radius: var(--r-sm); background: linear-gradient(135deg, var(--brand), var(--brand-d)); color: #fff; display: grid; place-items: center; font-size: 20px; }
.uploader__meta { min-width: 0; }
.uploader__meta strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uploader__meta span { font-size: 11.5px; color: var(--muted); }
.uploader__bar { grid-column: 1 / -1; height: 5px; background: var(--brand-50); border-radius: 999px; overflow: hidden; }
.uploader__bar-fill { display: block; height: 100%; width: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.uploader__remove { grid-row: 1; grid-column: 3; background: none; border: none; color: var(--muted); font-size: 14px; padding: 6px; border-radius: 6px; }
.uploader__remove:hover { background: #fdeaea; color: var(--danger); }
.editor__toolbar { display: flex; gap: 2px; border: 1px solid var(--line); border-bottom: none; border-radius: var(--r-sm) var(--r-sm) 0 0; padding: 5px; background: var(--bg); }
.editor__toolbar + .field__textarea { border-radius: 0 0 var(--r-sm) var(--r-sm); }
.editor__toolbar button { width: 30px; height: 28px; border: none; background: transparent; border-radius: 6px; font-size: 13px; color: var(--ink-2); }
.editor__toolbar button:hover { background: #fff; box-shadow: var(--sh-sm); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; background: var(--bg); border-radius: var(--r-md); border: 1px solid var(--line); }
.toggle-row strong { display: block; font-size: 13px; }
.toggle-row small { font-size: 11.5px; color: var(--muted); }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch__track { position: absolute; inset: 0; background: #d3d4e4; border-radius: 999px; transition: background .2s; }
.switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; box-shadow: var(--sh-sm); transition: transform .2s; }
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--brand-50); }
/* ============ SETTINGS ============ */
.settings { position: sticky; top: 78px; align-self: start; max-height: calc(100vh - 94px); overflow-y: auto; padding-bottom: 18px; }
.settings__group { padding: 0 18px 18px; display: grid; gap: 9px; border-bottom: 1px solid var(--line); padding-top: 16px; }
.settings__group:last-child { border-bottom: none; }
.settings__heading { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; gap: 3px; }
.seg__btn { flex: 1; border: none; background: transparent; padding: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); border-radius: 6px; transition: background .15s, color .15s; }
.seg__btn.is-active { background: var(--surface); color: var(--brand-d); box-shadow: var(--sh-sm); }
.levels { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.level { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); padding: 8px 4px; font-size: 11.5px; font-weight: 600; color: var(--ink-2); transition: all .15s; }
.level:hover { border-color: #c9c9ee; }
.level.is-active { border-color: var(--brand); background: var(--brand-50); color: var(--brand-d); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 5px; background: var(--brand-50); color: var(--brand-d); font-size: 12px; font-weight: 600; padding: 4px 6px 4px 10px; border-radius: 999px; }
.tag button { background: none; border: none; color: var(--brand-d); font-size: 12px; padding: 0 2px; line-height: 1; opacity: .65; }
.tag button:hover { opacity: 1; }
.tag-input { padding: 9px 12px; font-size: 13px; }
.settings__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: var(--r-md); padding: 12px 6px; text-align: center; }
.stat span { display: block; font-size: 20px; font-weight: 800; color: var(--brand-d); }
.stat small { font-size: 10.5px; font-weight: 600; color: var(--muted); }
/* ============ TOAST ============ */
.toast-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: grid; gap: 10px; z-index: 80; width: max-content; max-width: 90vw; }
.toast {
display: flex; align-items: center; gap: 10px; background: var(--ink); color: #fff;
padding: 12px 16px; border-radius: var(--r-md); box-shadow: var(--sh-lg);
font-size: 13px; font-weight: 600;
animation: toast-in .3s cubic-bezier(.2,.9,.3,1.4);
}
.toast.is-out { animation: toast-out .25s forwards; }
.toast__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }
.toast--info .toast__dot { background: var(--brand); }
.toast--warn .toast__dot { background: var(--amber); }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }
.pop { animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
/* ============ RESPONSIVE ============ */
@media (max-width: 1080px) {
.layout { grid-template-columns: 260px 1fr; }
.settings { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 760px) {
.layout { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
.tree { position: static; max-height: none; }
.editor__head, .tree, .editor { position: static; }
}
@media (max-width: 520px) {
.topbar { flex-wrap: wrap; padding: 10px 14px; }
.topbar__title h1 { max-width: 60vw; font-size: 15px; }
.autosave { display: none; }
.topbar__right { width: 100%; justify-content: flex-end; }
.btn--ghost#btn-preview span { display: none; }
.field-row { grid-template-columns: 1fr; }
.editor { padding: 0 16px 20px; }
}(function () {
"use strict";
/* ---------- seed data (fictional) ---------- */
var TYPE_ICON = { video: "🎬", reading: "📖", quiz: "✅", assignment: "📝" };
var uid = (function () { var n = 100; return function () { return "id" + (++n); }; })();
var course = {
name: "Intro to Generative Design",
price: 79,
pricing: "paid",
level: "Intermediate",
category: "Design & Creative",
tags: ["generative", "design", "p5.js", "creative-coding"],
modules: [
{ id: uid(), name: "Getting Started", collapsed: false, lessons: [
{ id: uid(), title: "Welcome & what you'll build", type: "video", min: 6, done: true, free: true, content: "A quick tour of the course, the tools we'll use, and the final gallery you'll ship." },
{ id: uid(), title: "Setting up your sketch", type: "reading", min: 9, done: true, free: false, content: "Install the toolkit and create your first blank canvas." }
]},
{ id: uid(), name: "Vectors & Fields", collapsed: false, lessons: [
{ id: uid(), title: "Working with vector fields", type: "video", min: 14, done: false, free: false, content: "Map a grid of points and steer them with a noise field for organic motion." },
{ id: uid(), title: "Flow lines & trails", type: "video", min: 11, done: false, free: false, content: "Trace particle paths to draw flowing line art." },
{ id: uid(), title: "Knowledge check", type: "quiz", min: 5, done: false, free: false, content: "Five questions on fields, vectors, and noise." }
]},
{ id: uid(), name: "Color & Export", collapsed: false, lessons: [
{ id: uid(), title: "Palette systems", type: "reading", min: 8, done: false, free: false, content: "Build harmonious palettes from a single seed color." },
{ id: uid(), title: "Final piece: ship a poster", type: "assignment", min: 30, done: false, free: false, content: "Combine fields, trails, and color into one high-res export." }
]}
]
};
var activeLessonId = course.modules[1].lessons[0].id;
var saveTimer = null;
/* ---------- helpers ---------- */
var $ = function (s, r) { return (r || document).querySelector(s); };
function el(tag, cls, html) { var e = document.createElement(tag); if (cls) e.className = cls; if (html != null) e.innerHTML = html; return e; }
function toast(msg, kind) {
var wrap = $("#toast-wrap");
var t = el("div", "toast" + (kind ? " toast--" + kind : ""));
t.appendChild(el("span", "toast__dot"));
t.appendChild(el("span", null, msg));
wrap.appendChild(t);
setTimeout(function () {
t.classList.add("is-out");
t.addEventListener("animationend", function () { t.remove(); });
}, 2600);
}
function findLesson(id) {
for (var m = 0; m < course.modules.length; m++) {
var ls = course.modules[m].lessons;
for (var i = 0; i < ls.length; i++) if (ls[i].id === id) return { mod: course.modules[m], modIndex: m, lesson: ls[i], index: i };
}
return null;
}
function markSaving() {
var as = $("#autosave");
as.textContent = "Saving…"; as.classList.add("is-saving");
clearTimeout(saveTimer);
saveTimer = setTimeout(function () { as.textContent = "All changes saved"; as.classList.remove("is-saving"); }, 700);
if ($("#status-pill").dataset.state === "published") setDraft();
}
function setDraft() {
var p = $("#status-pill"); p.dataset.state = "draft"; p.textContent = "Draft";
}
/* ---------- stats ---------- */
function recompute() {
var lessons = 0, mins = 0, done = 0;
course.modules.forEach(function (m) {
lessons += m.lessons.length;
m.lessons.forEach(function (l) { mins += (+l.min || 0); if (l.done) done++; });
});
$("#stat-modules").textContent = course.modules.length;
$("#stat-lessons").textContent = lessons;
$("#stat-mins").textContent = mins;
$("#tree-counter").textContent = lessons + (lessons === 1 ? " lesson" : " lessons");
var pct = lessons ? Math.round((done / lessons) * 100) : 0;
$("#completion-pct").textContent = pct + "%";
$("#completion-fill").style.width = pct + "%";
}
/* ---------- render tree ---------- */
function renderTree() {
var list = $("#module-list");
list.innerHTML = "";
course.modules.forEach(function (mod, mi) {
var modEl = el("div", "module" + (mod.collapsed ? " collapsed" : ""));
modEl.dataset.id = mod.id;
modEl.draggable = true;
var head = el("div", "module__head");
head.innerHTML =
'<span class="grip" title="Drag to reorder" aria-hidden="true"><svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor"><circle cx="9" cy="6" r="1.6"/><circle cx="15" cy="6" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="18" r="1.6"/><circle cx="15" cy="18" r="1.6"/></svg></span>' +
'<button class="module__toggle" aria-label="Toggle module"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg></button>';
var nameInput = el("input", "module__name");
nameInput.value = mod.name; nameInput.setAttribute("aria-label", "Module " + (mi + 1) + " name");
head.appendChild(nameInput);
head.appendChild(el("span", "module__count", mod.lessons.length + ""));
var del = el("button", "icon-btn", '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>');
del.setAttribute("aria-label", "Delete module");
head.appendChild(del);
modEl.appendChild(head);
var lessonsWrap = el("div", "lessons");
mod.lessons.forEach(function (les) {
var l = el("div", "lesson" + (les.done ? " done" : "") + (les.id === activeLessonId ? " is-active" : ""));
l.dataset.id = les.id; l.draggable = true; l.tabIndex = 0;
l.innerHTML =
'<span class="lesson__check" data-act="check" role="checkbox" aria-checked="' + (les.done ? "true" : "false") + '" tabindex="0">' + (les.done ? "✓" : "") + '</span>' +
'<span class="lesson__type">' + (TYPE_ICON[les.type] || "📄") + '</span>' +
'<span class="lesson__title">' + escapeHtml(les.title || "Untitled lesson") + '</span>' +
'<span class="lesson__min">' + (les.min || 0) + 'm</span>';
lessonsWrap.appendChild(l);
});
var addLes = el("button", "add-lesson", '+ Add lesson');
lessonsWrap.appendChild(addLes);
modEl.appendChild(lessonsWrap);
/* module-level events */
$(".module__toggle", head).addEventListener("click", function () { mod.collapsed = !mod.collapsed; modEl.classList.toggle("collapsed"); });
nameInput.addEventListener("input", function () { mod.name = nameInput.value; markSaving(); });
del.addEventListener("click", function () {
if (course.modules.length === 1) { toast("A course needs at least one module", "warn"); return; }
course.modules.splice(mi, 1);
if (!findLesson(activeLessonId)) activeLessonId = firstLessonId();
renderAll(); markSaving(); toast("Module removed");
});
addLes.addEventListener("click", function () {
var nl = { id: uid(), title: "New lesson", type: "video", min: 10, done: false, free: false, content: "" };
mod.lessons.push(nl); mod.collapsed = false; activeLessonId = nl.id;
renderAll(); markSaving(); toast("Lesson added");
});
lessonsWrap.querySelectorAll(".lesson").forEach(function (lEl) {
var lid = lEl.dataset.id;
lEl.addEventListener("click", function (e) {
if (e.target.closest('[data-act="check"]')) return;
activeLessonId = lid; renderTree(); loadEditor();
});
lEl.addEventListener("keydown", function (e) {
if (e.key === "Enter" || e.key === " ") { e.preventDefault(); activeLessonId = lid; renderTree(); loadEditor(); }
});
var chk = $('[data-act="check"]', lEl);
chk.addEventListener("click", function (e) { e.stopPropagation(); toggleDone(lid); });
chk.addEventListener("keydown", function (e) { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); e.stopPropagation(); toggleDone(lid); } });
});
attachLessonDnd(lessonsWrap, mod);
list.appendChild(modEl);
});
attachModuleDnd(list);
recompute();
}
function toggleDone(lid) {
var f = findLesson(lid); if (!f) return;
f.lesson.done = !f.lesson.done; renderTree(); markSaving();
}
function firstLessonId() {
for (var i = 0; i < course.modules.length; i++) if (course.modules[i].lessons.length) return course.modules[i].lessons[0].id;
return null;
}
function escapeHtml(s) { return String(s).replace(/[&<>"']/g, function (c) { return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]; }); }
/* ---------- drag & drop: modules ---------- */
function attachModuleDnd(list) {
var dragId = null;
list.querySelectorAll(".module").forEach(function (m) {
m.addEventListener("dragstart", function (e) {
if (e.target.closest(".lesson")) return;
dragId = m.dataset.id; m.classList.add("is-dragging");
e.dataTransfer.effectAllowed = "move";
});
m.addEventListener("dragend", function () { m.classList.remove("is-dragging"); list.querySelectorAll(".drag-over").forEach(function (x) { x.classList.remove("drag-over"); }); });
m.addEventListener("dragover", function (e) { if (!dragId || dragId === m.dataset.id) return; e.preventDefault(); m.classList.add("drag-over"); });
m.addEventListener("dragleave", function () { m.classList.remove("drag-over"); });
m.addEventListener("drop", function (e) {
e.preventDefault(); m.classList.remove("drag-over");
if (!dragId || dragId === m.dataset.id) return;
var from = course.modules.findIndex(function (x) { return x.id === dragId; });
var to = course.modules.findIndex(function (x) { return x.id === m.dataset.id; });
if (from < 0 || to < 0) return;
course.modules.splice(to, 0, course.modules.splice(from, 1)[0]);
renderTree(); markSaving();
});
});
}
/* ---------- drag & drop: lessons within a module ---------- */
function attachLessonDnd(wrap, mod) {
var dragId = null;
wrap.querySelectorAll(".lesson").forEach(function (l) {
l.addEventListener("dragstart", function (e) { e.stopPropagation(); dragId = l.dataset.id; l.classList.add("is-dragging"); e.dataTransfer.effectAllowed = "move"; });
l.addEventListener("dragend", function () { l.classList.remove("is-dragging"); wrap.querySelectorAll(".drag-over").forEach(function (x) { x.classList.remove("drag-over"); }); });
l.addEventListener("dragover", function (e) { if (!dragId || dragId === l.dataset.id) return; e.preventDefault(); e.stopPropagation(); l.classList.add("drag-over"); });
l.addEventListener("dragleave", function () { l.classList.remove("drag-over"); });
l.addEventListener("drop", function (e) {
e.preventDefault(); e.stopPropagation(); l.classList.remove("drag-over");
if (!dragId || dragId === l.dataset.id) return;
var from = mod.lessons.findIndex(function (x) { return x.id === dragId; });
var to = mod.lessons.findIndex(function (x) { return x.id === l.dataset.id; });
if (from < 0 || to < 0) return;
mod.lessons.splice(to, 0, mod.lessons.splice(from, 1)[0]);
renderTree(); markSaving();
});
});
}
/* ---------- editor ---------- */
function loadEditor() {
var f = findLesson(activeLessonId);
if (!f) { activeLessonId = firstLessonId(); f = findLesson(activeLessonId); }
if (!f) return;
$("#editor-crumb").textContent = "Module " + (f.modIndex + 1) + " · Lesson " + (f.index + 1);
$("#lesson-title").value = f.lesson.title;
$("#lesson-type").value = f.lesson.type;
$("#lesson-duration").value = f.lesson.min;
$("#lesson-content").value = f.lesson.content;
$("#lesson-free").checked = !!f.lesson.free;
$("#video-field").style.display = f.lesson.type === "video" ? "" : "none";
}
function bindEditor() {
$("#lesson-title").addEventListener("input", function () {
var f = findLesson(activeLessonId); if (!f) return;
f.lesson.title = this.value; var t = document.querySelector('.lesson[data-id="' + activeLessonId + '"] .lesson__title');
if (t) t.textContent = this.value || "Untitled lesson"; markSaving();
});
$("#lesson-type").addEventListener("change", function () {
var f = findLesson(activeLessonId); if (!f) return;
f.lesson.type = this.value; renderTree(); loadEditor(); markSaving();
});
$("#lesson-duration").addEventListener("input", function () {
var f = findLesson(activeLessonId); if (!f) return;
f.lesson.min = Math.max(0, +this.value || 0); renderTree(); markSaving();
});
$("#lesson-content").addEventListener("input", function () {
var f = findLesson(activeLessonId); if (!f) return; f.lesson.content = this.value; markSaving();
});
$("#lesson-free").addEventListener("change", function () {
var f = findLesson(activeLessonId); if (!f) return; f.lesson.free = this.checked; markSaving();
toast(this.checked ? "Lesson set as free preview" : "Free preview removed", "info");
});
$("#btn-duplicate").addEventListener("click", function () {
var f = findLesson(activeLessonId); if (!f) return;
var copy = JSON.parse(JSON.stringify(f.lesson)); copy.id = uid(); copy.title += " (copy)"; copy.done = false;
f.mod.lessons.splice(f.index + 1, 0, copy); activeLessonId = copy.id;
renderAll(); markSaving(); toast("Lesson duplicated");
});
$("#btn-delete-lesson").addEventListener("click", function () {
var f = findLesson(activeLessonId); if (!f) return;
var total = course.modules.reduce(function (s, m) { return s + m.lessons.length; }, 0);
if (total === 1) { toast("Add another lesson before deleting this one", "warn"); return; }
f.mod.lessons.splice(f.index, 1); activeLessonId = firstLessonId();
renderAll(); markSaving(); toast("Lesson deleted");
});
/* toolbar wraps selection */
document.querySelectorAll(".editor__toolbar button").forEach(function (b) {
b.addEventListener("click", function () {
var ta = $("#lesson-content"), s = ta.selectionStart, e = ta.selectionEnd, sel = ta.value.slice(s, e) || "text";
var map = { b: "**" + sel + "**", i: "_" + sel + "_", h: "## " + sel, ul: "- " + sel, link: "[" + sel + "](https://)" };
var ins = map[b.dataset.fmt] || sel;
ta.value = ta.value.slice(0, s) + ins + ta.value.slice(e);
ta.focus(); var f = findLesson(activeLessonId); if (f) f.lesson.content = ta.value; markSaving();
});
});
}
/* ---------- video uploader (mock) ---------- */
function bindUploader() {
var up = $("#uploader"), empty = $("#uploader-empty"), fileBox = $("#uploader-file"), bar = $("#uploader-bar");
function fakeUpload(name, size) {
empty.hidden = true; fileBox.hidden = false;
$("#uploader-name").textContent = name || "lesson-clip.mp4";
$("#uploader-size").textContent = (size || "126 MB") + " · 10:18";
bar.style.width = "0%"; var p = 0;
var iv = setInterval(function () {
p += Math.random() * 22; if (p >= 100) { p = 100; clearInterval(iv); toast("Video uploaded", "info"); }
bar.style.width = p + "%";
}, 200);
markSaving();
}
up.addEventListener("click", function () { if (fileBox.hidden) fakeUpload(); });
up.addEventListener("keydown", function (e) { if ((e.key === "Enter" || e.key === " ") && fileBox.hidden) { e.preventDefault(); fakeUpload(); } });
up.addEventListener("dragover", function (e) { e.preventDefault(); up.classList.add("is-dragover"); });
up.addEventListener("dragleave", function () { up.classList.remove("is-dragover"); });
up.addEventListener("drop", function (e) {
e.preventDefault(); up.classList.remove("is-dragover");
var fl = e.dataTransfer.files && e.dataTransfer.files[0];
fakeUpload(fl ? fl.name : "dropped-clip.mp4", fl ? (Math.round(fl.size / 1048576) + " MB") : null);
});
$("#uploader-remove").addEventListener("click", function (e) {
e.stopPropagation(); fileBox.hidden = true; empty.hidden = false; markSaving(); toast("Video removed");
});
}
/* ---------- settings ---------- */
function bindSettings() {
/* pricing segment */
$("#pricing-seg").querySelectorAll(".seg__btn").forEach(function (b) {
b.addEventListener("click", function () {
$("#pricing-seg").querySelectorAll(".seg__btn").forEach(function (x) { x.classList.remove("is-active"); });
b.classList.add("is-active"); course.pricing = b.dataset.price;
$("#price-field").style.display = course.pricing === "free" ? "none" : "";
markSaving();
});
});
$("#course-price").addEventListener("input", function () { course.price = +this.value || 0; markSaving(); });
/* difficulty */
$("#levels").querySelectorAll(".level").forEach(function (b) {
b.addEventListener("click", function () {
$("#levels").querySelectorAll(".level").forEach(function (x) { x.classList.remove("is-active"); });
b.classList.add("is-active"); course.level = b.dataset.level; markSaving();
});
});
$("#course-category").addEventListener("change", function () { course.category = this.value; markSaving(); });
/* tags */
renderTags();
$("#tag-input").addEventListener("keydown", function (e) {
if (e.key === "Enter") {
e.preventDefault(); var v = this.value.trim().replace(/^#/, "");
if (!v) return;
if (course.tags.indexOf(v) > -1) { toast("Tag already added", "warn"); this.value = ""; return; }
course.tags.push(v); this.value = ""; renderTags(); markSaving();
} else if (e.key === "Backspace" && !this.value && course.tags.length) {
course.tags.pop(); renderTags(); markSaving();
}
});
}
function renderTags() {
var box = $("#tags"); box.innerHTML = "";
course.tags.forEach(function (t, i) {
var tag = el("span", "tag");
tag.appendChild(document.createTextNode(t));
var x = el("button", null, "✕"); x.setAttribute("aria-label", "Remove tag " + t);
x.addEventListener("click", function () { course.tags.splice(i, 1); renderTags(); markSaving(); });
tag.appendChild(x); box.appendChild(tag);
});
}
/* ---------- publish bar ---------- */
function editCourseName() {
var h = $("#course-name-display");
if (!h || h.tagName !== "H1") return;
var input = el("input", "field__input");
input.value = course.name; input.style.maxWidth = "320px"; input.id = "course-name-display";
input.setAttribute("aria-label", "Course title");
h.replaceWith(input); input.focus(); input.select();
input.addEventListener("blur", commit);
input.addEventListener("keydown", function (e) { if (e.key === "Enter") input.blur(); });
function commit() {
course.name = input.value.trim() || "Untitled course";
var nh = el("h1"); nh.id = "course-name-display"; nh.textContent = course.name; nh.title = "Click to rename";
input.replaceWith(nh); nh.addEventListener("click", editCourseName); markSaving();
}
}
function bindTopbar() {
var nameH = $("#course-name-display"); nameH.title = "Click to rename";
nameH.addEventListener("click", editCourseName);
$("#btn-save").addEventListener("click", function () {
var as = $("#autosave"); as.textContent = "Saving…"; as.classList.add("is-saving");
setTimeout(function () { as.textContent = "All changes saved"; as.classList.remove("is-saving"); toast("Draft saved"); }, 500);
});
$("#btn-preview").addEventListener("click", function () { toast("Opening learner preview…", "info"); });
$("#btn-publish").addEventListener("click", function () {
var total = course.modules.reduce(function (s, m) { return s + m.lessons.length; }, 0);
if (total < 1) { toast("Add at least one lesson to publish", "warn"); return; }
var p = $("#status-pill");
if (p.dataset.state === "published") {
setDraft(); toast("Moved back to draft", "warn");
} else {
p.dataset.state = "published"; p.textContent = "Published"; p.classList.add("pop");
setTimeout(function () { p.classList.remove("pop"); }, 360);
toast("🚀 Course published — " + total + " lessons live");
}
});
}
/* ---------- init ---------- */
function renderAll() { renderTree(); loadEditor(); }
function init() {
renderTree();
bindEditor();
loadEditor();
bindUploader();
bindSettings();
bindTopbar();
$("#status-pill").addEventListener("click", function () {}); // noop, keep focusable styling neutral
}
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init);
else init();
})();<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>LMS — Course Builder</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="app">
<!-- ============ TOP / PUBLISH BAR ============ -->
<header class="topbar">
<div class="topbar__left">
<span class="logo" aria-hidden="true">
<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 10v6M2 10l10-5 10 5-10 5z"/><path d="M6 12v5c3 3 9 3 12 0v-5"/></svg>
</span>
<div class="topbar__title">
<div class="crumb">Courses <span aria-hidden="true">/</span> Builder</div>
<h1 id="course-name-display">Intro to Generative Design</h1>
</div>
<span class="status-pill" id="status-pill" data-state="draft">Draft</span>
</div>
<div class="topbar__right">
<span class="autosave" id="autosave">All changes saved</span>
<button class="btn btn--ghost" id="btn-preview" type="button">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-7 11-7 11 7 11 7-4 7-11 7-11-7-11-7z"/><circle cx="12" cy="12" r="3"/></svg>
Preview
</button>
<button class="btn btn--soft" id="btn-save" type="button">Save draft</button>
<button class="btn btn--primary" id="btn-publish" type="button">Publish</button>
</div>
</header>
<div class="layout">
<!-- ============ LEFT — MODULE / LESSON TREE ============ -->
<aside class="panel tree" aria-label="Course outline">
<div class="panel__head">
<h2>Curriculum</h2>
<span class="counter" id="tree-counter">0 lessons</span>
</div>
<div class="tree__progress">
<div class="tree__progress-row">
<span>Course completion</span>
<strong id="completion-pct">0%</strong>
</div>
<div class="bar"><span class="bar__fill" id="completion-fill" style="width:0%"></span></div>
</div>
<div class="tree__list" id="module-list" role="tree" aria-label="Modules and lessons"></div>
<button class="add-module" id="btn-add-module" type="button">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
Add module
</button>
</aside>
<!-- ============ CENTER — LESSON EDITOR ============ -->
<main class="panel editor" aria-label="Lesson editor">
<div class="editor__head">
<div class="editor__crumb" id="editor-crumb">Module 1 · Lesson 1</div>
<div class="editor__actions">
<button class="btn btn--ghost btn--sm" id="btn-duplicate" type="button">Duplicate</button>
<button class="btn btn--ghost btn--sm danger" id="btn-delete-lesson" type="button">Delete lesson</button>
</div>
</div>
<label class="field">
<span class="field__label">Lesson title</span>
<input class="field__input field__input--lg" id="lesson-title" type="text" placeholder="e.g. Working with vector fields" />
</label>
<div class="field-row">
<label class="field">
<span class="field__label">Lesson type</span>
<select class="field__input" id="lesson-type">
<option value="video">🎬 Video</option>
<option value="reading">📖 Reading</option>
<option value="quiz">✅ Quiz</option>
<option value="assignment">📝 Assignment</option>
</select>
</label>
<label class="field">
<span class="field__label">Estimated duration</span>
<div class="field__suffix">
<input class="field__input" id="lesson-duration" type="number" min="1" max="240" value="12" />
<span>min</span>
</div>
</label>
</div>
<div class="field" id="video-field">
<span class="field__label">Lesson video</span>
<div class="uploader" id="uploader" tabindex="0" role="button" aria-label="Upload lesson video">
<div class="uploader__empty" id="uploader-empty">
<svg viewBox="0 0 24 24" width="28" height="28" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
<p><strong>Drop a video</strong> or click to upload</p>
<span>MP4 or MOV · up to 2 GB</span>
</div>
<div class="uploader__file" id="uploader-file" hidden>
<span class="uploader__thumb" aria-hidden="true">▶</span>
<div class="uploader__meta">
<strong id="uploader-name">field-vectors-final.mp4</strong>
<span id="uploader-size">148 MB · 11:42</span>
</div>
<div class="uploader__bar"><span class="uploader__bar-fill" id="uploader-bar"></span></div>
<button class="uploader__remove" id="uploader-remove" type="button" aria-label="Remove video">✕</button>
</div>
</div>
</div>
<label class="field">
<span class="field__label">Lesson content</span>
<div class="editor__toolbar" aria-hidden="true">
<button type="button" data-fmt="b"><b>B</b></button>
<button type="button" data-fmt="i"><i>I</i></button>
<button type="button" data-fmt="h">H</button>
<button type="button" data-fmt="ul">•</button>
<button type="button" data-fmt="link">🔗</button>
</div>
<textarea class="field__input field__textarea" id="lesson-content" rows="6" placeholder="Outline what learners will build, watch, or practice in this lesson…"></textarea>
</label>
<label class="toggle-row">
<span>
<strong>Free preview</strong>
<small>Let non-enrolled learners watch this lesson</small>
</span>
<span class="switch"><input type="checkbox" id="lesson-free" /><span class="switch__track"></span></span>
</label>
</main>
<!-- ============ RIGHT — SETTINGS ============ -->
<aside class="panel settings" aria-label="Course settings">
<div class="panel__head"><h2>Course settings</h2></div>
<div class="settings__group">
<span class="settings__heading">Pricing</span>
<div class="seg" id="pricing-seg" role="tablist">
<button class="seg__btn is-active" data-price="paid" role="tab" type="button">Paid</button>
<button class="seg__btn" data-price="free" role="tab" type="button">Free</button>
</div>
<label class="field" id="price-field">
<span class="field__label">Price (USD)</span>
<div class="field__prefix">
<span>$</span>
<input class="field__input" id="course-price" type="number" min="0" step="1" value="79" />
</div>
</label>
</div>
<div class="settings__group">
<span class="settings__heading">Difficulty</span>
<div class="levels" id="levels">
<button class="level" data-level="Beginner" type="button">Beginner</button>
<button class="level is-active" data-level="Intermediate" type="button">Intermediate</button>
<button class="level" data-level="Advanced" type="button">Advanced</button>
</div>
</div>
<div class="settings__group">
<span class="settings__heading">Category</span>
<select class="field__input" id="course-category">
<option>Design & Creative</option>
<option>Development</option>
<option>Data & AI</option>
<option>Business</option>
<option>Marketing</option>
</select>
</div>
<div class="settings__group">
<span class="settings__heading">Tags</span>
<div class="tags" id="tags"></div>
<input class="field__input tag-input" id="tag-input" type="text" placeholder="Add a tag, press Enter" />
</div>
<div class="settings__group settings__stats">
<div class="stat"><span id="stat-modules">0</span><small>Modules</small></div>
<div class="stat"><span id="stat-lessons">0</span><small>Lessons</small></div>
<div class="stat"><span id="stat-mins">0</span><small>Minutes</small></div>
</div>
</aside>
</div>
</div>
<div class="toast-wrap" id="toast-wrap" aria-live="polite"></div>
<script src="script.js"></script>
</body>
</html>Course Builder
An instructor-facing builder for assembling a course, laid out as three working panes under a sticky publish bar. The left Curriculum panel is a collapsible tree of modules and lessons with drag grips, lesson-type emoji, per-lesson minute badges, round check-offs, and a live completion bar. The center pane is the lesson editor — a large title field, a type selector (video, reading, quiz, assignment), a duration stepper, a drag-and-drop mock video uploader with a simulated progress bar, a lightweight markdown toolbar over the content area, and a free-preview switch. The right rail collects course settings: paid/free pricing, difficulty levels, category, removable tags, and a running module/lesson/minute stat block.
Everything is vanilla JavaScript. You can add and remove modules and lessons, drag to reorder both, rename modules and the course title inline, and check lessons complete — each action recomputes the stats and completion percentage in place. Editing any field flips the status pill back to Draft and runs a faux autosave indicator; Publish validates that lessons exist, pops the pill to Published, and fires a toast. Duplicate, delete, upload, and tag actions all surface concise toast feedback.
The grid collapses gracefully: the settings rail drops below at tablet widths and the whole thing stacks into a single mobile-friendly column down to ~360px, with full keyboard support for lesson selection and check-offs.
Illustrative UI only — fictional courses, not a real learning platform.