[ Index ] |
|
Code source de FCKeditor 2.4 |
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 * File Name: fck_othercommands.js 22 * Definition of other commands that are not available internaly in the 23 * browser (see FCKNamedCommand). 24 * 25 * File Authors: 26 * Frederico Caldeira Knabben (www.fckeditor.net) 27 * Alfonso Martinez de Lizarrondo - Uritec (alfonso at uritec dot net) 28 */ 29 30 // ### General Dialog Box Commands. 31 var FCKDialogCommand = function( name, title, url, width, height, getStateFunction, getStateParam ) 32 { 33 this.Name = name ; 34 this.Title = title ; 35 this.Url = url ; 36 this.Width = width ; 37 this.Height = height ; 38 39 this.GetStateFunction = getStateFunction ; 40 this.GetStateParam = getStateParam ; 41 42 this.Resizable = false ; 43 } 44 45 FCKDialogCommand.prototype.Execute = function() 46 { 47 FCKDialog.OpenDialog( 'FCKDialog_' + this.Name , this.Title, this.Url, this.Width, this.Height, null, null, this.Resizable ) ; 48 } 49 50 FCKDialogCommand.prototype.GetState = function() 51 { 52 if ( this.GetStateFunction ) 53 return this.GetStateFunction( this.GetStateParam ) ; 54 else 55 return FCK_TRISTATE_OFF ; 56 } 57 58 // Generic Undefined command (usually used when a command is under development). 59 var FCKUndefinedCommand = function() 60 { 61 this.Name = 'Undefined' ; 62 } 63 64 FCKUndefinedCommand.prototype.Execute = function() 65 { 66 alert( FCKLang.NotImplemented ) ; 67 } 68 69 FCKUndefinedCommand.prototype.GetState = function() 70 { 71 return FCK_TRISTATE_OFF ; 72 } 73 74 // ### FontName 75 var FCKFontNameCommand = function() 76 { 77 this.Name = 'FontName' ; 78 } 79 80 FCKFontNameCommand.prototype.Execute = function( fontName ) 81 { 82 if (fontName == null || fontName == "") 83 { 84 // TODO: Remove font name attribute. 85 } 86 else 87 FCK.ExecuteNamedCommand( 'FontName', fontName ) ; 88 } 89 90 FCKFontNameCommand.prototype.GetState = function() 91 { 92 return FCK.GetNamedCommandValue( 'FontName' ) ; 93 } 94 95 // ### FontSize 96 var FCKFontSizeCommand = function() 97 { 98 this.Name = 'FontSize' ; 99 } 100 101 FCKFontSizeCommand.prototype.Execute = function( fontSize ) 102 { 103 if ( typeof( fontSize ) == 'string' ) fontSize = parseInt(fontSize, 10) ; 104 105 if ( fontSize == null || fontSize == '' ) 106 { 107 // TODO: Remove font size attribute (Now it works with size 3. Will it work forever?) 108 FCK.ExecuteNamedCommand( 'FontSize', 3 ) ; 109 } 110 else 111 FCK.ExecuteNamedCommand( 'FontSize', fontSize ) ; 112 } 113 114 FCKFontSizeCommand.prototype.GetState = function() 115 { 116 return FCK.GetNamedCommandValue( 'FontSize' ) ; 117 } 118 119 // ### FormatBlock 120 var FCKFormatBlockCommand = function() 121 { 122 this.Name = 'FormatBlock' ; 123 } 124 125 FCKFormatBlockCommand.prototype.Execute = function( formatName ) 126 { 127 if ( formatName == null || formatName == '' ) 128 FCK.ExecuteNamedCommand( 'FormatBlock', '<P>' ) ; 129 else if ( formatName == 'div' && FCKBrowserInfo.IsGecko ) 130 FCK.ExecuteNamedCommand( 'FormatBlock', 'div' ) ; 131 else 132 FCK.ExecuteNamedCommand( 'FormatBlock', '<' + formatName + '>' ) ; 133 } 134 135 FCKFormatBlockCommand.prototype.GetState = function() 136 { 137 return FCK.GetNamedCommandValue( 'FormatBlock' ) ; 138 } 139 140 // ### Preview 141 var FCKPreviewCommand = function() 142 { 143 this.Name = 'Preview' ; 144 } 145 146 FCKPreviewCommand.prototype.Execute = function() 147 { 148 FCK.Preview() ; 149 } 150 151 FCKPreviewCommand.prototype.GetState = function() 152 { 153 return FCK_TRISTATE_OFF ; 154 } 155 156 // ### Save 157 var FCKSaveCommand = function() 158 { 159 this.Name = 'Save' ; 160 } 161 162 FCKSaveCommand.prototype.Execute = function() 163 { 164 // Get the linked field form. 165 var oForm = FCK.GetParentForm() ; 166 167 if ( typeof( oForm.onsubmit ) == 'function' ) 168 { 169 var bRet = oForm.onsubmit() ; 170 if ( bRet != null && bRet === false ) 171 return ; 172 } 173 174 // Submit the form. 175 oForm.submit() ; 176 } 177 178 FCKSaveCommand.prototype.GetState = function() 179 { 180 return FCK_TRISTATE_OFF ; 181 } 182 183 // ### NewPage 184 var FCKNewPageCommand = function() 185 { 186 this.Name = 'NewPage' ; 187 } 188 189 FCKNewPageCommand.prototype.Execute = function() 190 { 191 FCKUndo.SaveUndoStep() ; 192 FCK.SetHTML( '' ) ; 193 FCKUndo.Typing = true ; 194 } 195 196 FCKNewPageCommand.prototype.GetState = function() 197 { 198 return FCK_TRISTATE_OFF ; 199 } 200 201 // ### Source button 202 var FCKSourceCommand = function() 203 { 204 this.Name = 'Source' ; 205 } 206 207 FCKSourceCommand.prototype.Execute = function() 208 { 209 if ( FCKConfig.SourcePopup ) // Until v2.2, it was mandatory for FCKBrowserInfo.IsGecko. 210 { 211 var iWidth = FCKConfig.ScreenWidth * 0.65 ; 212 var iHeight = FCKConfig.ScreenHeight * 0.65 ; 213 FCKDialog.OpenDialog( 'FCKDialog_Source', FCKLang.Source, 'dialog/fck_source.html', iWidth, iHeight, null, null, true ) ; 214 } 215 else 216 FCK.SwitchEditMode() ; 217 } 218 219 FCKSourceCommand.prototype.GetState = function() 220 { 221 return ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_ON ) ; 222 } 223 224 // ### Undo 225 var FCKUndoCommand = function() 226 { 227 this.Name = 'Undo' ; 228 } 229 230 FCKUndoCommand.prototype.Execute = function() 231 { 232 if ( FCKBrowserInfo.IsIE ) 233 FCKUndo.Undo() ; 234 else 235 FCK.ExecuteNamedCommand( 'Undo' ) ; 236 } 237 238 FCKUndoCommand.prototype.GetState = function() 239 { 240 if ( FCKBrowserInfo.IsIE ) 241 return ( FCKUndo.CheckUndoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ; 242 else 243 return FCK.GetNamedCommandState( 'Undo' ) ; 244 } 245 246 // ### Redo 247 var FCKRedoCommand = function() 248 { 249 this.Name = 'Redo' ; 250 } 251 252 FCKRedoCommand.prototype.Execute = function() 253 { 254 if ( FCKBrowserInfo.IsIE ) 255 FCKUndo.Redo() ; 256 else 257 FCK.ExecuteNamedCommand( 'Redo' ) ; 258 } 259 260 FCKRedoCommand.prototype.GetState = function() 261 { 262 if ( FCKBrowserInfo.IsIE ) 263 return ( FCKUndo.CheckRedoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ; 264 else 265 return FCK.GetNamedCommandState( 'Redo' ) ; 266 } 267 268 // ### Page Break 269 var FCKPageBreakCommand = function() 270 { 271 this.Name = 'PageBreak' ; 272 } 273 274 FCKPageBreakCommand.prototype.Execute = function() 275 { 276 // var e = FCK.EditorDocument.createElement( 'CENTER' ) ; 277 // e.style.pageBreakAfter = 'always' ; 278 279 // Tidy was removing the empty CENTER tags, so the following solution has 280 // been found. It also validates correctly as XHTML 1.0 Strict. 281 var e = FCK.EditorDocument.createElement( 'DIV' ) ; 282 e.style.pageBreakAfter = 'always' ; 283 e.innerHTML = '<span style="DISPLAY:none"> </span>' ; 284 285 var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', e ) ; 286 oFakeImage = FCK.InsertElement( oFakeImage ) ; 287 } 288 289 FCKPageBreakCommand.prototype.GetState = function() 290 { 291 return 0 ; // FCK_TRISTATE_OFF 292 } 293 294 // FCKUnlinkCommand - by Johnny Egeland (johnny@coretrek.com) 295 var FCKUnlinkCommand = function() 296 { 297 this.Name = 'Unlink' ; 298 } 299 300 FCKUnlinkCommand.prototype.Execute = function() 301 { 302 if ( FCKBrowserInfo.IsGecko ) 303 { 304 var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ; 305 if ( oLink ) 306 FCK.Selection.SelectNode( oLink ) ; 307 } 308 309 FCK.ExecuteNamedCommand( this.Name ) ; 310 311 if ( FCKBrowserInfo.IsGecko ) 312 FCK.Selection.Collapse( true ) ; 313 } 314 315 FCKUnlinkCommand.prototype.GetState = function() 316 { 317 var state = FCK.GetNamedCommandState( this.Name ) ; 318 319 // Check that it isn't an anchor 320 if ( state == FCK_TRISTATE_OFF && FCK.EditMode == FCK_EDITMODE_WYSIWYG ) 321 { 322 var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ; 323 var bIsAnchor = ( oLink && oLink.name.length > 0 && oLink.href.length == 0 ) ; 324 if ( bIsAnchor ) 325 state = FCK_TRISTATE_DISABLED ; 326 } 327 328 return state ; 329 } 330 331 // FCKSelectAllCommand 332 var FCKSelectAllCommand = function() 333 { 334 this.Name = 'SelectAll' ; 335 } 336 337 FCKSelectAllCommand.prototype = new FCKNamedCommand( 'SelectAll' ) ; 338 339 FCKSelectAllCommand.prototype.GetState = function() 340 { 341 return FCK_TRISTATE_OFF ; 342 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 15:28:05 2007 | par Balluche grâce à PHPXref 0.7 |