Skip to content

Commit 80fbf53

Browse files
committed
Refactor Browser HTML to use 1 less <div> element:
`<section class="section"><div class="skills-container" id="skills-container-xyz"></div></section>` --> `<section class="section skills-container" id="skills-container-xyz"></section>`
1 parent 7111cb3 commit 80fbf53

2 files changed

Lines changed: 41 additions & 50 deletions

File tree

index.html

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,34 +1922,22 @@ <h1>Skills</h1>
19221922
<div id="no-matching-skills" style="display:none"></div>
19231923

19241924
<h2>Languages</h2>
1925-
<section class="section">
1926-
<div class="skills-container" id="skills-container-languages"></div>
1927-
</section>
1925+
<section class="section skills-container" id="skills-container-languages"></section>
19281926

19291927
<h2>Tools</h2>
1930-
<section class="section">
1931-
<div class="skills-container" id="skills-container-tools"></div>
1932-
</section>
1928+
<section class="section skills-container" id="skills-container-tools"></section>
19331929

19341930
<h2>Frameworks</h2>
1935-
<section class="section">
1936-
<div class="skills-container" id="skills-container-frameworks"></div>
1937-
</section>
1931+
<section class="section skills-container" id="skills-container-frameworks"></section>
19381932

19391933
<h2>Operating Systems</h2>
1940-
<section class="section">
1941-
<div class="skills-container" id="skills-container-operating-systems"></div>
1942-
</section>
1934+
<section class="section skills-container" id="skills-container-operating-systems"></section>
19431935

19441936
<h2>Large Language Models (LLMs)</h2>
1945-
<section class="section">
1946-
<div class="skills-container" id="skills-container-llms"></div>
1947-
</section>
1937+
<section class="section skills-container" id="skills-container-llms"></section>
19481938

19491939
<h2>Editors</h2>
1950-
<section class="section">
1951-
<div class="skills-container" id="skills-container-editors"></div>
1952-
</section>
1940+
<section class="section skills-container" id="skills-container-editors"></section>
19531941
</div>
19541942
</div>
19551943

src/components/browser.js

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ const instructions = document.querySelector(".browser-instructions");
1616
const noSkillsMsg = document.getElementById("no-matching-skills");
1717
const draggingCursor = skillSections[0] ? getComputedStyle(skillSections[0]).getPropertyValue("--dragging-cursor").trim() : "grabbing";
1818

19-
// Skills search
19+
/**
20+
* Skills search: Filter skills based on search input
21+
*/
2022
function filterBrowser() {
2123
// Filter skills
2224
document.querySelectorAll(".skills-container .skill-entry").forEach(skill => {
@@ -25,13 +27,11 @@ function filterBrowser() {
2527

2628
// Hide section headings IFF ALL their skills are hidden
2729
document.querySelectorAll("#browser .inside h2").forEach(h2 => {
28-
const section = h2.nextElementSibling;
29-
if (!section?.classList.contains("section")) return;
30-
const skillsContainer = section.querySelector(".skills-container");
31-
if (!skillsContainer) return;
30+
const skillsContainer = h2.nextElementSibling;
31+
if (!skillsContainer?.classList.contains("section")) return;
3232
const anyVisible = Array.from(skillsContainer.querySelectorAll(".skill-entry"))
3333
.some(skill => skill.style.display !== "none");
34-
section.style.display = h2.style.display = anyVisible ? "" : "none";
34+
skillsContainer.style.display = h2.style.display = anyVisible ? "" : "none";
3535
});
3636

3737
// Hide browser instructions ONLY when filtering
@@ -51,12 +51,12 @@ function filterBrowser() {
5151
}
5252
}
5353

54-
// Skills sorting
54+
/**
55+
* Skills sorting
56+
*/
5557
function sortSkills() {
5658
skillSections.forEach(section => {
57-
const skillsContainer = section.querySelector(".skills-container");
58-
if (!skillsContainer) return;
59-
let skills = Array.from(skillsContainer.querySelectorAll(".skill-entry"));
59+
let skills = Array.from(section.querySelectorAll(".skill-entry"));
6060
if (sortMode === 0) { // Ascending
6161
skills.sort((a, b) =>
6262
getText(a, ".heading").localeCompare(getText(b, ".heading"))
@@ -66,14 +66,16 @@ function sortSkills() {
6666
getText(b, ".heading").localeCompare(getText(a, ".heading"))
6767
);
6868
} else { // Original
69-
skills = skillsContainer._originalOrder.slice();
69+
skills = section._originalOrder.slice();
7070
}
71-
skills.forEach(skill => skillsContainer.appendChild(skill));
71+
skills.forEach(skill => section.appendChild(skill));
7272
});
7373
sortMode = (sortMode + 1) % 3;
7474
}
7575

76-
// Show/hide skill description
76+
/**
77+
* Show/hide skill description
78+
*/
7779
const toggleContent = item => {
7880
// Prevent toggling content when sorting
7981
if (!isSorting) {
@@ -84,27 +86,28 @@ const toggleContent = item => {
8486
}
8587
};
8688

89+
/**
90+
* Initialize browser functionality
91+
*/
8792
export function initBrowser() {
8893
skillSections.forEach(section => {
89-
const skillsContainer = section.querySelector(".skills-container");
90-
if (skillsContainer) {
91-
skillsContainer._originalOrder = Array.from(skillsContainer.querySelectorAll(".skill-entry"));
92-
// Make skills sortable
93-
$(skillsContainer).sortable({
94-
axis: "y",
95-
containment: "parent",
96-
cursor: draggingCursor,
97-
handle: ".row",
98-
opacity: sortOpacity,
99-
scroll: true,
100-
scrollSpeed: sortSpeed,
101-
start: function() { isSorting = true; },
102-
stop: function() { setTimeout(() => { isSorting = false; }, 0); }
103-
}).on("sortupdate", function() {
104-
// Update original order after sorting
105-
this._originalOrder = Array.from(this.querySelectorAll(".skill-entry"));
106-
});
107-
}
94+
section._originalOrder = Array.from(section.querySelectorAll(".skill-entry"));
95+
96+
// Make skills sortable
97+
$(section).sortable({
98+
axis: "y",
99+
containment: "parent",
100+
cursor: draggingCursor,
101+
handle: ".row",
102+
opacity: sortOpacity,
103+
scroll: true,
104+
scrollSpeed: sortSpeed,
105+
start: function() { isSorting = true; },
106+
stop: function() { setTimeout(() => { isSorting = false; }, 0); }
107+
}).on("sortupdate", function() {
108+
// Update original order after sorting
109+
this._originalOrder = Array.from(this.querySelectorAll(".skill-entry"));
110+
});
108111
});
109112

110113
if (browserInput) {

0 commit comments

Comments
 (0)