[903] | 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 | * Active selection functions. (IE specific implementation) |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | // Get the selection type. |
---|
| 25 | FCKSelection.GetType = function() |
---|
| 26 | { |
---|
| 27 | return FCK.EditorDocument.selection.type ; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | // Retrieves the selected element (if any), just in the case that a single |
---|
| 31 | // element (object like and image or a table) is selected. |
---|
| 32 | FCKSelection.GetSelectedElement = function() |
---|
| 33 | { |
---|
| 34 | if ( this.GetType() == 'Control' ) |
---|
| 35 | { |
---|
| 36 | var oRange = FCK.EditorDocument.selection.createRange() ; |
---|
| 37 | |
---|
| 38 | if ( oRange && oRange.item ) |
---|
| 39 | return FCK.EditorDocument.selection.createRange().item(0) ; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | FCKSelection.GetParentElement = function() |
---|
| 44 | { |
---|
| 45 | switch ( this.GetType() ) |
---|
| 46 | { |
---|
| 47 | case 'Control' : |
---|
| 48 | return FCKSelection.GetSelectedElement().parentElement ; |
---|
| 49 | case 'None' : |
---|
| 50 | return null ; |
---|
| 51 | default : |
---|
| 52 | return FCK.EditorDocument.selection.createRange().parentElement() ; |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | FCKSelection.SelectNode = function( node ) |
---|
| 57 | { |
---|
| 58 | FCK.Focus() ; |
---|
| 59 | FCK.EditorDocument.selection.empty() ; |
---|
| 60 | var oRange ; |
---|
| 61 | try |
---|
| 62 | { |
---|
| 63 | // Try to select the node as a control. |
---|
| 64 | oRange = FCK.EditorDocument.body.createControlRange() ; |
---|
| 65 | oRange.addElement( node ) ; |
---|
| 66 | } |
---|
| 67 | catch(e) |
---|
| 68 | { |
---|
| 69 | // If failed, select it as a text range. |
---|
| 70 | oRange = FCK.EditorDocument.body.createTextRange() ; |
---|
| 71 | oRange.moveToElementText( node ) ; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | oRange.select() ; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | FCKSelection.Collapse = function( toStart ) |
---|
| 78 | { |
---|
| 79 | FCK.Focus() ; |
---|
| 80 | if ( this.GetType() == 'Text' ) |
---|
| 81 | { |
---|
| 82 | var oRange = FCK.EditorDocument.selection.createRange() ; |
---|
| 83 | oRange.collapse( toStart == null || toStart === true ) ; |
---|
| 84 | oRange.select() ; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | // The "nodeTagName" parameter must be Upper Case. |
---|
| 89 | FCKSelection.HasAncestorNode = function( nodeTagName ) |
---|
| 90 | { |
---|
| 91 | var oContainer ; |
---|
| 92 | |
---|
| 93 | if ( FCK.EditorDocument.selection.type == "Control" ) |
---|
| 94 | { |
---|
| 95 | oContainer = this.GetSelectedElement() ; |
---|
| 96 | } |
---|
| 97 | else |
---|
| 98 | { |
---|
| 99 | var oRange = FCK.EditorDocument.selection.createRange() ; |
---|
| 100 | oContainer = oRange.parentElement() ; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | while ( oContainer ) |
---|
| 104 | { |
---|
| 105 | if ( oContainer.tagName == nodeTagName ) return true ; |
---|
| 106 | oContainer = oContainer.parentNode ; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | return false ; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | // The "nodeTagName" parameter must be UPPER CASE. |
---|
| 113 | FCKSelection.MoveToAncestorNode = function( nodeTagName ) |
---|
| 114 | { |
---|
| 115 | var oNode, oRange ; |
---|
| 116 | |
---|
| 117 | if ( ! FCK.EditorDocument ) |
---|
| 118 | return null ; |
---|
| 119 | |
---|
| 120 | if ( FCK.EditorDocument.selection.type == "Control" ) |
---|
| 121 | { |
---|
| 122 | oRange = FCK.EditorDocument.selection.createRange() ; |
---|
| 123 | for ( i = 0 ; i < oRange.length ; i++ ) |
---|
| 124 | { |
---|
| 125 | if (oRange(i).parentNode) |
---|
| 126 | { |
---|
| 127 | oNode = oRange(i).parentNode ; |
---|
| 128 | break ; |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | else |
---|
| 133 | { |
---|
| 134 | oRange = FCK.EditorDocument.selection.createRange() ; |
---|
| 135 | oNode = oRange.parentElement() ; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | while ( oNode && oNode.nodeName != nodeTagName ) |
---|
| 139 | oNode = oNode.parentNode ; |
---|
| 140 | |
---|
| 141 | return oNode ; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | FCKSelection.Delete = function() |
---|
| 145 | { |
---|
| 146 | // Gets the actual selection. |
---|
| 147 | var oSel = FCK.EditorDocument.selection ; |
---|
| 148 | |
---|
| 149 | // Deletes the actual selection contents. |
---|
| 150 | if ( oSel.type.toLowerCase() != "none" ) |
---|
| 151 | { |
---|
| 152 | oSel.clear() ; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | return oSel ; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | |
---|