Skip to content

Commit

Permalink
Add dataset to div containing roles
Browse files Browse the repository at this point in the history
  • Loading branch information
recrwplay committed Sep 4, 2024
1 parent e257c6e commit 27be30d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions preview-src/docs-roles.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ For example, `label--beta-until-5.12` is displayed as `Beta until Neo4j 5.12`.
To override this value, include the product name in the label.
For example, `label--beta-until-bolt-1.0` is displayed as `Beta until Bolt 1.0`.

[role=test-role]
Paragraph with non-label role.


[role=label--beta-until-bolt-1.0 label--removed-2.0]
== Adding a product name to versioned labels
Expand Down
14 changes: 8 additions & 6 deletions src/js/60-docs-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ document.addEventListener('DOMContentLoaded', function () {
text: rolesData[dataLabel].displayText || '',
joinText: dataVersion ? rolesData[dataLabel].joinText || 'in' : '',
data: {
labelCategory: rolesData[dataLabel].labelCategory || '',
product: dataVersion ? dataProduct || rolesData[dataLabel].product || contentDataset.product || '' : '',
version: dataVersion || '',
function: rolesData[dataLabel].function || '',
event: rolesData[dataLabel].labelCategory === 'version' ? dataLabel : '',
},
}

Expand Down Expand Up @@ -127,9 +127,9 @@ document.addEventListener('DOMContentLoaded', function () {
const labelSpan = createElement('span', `label content-label label--${labelDetails.class}`)

// add dataset to the label
if (labelDetails.data.version) labelSpan.dataset.version = labelDetails.data.version
if (labelDetails.data.product !== '') labelSpan.dataset.product = labelDetails.data.product
if (labelDetails.data.function !== '') labelSpan.dataset.function = labelDetails.data.function
for (var d in labelDetails.data) {
if (labelDetails.data[d] !== '') labelSpan.dataset[d] = labelDetails.data[d]
}

labelSpan.appendChild(document.createTextNode(labelDetails.text))

Expand All @@ -148,8 +148,10 @@ document.addEventListener('DOMContentLoaded', function () {
label.classList.add('header-label')
}
labelsDiv.append(label)
const contentLabel = Array.from(label.classList).find((c) => c.startsWith('label--')).replace('label--', '')
roleDiv.dataset[camelCased(contentLabel)] = contentLabel

for (var d in label.dataset) {
roleDiv.dataset[d] = label.dataset[d]
}
}

if (roleDiv.nodeName === 'H1' || headings.includes(roleDiv.firstElementChild.nodeName)) {
Expand Down

0 comments on commit 27be30d

Please sign in to comment.