Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 605e818

Browse files
Zyntondmo-odoo
authored andcommitted
[ADD] Odoo: open link dialog on double click a link
1 parent def88d5 commit 605e818

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { FormatDomObjectModifierRenderer } from '../../plugin-renderer-dom-object/src/FormatDomObjectModifierRenderer';
2+
import { DomObjectRenderingEngine, DomObject } from '../../plugin-renderer-dom-object/src/DomObjectRenderingEngine';
3+
import { Format } from '../../core/src/Format';
4+
import { LinkFormat } from '../../plugin-link/src/LinkFormat';
5+
6+
export class LinkFormatDomObjectModifierRenderer extends FormatDomObjectModifierRenderer {
7+
static id = DomObjectRenderingEngine.id;
8+
engine: DomObjectRenderingEngine;
9+
predicate = LinkFormat;
10+
11+
/**
12+
* @override
13+
*/
14+
async render(format: Format, contents: DomObject[]): Promise<DomObject[]> {
15+
const domObjects = await super.render(format, contents);
16+
const link = domObjects[0];
17+
if ('tag' in link) {
18+
const dbclickCallback = (): void => {
19+
this.engine.editor.execCommand('openLinkDialog');
20+
};
21+
22+
const savedAttach = link.attach;
23+
link.attach = (el: HTMLElement): void => {
24+
if (savedAttach) {
25+
savedAttach(el);
26+
}
27+
el.addEventListener('dblclick', dbclickCallback);
28+
};
29+
const savedDetach = link.detach;
30+
link.detach = (el: HTMLElement): void => {
31+
if (savedDetach) {
32+
savedDetach(el);
33+
}
34+
el.removeEventListener('dblclick', dbclickCallback);
35+
};
36+
}
37+
return domObjects;
38+
}
39+
}

packages/plugin-odoo/src/Odoo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { isInBlockquote, Blockquote } from '../../plugin-blockquote/src/Blockquo
3232
import { OdooTableDomObjectRenderer } from './OdooTableDomObjectRenderer';
3333
import { FontAwesomeNode } from '../../plugin-fontawesome/src/FontAwesomeNode';
3434
import { Core } from '../../core/src/Core';
35+
import { LinkFormatDomObjectModifierRenderer } from './LinkFormatDomObjectModifierRenderer';
3536

3637
export enum OdooPaddingClasses {
3738
NONE = 'padding-none',
@@ -186,6 +187,7 @@ export class Odoo<T extends JWPluginConfig = JWPluginConfig> extends JWPlugin<T>
186187
OdooImageDomObjectRenderer,
187188
OdooFontAwesomeDomObjectRenderer,
188189
OdooTableDomObjectRenderer,
190+
LinkFormatDomObjectModifierRenderer,
189191
],
190192
components: [
191193
{

0 commit comments

Comments
 (0)