查找接触的信息CKEDITOR [英] Finding Touched elments CKEDITOR
问题描述
我现在在网上看了几天,但我似乎无法找到,如何我可以找到如果插入符号触摸元素。
这是一个[]< span>示例< / span>
例如,我们说插入符是标签[]。
现在我们想知道插入符号是否在span元素附近?
我们如何找到这个?我还需要知道span元素是在插入符号之前还是之后。
我使用CKEDITOR 4.0 api ...
尝试:
var range = CKEDITOR。 instances.yourEditorInstance.getSelection()。getRanges()[0];
range.optimize();
console.log(range.getBoundaryNodes());
另外:
console.log(range.getTouchedEndNode());
console.log(range.getTouchedStartNode());请注意,您的范围可能位于元素内部(例如 e4 )。 ,下面的图像),所以边界节点将永远是文本节点。请查看 DOM范围规范了解详情。 / p>
>
编辑:这些也值得尝试:
range.getNextNode();
range.getPreviousNode();
毕竟,可以检查:
var node = range.getNextNode();
console.log(node.type == CKEDITOR.NODE_ELEMENT&&& node.is('span'));
I am looking several days now on the web, but i can't seem to find out, how i can find if the caret is touching a element. Let me explain myself a little better with this example.
This is a[ ] <span>example</span>
As Example we say that the caret is the tag [ ].
And now we like to know if the caret is near a span element?
How can we find this? Also I need to know if the span element is before or after the caret.
I'm doing this with the CKEDITOR 4.0 api..
解决方案 Try this:
var range = CKEDITOR.instances.yourEditorInstance.getSelection().getRanges()[ 0 ];
range.optimize();
console.log( range.getBoundaryNodes() );
Also:
console.log( range.getTouchedEndNode() );
console.log( range.getTouchedStartNode() );
Note that your range may be located inside of an element (like e4, image below), so boundary nodes will always be text nodes. Check DOM range specification for more.
EDIT: These are also worth trying:
range.getNextNode();
range.getPreviousNode();
After all, once you have the node, you can check it:
var node = range.getNextNode();
console.log( node.type == CKEDITOR.NODE_ELEMENT && node.is( 'span' ) );
这篇关于查找接触的信息CKEDITOR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!