2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2010 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* Class for working with a selection range, much like the W3C DOM Range, but
22
* it is not intended to be an implementation of the W3C interface.
23
* (Gecko Implementation)
26
FCKDomRange.prototype.MoveToSelection = function()
28
this.Release( true ) ;
30
var oSel = this.Window.getSelection() ;
32
if ( oSel && oSel.rangeCount > 0 )
34
this._Range = FCKW3CRange.CreateFromRange( this.Window.document, oSel.getRangeAt(0) ) ;
35
this._UpdateElementInfo() ;
38
if ( this.Window.document )
39
this.MoveToElementStart( this.Window.document.body ) ;
42
FCKDomRange.prototype.Select = function()
44
var oRange = this._Range ;
47
var startContainer = oRange.startContainer ;
49
// If we have a collapsed range, inside an empty element, we must add
50
// something to it, otherwise the caret will not be visible.
51
if ( oRange.collapsed && startContainer.nodeType == 1 && startContainer.childNodes.length == 0 )
52
startContainer.appendChild( oRange._Document.createTextNode('') ) ;
54
var oDocRange = this.Window.document.createRange() ;
55
oDocRange.setStart( startContainer, oRange.startOffset ) ;
59
oDocRange.setEnd( oRange.endContainer, oRange.endOffset ) ;
63
// There is a bug in Firefox implementation (it would be too easy
64
// otherwise). The new start can't be after the end (W3C says it can).
65
// So, let's create a new range and collapse it to the desired point.
66
if ( e.toString().Contains( 'NS_ERROR_ILLEGAL_VALUE' ) )
68
oRange.collapse( true ) ;
69
oDocRange.setEnd( oRange.endContainer, oRange.endOffset ) ;
75
var oSel = this.Window.getSelection() ;
76
oSel.removeAllRanges() ;
78
// We must add a clone otherwise Firefox will have rendering issues.
79
oSel.addRange( oDocRange ) ;
83
// Not compatible with bookmark created with CreateBookmark2.
84
// The bookmark nodes will be deleted from the document.
85
FCKDomRange.prototype.SelectBookmark = function( bookmark )
87
var domRange = this.Window.document.createRange() ;
89
var startNode = this.GetBookmarkNode( bookmark, true ) ;
90
var endNode = this.GetBookmarkNode( bookmark, false ) ;
92
domRange.setStart( startNode.parentNode, FCKDomTools.GetIndexOf( startNode ) ) ;
93
FCKDomTools.RemoveNode( startNode ) ;
97
domRange.setEnd( endNode.parentNode, FCKDomTools.GetIndexOf( endNode ) ) ;
98
FCKDomTools.RemoveNode( endNode ) ;
101
var selection = this.Window.getSelection() ;
102
selection.removeAllRanges() ;
103
selection.addRange( domRange ) ;