Skip to content

Commit 241e3ab

Browse files
committed
- In Readonly mode, the ability to disable navigation by links has been added. By default, the option is enabled.
1 parent 74a3bf1 commit 241e3ab

File tree

4 files changed

+95
-32
lines changed

4 files changed

+95
-32
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
> - :house: [Internal]
1010
> - :nail_care: [Polish]
1111

12+
## 4.5.17
13+
14+
### :rocket: New Feature
15+
16+
- In Readonly mode, the ability to disable navigation by links has been added. By default, the option is enabled.
17+
18+
```js
19+
const editor = Jodit.make('#editor', {
20+
readonly: true,
21+
link: {
22+
preventReadOnlyNavigation: true
23+
}
24+
});
25+
```
26+
1227
## 4.5.12
1328

1429
#### :house: Internal

public/stand.html

+55-29
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
<h1>Jodit Test Document</h1>
4242
<form id="form">
4343
<div id="app"></div>
44-
<textarea id="editorNative"></textarea>
44+
<textarea id="editorNative">
45+
Hello <a href="https://xdsoft.net/jodit">Jodit</a> World!
46+
</textarea>
4547
</form>
4648
</div>
4749
<script>
@@ -51,10 +53,59 @@ <h1>Jodit Test Document</h1>
5153
// root.innerHTML = '<link rel="stylesheet" href="./build/es2021/jodit.fat.min.css"/><div id="edit"></div>';
5254
// const editor = Jodit.make('root.getElementById('edit')', {
5355
const editor = Jodit.make('#editorNative', {
54-
toolbarInlineForSelection: true,
55-
commandToHotkeys: {
56-
someCustomCommand: 'shift+space'
56+
// readonly: true,
57+
showXPathInStatusbar: false,
58+
placeholder: "Start typing...",
59+
toolbar: true,
60+
askBeforePasteHTML: false,
61+
cleanHTML: {
62+
pastedHTML: true,
5763
},
64+
buttons: [
65+
"fullsize",
66+
],
67+
style: {
68+
fontSize: "16px",
69+
lineHeight: "1.5",
70+
padding: "10px",
71+
// minheight: "65vh",
72+
maxheight: "65vh",
73+
},
74+
// iframe: true,
75+
iframeCSS: `
76+
body {
77+
margin: 0;
78+
padding: 0;
79+
font-size: 16px;
80+
line-height: 1.5;
81+
}
82+
table {
83+
border-collapse: collapse !important;
84+
width: 100% !important;
85+
border: 2px solid #000 !important;
86+
}
87+
th, td {
88+
border: 2px solid #000 !important;
89+
padding: 8px !important;
90+
text-align: left !important;
91+
}
92+
th {
93+
background-color: #f2f2f2 !important;
94+
}
95+
`,
96+
contentStyle: `
97+
table {
98+
border-collapse: collapse;
99+
width: 100%;
100+
border: 2px solid black !important;
101+
}
102+
th, td {
103+
border: 2px solid black !important;
104+
padding: 8px !important;
105+
text-align: left;
106+
}
107+
`,
108+
maxheight: "65vh",
58109
// direction: 'rtl',
59110
// tabIndex: 0,
60111
// shadowRoot: root,
@@ -141,31 +192,6 @@ <h1>Jodit Test Document</h1>
141192
},
142193
},
143194
});
144-
145-
editor.value = '<p style="font-size: 16.5pt; margin: 0"><a href="stand.html"><img src="https://xdsoft.net/jodit/finder/files/pexels-arianna-jade-4006617.jpg" id="lio" alt="Tada" style="margin: 1px 2px 3px 4px; border: 2px solid #f00;" title="Ola ha" width="300"></a>Body Subtitle</p>\n' +
146-
'<table><tbody><tr><th>header</th><td>1</td></tr></tbody></table>' +
147-
'<p style="font-size: 10pt; line-height: normal; margin: 7px 0 0 0;">To modify this template, place it into your Outlook editor.</p>';
148-
editor.value = '';
149-
// editor.events.fire(
150-
// 'openImageProperties',
151-
// editor.editor.querySelector('img')
152-
// );
153-
btn.onclick = () => {
154-
const start = performance.now();
155-
for (let i = 0; i < 100; i++) {
156-
editor.toolbar.build(editor.o.buttons);
157-
}
158-
const res = performance.now() - start;
159-
form.appendChild(
160-
editor.create.fromHTML(
161-
'<input name="content" value="' + res + '">'
162-
)
163-
);
164-
};
165-
166-
// delete editor;
167-
// const box = new UIBox(editor1);
168-
// alert(box.container.outerHTML);
169195
</script>
170196
<style>
171197
.class1 {

src/plugins/link/config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ declare module 'jodit/config' {
7373
selectOptionsClassName: IUIOption[];
7474

7575
hotkeys: string[];
76+
77+
/**
78+
* Prevent navigation to the link if it is readonly. Default: true
79+
*/
80+
preventReadOnlyNavigation: boolean;
7681
};
7782
}
7883
}
@@ -86,6 +91,7 @@ Config.prototype.link = {
8691
openInNewTabCheckbox: true,
8792
modeClassName: 'input',
8893
selectMultipleClassName: true,
94+
preventReadOnlyNavigation: true,
8995
selectSizeClassName: 3,
9096
selectOptionsClassName: [],
9197
hotkeys: ['ctrl+k', 'cmd+k']

src/plugins/link/link.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ export class link extends Plugin {
4343
/** @override */
4444
protected override afterInit(jodit: IJodit): void {
4545
if (jodit.o.link.followOnDblClick) {
46-
jodit.e.on('dblclick.link', this.onDblClickOnLink);
46+
jodit.e.on('dblclick.link', this.__onDblClickOnLink);
4747
}
4848

49+
jodit.e.on(jodit.editor, 'click.link', this.__onClickReadOnlyLink);
50+
4951
if (jodit.o.link.processPastedLink) {
5052
jodit.e.on('processPaste.link', this.onProcessPasteLink);
5153
}
@@ -76,7 +78,7 @@ export class link extends Plugin {
7678
}
7779

7880
@autobind
79-
private onDblClickOnLink(e: MouseEvent): void {
81+
private __onDblClickOnLink(e: MouseEvent): void {
8082
if (!Dom.isTag(e.target, 'a')) {
8183
return;
8284
}
@@ -348,9 +350,23 @@ export class link extends Plugin {
348350
protected override beforeDestruct(jodit: IJodit): void {
349351
jodit.e
350352
.off('generateLinkForm.link', this.__generateForm)
351-
.off('dblclick.link', this.onDblClickOnLink)
353+
.off('dblclick.link', this.__onDblClickOnLink)
354+
.off(jodit.editor, 'click.link', this.__onClickReadOnlyLink)
352355
.off('processPaste.link', this.onProcessPasteLink);
353356
}
357+
358+
@autobind
359+
private __onClickReadOnlyLink(e: MouseEvent): void {
360+
const { jodit } = this;
361+
362+
if (
363+
jodit.o.readonly &&
364+
jodit.o.link.preventReadOnlyNavigation &&
365+
Dom.isTag(e.target, 'a')
366+
) {
367+
e.preventDefault();
368+
}
369+
}
354370
}
355371

356372
pluginSystem.add('link', link);

0 commit comments

Comments
 (0)