Skip to content

Commit 40e8beb

Browse files
committed
Add link.openInNewTabCheckboxDefaultChecked option
Fixes #1289
1 parent 3933d56 commit 40e8beb

4 files changed

Lines changed: 78 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
## 4.11.12
1313

14+
#### :rocket: New Feature
15+
16+
- Add `link.openInNewTabCheckboxDefaultChecked` option to set default state of "Open in new tab" checkbox when inserting a new link ([#1289](https://github.com/xdan/jodit/issues/1289))
17+
1418
#### :bug: Bug Fix
1519

1620
- Fix pasting table into table cell creating invalid nesting and trailing empty paragraph ([#1314](https://github.com/xdan/jodit/issues/1314))

src/plugins/link/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ declare module 'jodit/config' {
5252
*/
5353
openInNewTabCheckbox: boolean;
5454

55+
/**
56+
* Default value for the `Open in new tab` checkbox when inserting a new link.
57+
*/
58+
openInNewTabCheckboxDefaultChecked: boolean;
59+
5560
/**
5661
* Use an input text to ask the classname or a select or not ask
5762
*/
@@ -89,6 +94,7 @@ Config.prototype.link = {
8994
processPastedLink: true,
9095
noFollowCheckbox: true,
9196
openInNewTabCheckbox: true,
97+
openInNewTabCheckboxDefaultChecked: false,
9298
modeClassName: 'input',
9399
selectMultipleClassName: true,
94100
preventReadOnlyNavigation: true,

src/plugins/link/link.test.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,69 @@ describe('Link plugin', () => {
498498
});
499499
});
500500

501+
describe('openInNewTabCheckboxDefaultChecked', () => {
502+
it('Should check "Open in new tab" by default when option is true', () => {
503+
const editor = getJodit({
504+
link: {
505+
openInNewTabCheckboxDefaultChecked: true
506+
}
507+
});
508+
509+
editor.value = '<p>|test</p>';
510+
setCursorToChar(editor);
511+
512+
clickButton('link', editor);
513+
514+
const popup = getOpenedPopup(editor);
515+
const target = popup.querySelector('[ref=target_checkbox]');
516+
517+
expect(target).is.not.null;
518+
expect(target.checked).is.true;
519+
});
520+
521+
it('Should not check "Open in new tab" by default when option is false', () => {
522+
const editor = getJodit({
523+
link: {
524+
openInNewTabCheckboxDefaultChecked: false
525+
}
526+
});
527+
528+
editor.value = '<p>|test</p>';
529+
setCursorToChar(editor);
530+
531+
clickButton('link', editor);
532+
533+
const popup = getOpenedPopup(editor);
534+
const target = popup.querySelector('[ref=target_checkbox]');
535+
536+
expect(target).is.not.null;
537+
expect(target.checked).is.false;
538+
});
539+
540+
it('Should insert link with target="_blank" when default checked is true', () => {
541+
const editor = getJodit({
542+
link: {
543+
openInNewTabCheckboxDefaultChecked: true
544+
}
545+
});
546+
547+
editor.value = '<p>|test</p>';
548+
setCursorToChar(editor);
549+
550+
clickButton('link', editor);
551+
552+
const popup = getOpenedPopup(editor);
553+
const url = popup.querySelector('[ref=url_input]');
554+
url.value = 'https://xdsoft.net';
555+
556+
simulateEvent('submit', popup.querySelector('form'));
557+
558+
expect(editor.value).equals(
559+
'<p><a href="https://xdsoft.net" target="_blank">https://xdsoft.net</a>test</p>'
560+
);
561+
});
562+
});
563+
501564
describe('In dialog', () => {
502565
describe('Edit exists link', () => {
503566
describe('Content input was not changed', () => {

src/plugins/link/link.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export class link extends Plugin {
150150
const i18n = jodit.i18n.bind(jodit),
151151
{
152152
openInNewTabCheckbox,
153+
openInNewTabCheckboxDefaultChecked,
153154
noFollowCheckbox,
154155
formTemplate,
155156
formClassName,
@@ -234,6 +235,10 @@ export class link extends Plugin {
234235
insert.textContent = i18n('Update');
235236
} else {
236237
Dom.hide(unlink);
238+
239+
if (openInNewTabCheckbox && target_checkbox) {
240+
target_checkbox.checked = openInNewTabCheckboxDefaultChecked;
241+
}
237242
}
238243

239244
jodit.editor.normalize();

0 commit comments

Comments
 (0)