source: sandbox/filemanager/tp/fckeditor/editor/_source/commandclasses/fckshowblocks.js @ 1575

Revision 1575, 2.2 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implentação, melhorias do modulo gerenciador de arquivos

  • Property svn:executable set to *
Line 
1/*
2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 * Copyright (C) 2003-2009 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 * FCKShowBlockCommand Class: the "Show Blocks" command.
22 */
23
24var FCKShowBlockCommand = function( name, defaultState )
25{
26        this.Name = name ;
27        if ( defaultState != undefined )
28                this._SavedState = defaultState ;
29        else
30                this._SavedState = null ;
31}
32
33FCKShowBlockCommand.prototype.Execute = function()
34{
35        var state = this.GetState() ;
36
37        if ( state == FCK_TRISTATE_DISABLED )
38                return ;
39
40        var body = FCK.EditorDocument.body ;
41
42        if ( state == FCK_TRISTATE_ON )
43                body.className = body.className.replace( /(^| )FCK__ShowBlocks/g, '' ) ;
44        else
45                body.className += ' FCK__ShowBlocks' ;
46
47        if ( FCKBrowserInfo.IsIE )
48        {
49                try
50                {
51                        FCK.EditorDocument.selection.createRange().select() ;
52                }
53                catch ( e )
54                {}
55        }
56        else
57        {
58                var focus = FCK.EditorWindow.getSelection().focusNode ;
59                if ( focus )
60                {
61                        if ( focus.nodeType != 1 )
62                                focus = focus.parentNode ;
63                        FCKDomTools.ScrollIntoView( focus, false ) ;
64                }
65        }
66
67        FCK.Events.FireEvent( 'OnSelectionChange' ) ;
68}
69
70FCKShowBlockCommand.prototype.GetState = function()
71{
72        if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
73                return FCK_TRISTATE_DISABLED ;
74
75        // On some cases FCK.EditorDocument.body is not yet available
76        if ( !FCK.EditorDocument )
77                return FCK_TRISTATE_OFF ;
78
79        if ( /FCK__ShowBlocks(?:\s|$)/.test( FCK.EditorDocument.body.className ) )
80                return FCK_TRISTATE_ON ;
81
82        return FCK_TRISTATE_OFF ;
83}
84
85FCKShowBlockCommand.prototype.SaveState = function()
86{
87        this._SavedState = this.GetState() ;
88}
89
90FCKShowBlockCommand.prototype.RestoreState = function()
91{
92        if ( this._SavedState != null && this.GetState() != this._SavedState )
93                this.Execute() ;
94}
Note: See TracBrowser for help on using the repository browser.