I have to determine if the selection is parented by an <A> tag in my plugin. I'm seeing that sometimes Firefox (Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3) returns the selection with an incorrect anchorNode. The anchorNode.length == Selection.anchorOffset, and the anchorOffset is suppose to be zero based, hence the selection starts after the anchor.
Anyway, the FCKSelection.HasAncestorNode('A') ultimately uses the parent of the anchorNode to check for ancestors. So I have to do this in my plugin code to determine if an <A> element is selected. Also understand that I only care to know if an <A> is anywhere in the selection.
var bInsideLink = ( tagName == 'A' || FCKSelection.HasAncestorNode( 'A' ) ) ;
if ( !bInsideLink && !document.all ) { // additional check for gecko
var allAnchors = FCK.EditorDocument.getElementsByTagName('A');
var oSel = FCK.EditorWindow.getSelection();
for ( var i=0; i < allAnchors.length; i++ ) {
if ( oSel.containsNode( allAnchors[i], true ) ) {
bInsideLink = true;
break;
}
}
}
I saw the problem in the following HTML when only selecting the word 'reference', selecting left to right, the second time. I can't think of anyway to set the anchor node correctly in the case where anchorNode.length == selection.anchorOffset so maybe there isn't anything for FCKeditor to do.
<p align="left" style="margin-left: 0px; text-indent: 0px; margin-bottom: 0px; margin-top: 0px;"><font face="'Arial',sans serif" color="#000000" style="font-size: 19px;">asdf </font><font face="'Arial',sans serif" color="#000000" style="font-size: 16px;">asdf </font><font face="'Arial',sans serif" color="#010101" style="font-size: 13px;">asdf</font><font face="'Arial',sans serif" color="#010101" style="font-size: 19px;"> adsff asdf </font><img width="24" height="43" alt="" id="ee46" onclick="TxtClickEmbObj(39,2,eval(this.x),eval(this.y));return false;" src="o.trm?cmd=getResrc&convId=10&relPath=images/eqn.gif"/><font face="'Arial',sans serif" color="#010101" style="font-size: 13px;"> </font><a href="javaScript:TxtRefAction(39,69)"><font face="'Arial',sans serif" color="#0000ff" style="font-size: 13px;"><u>reference</u></font></a><font face="'Arial',sans serif" color="#010101" style="font-size: 13px;"> </font><font face="'Arial',sans serif" color="#010101" style="font-size: 10px;"><sup>super </sup></font><font face="'Arial',sans serif" color="#010101" style="font-size: 10px;"><sub>sub </sub></font><font face="'Arial',sans serif" color="#010101" style="font-size: 13px;"> </font></p>
Anyway, the FCKSelection.HasAncestorNode('A') ultimately uses the parent of the anchorNode to check for ancestors. So I have to do this in my plugin code to determine if an <A> element is selected. Also understand that I only care to know if an <A> is anywhere in the selection.
var bInsideLink = ( tagName == 'A' || FCKSelection.HasAncestorNode( 'A' ) ) ;
if ( !bInsideLink && !document.all ) { // additional check for gecko
var allAnchors = FCK.EditorDocument.getElementsByTagName('A');
var oSel = FCK.EditorWindow.getSelection();
for ( var i=0; i < allAnchors.length; i++ ) {
if ( oSel.containsNode( allAnchors[i], true ) ) {
bInsideLink = true;
break;
}
}
}
I saw the problem in the following HTML when only selecting the word 'reference', selecting left to right, the second time. I can't think of anyway to set the anchor node correctly in the case where anchorNode.length == selection.anchorOffset so maybe there isn't anything for FCKeditor to do.
<p align="left" style="margin-left: 0px; text-indent: 0px; margin-bottom: 0px; margin-top: 0px;"><font face="'Arial',sans serif" color="#000000" style="font-size: 19px;">asdf </font><font face="'Arial',sans serif" color="#000000" style="font-size: 16px;">asdf </font><font face="'Arial',sans serif" color="#010101" style="font-size: 13px;">asdf</font><font face="'Arial',sans serif" color="#010101" style="font-size: 19px;"> adsff asdf </font><img width="24" height="43" alt="" id="ee46" onclick="TxtClickEmbObj(39,2,eval(this.x),eval(this.y));return false;" src="o.trm?cmd=getResrc&convId=10&relPath=images/eqn.gif"/><font face="'Arial',sans serif" color="#010101" style="font-size: 13px;"> </font><a href="javaScript:TxtRefAction(39,69)"><font face="'Arial',sans serif" color="#0000ff" style="font-size: 13px;"><u>reference</u></font></a><font face="'Arial',sans serif" color="#010101" style="font-size: 13px;"> </font><font face="'Arial',sans serif" color="#010101" style="font-size: 10px;"><sup>super </sup></font><font face="'Arial',sans serif" color="#010101" style="font-size: 10px;"><sub>sub </sub></font><font face="'Arial',sans serif" color="#010101" style="font-size: 13px;"> </font></p>