FCKSelection有2个方法: HasAncestorNode和MoveToAncestorNode,他们有什么区别??
[b]问题补充:[/b]
貌似选中的结点名和MoveToAncestorNode 的参数名相同时
MoveToAncestorNode 会返回null
[b]问题补充:[/b]
var FCKToolbarButton=function (A,B,C,D,E,F,G) {
this.CommandName=A;
this.Label=B;
this.Tooltip=C;
this.Style=D;
this.SourceView=E?true:false;
this.ContextSensitive=F?true:false;
if(G==null)this.IconPath=FCKConfig.SkinPath+'toolbar/'+A.toLowerCase()+'.gif';
else if(typeof(G)=='number')this.IconPath=[FCKConfig.SkinPath+'fck_strip.gif',16,G];
else this.IconPath=G;
};
SourceView和ContextSensitive是干什么的??
源码你要多看看:
HasAncestorNode只做判断,返回ture和false
[code="js"]
HasAncestorNode = function(A){
var B;
if(FCK.EditorDocument.selection.type=="Control"){
B=this.GetSelectedElement();
}else{
var C=FCK.EditorDocument.selection.createRange();
B=C.parentElement();
};
while (B){
if (B.tagName==A)
return true;
B=B.parentNode;
};
return false;
}
[/code]
MoveToAncestorNode根据提供的节点向上递归定位到指定节点并返回
[code="js"]
FCKSelection.MoveToAncestorNode = function( nodeTagName )
{
var oNode, oRange ;
if ( ! FCK.EditorDocument )
return null ;
if ( FCK.EditorDocument.selection.type == "Control" )
{
oRange = FCK.EditorDocument.selection.createRange() ;
for ( i = 0 ; i < oRange.length ; i++ )
{
if (oRange(i).parentNode)
{
oNode = oRange(i).parentNode ;
break ;
}
}
}
else
{
oRange = FCK.EditorDocument.selection.createRange() ;
oNode = oRange.parentElement() ;
}
while ( oNode && oNode.nodeName != nodeTagName )
oNode = oNode.parentNode ;
return oNode ;
}[/code]
HasAncestorNode 查询是否有祖先节点
MoveToAncestorNode 移至祖先节点