Skip to content

Commit

Permalink
add: #898 options-linkTargetNewWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 committed Dec 8, 2021
1 parent 452ca55 commit df5e22f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ videoAccept : Define the "accept" attribute of the input. default: "*" {St
tableCellControllerPosition : Define position to the table cell controller('cell', 'top'). default: 'cell' {String}

// Link-----------------------------------------------------------------------------------------------------------
linkTargetNewWindow : Default checked value of the "Open in new window" checkbox. default: false {Boolean}
linkProtocol : Default protocol for the links. ('link', 'image', 'video', 'audio')
This applies to all plugins that enter the internet url. default: null {String}
linkRel : Defines "rel" attribute list of anchor tag. default: [] {Array}
Expand Down
3 changes: 3 additions & 0 deletions sample/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ <h4 style="color: #b94a48;">--Table</h4>

<br>
<h4 style="color: #b94a48;">--Link</h4>
<label><input type="checkbox" id="linkTargetNewWindow">&nbsp;&nbsp;linkTargetNewWindow</label>
<br><br>
<label><input type="checkbox" id="linkProtocol">&nbsp;&nbsp;linkProtocol</label>
<input type="text" id="linkProtocol_value" placeholder="https://" style="width: 200px">
<br><br>
Expand Down Expand Up @@ -687,6 +689,7 @@ <h2 class="sub-title">Applied options</h2>
tableCellControllerPosition: document.getElementById('tableCellControllerPosition').checked ? document.getElementById('tableCellControllerPosition_value').value : undefined,
hrItems: document.getElementById('hrItems').checked ? [ {name: "Outset", style: "border-style: outset;"} ] : undefined,
tabDisable: document.getElementById('tabDisable').checked,
linkTargetNewWindow: document.getElementById('linkTargetNewWindow').checked ? true : undefined,
linkProtocol: document.getElementById('linkProtocol').checked ? document.getElementById('linkProtocol_value').value : undefined,
linkRel: document.getElementById('linkRel').checked ? ['author', 'external', 'help', 'license', 'next', 'follow', 'nofollow', 'noreferrer', 'noopener', 'prev', 'search', 'tag'] : undefined,
linkRelDefault: document.getElementById('linkRelDefault').checked ? {default: 'nofollow', check_new_window: 'noreferrer noopener', check_bookmark: 'bookmark'} : undefined,
Expand Down
1 change: 1 addition & 0 deletions src/lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ export default {
/** Table */
options.tableCellControllerPosition = typeof options.tableCellControllerPosition === 'string' ? options.tableCellControllerPosition.toLowerCase() : 'cell';
/** Link */
options.linkTargetNewWindow = !!options.linkTargetNewWindow;
options.linkProtocol = typeof options.linkProtocol === 'string' ? options.linkProtocol : null;
options.linkRel = Array.isArray(options.linkRel) ? options.linkRel : [];
options.linkRelDefault = options.linkRelDefault || {};
Expand Down
4 changes: 4 additions & 0 deletions src/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ export interface SunEditorOptions {
* Link
* =====
*/
/**
* Default checked value of the "Open in new window" checkbox.
*/
linkTargetNewWindow?: boolean;
/**
* Protocol for the links (if link has been added without any protocol this one will be used).
*/
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/modules/_anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default {
if (!update) {
this.plugins.anchor.init.call(this, contextAnchor);
contextAnchor.anchorText.value = this.getSelection().toString().trim();
contextAnchor.newWindowCheck.checked = this.options.anchor;
contextAnchor.newWindowCheck.checked = this.options.linkTargetNewWindow;
} else if (contextAnchor.linkAnchor) {
this.context.dialog.updateModal = true;
const href = contextAnchor.linkAnchor.href;
Expand Down
4 changes: 3 additions & 1 deletion test/dev/suneditor_build_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ let ss = window.ss = suneditor.create(document.getElementById('editor1'), {
// <p>​<strong><span style="color: rgb(255, 94, 0);">SunEditor</span></strong>&nbsp;<em><span style="background-color: rgb(250, 237, 125);">distributed under</span></em>&nbsp;the <a href="https://github.com/JiHong88/SunEditor/blob/master/LICENSE.txt" target="_blank">MIT</a>&nbsp;license.<br>
// </p>
// `,
value: "ss",
linkTargetNewWindow: true,
imageAlignShow: false,
plugins: {...{custom_container}, ...plugins},
katex: Katex,
Expand Down Expand Up @@ -481,7 +483,7 @@ let ss = window.ss = suneditor.create(document.getElementById('editor1'), {
// italic: 'u'
// },
tableCellControllerPosition: 'top',
lang: lang.fr,
// lang: lang.fr,
// value: '',
// imageAccept: "*",
// videoAccept: "*",
Expand Down

0 comments on commit df5e22f

Please sign in to comment.