Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ export default class Tooltip {

/**
* Module constructor
*
* @param {string} nonce - The nonce to apply to the injected styles.
*/
constructor() {
this.loadStyles();
constructor(nonce?: string) {
this.loadStyles(nonce);
this.prepare();

window.addEventListener('scroll', this.handleWindowScroll, {passive: true});
Expand Down Expand Up @@ -233,8 +235,10 @@ export default class Tooltip {

/**
* Append CSS file
*
* @param {string} nonce - The nonce to apply to the injected styles.
*/
private loadStyles(): void {
private loadStyles(nonce?: string): void {
const id = 'codex-tooltips-style';

if (document.getElementById(id)) {
Expand All @@ -247,6 +251,11 @@ export default class Tooltip {
id,
});

// Apply nonce to injected styles.
if (nonce) {
tag.setAttribute('nonce', nonce);
}

/**
* Append styles at the top of HEAD tag
*/
Expand Down