mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-19 22:11:45 +08:00
Refactor new tab opening mechanism and update link options in TinyMCE v6 [SCI-8737] (#5866)
Refactor new tab opening mechanism and update link options in TinyMCE v6 [SCI-8737]
This commit is contained in:
parent
9de4d455a5
commit
c8bc4bef01
1 changed files with 22 additions and 3 deletions
25
app/javascript/packs/tiny_mce.js
vendored
25
app/javascript/packs/tiny_mce.js
vendored
|
@ -247,12 +247,12 @@ window.TinyMCE = (() => {
|
|||
object_resizing: true,
|
||||
elementpath: false,
|
||||
quickbars_insert_toolbar: false,
|
||||
default_link_target: '_blank',
|
||||
link_default_target: 'external',
|
||||
mobile: {
|
||||
menubar: 'file edit view insert format table'
|
||||
},
|
||||
target_list: [
|
||||
{ title: 'New page', value: '_blank' },
|
||||
link_target_list: [
|
||||
{ title: 'New page', value: 'external' },
|
||||
{ title: 'Same page', value: '_self' }
|
||||
],
|
||||
style_formats: [
|
||||
|
@ -432,6 +432,19 @@ window.TinyMCE = (() => {
|
|||
editor.on('init', () => {
|
||||
restoreDraftNotification(selector, editor);
|
||||
});
|
||||
|
||||
editor.on('BeforeSetContent GetContent', function(e) {
|
||||
if (e.content && e.content.includes('target="external"')) {
|
||||
const div = document.createElement('div');
|
||||
div.innerHTML = e.content;
|
||||
const links = div.querySelectorAll('a[target="external"]');
|
||||
links.forEach(link => {
|
||||
link.removeAttribute('target');
|
||||
link.setAttribute('rel', 'external');
|
||||
});
|
||||
e.content = div.innerHTML;
|
||||
}
|
||||
});
|
||||
},
|
||||
save_onsavecallback: (editor) => { saveAction(editor); }
|
||||
});
|
||||
|
@ -487,3 +500,9 @@ $(document).on('turbolinks:before-visit', (e) => {
|
|||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// Open rel="external" links in new tabs
|
||||
$('a[rel*=external]').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
window.open(this.href, '_blank', 'noopener');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue