Skip to content

Commit 971abc1

Browse files
authored
fix expand/collapse role mapping bugs and fix 'Show/Hide Columns:' issue (#74)
1 parent 319cc7b commit 971abc1

File tree

1 file changed

+51
-78
lines changed

1 file changed

+51
-78
lines changed

script/mapping-tables.js

Lines changed: 51 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -229,28 +229,7 @@ function mappingTables() {
229229

230230
var expandCollapseDetails = function (detCont, action) {
231231
queryAll('details', detCont).forEach(function (details) {
232-
var detailsSummary = details.querySelector('summary');
233-
var detailsNotSummary = Array.prototype.slice
234-
.call(details.children)
235-
.filter(function (child) {
236-
return child !== detailsSummary;
237-
});
238-
239-
if (action == 'collapse') {
240-
details.classList.remove('open');
241-
details.open = false;
242-
detailsSummary.setAttribute('aria-expanded', false);
243-
detailsNotSummary.forEach(function (element) {
244-
hideElement(element);
245-
});
246-
} else {
247-
details.classList.add('open');
248-
details.open = true;
249-
detailsSummary.setAttribute('aria-expanded', true);
250-
detailsNotSummary.forEach(function (element) {
251-
showElement(element);
252-
});
253-
}
232+
details.open = action !== 'collapse'
254233
});
255234
};
256235

@@ -277,58 +256,60 @@ function mappingTables() {
277256
'<span>' + mappingTableLabels.showHideCols + '</span>';
278257

279258
for (var i = 0, len = colHeaders.length; i < len; i++) {
280-
var toggleLabel = colHeaders[i]
281-
.replace(/<a [^<]+>|<\/a>/g, '')
282-
.replace(/<sup>\[Note [0-9]+\]<\/sup>/g, '');
283-
284-
var showHideColButton = document.createElement('button');
285-
showHideColButton.className = 'hide-col';
286-
showHideColButton.setAttribute('aria-pressed', false);
287-
showHideColButton.setAttribute(
288-
'title',
289-
mappingTableLabels.hideToolTipText
290-
);
291-
showHideColButton.innerHTML =
292-
'<span class="action">' +
293-
mappingTableLabels.hideActionText +
294-
'</span>' +
295-
toggleLabel;
296-
297-
showHideColButton.addEventListener('click', function () {
298-
var index = getElementIndex(showHideColButton) + 1;
299-
var wasHidden = showHideColButton.className === 'hide-col';
300-
301-
queryAll(
302-
'tr>th:nth-child(' + index + '), tr>td:nth-child(' + index + ')',
303-
tableInfo.table
304-
).forEach(function (element) {
305-
if (wasHidden) {
306-
hideElement(element);
307-
} else {
308-
showElement(element);
309-
}
310-
});
311-
312-
showHideColButton.className = wasHidden ? 'show-col' : 'hide-col';
313-
showHideColButton.setAttribute('aria-pressed', wasHidden);
259+
(function (i) {
260+
var toggleLabel = colHeaders[i]
261+
.replace(/<a [^<]+>|<\/a>/g, '')
262+
.replace(/<sup>\[Note [0-9]+\]<\/sup>/g, '');
263+
264+
var showHideColButton = document.createElement('button');
265+
showHideColButton.className = 'hide-col';
266+
showHideColButton.setAttribute('aria-pressed', false);
314267
showHideColButton.setAttribute(
315268
'title',
316-
wasHidden
317-
? mappingTableLabels.showToolTipText
318-
: mappingTableLabels.hideToolTipText
269+
mappingTableLabels.hideToolTipText
319270
);
320-
showHideColButton.querySelector('span').innerText = wasHidden
321-
? mappingTableLabels.showActionText
322-
: mappingTableLabels.hideActionText;
323-
});
324-
queryAll('span', showHideColButton)
325-
.filter(function (span) {
326-
return !span.classList.contains('action');
327-
})
328-
.forEach(function (span) {
329-
span.parentNode.removeChild(span);
271+
showHideColButton.innerHTML =
272+
'<span class="action">' +
273+
mappingTableLabels.hideActionText +
274+
'</span>' +
275+
toggleLabel;
276+
277+
showHideColButton.addEventListener('click', function () {
278+
var index = getElementIndex(showHideColButton);
279+
var wasHidden = showHideColButton.className === 'hide-col';
280+
281+
queryAll(
282+
'tr>th:nth-child(' + index + '), tr>td:nth-child(' + index + ')',
283+
tableInfo.table
284+
).forEach(function (element) {
285+
if (wasHidden) {
286+
hideElement(element);
287+
} else {
288+
showElement(element);
289+
}
290+
});
291+
292+
showHideColButton.className = wasHidden ? 'show-col' : 'hide-col';
293+
showHideColButton.setAttribute('aria-pressed', wasHidden);
294+
showHideColButton.setAttribute(
295+
'title',
296+
wasHidden
297+
? mappingTableLabels.showToolTipText
298+
: mappingTableLabels.hideToolTipText
299+
);
300+
showHideColButton.querySelector('span').innerText = wasHidden
301+
? mappingTableLabels.showActionText
302+
: mappingTableLabels.hideActionText;
330303
});
331-
showHideCols.appendChild(showHideColButton);
304+
queryAll('span', showHideColButton)
305+
.filter(function (span) {
306+
return !span.classList.contains('action');
307+
})
308+
.forEach(function (span) {
309+
span.parentNode.removeChild(span);
310+
});
311+
showHideCols.appendChild(showHideColButton);
312+
})(i)
332313
}
333314

334315
tableInfo.tableContainer.insertBefore(
@@ -405,14 +386,6 @@ function mapTables(respecEvents) {
405386
});
406387
}
407388

408-
409-
function expandReferredDetails(summaryFragId) {
410-
// if details element is not open, activate click on summary
411-
if (!summaryFragId.parentNode.open) {
412-
summaryFragId.click();
413-
}
414-
}
415-
416389
if (respecEvents) {
417390
// Fix the scroll-to-fragID:
418391
// - if running with ReSpec, do not invoke the mapping tables script until

0 commit comments

Comments
 (0)