2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2007 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 ) ;
41
FCK.Events.AttachEvent( 'OnBlur', FCK_OnBlur ) ;
42
FCK.Events.AttachEvent( 'OnFocus', FCK_OnFocus ) ;
46
// Out:[TargetWindow]([TargetId])
47
var oOutMatch = sLocation.match( /^Out:(.+)\((\w+)\)$/ ) ;
50
eToolbarTarget = eval( 'parent.' + oOutMatch[1] ).document.getElementById( oOutMatch[2] ) ;
55
oOutMatch = sLocation.match( /^Out:(\w+)$/ ) ;
57
eToolbarTarget = parent.document.getElementById( oOutMatch[1] ) ;
60
if ( !eToolbarTarget )
62
alert( 'Invalid value for "ToolbarLocation"' ) ;
63
return this._Init( 'In' ) ;
66
// If it is a shared toolbar, it may be already available in the target element.
67
oToolbarSet = eToolbarTarget.__FCKToolbarSet ;
71
// Create the IFRAME that will hold the toolbar inside the target element.
72
var eToolbarIFrame = FCKTools.GetElementDocument( eToolbarTarget ).createElement( 'iframe' ) ;
73
eToolbarIFrame.src = 'javascript:void(0)' ;
74
eToolbarIFrame.frameBorder = 0 ;
75
eToolbarIFrame.width = '100%' ;
76
eToolbarIFrame.height = '10' ;
77
eToolbarTarget.appendChild( eToolbarIFrame ) ;
78
eToolbarIFrame.unselectable = 'on' ;
80
// Write the basic HTML for the toolbar (copy from the editor main page).
81
var eTargetDocument = eToolbarIFrame.contentWindow.document ;
82
eTargetDocument.open() ;
83
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>' ) ;
84
eTargetDocument.close() ;
86
eTargetDocument.oncontextmenu = FCKTools.CancelEvent ;
88
// Load external resources (must be done here, otherwise Firefox will not
89
// have the document DOM ready to be used right away.
90
FCKTools.AppendStyleSheet( eTargetDocument, FCKConfig.SkinPath + 'fck_editor.css' ) ;
92
oToolbarSet = eToolbarTarget.__FCKToolbarSet = new FCKToolbarSet( eTargetDocument ) ;
93
oToolbarSet._IFrame = eToolbarIFrame ;
96
FCK.IECleanup.AddItem( eToolbarTarget, FCKToolbarSet_Target_Cleanup ) ;
99
oToolbarSet.CurrentInstance = FCK ;
101
FCK.AttachToOnSelectionChange( oToolbarSet.RefreshItemsState ) ;
106
function FCK_OnBlur( editorInstance )
108
var eToolbarSet = editorInstance.ToolbarSet ;
110
if ( eToolbarSet.CurrentInstance == editorInstance )
111
eToolbarSet.Disable() ;
114
function FCK_OnFocus( editorInstance )
116
var oToolbarset = editorInstance.ToolbarSet ;
117
var oInstance = editorInstance || FCK ;
119
// Unregister the toolbar window from the current instance.
120
oToolbarset.CurrentInstance.FocusManager.RemoveWindow( oToolbarset._IFrame.contentWindow ) ;
122
// Set the new current instance.
123
oToolbarset.CurrentInstance = oInstance ;
125
// Register the toolbar window in the current instance.
126
oInstance.FocusManager.AddWindow( oToolbarset._IFrame.contentWindow, true ) ;
128
oToolbarset.Enable() ;
131
function FCKToolbarSet_Cleanup()
133
this._TargetElement = null ;
134
this._IFrame = null ;
137
function FCKToolbarSet_Target_Cleanup()
139
this.__FCKToolbarSet = null ;
142
var FCKToolbarSet = function( targetDocument )
144
this._Document = targetDocument ;
146
// Get the element that will hold the elements structure.
147
this._TargetElement = targetDocument.getElementById( 'xToolbar' ) ;
149
// Setup the expand and collapse handlers.
150
var eExpandHandle = targetDocument.getElementById( 'xExpandHandle' ) ;
151
var eCollapseHandle = targetDocument.getElementById( 'xCollapseHandle' ) ;
153
eExpandHandle.title = FCKLang.ToolbarExpand ;
154
eExpandHandle.onclick = FCKToolbarSet_Expand_OnClick ;
156
eCollapseHandle.title = FCKLang.ToolbarCollapse ;
157
eCollapseHandle.onclick = FCKToolbarSet_Collapse_OnClick ;
159
// Set the toolbar state at startup.
160
if ( !FCKConfig.ToolbarCanCollapse || FCKConfig.ToolbarStartExpanded )
165
// Enable/disable the collapse handler
166
eCollapseHandle.style.display = FCKConfig.ToolbarCanCollapse ? '' : 'none' ;
168
if ( FCKConfig.ToolbarCanCollapse )
169
eCollapseHandle.style.display = '' ;
171
targetDocument.getElementById( 'xTBLeftBorder' ).style.display = '' ;
173
// Set the default properties.
174
this.Toolbars = new Array() ;
175
this.IsLoaded = false ;
178
FCK.IECleanup.AddItem( this, FCKToolbarSet_Cleanup ) ;
181
function FCKToolbarSet_Expand_OnClick()
183
FCK.ToolbarSet.Expand() ;
186
function FCKToolbarSet_Collapse_OnClick()
188
FCK.ToolbarSet.Collapse() ;
191
FCKToolbarSet.prototype.Expand = function()
193
this._ChangeVisibility( false ) ;
196
FCKToolbarSet.prototype.Collapse = function()
198
this._ChangeVisibility( true ) ;
201
FCKToolbarSet.prototype._ChangeVisibility = function( collapse )
203
this._Document.getElementById( 'xCollapsed' ).style.display = collapse ? '' : 'none' ;
204
this._Document.getElementById( 'xExpanded' ).style.display = collapse ? 'none' : '' ;
206
if ( FCKBrowserInfo.IsGecko )
208
// I had to use "setTimeout" because Gecko was not responding in a right
209
// way when calling window.onresize() directly.
210
FCKTools.RunFunction( window.onresize ) ;
214
FCKToolbarSet.prototype.Load = function( toolbarSetName )
216
this.Name = toolbarSetName ;
218
this.Items = new Array() ;
220
// Reset the array of toolbat items that are active only on WYSIWYG mode.
221
this.ItemsWysiwygOnly = new Array() ;
223
// Reset the array of toolbar items that are sensitive to the cursor position.
224
this.ItemsContextSensitive = new Array() ;
226
// Cleanup the target element.
227
this._TargetElement.innerHTML = '' ;
229
var ToolbarSet = FCKConfig.ToolbarSets[toolbarSetName] ;
233
alert( FCKLang.UnknownToolbarSet.replace( /%1/g, toolbarSetName ) ) ;
237
this.Toolbars = new Array() ;
239
for ( var x = 0 ; x < ToolbarSet.length ; x++ )
241
var oToolbarItems = ToolbarSet[x] ;
243
// If the configuration for the toolbar is missing some element or has any extra comma
244
// this item won't be valid, so skip it and keep on processing.
245
if ( !oToolbarItems )
250
if ( typeof( oToolbarItems ) == 'string' )
252
if ( oToolbarItems == '/' )
253
oToolbar = new FCKToolbarBreak() ;
257
oToolbar = new FCKToolbar() ;
259
for ( var j = 0 ; j < oToolbarItems.length ; j++ )
261
var sItem = oToolbarItems[j] ;
264
oToolbar.AddSeparator() ;
267
var oItem = FCKToolbarItems.GetItem( sItem ) ;
270
oToolbar.AddItem( oItem ) ;
272
this.Items.push( oItem ) ;
274
if ( !oItem.SourceView )
275
this.ItemsWysiwygOnly.push( oItem ) ;
277
if ( oItem.ContextSensitive )
278
this.ItemsContextSensitive.push( oItem ) ;
283
// oToolbar.AddTerminator() ;
286
oToolbar.Create( this._TargetElement ) ;
288
this.Toolbars[ this.Toolbars.length ] = oToolbar ;
291
FCKTools.DisableSelection( this._Document.getElementById( 'xCollapseHandle' ).parentNode ) ;
293
if ( FCK.Status != FCK_STATUS_COMPLETE )
294
FCK.Events.AttachEvent( 'OnStatusChange', this.RefreshModeState ) ;
296
this.RefreshModeState() ;
298
this.IsLoaded = true ;
299
this.IsEnabled = true ;
301
FCKTools.RunFunction( this.OnLoad ) ;
304
FCKToolbarSet.prototype.Enable = function()
306
if ( this.IsEnabled )
309
this.IsEnabled = true ;
311
var aItems = this.Items ;
312
for ( var i = 0 ; i < aItems.length ; i++ )
313
aItems[i].RefreshState() ;
316
FCKToolbarSet.prototype.Disable = function()
318
if ( !this.IsEnabled )
321
this.IsEnabled = false ;
323
var aItems = this.Items ;
324
for ( var i = 0 ; i < aItems.length ; i++ )
325
aItems[i].Disable() ;
328
FCKToolbarSet.prototype.RefreshModeState = function( editorInstance )
330
if ( FCK.Status != FCK_STATUS_COMPLETE )
333
var oToolbarSet = editorInstance ? editorInstance.ToolbarSet : this ;
334
var aItems = oToolbarSet.ItemsWysiwygOnly ;
336
if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
338
// Enable all buttons that are available on WYSIWYG mode only.
339
for ( var i = 0 ; i < aItems.length ; i++ )
342
// Refresh the buttons state.
343
oToolbarSet.RefreshItemsState( editorInstance ) ;
347
// Refresh the buttons state.
348
oToolbarSet.RefreshItemsState( editorInstance ) ;
350
// Disable all buttons that are available on WYSIWYG mode only.
351
for ( var j = 0 ; j < aItems.length ; j++ )
352
aItems[j].Disable() ;
356
FCKToolbarSet.prototype.RefreshItemsState = function( editorInstance )
359
var aItems = ( editorInstance ? editorInstance.ToolbarSet : this ).ItemsContextSensitive ;
361
for ( var i = 0 ; i < aItems.length ; i++ )
362
aItems[i].RefreshState() ;