2
* FCKeditor - The text editor for internet
3
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
5
* Licensed under the terms of the GNU Lesser General Public License:
6
* http://www.opensource.org/licenses/lgpl-license.php
8
* For further information visit:
9
* http://www.fckeditor.net/
11
* "Support Open Source software. What about a donation today?"
13
* File Name: fckselection_gecko.js
14
* Active selection functions. (Gecko specific implementation)
17
* Frederico Caldeira Knabben (fredck@fckeditor.net)
20
// Get the selection type (like document.select.type in IE).
21
FCKSelection.GetType = function()
23
// if ( ! this._Type )
25
// By default set the type to "Text".
28
// Check if the actual selection is a Control (IMG, TABLE, HR, etc...).
30
try { oSel = FCK.EditorWindow.getSelection() ; }
33
if ( oSel && oSel.rangeCount == 1 )
35
var oRange = oSel.getRangeAt(0) ;
36
if ( oRange.startContainer == oRange.endContainer && (oRange.endOffset - oRange.startOffset) == 1 )
37
this._Type = 'Control' ;
43
// Retrieves the selected element (if any), just in the case that a single
44
// element (object like and image or a table) is selected.
45
FCKSelection.GetSelectedElement = function()
47
if ( this.GetType() == 'Control' )
49
var oSel = FCK.EditorWindow.getSelection() ;
50
return oSel.anchorNode.childNodes[ oSel.anchorOffset ] ;
54
FCKSelection.GetParentElement = function()
56
if ( this.GetType() == 'Control' )
57
return FCKSelection.GetSelectedElement().parentNode ;
60
var oSel = FCK.EditorWindow.getSelection() ;
63
var oNode = oSel.anchorNode ;
65
while ( oNode && oNode.nodeType != 1 )
66
oNode = oNode.parentNode ;
73
FCKSelection.SelectNode = function( element )
77
var oRange = FCK.EditorDocument.createRange() ;
78
oRange.selectNode( element ) ;
80
var oSel = FCK.EditorWindow.getSelection() ;
81
oSel.removeAllRanges() ;
82
oSel.addRange( oRange ) ;
85
FCKSelection.Collapse = function( toStart )
87
var oSel = FCK.EditorWindow.getSelection() ;
89
if ( toStart == null || toStart === true )
90
oSel.collapseToStart() ;
92
oSel.collapseToEnd() ;
95
// The "nodeTagName" parameter must be Upper Case.
96
FCKSelection.HasAncestorNode = function( nodeTagName )
98
var oContainer = this.GetSelectedElement() ;
99
if ( ! oContainer && FCK.EditorWindow )
101
try { oContainer = FCK.EditorWindow.getSelection().getRangeAt(0).startContainer ; }
107
if ( oContainer.nodeType == 1 && oContainer.tagName == nodeTagName ) return true ;
108
oContainer = oContainer.parentNode ;
114
// The "nodeTagName" parameter must be Upper Case.
115
FCKSelection.MoveToAncestorNode = function( nodeTagName )
119
var oContainer = this.GetSelectedElement() ;
121
oContainer = FCK.EditorWindow.getSelection().getRangeAt(0).startContainer ;
125
if ( oContainer.tagName == nodeTagName )
127
oContainer = oContainer.parentNode ;
132
FCKSelection.Delete = function()
134
// Gets the actual selection.
135
var oSel = FCK.EditorWindow.getSelection() ;
137
// Deletes the actual selection contents.
138
for ( var i = 0 ; i < oSel.rangeCount ; i++ )
140
oSel.getRangeAt(i).deleteContents() ;
146
// START iCM MODIFICATIONS
148
// Move the cursor position (the selection point) to a specific offset within a specific node
149
// If no offset specified, the start of the node is assumed
150
FCKSelection.SetCursorPosition = function ( oNode, nOffset )
152
if ( typeof nOffset == "undefined" ) nOffset = 0 ;
154
var oSel = FCK.EditorWindow.getSelection() ;
155
var oRange = FCK.EditorDocument.createRange() ;
157
oRange.setStart( oNode, nOffset ) ;
158
oRange.collapse( true ) ;
160
oSel.removeAllRanges() ;
161
oSel.addRange( oRange );
163
if ( oNode.scrollIntoView )
164
oNode.scrollIntoView( false );
167
// END iCM MODIFICATIONS