source: sandbox/2.3-MailArchiver/expressoMail1_2/js/fckeditor/editor/_source/internals/fckselection_ie.js @ 6779

Revision 6779, 3.2 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

Line 
1/*
2 * FCKeditor - The text editor for internet
3 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
4 *
5 * Licensed under the terms of the GNU Lesser General Public License:
6 *              http://www.opensource.org/licenses/lgpl-license.php
7 *
8 * For further information visit:
9 *              http://www.fckeditor.net/
10 *
11 * "Support Open Source software. What about a donation today?"
12 *
13 * File Name: fckselection_ie.js
14 *      Active selection functions. (IE specific implementation)
15 *
16 * File Authors:
17 *              Frederico Caldeira Knabben (fredck@fckeditor.net)
18 */
19
20// Get the selection type.
21FCKSelection.GetType = function()
22{
23        return FCK.EditorDocument.selection.type ;
24}
25
26// Retrieves the selected element (if any), just in the case that a single
27// element (object like and image or a table) is selected.
28FCKSelection.GetSelectedElement = function()
29{
30        if ( this.GetType() == 'Control' )
31        {
32                var oRange = FCK.EditorDocument.selection.createRange() ;
33
34                if ( oRange && oRange.item )
35                        return FCK.EditorDocument.selection.createRange().item(0) ;
36        }
37}
38
39FCKSelection.GetParentElement = function()
40{
41        switch ( this.GetType() )
42        {
43                case 'Control' :
44                        return FCKSelection.GetSelectedElement().parentElement ;
45                case 'None' :
46                        return ;
47                default :
48                        return FCK.EditorDocument.selection.createRange().parentElement() ;
49        }
50}
51
52FCKSelection.SelectNode = function( node )
53{
54        FCK.Focus() ;
55        FCK.EditorDocument.selection.empty() ;
56
57        try
58        {
59                // Try to select the node as a control.
60                var oRange = FCK.EditorDocument.body.createControlRange() ;
61                oRange.addElement( node ) ;
62        }
63        catch(e)
64        {
65                // If failed, select it as a text range.
66                var oRange = FCK.EditorDocument.selection.createRange() ;
67                oRange.moveToElementText( node ) ;
68        }
69
70        oRange.select() ;
71}
72
73FCKSelection.Collapse = function( toStart )
74{
75        FCK.Focus() ;
76        if ( this.GetType() == 'Text' )
77        {
78                var oRange = FCK.EditorDocument.selection.createRange() ;
79                oRange.collapse( toStart == null || toStart === true ) ;
80                oRange.select() ;
81        }
82}
83
84// The "nodeTagName" parameter must be Upper Case.
85FCKSelection.HasAncestorNode = function( nodeTagName )
86{
87        var oContainer ;
88
89        if ( FCK.EditorDocument.selection.type == "Control" )
90        {
91                oContainer = this.GetSelectedElement() ;
92        }
93        else
94        {
95                var oRange  = FCK.EditorDocument.selection.createRange() ;
96                oContainer = oRange.parentElement() ;
97        }
98
99        while ( oContainer )
100        {
101                if ( oContainer.tagName == nodeTagName ) return true ;
102                oContainer = oContainer.parentNode ;
103        }
104
105        return false ;
106}
107
108// The "nodeTagName" parameter must be UPPER CASE.
109FCKSelection.MoveToAncestorNode = function( nodeTagName )
110{
111        var oNode ;
112
113        if ( FCK.EditorDocument.selection.type == "Control" )
114        {
115                var oRange = FCK.EditorDocument.selection.createRange() ;
116                for ( i = 0 ; i < oRange.length ; i++ )
117                {
118                        if (oRange(i).parentNode)
119                        {
120                                oNode = oRange(i).parentNode ;
121                                break ;
122                        }
123                }
124        }
125        else
126        {
127                var oRange  = FCK.EditorDocument.selection.createRange() ;
128                oNode = oRange.parentElement() ;
129        }
130
131        while ( oNode && oNode.nodeName != nodeTagName )
132                oNode = oNode.parentNode ;
133
134        return oNode ;
135}
136
137FCKSelection.Delete = function()
138{
139        // Gets the actual selection.
140        var oSel = FCK.EditorDocument.selection ;
141
142        // Deletes the actual selection contents.
143        if ( oSel.type.toLowerCase() != "none" )
144        {
145                oSel.clear() ;
146        }
147
148        return oSel ;
149}
150
151
Note: See TracBrowser for help on using the repository browser.