[1349] | 1 | /* |
---|
| 2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net |
---|
| 3 | * Copyright (C) 2003-2007 Frederico Caldeira Knabben |
---|
| 4 | * |
---|
| 5 | * == BEGIN LICENSE == |
---|
| 6 | * |
---|
| 7 | * Licensed under the terms of any of the following licenses at your |
---|
| 8 | * choice: |
---|
| 9 | * |
---|
| 10 | * - GNU General Public License Version 2 or later (the "GPL") |
---|
| 11 | * http://www.gnu.org/licenses/gpl.html |
---|
| 12 | * |
---|
| 13 | * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") |
---|
| 14 | * http://www.gnu.org/licenses/lgpl.html |
---|
| 15 | * |
---|
| 16 | * - Mozilla Public License Version 1.1 or later (the "MPL") |
---|
| 17 | * http://www.mozilla.org/MPL/MPL-1.1.html |
---|
| 18 | * |
---|
| 19 | * == END LICENSE == |
---|
| 20 | * |
---|
| 21 | * Class for working with a selection range, much like the W3C DOM Range, but |
---|
| 22 | * it is not intented to be an implementation of the W3C interface. |
---|
| 23 | * (Gecko Implementation) |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | FCKDomRange.prototype.MoveToSelection = function() |
---|
| 27 | { |
---|
| 28 | this.Release( true ) ; |
---|
| 29 | |
---|
| 30 | var oSel = this.Window.getSelection() ; |
---|
| 31 | |
---|
| 32 | if ( oSel.rangeCount == 1 ) |
---|
| 33 | { |
---|
| 34 | this._Range = FCKW3CRange.CreateFromRange( this.Window.document, oSel.getRangeAt(0) ) ; |
---|
| 35 | this._UpdateElementInfo() ; |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | FCKDomRange.prototype.Select = function() |
---|
| 40 | { |
---|
| 41 | var oRange = this._Range ; |
---|
| 42 | if ( oRange ) |
---|
| 43 | { |
---|
| 44 | var oDocRange = this.Window.document.createRange() ; |
---|
| 45 | oDocRange.setStart( oRange.startContainer, oRange.startOffset ) ; |
---|
| 46 | |
---|
| 47 | try |
---|
| 48 | { |
---|
| 49 | oDocRange.setEnd( oRange.endContainer, oRange.endOffset ) ; |
---|
| 50 | } |
---|
| 51 | catch ( e ) |
---|
| 52 | { |
---|
| 53 | // There is a bug in Firefox implementation (it would be too easy |
---|
| 54 | // otherwhise). The new start can't be after the end (W3C says it can). |
---|
| 55 | // So, let's create a new range and collapse it to the desired point. |
---|
| 56 | if ( e.toString().Contains( 'NS_ERROR_ILLEGAL_VALUE' ) ) |
---|
| 57 | { |
---|
| 58 | oRange.collapse( true ) ; |
---|
| 59 | oDocRange.setEnd( oRange.endContainer, oRange.endOffset ) ; |
---|
| 60 | } |
---|
| 61 | else |
---|
| 62 | throw( e ) ; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | var oSel = this.Window.getSelection() ; |
---|
| 66 | oSel.removeAllRanges() ; |
---|
| 67 | |
---|
| 68 | // We must add a clone otherwise Firefox will have rendering issues. |
---|
| 69 | oSel.addRange( oDocRange ) ; |
---|
| 70 | } |
---|
| 71 | } |
---|