Open link in a new tab in /pad
This commit is contained in:
parent
2d30393243
commit
a0340f1419
58
www/pad/links.js
Normal file
58
www/pad/links.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
define(function () {
|
||||||
|
// Adds a context menu entry to open the selected link in a new tab.
|
||||||
|
// See https://github.com/xwiki-contrib/application-ckeditor/commit/755d193497bf23ed874d874b4ae92fbee887fc10
|
||||||
|
return {
|
||||||
|
addSupportForOpeningLinksInNewTab : function (Ckeditor) {
|
||||||
|
return function(event) {
|
||||||
|
var editor = event.editor;
|
||||||
|
if (!Ckeditor.plugins.link) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editor.addCommand( 'openLink', {
|
||||||
|
exec: function(editor) {
|
||||||
|
var anchor = getActiveLink(editor);
|
||||||
|
if (anchor) {
|
||||||
|
var href = anchor.getAttribute('href');
|
||||||
|
if (href) {
|
||||||
|
window.open(href);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (typeof editor.addMenuItem === 'function') {
|
||||||
|
editor.addMenuItem('openLink', {
|
||||||
|
label: 'Open Link in New Tab',
|
||||||
|
command: 'openLink',
|
||||||
|
group: 'link',
|
||||||
|
order: -1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (editor.contextMenu) {
|
||||||
|
editor.contextMenu.addListener(function(startElement, selection, path) {
|
||||||
|
if (startElement) {
|
||||||
|
var anchor = getActiveLink(editor);
|
||||||
|
if (anchor && anchor.getAttribute('href')) {
|
||||||
|
return {openLink: Ckeditor.TRISTATE_OFF};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
editor.contextMenu._.panelDefinition.css.push('.cke_button__openLink_icon {' +
|
||||||
|
Ckeditor.skin.getIconStyle('link') + '}');
|
||||||
|
}
|
||||||
|
// Returns the DOM element of the active (currently focused) link. It has also support for linked image widgets.
|
||||||
|
// @return {CKEDITOR.dom.element}
|
||||||
|
var getActiveLink = function(editor) {
|
||||||
|
var anchor = Ckeditor.plugins.link.getSelectedLink(editor),
|
||||||
|
// We need to do some special checking against widgets availability.
|
||||||
|
activeWidget = editor.widgets && editor.widgets.focused;
|
||||||
|
// If default way of getting links didn't return anything useful..
|
||||||
|
if (!anchor && activeWidget && activeWidget.name == 'image' && activeWidget.parts.link) {
|
||||||
|
// Since CKEditor 4.4.0 image widgets may be linked.
|
||||||
|
anchor = activeWidget.parts.link;
|
||||||
|
}
|
||||||
|
return anchor;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
@ -12,12 +12,13 @@ define([
|
|||||||
'/common/cryptpad-common.js',
|
'/common/cryptpad-common.js',
|
||||||
'/common/visible.js',
|
'/common/visible.js',
|
||||||
'/common/notify.js',
|
'/common/notify.js',
|
||||||
|
'/pad/links.js',
|
||||||
'/bower_components/file-saver/FileSaver.min.js',
|
'/bower_components/file-saver/FileSaver.min.js',
|
||||||
'/bower_components/diff-dom/diffDOM.js',
|
'/bower_components/diff-dom/diffDOM.js',
|
||||||
'/bower_components/jquery/dist/jquery.min.js',
|
'/bower_components/jquery/dist/jquery.min.js',
|
||||||
], function (Crypto, realtimeInput, Hyperjson,
|
], function (Crypto, realtimeInput, Hyperjson,
|
||||||
Toolbar, Cursor, JsonOT, TypingTest, JSONSortify, TextPatcher, Cryptpad,
|
Toolbar, Cursor, JsonOT, TypingTest, JSONSortify, TextPatcher, Cryptpad,
|
||||||
Visible, Notify) {
|
Visible, Notify, Links) {
|
||||||
var $ = window.jQuery;
|
var $ = window.jQuery;
|
||||||
var saveAs = window.saveAs;
|
var saveAs = window.saveAs;
|
||||||
var Messages = Cryptpad.Messages;
|
var Messages = Cryptpad.Messages;
|
||||||
@ -102,6 +103,7 @@ define([
|
|||||||
customConfig: '/customize/ckeditor-config.js',
|
customConfig: '/customize/ckeditor-config.js',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
editor.on('instanceReady', Links.addSupportForOpeningLinksInNewTab(Ckeditor));
|
||||||
editor.on('instanceReady', function (Ckeditor) {
|
editor.on('instanceReady', function (Ckeditor) {
|
||||||
var $bar = $('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox');
|
var $bar = $('#pad-iframe')[0].contentWindow.$('#cke_1_toolbox');
|
||||||
var parsedHash = Cryptpad.parsePadUrl(window.location.href);
|
var parsedHash = Cryptpad.parsePadUrl(window.location.href);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user