import torrus 1.0.9
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / commandclasses / fckshowblocks.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * FCKShowBlockCommand Class: the "Show Blocks" command.\r
22  */\r
23 \r
24 var FCKShowBlockCommand = function( name, defaultState )\r
25 {\r
26         this.Name = name ;\r
27         if ( defaultState != undefined )\r
28                 this._SavedState = defaultState ;\r
29         else\r
30                 this._SavedState = null ;\r
31 }\r
32 \r
33 FCKShowBlockCommand.prototype.Execute = function()\r
34 {\r
35         var state = this.GetState() ;\r
36 \r
37         if ( state == FCK_TRISTATE_DISABLED )\r
38                 return ;\r
39 \r
40         var body = FCK.EditorDocument.body ;\r
41 \r
42         if ( state == FCK_TRISTATE_ON )\r
43                 body.className = body.className.replace( /(^| )FCK__ShowBlocks/g, '' ) ;\r
44         else\r
45                 body.className += ' FCK__ShowBlocks' ;\r
46 \r
47         if ( FCKBrowserInfo.IsIE )\r
48         {\r
49                 try\r
50                 {\r
51                         FCK.EditorDocument.selection.createRange().select() ;\r
52                 }\r
53                 catch ( e )\r
54                 {}\r
55         }\r
56         else\r
57         {\r
58                 var focus = FCK.EditorWindow.getSelection().focusNode ;\r
59                 if ( focus )\r
60                 {\r
61                         if ( focus.nodeType != 1 )\r
62                                 focus = focus.parentNode ;\r
63                         FCKDomTools.ScrollIntoView( focus, false ) ;\r
64                 }\r
65         }\r
66 \r
67         FCK.Events.FireEvent( 'OnSelectionChange' ) ;\r
68 }\r
69 \r
70 FCKShowBlockCommand.prototype.GetState = function()\r
71 {\r
72         if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
73                 return FCK_TRISTATE_DISABLED ;\r
74 \r
75         // On some cases FCK.EditorDocument.body is not yet available\r
76         if ( !FCK.EditorDocument )\r
77                 return FCK_TRISTATE_OFF ;\r
78 \r
79         if ( /FCK__ShowBlocks(?:\s|$)/.test( FCK.EditorDocument.body.className ) )\r
80                 return FCK_TRISTATE_ON ;\r
81 \r
82         return FCK_TRISTATE_OFF ;\r
83 }\r
84 \r
85 FCKShowBlockCommand.prototype.SaveState = function()\r
86 {\r
87         this._SavedState = this.GetState() ;\r
88 }\r
89 \r
90 FCKShowBlockCommand.prototype.RestoreState = function()\r
91 {\r
92         if ( this._SavedState != null && this.GetState() != this._SavedState )\r
93                 this.Execute() ;\r
94 }\r