editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

Inline link tool, open in new window option

Open sietseveenman opened this issue 5 years ago • 12 comments

I would like to add a 'open in new window' checkbox to the inline link tool. this would add target="_blank" to the element. How can I overwrite the default inline link tool? I think this would be a very useful standard feature for the inline link tool.

sietseveenman avatar Mar 12 '20 13:03 sietseveenman

Also faced this issue but quickly managed to fix it with JS. Built in would be nice though.

const links = document.getElementsByTagName('a');
for (let link of links) {
  link.setAttribute('target', '_blank')
  link.setAttribute('rel', 'noopener')
  link.setAttribute('aria-label', 'External link (opens in new tab)')
}

arpadgabor avatar Mar 12 '20 19:03 arpadgabor

@sietseveenman hi! it will be added in the next 2.17 release

khaydarov avatar Mar 14 '20 19:03 khaydarov

@khaydarov awesome new release! But I think my issue was misunderstood. I would like to add a checkbox input to the Inline tool (see screenshot). It would be great to have an option to add target="_blank" to the link created in the text

Screenshot 2020-03-16 at 14 01 27

sietseveenman avatar Mar 16 '20 13:03 sietseveenman

In 2.17 we have resolved #1028, not this issue.

neSpecc avatar Mar 16 '20 13:03 neSpecc

In 2.17 we have resolved #1028, not this issue.

Thanks neSpecc. I am working an a custom inline toolbar button to add the target="_blank". That will be fine for now but it would be great to have this functionality baked in to the inline link tool.

sietseveenman avatar Mar 16 '20 14:03 sietseveenman

Hi @neSpecc, hi @sietseveenman.

We had the same issue and created our own Inline "Link" Tool based on the current implementation (https://github.com/codex-team/editor.js/blob/master/src/components/inline-tools/inline-tool-link.ts).

It looks like this now:

image

I share the code with anyone interested: https://gist.github.com/natterstefan/0e6c22ed7af59c221b8a80e68b5cdb22

natterstefan avatar Mar 16 '20 15:03 natterstefan

Hey @natterstefan That is exactly what I meant, looks good! Do you intent to use the 'title' input to add a title="yadadoodle" to the link for when the user hovers the link?

@neSpecc This would be a great standard feature imho

sietseveenman avatar Mar 16 '20 16:03 sietseveenman

Hi @sietseveenman,

thank you very much.

Do you intent to use the 'title' input to add a title="yadadoodle" to the link for when the user hovers the link?

Yes, exactly.

@neSpecc, let me know, if I can be of help. Check out the gist for more details.

natterstefan avatar Mar 16 '20 16:03 natterstefan

+1 for this feature request :) I've currently fixed this by explicitly adding the '_blank' property to all links. At the moment I'm usually linking to pdfs so thats fine. But obviously it would be better to make the blank property optional with some kind of checkbox as proposed by @natterstefan

MichaelGr3 avatar Mar 31 '20 23:03 MichaelGr3

@neSpecc would it be possible to set a default target for all links? i would like all links to have target="_blank"

bettysteger avatar Feb 05 '24 14:02 bettysteger