mirror of
https://github.com/codex-team/editor.js
synced 2024-06-09 17:32:31 +02:00
Add nonce to codex-tooltip
This commit is contained in:
parent
ee188bfe5d
commit
1f759cc341
|
@ -46,14 +46,14 @@ export default class TooltipAPI extends Module {
|
|||
* @param {TooltipOptions} options - tooltip options
|
||||
*/
|
||||
public show(element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void {
|
||||
tooltip.show(element, content, options);
|
||||
tooltip.show(element, content, options, this.config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method hides tooltip on HTML page
|
||||
*/
|
||||
public hide(): void {
|
||||
tooltip.hide();
|
||||
tooltip.hide(false, this.config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,6 +64,6 @@ export default class TooltipAPI extends Module {
|
|||
* @param {TooltipOptions} options - tooltip options
|
||||
*/
|
||||
public onHover(element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void {
|
||||
tooltip.onHover(element, content, options);
|
||||
tooltip.onHover(element, content, options, this.config);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
import CodeXTooltips from 'codex-tooltip';
|
||||
import type { TooltipOptions, TooltipContent } from 'codex-tooltip/types';
|
||||
import { EditorConfig } from '../../../types';
|
||||
|
||||
/**
|
||||
* Tooltips lib: CodeX Tooltips
|
||||
|
@ -16,13 +17,15 @@ let lib: null | CodeXTooltips = null;
|
|||
* If library is needed, but it is not initialized yet, this function will initialize it
|
||||
*
|
||||
* For example, if editor was destroyed and then initialized again
|
||||
*
|
||||
* @param {string} nonce - The nonce to apply to the injected styles.
|
||||
*/
|
||||
function prepare(): void {
|
||||
export function prepare(nonce?: string): void {
|
||||
if (lib) {
|
||||
return;
|
||||
}
|
||||
|
||||
lib = new CodeXTooltips();
|
||||
lib = new CodeXTooltips(nonce);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,9 +34,10 @@ function prepare(): void {
|
|||
* @param {HTMLElement} element - any HTML element in DOM
|
||||
* @param content - tooltip's content
|
||||
* @param options - showing settings
|
||||
* @param {EditorConfig} config - The EditorJS config
|
||||
*/
|
||||
export function show(element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void {
|
||||
prepare();
|
||||
export function show(element: HTMLElement, content: TooltipContent, options?: TooltipOptions, config?: EditorConfig): void {
|
||||
prepare(config?.style.nonce);
|
||||
|
||||
lib?.show(element, content, options);
|
||||
}
|
||||
|
@ -42,9 +46,10 @@ export function show(element: HTMLElement, content: TooltipContent, options?: To
|
|||
* Hides tooltip
|
||||
*
|
||||
* @param skipHidingDelay — pass true to immediately hide the tooltip
|
||||
* @param {EditorConfig} config - The EditorJS config
|
||||
*/
|
||||
export function hide(skipHidingDelay = false): void {
|
||||
prepare();
|
||||
export function hide(skipHidingDelay = false, config?: EditorConfig): void {
|
||||
prepare(config?.style.nonce);
|
||||
|
||||
lib?.hide(skipHidingDelay);
|
||||
}
|
||||
|
@ -55,9 +60,10 @@ export function hide(skipHidingDelay = false): void {
|
|||
* @param {HTMLElement} element - any HTML element in DOM
|
||||
* @param content - tooltip's content
|
||||
* @param options - showing settings
|
||||
* @param {EditorConfig} config - The EditorJS config
|
||||
*/
|
||||
export function onHover(element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void {
|
||||
prepare();
|
||||
export function onHover(element: HTMLElement, content: TooltipContent, options?: TooltipOptions, config?: EditorConfig): void {
|
||||
prepare(config?.style.nonce);
|
||||
|
||||
lib?.onHover(element, content, options);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue