[ 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: fckselection_gecko.js 22 * Active selection functions. (Gecko specific implementation) 23 * 24 * File Authors: 25 * Frederico Caldeira Knabben (www.fckeditor.net) 26 */ 27 28 // Get the selection type (like document.select.type in IE). 29 FCKSelection.GetType = function() 30 { 31 // if ( ! this._Type ) 32 // { 33 // By default set the type to "Text". 34 this._Type = 'Text' ; 35 36 // Check if the actual selection is a Control (IMG, TABLE, HR, etc...). 37 var oSel ; 38 try { oSel = FCK.EditorWindow.getSelection() ; } 39 catch (e) {} 40 41 if ( oSel && oSel.rangeCount == 1 ) 42 { 43 var oRange = oSel.getRangeAt(0) ; 44 if ( oRange.startContainer == oRange.endContainer && (oRange.endOffset - oRange.startOffset) == 1 && oRange.startContainer.nodeType != Node.TEXT_NODE ) 45 this._Type = 'Control' ; 46 } 47 // } 48 return this._Type ; 49 } 50 51 // Retrieves the selected element (if any), just in the case that a single 52 // element (object like and image or a table) is selected. 53 FCKSelection.GetSelectedElement = function() 54 { 55 if ( this.GetType() == 'Control' ) 56 { 57 var oSel = FCK.EditorWindow.getSelection() ; 58 return oSel.anchorNode.childNodes[ oSel.anchorOffset ] ; 59 } 60 return null ; 61 } 62 63 FCKSelection.GetParentElement = function() 64 { 65 if ( this.GetType() == 'Control' ) 66 return FCKSelection.GetSelectedElement().parentNode ; 67 else 68 { 69 var oSel = FCK.EditorWindow.getSelection() ; 70 if ( oSel ) 71 { 72 var oNode = oSel.anchorNode ; 73 74 while ( oNode && oNode.nodeType != 1 ) 75 oNode = oNode.parentNode ; 76 77 return oNode ; 78 } 79 } 80 return null ; 81 } 82 83 FCKSelection.SelectNode = function( element ) 84 { 85 // FCK.Focus() ; 86 87 var oRange = FCK.EditorDocument.createRange() ; 88 oRange.selectNode( element ) ; 89 90 var oSel = FCK.EditorWindow.getSelection() ; 91 oSel.removeAllRanges() ; 92 oSel.addRange( oRange ) ; 93 } 94 95 FCKSelection.Collapse = function( toStart ) 96 { 97 var oSel = FCK.EditorWindow.getSelection() ; 98 99 if ( toStart == null || toStart === true ) 100 oSel.collapseToStart() ; 101 else 102 oSel.collapseToEnd() ; 103 } 104 105 // The "nodeTagName" parameter must be Upper Case. 106 FCKSelection.HasAncestorNode = function( nodeTagName ) 107 { 108 var oContainer = this.GetSelectedElement() ; 109 if ( ! oContainer && FCK.EditorWindow ) 110 { 111 try { oContainer = FCK.EditorWindow.getSelection().getRangeAt(0).startContainer ; } 112 catch(e){} 113 } 114 115 while ( oContainer ) 116 { 117 if ( oContainer.nodeType == 1 && oContainer.tagName == nodeTagName ) return true ; 118 oContainer = oContainer.parentNode ; 119 } 120 121 return false ; 122 } 123 124 // The "nodeTagName" parameter must be Upper Case. 125 FCKSelection.MoveToAncestorNode = function( nodeTagName ) 126 { 127 var oNode ; 128 129 var oContainer = this.GetSelectedElement() ; 130 if ( ! oContainer ) 131 oContainer = FCK.EditorWindow.getSelection().getRangeAt(0).startContainer ; 132 133 while ( oContainer ) 134 { 135 if ( oContainer.nodeName == nodeTagName ) 136 return oContainer ; 137 138 oContainer = oContainer.parentNode ; 139 } 140 return null ; 141 } 142 143 FCKSelection.Delete = function() 144 { 145 // Gets the actual selection. 146 var oSel = FCK.EditorWindow.getSelection() ; 147 148 // Deletes the actual selection contents. 149 for ( var i = 0 ; i < oSel.rangeCount ; i++ ) 150 { 151 oSel.getRangeAt(i).deleteContents() ; 152 } 153 154 return oSel ; 155 }
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 |