如何加上「;点击链接弹出窗口“;进入TinyMCE 4
我在这张照片上实现了这样的想法: 如果单击链接,将出现弹出窗口,您可以跟随该链接。如何加上「;点击链接弹出窗口“;进入TinyMCE 4,tinymce,tinymce-4,Tinymce,Tinymce 4,我在这张照片上实现了这样的想法: 如果单击链接,将出现弹出窗口,您可以跟随该链接。jQuery(函数($){ jQuery(function($){ /** * add the follow link popup to all TinyMCE instances */ if (!window.tinymce) return; tinymce.on('AddEditor', function( event ) { tinymce.editors.forEach(function(e
jQuery(函数($){
jQuery(function($){
/**
* add the follow link popup to all TinyMCE instances
*/
if (!window.tinymce) return;
tinymce.on('AddEditor', function( event ) {
tinymce.editors.forEach(function(editor) {
if (!editor.isFollowLinkAdded) {
editor.isFollowLinkAdded = true;
editor.on('blur', function(e) {
jQuery(e.target.contentDocument.body).find('#followLink').remove();
});
editor.on('click', function(e) {
var link = jQuery(e.target).closest('a');
jQuery(e.view.document.body).find('#followLink').remove();
if (link.length) {
e.preventDefault();
var POPUP_WIDTH = 215,
isRightSide = (jQuery(e.view.document).width()-e.pageX) >= POPUP_WIDTH,
boxCss = {
top: e.pageY,
padding: '6px 10px',
position: 'absolute',
backgroundColor: '#ffffff',
border: '1px solid #a8a8a8',
borderRadius: '2px',
boxShadow: '0 1px 3px rgba(0, 0, 0, 0.2)',
color: '#666666',
cursor: 'pointer',
whiteSpace: 'nowrap',
zIndex: 502
};
boxCss[(isRightSide) ? 'left' : 'right'] = (isRightSide) ? e.pageX : jQuery(e.view.document).width()-e.pageX;
jQuery('<a/>', {
href: link.attr('href'),
text: link.attr('href'),
target: '_blank'
}).css({
cursor: 'pointer',
display: 'inline-block',
maxWidth: '100px',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}).wrap(
jQuery('<p/>', {
text: 'Click to follow: ',
id: 'followLink',
}).on('click', function(){
var win = window.open(link.attr('href'), '_blank');
win.focus();
}).css(boxCss)
).parent().appendTo(e.view.document.body);
}
});
}
});
}, true );
/**
*将以下链接弹出窗口添加到所有TinyMCE实例
*/
如果(!window.tinymce)返回;
tinymce.on('AddEditor',函数(事件){
tinymce.editors.forEach(函数(编辑器){
如果(!editor.isFollowLinkAdded){
editor.isFollowLinkAdded=true;
编辑器.on('blur',函数(e){
jQuery(e.target.contentDocument.body).find('#followLink').remove();
});
编辑者:点击功能(e){
var-link=jQuery(e.target).closest('a');
jQuery(e.view.document.body).find('#followLink').remove();
if(链接长度){
e、 预防默认值();
var\u宽度=215,
isRightSide=(jQuery(e.view.document).width()-e.pageX)>=弹出窗口宽度,
boxCss={
上图:e.pageY,
填充:“6px 10px”,
位置:'绝对',
背景颜色:“#ffffff”,
边框:“1px实心#a8a8a8”,
边界半径:“2px”,
boxShadow:'0 1px 3px rgba(0,0,0,0.2)',
颜色:“#666666”,
光标:“指针”,
空白:“nowrap”,
zIndex:502
};
boxCss[(isRightSide)-“左”:“右”]=(isRightSide)–e.pageX:jQuery(e.view.document).width()-e.pageX;
jQuery(“”{
href:link.attr('href'),
文本:link.attr('href'),
目标:“\u blank”
}).css({
光标:“指针”,
显示:“内联块”,
maxWidth:'100px',
溢出:“隐藏”,
textOverflow:'省略号',
空白:“nowrap”
}).包裹(
jQuery(“”{
文本:“单击以跟随:”,
id:“followLink”,
}).on('单击',函数()){
var win=window.open(link.attr('href'),'u blank');
win.focus();
}).css(boxCss)
).parent().appendTo(如view.document.body);
}
});
}
});
},对);
})) TinyMCE 4(4.5.3)的最新版本包括在编辑器的右键单击菜单中打开链接的选项-无需编写自己的自定义代码。感谢您的回答。我可以作为一个附加选项,但是,当用户点击编辑器中的任何链接时,显示follow链接弹出窗口会更方便/明显,就像谷歌文档/工作表一样。