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 * 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 FCK.Events.FireEvent( 'OnSelectionChange' ) ; 48} 49 50FCKShowBlockCommand.prototype.GetState = function() 51{ 52 if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG ) 53 return FCK_TRISTATE_DISABLED ; 54 55 // On some cases FCK.EditorDocument.body is not yet available, so try/catch. 56 try 57 { 58 if ( /FCK__ShowBlocks(?:\s|$)/.test( FCK.EditorDocument.body.className ) ) 59 return FCK_TRISTATE_ON ; 60 } 61 catch (e) 62 {} 63 64 return FCK_TRISTATE_OFF ; 65} 66 67FCKShowBlockCommand.prototype.SaveState = function() 68{ 69 this._SavedState = this.GetState() ; 70} 71 72FCKShowBlockCommand.prototype.RestoreState = function() 73{ 74 if ( this._SavedState != null && this.GetState() != this._SavedState ) 75 this.Execute() ; 76} 77