Jquery tinymce,阻止移除对象?
你好,我现在正在使用tinymce最新版本。我在我的内容中有一张图片,我禁止它被调整大小Jquery tinymce,阻止移除对象?,jquery,tinymce,Jquery,Tinymce,你好,我现在正在使用tinymce最新版本。我在我的内容中有一张图片,我禁止它被调整大小 现在,我想知道是否有一种可能的方法,使你不能删除它呢 您需要避免可能删除这些图像的操作。在无法避免删除图像的情况下,必须确保在正确的位置重新插入图像。为此,您需要一个函数来检查实际编辑器选择中的图像,另一个函数负责插入 为了保留图像,您需要调整的操作(操纵插入符号): 退格,ENTF(js键码8和46):范围已通过 // this is tinymce 3 syntax, tinymce 4 looks o
现在,我想知道是否有一种可能的方法,使你不能删除它呢 您需要避免可能删除这些图像的操作。在无法避免删除图像的情况下,必须确保在正确的位置重新插入图像。为此,您需要一个函数来检查实际编辑器选择中的图像,另一个函数负责插入 为了保留图像,您需要调整的操作(操纵插入符号): 退格,ENTF(js键码8和46):范围已通过
// this is tinymce 3 syntax, tinymce 4 looks only a bit different
ed.onKeyDown.add(function onkeydown(ed, e) {
var rng = ed.selection.getRng();
if (e.keyCode == 46 && rng.collapsed) { // BACKSPACE
// manipulate the caret in the editor and set if after the image, in case there are several adjacent images set the caret after all these image
}
else if (e.keyCode == 8 && rng.collapsed) { // ENTF
// manipulate the caret in the editor and set if before the image, in case there are several adjacent images set the caret before all these image
}
});
还有一种情况是,内容被选中,因此范围不会被折叠(Backspace、Entf、cmd/ctrl+x、cmd/ctrl+v、用字符覆盖所选内容)
在这种情况下,您需要检查onKeyDown是否在所选内容中有图像。您需要保存这些元素,并在默认浏览器操作后重新插入这些元素
var image_string = '';
var node = ed.selection.getNode();
var $node = $(node);
// checks if a node is inside the range
rangeIntersectsNode: function (range, node) {
var nodeRange;
if (range.intersectsNode) {
return range.intersectsNode(node);
}
else {
nodeRange = tinymce.isIE && !window.is_ie9 ? this.editor.selection.getRng(1) : node.ownerDocument.createRange();
try {
nodeRange.selectNode(node);
} catch (e) {
nodeRange.selectNodeContents(node);
}
return range.compareBoundaryPoints(tinymce.isIE && !window.is_ie9 ? 3 : Range.END_TO_START, nodeRange) == -1 &&
range.compareBoundaryPoints(tinymce.isIE && !window.is_ie9 ? 1 : Range.START_TO_END, nodeRange) == 1;
}
},
// save image html to string-variable
$(paragraph).find('img').each(function(){
if (rangeIntersectsNode(rng, this))
{
image_string += $(this).clone().wrap('<div>').parent().html();
}
});
对于粘贴(ctrl+v),我们需要一种不同的方法。您需要使用函数(tinymce config param)。
检查所选内容中的图像并使用上述功能性,然后直接插入包含粘贴内容的字符串:
o.content = o.content + image_string;
此外,请注意:如果没有自己的浏览器插件,您将无法截获通过浏览器菜单执行的删除操作。您需要避免可能删除这些图像的操作。在无法避免删除图像的情况下,必须确保在正确的位置重新插入图像。为此,您需要一个函数来检查实际编辑器选择中的图像,另一个函数负责插入 为了保留图像,您需要调整的操作(操纵插入符号): 退格,ENTF(js键码8和46):范围已通过
// this is tinymce 3 syntax, tinymce 4 looks only a bit different
ed.onKeyDown.add(function onkeydown(ed, e) {
var rng = ed.selection.getRng();
if (e.keyCode == 46 && rng.collapsed) { // BACKSPACE
// manipulate the caret in the editor and set if after the image, in case there are several adjacent images set the caret after all these image
}
else if (e.keyCode == 8 && rng.collapsed) { // ENTF
// manipulate the caret in the editor and set if before the image, in case there are several adjacent images set the caret before all these image
}
});
还有一种情况是,内容被选中,因此范围不会被折叠(Backspace、Entf、cmd/ctrl+x、cmd/ctrl+v、用字符覆盖所选内容)
在这种情况下,您需要检查onKeyDown是否在所选内容中有图像。您需要保存这些元素,并在默认浏览器操作后重新插入这些元素
var image_string = '';
var node = ed.selection.getNode();
var $node = $(node);
// checks if a node is inside the range
rangeIntersectsNode: function (range, node) {
var nodeRange;
if (range.intersectsNode) {
return range.intersectsNode(node);
}
else {
nodeRange = tinymce.isIE && !window.is_ie9 ? this.editor.selection.getRng(1) : node.ownerDocument.createRange();
try {
nodeRange.selectNode(node);
} catch (e) {
nodeRange.selectNodeContents(node);
}
return range.compareBoundaryPoints(tinymce.isIE && !window.is_ie9 ? 3 : Range.END_TO_START, nodeRange) == -1 &&
range.compareBoundaryPoints(tinymce.isIE && !window.is_ie9 ? 1 : Range.START_TO_END, nodeRange) == 1;
}
},
// save image html to string-variable
$(paragraph).find('img').each(function(){
if (rangeIntersectsNode(rng, this))
{
image_string += $(this).clone().wrap('<div>').parent().html();
}
});
对于粘贴(ctrl+v),我们需要一种不同的方法。您需要使用函数(tinymce config param)。
检查所选内容中的图像并使用上述功能性,然后直接插入包含粘贴内容的字符串:
o.content = o.content + image_string;
此外,请注意:如果没有自己的浏览器插件,您将无法截获在浏览器菜单上发生的删除操作。我们有类似的功能,但很难执行achieve@Thariama我重新体会到了这一点,两天前我开始做这个,但仍然不知道怎么做:pokay,我会给你写一个答案,告诉你在哪里应该注意的要点。我们有这样的东西,但很难做到achieve@Thariama我重新体会到了这一点,两天前我开始做这件事,但仍然不知道如何做:pokay,我会写一个答案,告诉你在哪里需要注意的要点