[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 /* 2 * FCKeditor - The text editor for internet 3 * Copyright (C) 2003-2006 Frederico Caldeira Knabben 4 * 5 * Licensed under the terms of the GNU Lesser General Public License: 6 * http://www.opensource.org/licenses/lgpl-license.php 7 * 8 * For further information visit: 9 * http://www.fckeditor.net/ 10 * 11 * "Support Open Source software. What about a donation today?" 12 * 13 * File Name: fcktoolbarset.js 14 * Defines the FCKToolbarSet object that is used to load and draw the 15 * toolbar. 16 * 17 * File Authors: 18 * Frederico Caldeira Knabben (fredck@fckeditor.net) 19 */ 20 21 function FCKToolbarSet_Create( overhideLocation ) 22 { 23 var oToolbarSet ; 24 25 var sLocation = overhideLocation || FCKConfig.ToolbarLocation ; 26 switch ( sLocation ) 27 { 28 case 'In' : 29 document.getElementById( 'xToolbarRow' ).style.display = '' ; 30 oToolbarSet = new FCKToolbarSet( document ) ; 31 break ; 32 33 // case 'OutTop' : 34 // Not supported. 35 36 default : 37 FCK.Events.AttachEvent( 'OnBlur', FCK_OnBlur ) ; 38 FCK.Events.AttachEvent( 'OnFocus', FCK_OnFocus ) ; 39 40 var eToolbarTarget ; 41 42 // Out:[TargetWindow]([TargetId]) 43 var oOutMatch = sLocation.match( /^Out:(.+)\((\w+)\)$/ ) ; 44 if ( oOutMatch ) 45 { 46 eToolbarTarget = eval( 'parent.' + oOutMatch[1] ).document.getElementById( oOutMatch[2] ) ; 47 } 48 else 49 { 50 // Out:[TargetId] 51 oOutMatch = sLocation.match( /^Out:(\w+)$/ ) ; 52 if ( oOutMatch ) 53 eToolbarTarget = parent.document.getElementById( oOutMatch[1] ) ; 54 } 55 56 if ( !eToolbarTarget ) 57 { 58 alert( 'Invalid value for "ToolbarLocation"' ) ; 59 return this._Init( 'In' ) ; 60 } 61 62 // If it is a shared toolbar, it may be already available in the target element. 63 if ( oToolbarSet = eToolbarTarget.__FCKToolbarSet ) 64 break ; 65 66 // Create the IFRAME that will hold the toolbar inside the target element. 67 var eToolbarIFrame = FCKTools.GetElementDocument( eToolbarTarget ).createElement( 'iframe' ) ; 68 eToolbarIFrame.frameBorder = 0 ; 69 eToolbarIFrame.width = '100%' ; 70 eToolbarIFrame.height = '10' ; 71 eToolbarTarget.appendChild( eToolbarIFrame ) ; 72 eToolbarIFrame.unselectable = 'on' ; 73 74 // Write the basic HTML for the toolbar (copy from the editor main page). 75 var eTargetDocument = eToolbarIFrame.contentWindow.document ; 76 eTargetDocument.open() ; 77 eTargetDocument.write( '<html><head><script type="text/javascript"> window.onload = window.onresize = function() { window.frameElement.height = document.body.scrollHeight ; } </script></head><body style="overflow: hidden">' + document.getElementById( 'xToolbarSpace' ).innerHTML + '</body></html>' ) ; 78 eTargetDocument.close() ; 79 80 eTargetDocument.oncontextmenu = FCKTools.CancelEvent ; 81 82 // Load external resources (must be done here, otherwise Firefox will not 83 // have the document DOM ready to be used right away. 84 FCKTools.AppendStyleSheet( eTargetDocument, FCKConfig.SkinPath + 'fck_editor.css' ) ; 85 86 oToolbarSet = eToolbarTarget.__FCKToolbarSet = new FCKToolbarSet( eTargetDocument ) ; 87 oToolbarSet._IFrame = eToolbarIFrame ; 88 89 if ( FCK.IECleanup ) 90 FCK.IECleanup.AddItem( eToolbarTarget, FCKToolbarSet_Target_Cleanup ) ; 91 } 92 93 oToolbarSet.CurrentInstance = FCK ; 94 95 FCK.AttachToOnSelectionChange( oToolbarSet.RefreshItemsState ) ; 96 97 return oToolbarSet ; 98 } 99 100 function FCK_OnBlur( editorInstance ) 101 { 102 var eToolbarSet = editorInstance.ToolbarSet ; 103 104 if ( eToolbarSet.CurrentInstance == editorInstance ) 105 eToolbarSet.Disable() ; 106 } 107 108 function FCK_OnFocus( editorInstance ) 109 { 110 var oToolbarset = editorInstance.ToolbarSet ; 111 var oInstance = editorInstance || FCK ; 112 113 // Unregister the toolbar window from the current instance. 114 oToolbarset.CurrentInstance.FocusManager.RemoveWindow( oToolbarset._IFrame.contentWindow ) ; 115 116 // Set the new current instance. 117 oToolbarset.CurrentInstance = oInstance ; 118 119 // Register the toolbar window in the current instance. 120 oInstance.FocusManager.AddWindow( oToolbarset._IFrame.contentWindow, true ) ; 121 122 oToolbarset.Enable() ; 123 } 124 125 function FCKToolbarSet_Cleanup() 126 { 127 this._TargetElement = null ; 128 this._IFrame = null ; 129 } 130 131 function FCKToolbarSet_Target_Cleanup() 132 { 133 this.__FCKToolbarSet = null ; 134 } 135 136 var FCKToolbarSet = function( targetDocument ) 137 { 138 this._Document = targetDocument ; 139 140 // Get the element that will hold the elements structure. 141 this._TargetElement = targetDocument.getElementById( 'xToolbar' ) ; 142 143 // Setup the expand and collapse handlers. 144 var eExpandHandle = targetDocument.getElementById( 'xExpandHandle' ) ; 145 var eCollapseHandle = targetDocument.getElementById( 'xCollapseHandle' ) ; 146 147 eExpandHandle.title = FCKLang.ToolbarExpand ; 148 eExpandHandle.onclick = FCKToolbarSet_Expand_OnClick ; 149 150 eCollapseHandle.title = FCKLang.ToolbarCollapse ; 151 eCollapseHandle.onclick = FCKToolbarSet_Collapse_OnClick ; 152 153 // Set the toolbar state at startup. 154 if ( !FCKConfig.ToolbarCanCollapse || FCKConfig.ToolbarStartExpanded ) 155 this.Expand() ; 156 else 157 this.Collapse() ; 158 159 // Enable/disable the collapse handler 160 eCollapseHandle.style.display = FCKConfig.ToolbarCanCollapse ? '' : 'none' ; 161 162 if ( FCKConfig.ToolbarCanCollapse ) 163 eCollapseHandle.style.display = '' ; 164 else 165 targetDocument.getElementById( 'xTBLeftBorder' ).style.display = '' ; 166 167 // Set the default properties. 168 this.Toolbars = new Array() ; 169 this.IsLoaded = false ; 170 171 if ( FCK.IECleanup ) 172 FCK.IECleanup.AddItem( this, FCKToolbarSet_Cleanup ) ; 173 } 174 175 function FCKToolbarSet_Expand_OnClick() 176 { 177 FCK.ToolbarSet.Expand() ; 178 } 179 180 function FCKToolbarSet_Collapse_OnClick() 181 { 182 FCK.ToolbarSet.Collapse() ; 183 } 184 185 FCKToolbarSet.prototype.Expand = function() 186 { 187 this._ChangeVisibility( false ) ; 188 } 189 190 FCKToolbarSet.prototype.Collapse = function() 191 { 192 this._ChangeVisibility( true ) ; 193 } 194 195 FCKToolbarSet.prototype._ChangeVisibility = function( collapse ) 196 { 197 this._Document.getElementById( 'xCollapsed' ).style.display = collapse ? '' : 'none' ; 198 this._Document.getElementById( 'xExpanded' ).style.display = collapse ? 'none' : '' ; 199 200 if ( FCKBrowserInfo.IsGecko ) 201 { 202 // I had to use "setTimeout" because Gecko was not responding in a right 203 // way when calling window.onresize() directly. 204 FCKTools.RunFunction( window.onresize ) ; 205 } 206 } 207 208 FCKToolbarSet.prototype.Load = function( toolbarSetName ) 209 { 210 this.Name = toolbarSetName ; 211 212 this.Items = new Array() ; 213 214 // Reset the array of toolbat items that are active only on WYSIWYG mode. 215 this.ItemsWysiwygOnly = new Array() ; 216 217 // Reset the array of toolbar items that are sensitive to the cursor position. 218 this.ItemsContextSensitive = new Array() ; 219 220 // Cleanup the target element. 221 this._TargetElement.innerHTML = '' ; 222 223 var ToolbarSet = FCKConfig.ToolbarSets[toolbarSetName] ; 224 225 if ( !ToolbarSet ) 226 { 227 alert( FCKLang.UnknownToolbarSet.replace( /%1/g, toolbarSetName ) ) ; 228 return ; 229 } 230 231 this.Toolbars = new Array() ; 232 233 for ( var x = 0 ; x < ToolbarSet.length ; x++ ) 234 { 235 var oToolbarItems = ToolbarSet[x] ; 236 237 var oToolbar ; 238 239 if ( typeof( oToolbarItems ) == 'string' ) 240 { 241 if ( oToolbarItems == '/' ) 242 oToolbar = new FCKToolbarBreak() ; 243 } 244 else 245 { 246 oToolbar = new FCKToolbar() ; 247 248 for ( var j = 0 ; j < oToolbarItems.length ; j++ ) 249 { 250 var sItem = oToolbarItems[j] ; 251 252 if ( sItem == '-') 253 oToolbar.AddSeparator() ; 254 else 255 { 256 var oItem = FCKToolbarItems.GetItem( sItem ) ; 257 if ( oItem ) 258 { 259 oToolbar.AddItem( oItem ) ; 260 261 this.Items.push( oItem ) ; 262 263 if ( !oItem.SourceView ) 264 this.ItemsWysiwygOnly.push( oItem ) ; 265 266 if ( oItem.ContextSensitive ) 267 this.ItemsContextSensitive.push( oItem ) ; 268 } 269 } 270 } 271 272 // oToolbar.AddTerminator() ; 273 } 274 275 oToolbar.Create( this._TargetElement ) ; 276 277 this.Toolbars[ this.Toolbars.length ] = oToolbar ; 278 } 279 280 FCKTools.DisableSelection( this._Document.getElementById( 'xCollapseHandle' ).parentNode ) ; 281 282 if ( FCK.Status != FCK_STATUS_COMPLETE ) 283 FCK.Events.AttachEvent( 'OnStatusChange', this.RefreshModeState ) ; 284 else 285 this.RefreshModeState() ; 286 287 this.IsLoaded = true ; 288 this.IsEnabled = true ; 289 290 FCKTools.RunFunction( this.OnLoad ) ; 291 } 292 293 FCKToolbarSet.prototype.Enable = function() 294 { 295 if ( this.IsEnabled ) 296 return ; 297 298 this.IsEnabled = true ; 299 300 var aItems = this.Items ; 301 for ( var i = 0 ; i < aItems.length ; i++ ) 302 aItems[i].RefreshState() ; 303 } 304 305 FCKToolbarSet.prototype.Disable = function() 306 { 307 if ( !this.IsEnabled ) 308 return ; 309 310 this.IsEnabled = false ; 311 312 var aItems = this.Items ; 313 for ( var i = 0 ; i < aItems.length ; i++ ) 314 aItems[i].Disable() ; 315 } 316 317 FCKToolbarSet.prototype.RefreshModeState = function( editorInstance ) 318 { 319 if ( FCK.Status != FCK_STATUS_COMPLETE ) 320 return ; 321 322 var oToolbarSet = editorInstance ? editorInstance.ToolbarSet : this ; 323 var aItems = oToolbarSet.ItemsWysiwygOnly ; 324 325 if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ) 326 { 327 // Enable all buttons that are available on WYSIWYG mode only. 328 for ( var i = 0 ; i < aItems.length ; i++ ) 329 aItems[i].Enable() ; 330 331 // Refresh the buttons state. 332 oToolbarSet.RefreshItemsState( editorInstance ) ; 333 } 334 else 335 { 336 // Refresh the buttons state. 337 oToolbarSet.RefreshItemsState( editorInstance ) ; 338 339 // Disable all buttons that are available on WYSIWYG mode only. 340 for ( var i = 0 ; i < aItems.length ; i++ ) 341 aItems[i].Disable() ; 342 } 343 } 344 345 FCKToolbarSet.prototype.RefreshItemsState = function( editorInstance ) 346 { 347 348 var aItems = ( editorInstance ? editorInstance.ToolbarSet : this ).ItemsContextSensitive ; 349 350 for ( var i = 0 ; i < aItems.length ; i++ ) 351 aItems[i].RefreshState() ; 352 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |