Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
198 lines (170 loc) · 5.5 KB
/
Copy pathscript.js
File metadata and controls
198 lines (170 loc) · 5.5 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
// Acronym tooltips — wrap known acronyms in <abbr> with title
const ACRONYMS = {
'SDLC': 'Software Development Life Cycle',
'SFIA': 'Skills Framework for the Information Age',
'NIST': 'National Institute of Standards and Technology',
'RMF': 'Risk Management Framework',
'QA': 'Quality Assurance',
'PR': 'Pull Request',
'PRs': 'Pull Requests',
'CI': 'Continuous Integration',
'ADR': 'Architecture Decision Record',
'ADRs': 'Architecture Decision Records',
'IP': 'Intellectual Property',
'CLI': 'Command Line Interface',
'API': 'Application Programming Interface',
'APIs': 'Application Programming Interfaces',
'IDE': 'Integrated Development Environment',
'AI': 'Artificial Intelligence',
'PDF': 'Portable Document Format'
};
function wrapAcronyms() {
const keys = Object.keys(ACRONYMS).sort((a, b) => b.length - a.length);
const pattern = new RegExp('\\b(' + keys.map(k => k.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|') + ')\\b', 'g');
const skipTags = new Set(['SCRIPT', 'STYLE', 'CODE', 'PRE', 'ABBR', 'A', 'BUTTON', 'TEXTAREA', 'INPUT']);
const root = document.querySelector('.content');
if (!root) return;
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
acceptNode(node) {
if (!node.nodeValue || !node.nodeValue.trim()) return NodeFilter.FILTER_REJECT;
let p = node.parentNode;
while (p && p !== root) {
if (skipTags.has(p.tagName)) return NodeFilter.FILTER_REJECT;
p = p.parentNode;
}
return pattern.test(node.nodeValue) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
}
});
const targets = [];
let n;
while ((n = walker.nextNode())) targets.push(n);
targets.forEach((textNode) => {
const text = textNode.nodeValue;
const frag = document.createDocumentFragment();
let lastIndex = 0;
pattern.lastIndex = 0;
let m;
while ((m = pattern.exec(text)) !== null) {
if (m.index > lastIndex) {
frag.appendChild(document.createTextNode(text.slice(lastIndex, m.index)));
}
const abbr = document.createElement('abbr');
abbr.textContent = m[0];
const key = ACRONYMS[m[0]] ? m[0] : (ACRONYMS[m[0].replace(/s$/, '')] ? m[0].replace(/s$/, '') : m[0]);
abbr.setAttribute('title', ACRONYMS[m[0]] || ACRONYMS[key] || m[0]);
abbr.setAttribute('data-tip', ACRONYMS[m[0]] || ACRONYMS[key] || m[0]);
frag.appendChild(abbr);
lastIndex = m.index + m[0].length;
}
if (lastIndex < text.length) {
frag.appendChild(document.createTextNode(text.slice(lastIndex)));
}
textNode.parentNode.replaceChild(frag, textNode);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', wrapAcronyms);
} else {
wrapAcronyms();
}
// Progress bar
const progressBar = document.getElementById('progressBar');
function updateProgress() {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
const scrollHeight = document.documentElement.scrollHeight - window.innerHeight;
const percent = scrollHeight > 0 ? (scrollTop / scrollHeight) * 100 : 0;
progressBar.style.width = percent + '%';
}
window.addEventListener('scroll', updateProgress, { passive: true });
updateProgress();
// Nav highlight on scroll
const sections = document.querySelectorAll('.section, .hero');
const navItems = document.querySelectorAll('.nav-item');
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const id = entry.target.id;
navItems.forEach((item) => {
item.classList.toggle('active', item.dataset.section === id);
});
}
});
},
{ rootMargin: '-40% 0px -55% 0px', threshold: 0 }
);
sections.forEach((sec) => observer.observe(sec));
// Mobile nav toggle
const navToggle = document.getElementById('navToggle');
const sidebar = document.getElementById('sidebar');
navToggle.addEventListener('click', () => {
sidebar.classList.toggle('open');
});
// Close sidebar on nav click (mobile)
navItems.forEach((item) => {
item.addEventListener('click', () => {
if (window.innerWidth <= 768) {
sidebar.classList.remove('open');
}
});
});
// Rubric tabs
const tabs = document.querySelectorAll('.rubric-tab');
const panels = document.querySelectorAll('.rubric-panel');
tabs.forEach((tab) => {
tab.addEventListener('click', () => {
const key = tab.dataset.tab;
tabs.forEach((t) => t.classList.toggle('active', t === tab));
panels.forEach((p) => p.classList.toggle('active', p.dataset.panel === key));
});
});
// Copy template
const copyBtn = document.getElementById('copyTemplate');
const templateContent = `# Engineer AI Usage Assessment
## Summary
- Engineer:
- Reviewer:
- Review period:
- Team / area:
## Scores
- Framing:
- Delegation:
- Evaluation:
- Operationalization:
- Governance:
## Provisional overall (median):
## Final overall:
## Evidence
### Framing
-
### Delegation
-
### Evaluation
-
### Operationalization
-
### Governance
-
## Growth priorities for next cycle
1.
2.
3.
`;
if (copyBtn) {
copyBtn.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(templateContent);
copyBtn.textContent = 'Copied ✓';
copyBtn.classList.add('copied');
setTimeout(() => {
copyBtn.textContent = 'Copy Template';
copyBtn.classList.remove('copied');
}, 1800);
} catch (e) {
copyBtn.textContent = 'Copy failed';
setTimeout(() => {
copyBtn.textContent = 'Copy Template';
}, 1800);
}
});
}