Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
fix(Demos): Clean up demos, move script from .html to .ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijay committed Aug 30, 2019
1 parent 2cc7861 commit 446794e
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 22,789 deletions.
65 changes: 65 additions & 0 deletions src/common/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,68 @@
*/

import './syntaxHighlight'

const ready = (): void => {
const themeSelect = document.querySelector('#theme-select')

if (themeSelect) {
themeSelect.addEventListener('change', event => {
const element = event.target as HTMLInputElement
const theme = element.value

document
.querySelectorAll('link[rel="stylesheet"]')
.forEach(node =>
node.id === theme
? ((<HTMLInputElement>node).disabled = false)
: ((<HTMLInputElement>node).disabled = true)
)
})
}

const referenceListItemSel = '[itemprop="references"] > li'
const titleSel = '[itemprop="title"]'
const datePublishedSel = '[itemprop="datePublished"]'
const publicationIssueSel =
'[itemtype="https://schema.stenci.la/PublicationIssue"]'

document.querySelectorAll(referenceListItemSel).forEach(node => {
const datePublished = node.querySelector(datePublishedSel) as HTMLElement
const title = node.querySelector(titleSel) as HTMLElement

if (title) {
const titleCopy = title.cloneNode(true) as HTMLElement

// Add title node after original datePublished node
if (datePublished && datePublished.parentNode) {
datePublished.parentNode.insertBefore(
titleCopy,
datePublished.nextSibling
)
}

// Add datePublished node after PublicationIssue node (if exists)
const publicationIssue = node.querySelector(
publicationIssueSel
) as HTMLElement
const datePublishedCopy = datePublished.cloneNode(true) as HTMLElement

if (publicationIssue && publicationIssue.parentNode) {
publicationIssue.parentNode.insertBefore(
datePublishedCopy,
publicationIssue.nextSibling
)
} else {
// Otherwise, add node after titleCopy
if (titleCopy && titleCopy.parentNode) {
titleCopy.parentNode.insertBefore(
datePublishedCopy,
titleCopy.nextSibling
)
}
}
}
})
}

document.addEventListener('DOMContentLoaded', ready)
Loading

0 comments on commit 446794e

Please sign in to comment.