Skip to content

Commit

Permalink
move status filter to non-removed script (#621)
Browse files Browse the repository at this point in the history
Moves the script that makes the status filter work to a new .js file that doesn't get cleaned out after Respec is done
  • Loading branch information
Michael Cooper authored Apr 8, 2022
1 parent 110b64e commit 3d96351
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
33 changes: 0 additions & 33 deletions guidelines/guidelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,38 +165,6 @@ function addStatusMarkers() {
});
}

function enableStatusFilter() {
var filterActive = false;
var button = document.querySelector('#status-filter');
var statusLabels = (button.getAttribute('data-status-filter') || '').split(',');
var statusSelector = statusLabels.map(function (status) {
return '[data-status="'+ status +'"]'
}).join(',')

function toggleStatus() {
filterActive = !filterActive; // Toggle
var sections = document.querySelectorAll(statusSelector);
sections.forEach(function (section) {
if (section.hasAttribute('data-no-filter')) {
return; // Use this to override the filter
}
var sectionId = section.id || findHeading(section).id;
var tocLink = document.querySelector('#toc a[href="#' + sectionId + '"]'); // this may be null due to TOC depth limit
var tocItem = tocLink == null ? null : tocLink.parentNode;
if (filterActive) {
section.setAttribute('hidden', '');
if (tocItem != null) tocItem.setAttribute('hidden', '');
} else {
section.removeAttribute('hidden');
if (tocItem != null) tocItem.removeAttribute('hidden');
}
});
button.textContent = (filterActive ? 'Reveal' : 'Hide') + ' placeholder & exploratory sections';
}
button.addEventListener('click', toggleStatus);
toggleStatus(); // Active by default
}

function termTitles() {
// put definitions into title attributes of term references
document.querySelectorAll('.internalDFN').forEach(function(node){
Expand Down Expand Up @@ -378,5 +346,4 @@ function postRespec() {
removeImgSize();
outputJson();
moveStatusFilterToToc();
enableStatusFilter();
}
1 change: 1 addition & 0 deletions guidelines/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<script src="guidelines.js" class="remove"></script>
<script src="respec-config.js" class="remove"></script>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove"></script>
<script src="wcag3.js"></script>
<link rel="stylesheet" type="text/css" href="guidelines.css" />
</head>
<body>
Expand Down
35 changes: 35 additions & 0 deletions guidelines/wcag3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function enableStatusFilter() {
var filterActive = false;
var button = document.querySelector('#status-filter');
var statusLabels = (button.getAttribute('data-status-filter') || '').split(',');
var statusSelector = statusLabels.map(function (status) {
return '[data-status="'+ status +'"]'
}).join(',')

function toggleStatus() {
filterActive = !filterActive; // Toggle
var sections = document.querySelectorAll(statusSelector);
sections.forEach(function (section) {
if (section.hasAttribute('data-no-filter')) {
return; // Use this to override the filter
}
var sectionId = section.id || findHeading(section).id;
var tocLink = document.querySelector('#toc a[href="#' + sectionId + '"]'); // this may be null due to TOC depth limit
var tocItem = tocLink == null ? null : tocLink.parentNode;
if (filterActive) {
section.setAttribute('hidden', '');
if (tocItem != null) tocItem.setAttribute('hidden', '');
} else {
section.removeAttribute('hidden');
if (tocItem != null) tocItem.removeAttribute('hidden');
}
});
button.textContent = (filterActive ? 'Reveal' : 'Hide') + ' placeholder & exploratory sections';
}
button.addEventListener('click', toggleStatus);
toggleStatus(); // Active by default
}

window.addEventListener('load', (event) => {
enableStatusFilter();
});

0 comments on commit 3d96351

Please sign in to comment.