Skip to content

Commit f31bc37

Browse files
authored
CCM-12397: resolve sonar maintainability issues (#56)
1 parent a2a596a commit f31bc37

File tree

6 files changed

+38
-74
lines changed

6 files changed

+38
-74
lines changed

docs/_includes/head_custom.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55

66
<script type="module">
7-
await window.nhsce.UseMermaid(document);
7+
await globalThis.nhsce.UseMermaid(document);
88
$(document).ready(function() {
9-
window.nhsce.hookFullScreen();
9+
globalThis.nhsce.hookFullScreen();
1010
});
1111
</script>
1212
<link rel="stylesheet" href="{{ '/assets-webpack/css/main.css' | relative_url }}">

docs/_sass/swagger-ui.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@
104104
.swagger-ui svg:not(:root) {
105105
overflow: hidden;
106106
}
107-
.swagger-ui button,
108-
.swagger-ui input,
109107
.swagger-ui optgroup,
110108
.swagger-ui select,
111109
.swagger-ui button,

docs/assets/js/imageopen.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
window.onload = function() {
1+
window.onload = function () {
22
const gallery = document.querySelectorAll("img")
3-
gallery.forEach(image =>
4-
{
5-
let src = image.getAttribute('src')
6-
7-
image.addEventListener('click', function ()
8-
{
9-
window.open(src)
10-
} )
11-
12-
image.addEventListener('mouseover', (event) =>
13-
{
14-
event.target.style.cursor = "pointer";
15-
});
16-
})
3+
for (const image of gallery) {
4+
const src = image.getAttribute('src');
5+
image.addEventListener('click', function () {
6+
window.open(src);
7+
});
8+
image.addEventListener('mouseover', (event) => {
9+
event.target.style.cursor = "pointer";
10+
});
11+
}
1712
};

docs/assets/js/nhs-notify.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ function nhsNotifyDefaults() {
2525
function tempViewFullScreen() {
2626
viewFullScreen();
2727
let buttons = document.getElementsByName(nhsNotify.buttonName);
28-
buttons.forEach((item) => {
28+
for (const item of buttons) {
2929
item.style.display = "none";
30-
});
30+
}
3131
}
3232

3333
function viewFullScreen() {
@@ -74,9 +74,9 @@ function afterChange(currentStatus, newStatus) {
7474
let buttons = document.getElementsByName(buttonName);
7575
localStorage.setItem(storageName, newStatus);
7676

77-
buttons.forEach((item) => {
77+
for ( const item of buttons ) {
7878
item.textContent = currentStatus + " View";
79-
});
79+
}
8080
}
8181

8282
function fullScreenToggle() {

docs/src/index.js

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import { Canvg, presets } from "canvg";
22
import Reveal from "reveal.js";
33
import RevealMarkdown from "reveal.js/plugin/markdown/markdown.esm.js";
4-
import Markdown from "reveal.js/plugin/markdown/markdown.esm.js";
4+
import RevealMenu from "reveal.js-menu/menu.esm.js";
55
import "reveal.js/dist/reveal.css";
66
import "reveal.js/dist/theme/black.css";
77
import "@fontsource/source-sans-pro";
8-
import RevealMenu from "reveal.js-menu/menu.esm.js";
98
import "reveal.js-menu/menu.css";
109
import mermaid from "mermaid";
11-
import mermaidAPI from "mermaid";
12-
import RevealNotes from "reveal.js";
10+
import RevealNotes from "reveal.js/plugin/notes/notes.esm.js";
11+
1312

1413
const preset = presets.offscreen();
1514

1615
let x = RevealMarkdown;
1716
let $ = require("jquery");
18-
global.jQuery = $;
19-
global.$ = $;
20-
window.jQuery = $;
21-
window.$ = $;
17+
globalThis.jQuery = $;
18+
globalThis.$ = $;
2219

2320
mermaid.startOnLoad = false;
2421

@@ -51,13 +48,6 @@ function LoadUpReveal(
5148
pluginsToLoad.push(RevealMarkdown);
5249
if (showMenu) pluginsToLoad.push(RevealMenu);
5350
pluginsToLoad.push(RevealNotes);
54-
let sleepTime = 100;
55-
let selectorToUse =
56-
"div." +
57-
deckid +
58-
" > div.slides > section.present > div.mermaid, div." +
59-
deckid +
60-
" > div.slides > section.present > pre > code.mermaid";
6151
let selectorToUseOnSlideChange = "div.mermaid, code.mermaid";
6252
let deck1 = new Reveal(document.querySelector("div." + deckid), {
6353
embedded: embed,
@@ -110,13 +100,11 @@ function LoadUpReveal(
110100
if (useMermaid) {
111101
currentSlide = deck1.getCurrentSlide();
112102
}
113-
let notes = deck1.getSlideNotes(currentSlide);
114103
UseMermaidNow(currentSlide, selectorToUseOnSlideChange);
115104
});
116105

117106
deck1.on("slidechanged", (event) => {
118107
if (useMermaid) {
119-
let notes = deck1.getSlideNotes(event.currentSlide);
120108
RemoveProcessed(event.previousSlide);
121109
UseMermaidNow(event.currentSlide, selectorToUseOnSlideChange);
122110
}
@@ -136,18 +124,17 @@ function RemoveProcessed(slideToRemoveFrom) {
136124
let selectorToUse =
137125
"div.mermaid[data-processed], code.mermaid[data-processed]";
138126
let toRender = slideToRemoveFrom.querySelectorAll(selectorToUse);
139-
toRender.forEach((item) => {
127+
for ( const item of toRender ) {
140128
if (item.hasAttribute(processedAttribName)) {
141129
while (item.firstChild) {
142-
item.removeChild(item.firstChild);
130+
item.firstChild.remove();
143131
}
144132
item.removeAttribute(processedAttribName);
145133

146134
let rawCode = item.rawCode;
147135
item.innerHTML = rawCode;
148136
}
149-
});
150-
let toRenderCheck = slideToRemoveFrom.querySelectorAll(selectorToUse);
137+
}
151138
}
152139

153140
function mermaidCb(id, addlinks) {
@@ -198,31 +185,20 @@ export async function UseMermaidNow(
198185
) {
199186
let toRender = useMermaidOn.querySelectorAll(selector);
200187
if (toRender.length > 0) {
201-
toRender.forEach((item) => {
188+
for ( const item of toRender) {
202189
if (!item.hasOwnProperty("rawCode")) item.rawCode = item.innerHTML;
203-
});
204-
205-
//await mermaid.run();
206-
207-
//await mermaid.run(undefined, toRender, (id) => {
208-
// mermaidCb(id, addlinks);
209-
//});
190+
}
210191

211192
mermaid.init(undefined, toRender, (id) => {
212193
mermaidCb(id, addlinks);
213194
});
214-
let afterRender = useMermaidOn.querySelectorAll(selector);
215-
afterRender.forEach((item) => {
216-
let x = 1;
217-
});
218195
}
219196
}
220197

221198
export async function UseMermaid(
222199
document,
223200
addlinks = true,
224201
selector = ".language-mermaid",
225-
excludeSelector = "div.slides > section"
226202
) {
227203
$(async function () {
228204
MermaidInit(addlinks);
@@ -291,7 +267,7 @@ function addLinks(id) {
291267
function drawCanvas(id, callback) {
292268
let svg = document.getElementById(id);
293269
let { width, height } = svg.getBoundingClientRect();
294-
let pixelRatio = 2; //window.devicePixelRatio || 1;
270+
let pixelRatio = 2;
295271

296272
// lets scale the canvas and change its CSS width/height to make it high res.
297273
// canvas.style.width = canvas.width +'px';
@@ -301,9 +277,6 @@ function drawCanvas(id, callback) {
301277
let canvas = (canvas = new OffscreenCanvas(newWidth, newHeight)); // document.createElement('canvas'); // Create a Canvas element.
302278
let ctx = canvas.getContext("2d"); // For Canvas returns 2D graphic.
303279

304-
// ctx.fillStyle = 'white'; // background color for the canvas
305-
// ctx.fillRect(0, 0, width, height); // fill the color on the canvas
306-
307280
// Now that its high res we need to compensate so our images can be drawn as
308281
//normal, by scaling everything up by the pixelRatio.
309282
// ctx.setTransform(pixelRatio,0,0,pixelRatio,0,0);
@@ -321,7 +294,6 @@ function drawCanvas(id, callback) {
321294
callback(img);
322295
});
323296

324-
//img.style.width = width +'px';
325297
});
326298
});
327299
}
@@ -331,8 +303,7 @@ export function hookFullScreen() {
331303
cb.checked = localStorage.getItem("cb-checked") === "true";
332304

333305
fullScreen();
334-
cb.onchange = function (evt) {
335-
let x = 1;
306+
cb.onchange = function () {
336307
fullScreen();
337308
};
338309
}

docs/webpack.config.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
22
const CopyPlugin = require("copy-webpack-plugin");
33
const devMode = process.env.NODE_ENV !== "production";
44

5-
const path = require('path');
5+
const path = require('node:path');
66

77
module.exports = {
88
entry: './src/index.js',
@@ -28,22 +28,22 @@ module.exports = {
2828
},
2929
],
3030
},
31-
plugins: [].concat(
31+
plugins:
3232
[
3333
new MiniCssExtractPlugin(
34-
{
35-
// Options similar to the same options in webpackOptions.output
36-
// all options are optional
37-
filename: "css/[name].css",
38-
chunkFilename: "[id].css",
39-
ignoreOrder: false, // Enable to remove warnings about conflicting order
40-
}),
34+
{
35+
// Options similar to the same options in webpackOptions.output
36+
// all options are optional
37+
filename: "css/[name].css",
38+
chunkFilename: "[id].css",
39+
ignoreOrder: false, // Enable to remove warnings about conflicting order
40+
}),
4141
new CopyPlugin({
4242
patterns: [
4343
{ from: "node_modules/reveal.js-menu/", to: "reveal.js-menu/" },
4444
//{ from: "node_modules/reveal.js-menu/font-awesome/", to: "reveal.js-menu/font-awesome/" },
4545
//{ from: "node_modules/reveal.js-menu/menu.css", to: "reveal.js-menu/menu.css" },
4646
],
4747
}),
48-
]),
48+
],
4949
};

0 commit comments

Comments
 (0)