| 1 |
/* |
| 2 |
|
| 3 |
* FCKeditor - The text editor for Internet - http://www.fckeditor.net |
| 4 |
|
| 5 |
* Copyright (C) 2003-2009 Frederico Caldeira Knabben |
| 6 |
|
| 7 |
* |
| 8 |
|
| 9 |
* == BEGIN LICENSE == |
| 10 |
|
| 11 |
* |
| 12 |
|
| 13 |
* Licensed under the terms of any of the following licenses at your |
| 14 |
|
| 15 |
* choice: |
| 16 |
|
| 17 |
* |
| 18 |
|
| 19 |
* - GNU General Public License Version 2 or later (the "GPL") |
| 20 |
|
| 21 |
* http://www.gnu.org/licenses/gpl.html |
| 22 |
|
| 23 |
* |
| 24 |
|
| 25 |
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL") |
| 26 |
|
| 27 |
* http://www.gnu.org/licenses/lgpl.html |
| 28 |
|
| 29 |
* |
| 30 |
|
| 31 |
* - Mozilla Public License Version 1.1 or later (the "MPL") |
| 32 |
|
| 33 |
* http://www.mozilla.org/MPL/MPL-1.1.html |
| 34 |
|
| 35 |
* |
| 36 |
|
| 37 |
* == END LICENSE == |
| 38 |
|
| 39 |
* |
| 40 |
|
| 41 |
* FCKShowBlockCommand Class: the "Show Blocks" command. |
| 42 |
|
| 43 |
*/ |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
var FCKShowBlockCommand = function( name, defaultState ) |
| 48 |
|
| 49 |
{ |
| 50 |
|
| 51 |
this.Name = name ; |
| 52 |
|
| 53 |
if ( defaultState != undefined ) |
| 54 |
|
| 55 |
this._SavedState = defaultState ; |
| 56 |
|
| 57 |
else |
| 58 |
|
| 59 |
this._SavedState = null ; |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
FCKShowBlockCommand.prototype.Execute = function() |
| 66 |
|
| 67 |
{ |
| 68 |
|
| 69 |
var state = this.GetState() ; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
if ( state == FCK_TRISTATE_DISABLED ) |
| 74 |
|
| 75 |
return ; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
var body = FCK.EditorDocument.body ; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
if ( state == FCK_TRISTATE_ON ) |
| 84 |
|
| 85 |
body.className = body.className.replace( /(^| )FCK__ShowBlocks/g, '' ) ; |
| 86 |
|
| 87 |
else |
| 88 |
|
| 89 |
body.className += ' FCK__ShowBlocks' ; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
if ( FCKBrowserInfo.IsIE ) |
| 94 |
|
| 95 |
{ |
| 96 |
|
| 97 |
try |
| 98 |
|
| 99 |
{ |
| 100 |
|
| 101 |
FCK.EditorDocument.selection.createRange().select() ; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
catch ( e ) |
| 106 |
|
| 107 |
{} |
| 108 |
|
| 109 |
} |
| 110 |
|
| 111 |
else |
| 112 |
|
| 113 |
{ |
| 114 |
|
| 115 |
var focus = FCK.EditorWindow.getSelection().focusNode ; |
| 116 |
|
| 117 |
if ( focus ) |
| 118 |
|
| 119 |
{ |
| 120 |
|
| 121 |
if ( focus.nodeType != 1 ) |
| 122 |
|
| 123 |
focus = focus.parentNode ; |
| 124 |
|
| 125 |
FCKDomTools.ScrollIntoView( focus, false ) ; |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
FCK.Events.FireEvent( 'OnSelectionChange' ) ; |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
FCKShowBlockCommand.prototype.GetState = function() |
| 140 |
|
| 141 |
{ |
| 142 |
|
| 143 |
if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG ) |
| 144 |
|
| 145 |
return FCK_TRISTATE_DISABLED ; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
// On some cases FCK.EditorDocument.body is not yet available |
| 150 |
|
| 151 |
if ( !FCK.EditorDocument ) |
| 152 |
|
| 153 |
return FCK_TRISTATE_OFF ; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
if ( /FCK__ShowBlocks(?:\s|$)/.test( FCK.EditorDocument.body.className ) ) |
| 158 |
|
| 159 |
return FCK_TRISTATE_ON ; |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
return FCK_TRISTATE_OFF ; |
| 164 |
|
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
FCKShowBlockCommand.prototype.SaveState = function() |
| 170 |
|
| 171 |
{ |
| 172 |
|
| 173 |
this._SavedState = this.GetState() ; |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
FCKShowBlockCommand.prototype.RestoreState = function() |
| 180 |
|
| 181 |
{ |
| 182 |
|
| 183 |
if ( this._SavedState != null && this.GetState() != this._SavedState ) |
| 184 |
|
| 185 |
this.Execute() ; |
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
|