This repository was archived by the owner on Apr 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarketplace.js
More file actions
198 lines (178 loc) · 7.37 KB
/
marketplace.js
File metadata and controls
198 lines (178 loc) · 7.37 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
// marketplace.js — Marketplace rendering + filtering
document.addEventListener("DOMContentLoaded", function () {
"use strict";
var D = window.MARKETPLACE_DATA;
if (!D) return;
var frameworkMap = {};
D.frameworks.forEach(function (f) { frameworkMap[f.id] = f; });
var auditorMap = {};
D.auditors.forEach(function (a) { auditorMap[a.id] = a; });
var colorVar = { red: "#ef4444", blue: "#3b82f6", purple: "#a855f7", cyan: "#06b6d4", amber: "#f59e0b" };
var selected = {}; // framework id → true
// DOM
var chipRow = document.getElementById("framework-row");
var summary = document.getElementById("filter-summary");
var grid = document.getElementById("auditor-grid");
var backdrop = document.getElementById("mp-modal-backdrop");
var modal = document.getElementById("mp-modal");
if (!chipRow || !grid || !modal) return;
// ── Build framework chips (once) ─────────────────────────────
var chipEls = {}; // fwId → button element
D.frameworks.forEach(function (fw) {
var btn = document.createElement("button");
btn.className = "framework-chip";
btn.textContent = fw.shortName;
btn.title = fw.name;
btn.addEventListener("click", function () {
if (selected[fw.id]) { delete selected[fw.id]; }
else { selected[fw.id] = true; }
applyFilter();
});
chipRow.appendChild(btn);
chipEls[fw.id] = btn;
});
// ── Build auditor cards (once) ───────────────────────────────
var cardEls = []; // { id, el, pillsEl }
D.auditors.forEach(function (a) {
var card = document.createElement("div");
card.className = "mp-card";
card.setAttribute("data-aid", a.id);
card.innerHTML =
'<div class="mp-card-header">' +
'<i class="ph ph-' + a.icon + '" style="color:' + (colorVar[a.color] || "#fff") + ';font-size:1.5rem"></i>' +
'<span class="mp-card-name">' + a.name + '</span>' +
'</div>' +
'<p class="mp-card-desc">' + a.description + '</p>' +
'<div class="mp-card-pills"></div>' +
'<button class="mp-card-learn-more">Learn More</button>';
card.querySelector(".mp-card-learn-more").addEventListener("click", function (e) {
e.stopPropagation();
openModal(a.id);
});
grid.appendChild(card);
cardEls.push({ id: a.id, el: card, pillsEl: card.querySelector(".mp-card-pills") });
});
// ── Apply filter (toggles classes, no DOM rebuild) ───────────
function applyFilter() {
var keys = Object.keys(selected);
var n = keys.length;
// Update chip active states
D.frameworks.forEach(function (fw) {
chipEls[fw.id].classList.toggle("active", !!selected[fw.id]);
});
// Build matching auditor set
var matching = {};
keys.forEach(function (fwId) {
var fw = frameworkMap[fwId];
if (fw) fw.auditorIds.forEach(function (id) { matching[id] = true; });
});
// Update card states + pills
cardEls.forEach(function (c) {
var el = c.el;
if (n === 0) {
el.classList.remove("dimmed", "highlighted");
c.pillsEl.innerHTML = "";
return;
}
var match = !!matching[c.id];
el.classList.toggle("dimmed", !match);
el.classList.toggle("highlighted", match);
// Show matching framework pills
if (match) {
var pills = "";
keys.forEach(function (fwId) {
var fw = frameworkMap[fwId];
if (fw && fw.auditorIds.indexOf(c.id) !== -1) {
pills += '<span class="mp-pill">' + fw.shortName + '</span>';
}
});
c.pillsEl.innerHTML = pills;
} else {
c.pillsEl.innerHTML = "";
}
});
// Update summary bar
if (n === 0) {
summary.style.display = "none";
} else {
summary.style.display = "flex";
summary.innerHTML = '<span>' + n + ' framework' + (n > 1 ? 's' : '') + ' selected</span>';
var clearBtn = document.createElement("button");
clearBtn.className = "clear-btn";
clearBtn.textContent = "Clear all";
clearBtn.addEventListener("click", function () {
selected = {};
applyFilter();
});
summary.appendChild(clearBtn);
}
}
// ── Modal ────────────────────────────────────────────────────
function openModal(auditorId) {
var a = auditorMap[auditorId];
if (!a) return;
var body = modal.querySelector(".mp-modal-body");
modal.querySelector(".mp-modal-title").innerHTML =
'<i class="ph ph-' + a.icon + '" style="color:' + (colorVar[a.color] || '#fff') + '"></i> ' + a.name;
var html = '';
var details = D.complianceDetails[auditorId];
var subtitle = details ? details.controlArea : a.category;
html += '<p class="mp-modal-subtitle">' + subtitle + '</p>';
html += '<p class="mp-modal-desc">' + a.description + '</p>';
// Compliance detail cards (flat, matching screenshot)
if (details && details.details.length) {
details.details.forEach(function (d) {
var fw = frameworkMap[d.framework];
var region = fw ? fw.region : "";
html +=
'<div class="mp-detail-card">' +
'<div class="mp-detail-header">' +
'<span class="mp-detail-fw">' + d.frameworkName + '</span>' +
'<span class="mp-detail-clause">' + d.clause + '</span>' +
(region ? '<span class="mp-detail-region">' + region + '</span>' : '') +
'</div>' +
'<div class="mp-detail-section">' +
'<div class="mp-detail-label"><i class="ph ph-book-open"></i> ORIGINAL REGULATION TEXT</div>' +
'<blockquote class="mp-detail-quote">' + d.originalText + '</blockquote>' +
'</div>' +
'<div class="mp-detail-section">' +
'<div class="mp-detail-label mp-detail-label--green"><i class="ph ph-check-circle"></i> HOW THIS AUDITOR HELPS</div>' +
'<p class="mp-detail-comply">' + d.howWeComply + '</p>' +
'</div>' +
'</div>';
});
} else {
// Fallback: show requiring frameworks
var reqFws = D.frameworks.filter(function (fw) {
return fw.auditorIds.indexOf(auditorId) !== -1;
});
if (reqFws.length) {
html += '<p class="mp-modal-section-label">Required by ' + reqFws.length + ' compliance frameworks</p>';
html += '<div class="mp-modal-fw-grid">';
reqFws.forEach(function (fw) {
html +=
'<div class="mp-modal-fw-item">' +
'<strong>' + fw.shortName + '</strong>' +
'<span class="mp-modal-fw-desc">' + fw.name + '</span>' +
'<span class="mp-modal-fw-region">' + fw.region + '</span>' +
'</div>';
});
html += '</div>';
}
}
body.innerHTML = html;
backdrop.classList.add("visible");
modal.classList.add("visible");
document.body.style.overflow = "hidden";
}
function closeModal() {
backdrop.classList.remove("visible");
modal.classList.remove("visible");
document.body.style.overflow = "";
}
backdrop.addEventListener("click", closeModal);
modal.querySelector(".mp-modal-close").addEventListener("click", closeModal);
document.addEventListener("keydown", function (e) {
if (e.key === "Escape") closeModal();
});
});