Skip to content

Commit

Permalink
enhance(noscript): turn <noscript> into css classes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Aug 6, 2024
1 parent 4f0a8e8 commit ff16f47
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
14 changes: 6 additions & 8 deletions site/GrapherPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ window.Grapher.renderSingleGrapherOnGrapherPage(jsonConfig)`
<meta property="og:image:width" content={imageWidth} />
<meta property="og:image:height" content={imageHeight} />
<IFrameDetector />
<noscript>
<style>{`
figure { display: none !important; }
`}</style>
</noscript>
<link rel="preconnect" href={dataApiOrigin} />
{flatten(
variableIds.map((variableId) =>
Expand Down Expand Up @@ -120,18 +115,21 @@ window.Grapher.renderSingleGrapherOnGrapherPage(jsonConfig)`
<body className={GRAPHER_PAGE_BODY_CLASS}>
<SiteHeader baseUrl={baseUrl} />
<main>
<figure data-grapher-src={`/grapher/${grapher.slug}`}>
<figure
className="js--hide-if-js-disabled"
data-grapher-src={`/grapher/${grapher.slug}`}
>
<LoadingIndicator />
</figure>
<noscript id="fallback">
<div className="js--hide-if-js-enabled" id="fallback">
{grapher.slug && (
<GrapherImage
slug={grapher.slug}
alt={grapher.title}
/>
)}
<p>Interactive visualization requires JavaScript</p>
</noscript>
</div>

{((relatedArticles && relatedArticles.length !== 0) ||
(relatedCharts && relatedCharts.length !== 0)) && (
Expand Down
4 changes: 2 additions & 2 deletions site/blocks/RelatedCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export const RelatedCharts = ({
key={activeChartSlug}
data-grapher-src={grapherUrl}
>
<noscript>
<div className="js--hide-if-js-enabled">
<a href={grapherUrl}>
<GrapherImage
slug={activeChartSlug}
alt={activeChart?.title}
/>
</a>
</noscript>
</div>
</figure>
)

Expand Down
11 changes: 11 additions & 0 deletions site/css/noscript.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.js--hide-if-js-disabled {
@at-root html.js-disabled & {
display: none;
}
}

.js--hide-if-js-enabled {
@at-root html.js-enabled & {
display: none;
}
}
4 changes: 2 additions & 2 deletions site/gdocs/components/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ export default function Chart({
}}
>
{isExplorer ? (
<noscript>
<div className="js--hide-if-js-enabled">
<p className="align-center">
Interactive visualization requires JavaScript.
</p>
</noscript>
</div>
) : (
resolvedSlug && (
<a href={resolvedUrl} target="_blank" rel="noopener">
Expand Down
1 change: 1 addition & 0 deletions site/owid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@import "css/grid.scss";
@import "css/layout.scss";
@import "css/general.scss";
@import "css/noscript.scss";
@import "./collections/CollectionsPage.scss";
@import "./SiteSearchNavigation.scss";
@import "./site/search/Autocomplete.scss";
Expand Down

0 comments on commit ff16f47

Please sign in to comment.