开发者

CKEditor plugin get first image in editor contents

I have the code which gets the currently selected image, but I would like to get the first image in contents if one has not already been selected. Im using the code below which has been adapted from original which returned an href.

 var range = selection.getRanges(true)[0];
 range.shrink(CKEDITOR.SHRINK_TEXT);
 var root = range.getCommonAncestor();
 return root.getAscendant('img', true);

How could I get the first image 开发者_运维问答which appears in the contents?


As I can understand you need DOM node instead the CKEditor node, right? If so getAscendant('img', true) returns CKEDITOR.dom.node so you can get native DOM node from $ object.

var img = root.getAscendant('img', true);
if (img)
  return img.$.src;

Or then use the img.getAttribute( 'src' )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜