2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2009 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* Defines the FCKToolbarSet object that is used to load and draw the
25
function FCKToolbarSet_Create( overhideLocation )
29
var sLocation = overhideLocation || FCKConfig.ToolbarLocation ;
33
document.getElementById( 'xToolbarRow' ).style.display = '' ;
34
oToolbarSet = new FCKToolbarSet( document ) ;
37
oToolbarSet = new FCKToolbarSet( document ) ;
44
FCK.Events.AttachEvent( 'OnBlur', FCK_OnBlur ) ;
45
FCK.Events.AttachEvent( 'OnFocus', FCK_OnFocus ) ;
49
// Out:[TargetWindow]([TargetId])
50
var oOutMatch = sLocation.match( /^Out:(.+)\((\w+)\)$/ ) ;
53
if ( FCKBrowserInfo.IsAIR )
54
FCKAdobeAIR.ToolbarSet_GetOutElement( window, oOutMatch ) ;
56
eToolbarTarget = eval( 'parent.' + oOutMatch[1] ).document.getElementById( oOutMatch[2] ) ;
61
oOutMatch = sLocation.match( /^Out:(\w+)$/ ) ;
63
eToolbarTarget = parent.document.getElementById( oOutMatch[1] ) ;
66
if ( !eToolbarTarget )
68
alert( 'Invalid value for "ToolbarLocation"' ) ;
69
return arguments.callee( 'In' );
72
// If it is a shared toolbar, it may be already available in the target element.
73
oToolbarSet = eToolbarTarget.__FCKToolbarSet ;
77
// Create the IFRAME that will hold the toolbar inside the target element.
78
var eToolbarIFrame = FCKTools.GetElementDocument( eToolbarTarget ).createElement( 'iframe' ) ;
79
eToolbarIFrame.src = 'javascript:void(0)' ;
80
eToolbarIFrame.frameBorder = 0 ;
81
eToolbarIFrame.width = '100%' ;
82
eToolbarIFrame.height = '10' ;
83
eToolbarTarget.appendChild( eToolbarIFrame ) ;
84
eToolbarIFrame.unselectable = 'on' ;
86
// Write the basic HTML for the toolbar (copy from the editor main page).
87
var eTargetDocument = eToolbarIFrame.contentWindow.document ;
89
// Workaround for Safari 12256. Ticket #63
91
if ( FCKBrowserInfo.IsSafari )
92
sBase = '<base href="' + window.document.location + '">' ;
94
// Initialize the IFRAME document body.
95
eTargetDocument.open() ;
96
eTargetDocument.write( '<html><head>' + sBase + '<script type="text/javascript"> var adjust = function() { window.frameElement.height = document.body.scrollHeight ; }; '
97
+ 'window.onresize = window.onload = '
98
+ 'function(){' // poll scrollHeight until it no longer changes for 1 sec.
100
+ 'var lastHeight = -1;'
101
+ 'var lastChange = 0;'
102
+ 'var poller = function(){'
103
+ 'var currentHeight = document.body.scrollHeight || 0;'
104
+ 'var currentTime = (new Date()).getTime();'
105
+ 'if (currentHeight != lastHeight){'
106
+ 'lastChange = currentTime;'
108
+ 'lastHeight = document.body.scrollHeight;'
110
+ 'if (lastChange < currentTime - 1000) clearInterval(timer);'
112
+ 'timer = setInterval(poller, 100);'
114
+ '</script></head><body style="overflow: hidden">' + document.getElementById( 'xToolbarSpace' ).innerHTML + '</body></html>' ) ;
115
eTargetDocument.close() ;
117
if( FCKBrowserInfo.IsAIR )
118
FCKAdobeAIR.ToolbarSet_InitOutFrame( eTargetDocument ) ;
120
FCKTools.AddEventListener( eTargetDocument, 'contextmenu', FCKTools.CancelEvent ) ;
122
// Load external resources (must be done here, otherwise Firefox will not
123
// have the document DOM ready to be used right away.
124
FCKTools.AppendStyleSheet( eTargetDocument, FCKConfig.SkinEditorCSS ) ;
126
oToolbarSet = eToolbarTarget.__FCKToolbarSet = new FCKToolbarSet( eTargetDocument ) ;
127
oToolbarSet._IFrame = eToolbarIFrame ;
130
FCK.IECleanup.AddItem( eToolbarTarget, FCKToolbarSet_Target_Cleanup ) ;
133
oToolbarSet.CurrentInstance = FCK ;
134
if ( !oToolbarSet.ToolbarItems )
135
oToolbarSet.ToolbarItems = FCKToolbarItems ;
137
FCK.AttachToOnSelectionChange( oToolbarSet.RefreshItemsState ) ;
142
function FCK_OnBlur( editorInstance )
144
var eToolbarSet = editorInstance.ToolbarSet ;
146
if ( eToolbarSet.CurrentInstance == editorInstance )
147
eToolbarSet.Disable() ;
150
function FCK_OnFocus( editorInstance )
152
var oToolbarset = editorInstance.ToolbarSet ;
153
var oInstance = editorInstance || FCK ;
155
// Unregister the toolbar window from the current instance.
156
oToolbarset.CurrentInstance.FocusManager.RemoveWindow( oToolbarset._IFrame.contentWindow ) ;
158
// Set the new current instance.
159
oToolbarset.CurrentInstance = oInstance ;
161
// Register the toolbar window in the current instance.
162
oInstance.FocusManager.AddWindow( oToolbarset._IFrame.contentWindow, true ) ;
164
oToolbarset.Enable() ;
167
function FCKToolbarSet_Cleanup()
169
this._TargetElement = null ;
170
this._IFrame = null ;
173
function FCKToolbarSet_Target_Cleanup()
175
this.__FCKToolbarSet = null ;
178
var FCKToolbarSet = function( targetDocument )
180
this._Document = targetDocument ;
182
// Get the element that will hold the elements structure.
183
this._TargetElement = targetDocument.getElementById( 'xToolbar' ) ;
185
// Setup the expand and collapse handlers.
186
var eExpandHandle = targetDocument.getElementById( 'xExpandHandle' ) ;
187
var eCollapseHandle = targetDocument.getElementById( 'xCollapseHandle' ) ;
189
eExpandHandle.title = FCKLang.ToolbarExpand ;
190
FCKTools.AddEventListener( eExpandHandle, 'click', FCKToolbarSet_Expand_OnClick ) ;
192
eCollapseHandle.title = FCKLang.ToolbarCollapse ;
193
FCKTools.AddEventListener( eCollapseHandle, 'click', FCKToolbarSet_Collapse_OnClick ) ;
195
// Set the toolbar state at startup.
196
if ( !FCKConfig.ToolbarCanCollapse || FCKConfig.ToolbarStartExpanded )
201
// Enable/disable the collapse handler
202
eCollapseHandle.style.display = FCKConfig.ToolbarCanCollapse ? '' : 'none' ;
204
if ( FCKConfig.ToolbarCanCollapse )
205
eCollapseHandle.style.display = '' ;
207
targetDocument.getElementById( 'xTBLeftBorder' ).style.display = '' ;
209
// Set the default properties.
210
this.Toolbars = new Array() ;
211
this.IsLoaded = false ;
214
FCK.IECleanup.AddItem( this, FCKToolbarSet_Cleanup ) ;
217
function FCKToolbarSet_Expand_OnClick()
219
FCK.ToolbarSet.Expand() ;
222
function FCKToolbarSet_Collapse_OnClick()
224
FCK.ToolbarSet.Collapse() ;
227
FCKToolbarSet.prototype.Expand = function()
229
this._ChangeVisibility( false ) ;
232
FCKToolbarSet.prototype.Collapse = function()
234
this._ChangeVisibility( true ) ;
237
FCKToolbarSet.prototype._ChangeVisibility = function( collapse )
239
this._Document.getElementById( 'xCollapsed' ).style.display = collapse ? '' : 'none' ;
240
this._Document.getElementById( 'xExpanded' ).style.display = collapse ? 'none' : '' ;
242
if ( FCKBrowserInfo.IsGecko )
244
// I had to use "setTimeout" because Gecko was not responding in a right
245
// way when calling window.onresize() directly.
246
FCKTools.RunFunction( window.onresize ) ;
250
FCKToolbarSet.prototype.Load = function( toolbarSetName )
252
this.Name = toolbarSetName ;
254
this.Items = new Array() ;
256
// Reset the array of toolbar items that are active only on WYSIWYG mode.
257
this.ItemsWysiwygOnly = new Array() ;
259
// Reset the array of toolbar items that are sensitive to the cursor position.
260
this.ItemsContextSensitive = new Array() ;
262
// Cleanup the target element.
263
this._TargetElement.innerHTML = '' ;
265
var ToolbarSet = FCKConfig.ToolbarSets[toolbarSetName] ;
269
alert( FCKLang.UnknownToolbarSet.replace( /%1/g, toolbarSetName ) ) ;
273
this.Toolbars = new Array() ;
275
for ( var x = 0 ; x < ToolbarSet.length ; x++ )
277
var oToolbarItems = ToolbarSet[x] ;
279
// If the configuration for the toolbar is missing some element or has any extra comma
280
// this item won't be valid, so skip it and keep on processing.
281
if ( !oToolbarItems )
286
if ( typeof( oToolbarItems ) == 'string' )
288
if ( oToolbarItems == '/' )
289
oToolbar = new FCKToolbarBreak() ;
293
oToolbar = new FCKToolbar() ;
295
for ( var j = 0 ; j < oToolbarItems.length ; j++ )
297
var sItem = oToolbarItems[j] ;
300
oToolbar.AddSeparator() ;
303
var oItem = FCKToolbarItems.GetItem( sItem ) ;
306
oToolbar.AddItem( oItem ) ;
308
this.Items.push( oItem ) ;
310
if ( !oItem.SourceView )
311
this.ItemsWysiwygOnly.push( oItem ) ;
313
if ( oItem.ContextSensitive )
314
this.ItemsContextSensitive.push( oItem ) ;
319
// oToolbar.AddTerminator() ;
322
oToolbar.Create( this._TargetElement ) ;
324
this.Toolbars[ this.Toolbars.length ] = oToolbar ;
327
FCKTools.DisableSelection( this._Document.getElementById( 'xCollapseHandle' ).parentNode ) ;
329
if ( FCK.Status != FCK_STATUS_COMPLETE )
330
FCK.Events.AttachEvent( 'OnStatusChange', this.RefreshModeState ) ;
332
this.RefreshModeState() ;
334
this.IsLoaded = true ;
335
this.IsEnabled = true ;
337
FCKTools.RunFunction( this.OnLoad ) ;
340
FCKToolbarSet.prototype.Enable = function()
342
if ( this.IsEnabled )
345
this.IsEnabled = true ;
347
var aItems = this.Items ;
348
for ( var i = 0 ; i < aItems.length ; i++ )
349
aItems[i].RefreshState() ;
352
FCKToolbarSet.prototype.Disable = function()
354
if ( !this.IsEnabled )
357
this.IsEnabled = false ;
359
var aItems = this.Items ;
360
for ( var i = 0 ; i < aItems.length ; i++ )
361
aItems[i].Disable() ;
364
FCKToolbarSet.prototype.RefreshModeState = function( editorInstance )
366
if ( FCK.Status != FCK_STATUS_COMPLETE )
369
var oToolbarSet = editorInstance ? editorInstance.ToolbarSet : this ;
370
var aItems = oToolbarSet.ItemsWysiwygOnly ;
372
if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
374
// Enable all buttons that are available on WYSIWYG mode only.
375
for ( var i = 0 ; i < aItems.length ; i++ )
378
// Refresh the buttons state.
379
oToolbarSet.RefreshItemsState( editorInstance ) ;
383
// Refresh the buttons state.
384
oToolbarSet.RefreshItemsState( editorInstance ) ;
386
// Disable all buttons that are available on WYSIWYG mode only.
387
for ( var j = 0 ; j < aItems.length ; j++ )
388
aItems[j].Disable() ;
392
FCKToolbarSet.prototype.RefreshItemsState = function( editorInstance )
395
var aItems = ( editorInstance ? editorInstance.ToolbarSet : this ).ItemsContextSensitive ;
397
for ( var i = 0 ; i < aItems.length ; i++ )
398
aItems[i].RefreshState() ;