[ Index ] |
|
Code source de FCKeditor 2.4 |
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 * File Name: fckdomrange_ie.js 22 * Class for working with a selection range, much like the W3C DOM Range, but 23 * it is not intented to be an implementation of the W3C interface. 24 * (IE Implementation) 25 * 26 * File Authors: 27 * Frederico Caldeira Knabben (www.fckeditor.net) 28 */ 29 30 FCKDomRange.prototype.MoveToSelection = function() 31 { 32 this.Release( true ) ; 33 34 this._Range = new FCKW3CRange( this.Window.document ) ; 35 36 var oSel = this.Window.document.selection ; 37 38 if ( oSel.type != 'Control' ) 39 { 40 // Set the start boundary. 41 eMarker = this._GetSelectionMarkerTag( true ) ; 42 this._Range.setStart( eMarker.parentNode, FCKDomTools.GetIndexOf( eMarker ) ) ; 43 eMarker.parentNode.removeChild( eMarker ) ; 44 45 // Set the end boundary. 46 var eMarker = this._GetSelectionMarkerTag( false ) ; 47 this._Range.setEnd( eMarker.parentNode, FCKDomTools.GetIndexOf( eMarker ) ) ; 48 eMarker.parentNode.removeChild( eMarker ) ; 49 50 this._UpdateElementInfo() ; 51 } 52 else 53 { 54 var oControl = oSel.createRange().item(0) ; 55 56 if ( oControl ) 57 { 58 this._Range.setStartBefore( oControl ) ; 59 this._Range.setEndAfter( oControl ) ; 60 this._UpdateElementInfo() ; 61 } 62 } 63 } 64 65 FCKDomRange.prototype.Select = function() 66 { 67 if ( this._Range ) 68 { 69 var bIsCollapsed = this.CheckIsCollapsed() ; 70 71 // Create marker tags for the start and end boundaries. 72 var eStartMarker = this._GetRangeMarkerTag( true ) ; 73 74 if ( !bIsCollapsed ) 75 var eEndMarker = this._GetRangeMarkerTag( false ) ; 76 77 // Create the main range which will be used for the selection. 78 var oIERange = this.Window.document.body.createTextRange() ; 79 80 // Position the range at the start boundary. 81 oIERange.moveToElementText( eStartMarker ) ; 82 oIERange.moveStart( 'character', 1 ) ; 83 84 if ( !bIsCollapsed ) 85 { 86 // Create a tool range for the end. 87 var oIERangeEnd = this.Window.document.body.createTextRange() ; 88 89 // Position the tool range at the end. 90 oIERangeEnd.moveToElementText( eEndMarker ) ; 91 92 // Move the end boundary of the main range to match the tool range. 93 oIERange.setEndPoint( 'EndToEnd', oIERangeEnd ) ; 94 oIERange.moveEnd( 'character', -1 ) ; 95 } 96 97 // Remove the markers (reset the position, because of the changes in the DOM tree). 98 this._Range.setStartBefore( eStartMarker ) ; 99 eStartMarker.parentNode.removeChild( eStartMarker ) ; 100 101 if ( bIsCollapsed ) 102 { 103 // The following trick is needed so IE makes collapsed selections 104 // inside empty blocks visible (expands the block). 105 try 106 { 107 oIERange.pasteHTML(' ') ; 108 oIERange.moveStart( 'character', -1 ) ; 109 } 110 catch (e){} 111 oIERange.select() ; 112 oIERange.pasteHTML('') ; 113 } 114 else 115 { 116 this._Range.setEndBefore( eEndMarker ) ; 117 eEndMarker.parentNode.removeChild( eEndMarker ) ; 118 oIERange.select() ; 119 } 120 } 121 } 122 123 FCKDomRange.prototype._GetSelectionMarkerTag = function( toStart ) 124 { 125 // Get a range for the start boundary. 126 var oRange = this.Window.document.selection.createRange() ; 127 oRange.collapse( toStart === true ) ; 128 129 // Paste a marker element at the collapsed range and get it from the DOM. 130 var sMarkerId = 'fck_dom_range_temp_' + (new Date()).valueOf() + '_' + Math.floor(Math.random()*1000) ; 131 oRange.pasteHTML( '<span id="' + sMarkerId + '"></span>' ) ; 132 return this.Window.document.getElementById( sMarkerId ) ; 133 } 134 135 FCKDomRange.prototype._GetRangeMarkerTag = function( toStart ) 136 { 137 // Get a range for the start boundary. 138 var oRange = this._Range ; 139 140 // insertNode() will add the node at the beginning of the Range, updating 141 // the endOffset if necessary. So, we can work with the current range in this case. 142 if ( !toStart ) 143 { 144 oRange = oRange.cloneRange() ; 145 oRange.collapse( toStart === true ) ; 146 } 147 148 var eSpan = this.Window.document.createElement( 'span' ) ; 149 eSpan.innerHTML = ' ' ; 150 oRange.insertNode( eSpan ) ; 151 152 return eSpan ; 153 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 15:28:05 2007 | par Balluche grâce à PHPXref 0.7 |