2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * FCKShowBlockCommand Class: the "Show Blocks" command.
\r
24 var FCKShowBlockCommand = function( name, defaultState )
\r
27 if ( defaultState != undefined )
\r
28 this._SavedState = defaultState ;
\r
30 this._SavedState = null ;
\r
33 FCKShowBlockCommand.prototype.Execute = function()
\r
35 var state = this.GetState() ;
\r
37 if ( state == FCK_TRISTATE_DISABLED )
\r
40 var body = FCK.EditorDocument.body ;
\r
42 if ( state == FCK_TRISTATE_ON )
\r
43 body.className = body.className.replace( /(^| )FCK__ShowBlocks/g, '' ) ;
\r
45 body.className += ' FCK__ShowBlocks' ;
\r
47 if ( FCKBrowserInfo.IsIE )
\r
51 FCK.EditorDocument.selection.createRange().select() ;
\r
58 var focus = FCK.EditorWindow.getSelection().focusNode ;
\r
61 if ( focus.nodeType != 1 )
\r
62 focus = focus.parentNode ;
\r
63 FCKDomTools.ScrollIntoView( focus, false ) ;
\r
67 FCK.Events.FireEvent( 'OnSelectionChange' ) ;
\r
70 FCKShowBlockCommand.prototype.GetState = function()
\r
72 if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
\r
73 return FCK_TRISTATE_DISABLED ;
\r
75 // On some cases FCK.EditorDocument.body is not yet available
\r
76 if ( !FCK.EditorDocument )
\r
77 return FCK_TRISTATE_OFF ;
\r
79 if ( /FCK__ShowBlocks(?:\s|$)/.test( FCK.EditorDocument.body.className ) )
\r
80 return FCK_TRISTATE_ON ;
\r
82 return FCK_TRISTATE_OFF ;
\r
85 FCKShowBlockCommand.prototype.SaveState = function()
\r
87 this._SavedState = this.GetState() ;
\r
90 FCKShowBlockCommand.prototype.RestoreState = function()
\r
92 if ( this._SavedState != null && this.GetState() != this._SavedState )
\r