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

Commit

Permalink
fix(Javascript): Allow themes to be loaded in Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Feb 12, 2020
1 parent 3b50050 commit 4f307e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/shared/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const onReadyHandler = (): void => {
}

export const load = (): void => {
// Do not do anything if not in the browser
// (e.g. when loading themes in Node.js)
if (typeof window === 'undefined') return

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', onReadyHandler)
} else {
Expand Down
9 changes: 9 additions & 0 deletions src/themes/plos/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { load } from '../../shared/js'

load()

/*
This is old code, currently commented out with the view to
consolidating in shared.
export const init = (): void => {
const referenceListItemSel = '[itemprop="references"] > li'
const datePublishedSel = '[itemprop="datePublished"]'
Expand All @@ -22,3 +30,4 @@ export const init = (): void => {
}
document.addEventListener('DOMContentLoaded', init)
*/

0 comments on commit 4f307e5

Please sign in to comment.