~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/FCK/editor/_source/internals/fcktoolbarset.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * Defines the FCKToolbarSet object that is used to load and draw the
 
22
 * toolbar.
 
23
 */
 
24
 
 
25
function FCKToolbarSet_Create( overhideLocation )
 
26
{
 
27
        var oToolbarSet ;
 
28
 
 
29
        var sLocation = overhideLocation || FCKConfig.ToolbarLocation ;
 
30
        switch ( sLocation )
 
31
        {
 
32
                case 'In' :
 
33
                                document.getElementById( 'xToolbarRow' ).style.display = '' ;
 
34
                                oToolbarSet = new FCKToolbarSet( document ) ;
 
35
                        break ;
 
36
 
 
37
//              case 'OutTop' :
 
38
                        // Not supported.
 
39
 
 
40
                default :
 
41
                        FCK.Events.AttachEvent( 'OnBlur', FCK_OnBlur ) ;
 
42
                        FCK.Events.AttachEvent( 'OnFocus', FCK_OnFocus ) ;
 
43
 
 
44
                        var eToolbarTarget ;
 
45
 
 
46
                        // Out:[TargetWindow]([TargetId])
 
47
                        var oOutMatch = sLocation.match( /^Out:(.+)\((\w+)\)$/ ) ;
 
48
                        if ( oOutMatch )
 
49
                        {
 
50
                                eToolbarTarget = eval( 'parent.' + oOutMatch[1] ).document.getElementById( oOutMatch[2] ) ;
 
51
                        }
 
52
                        else
 
53
                        {
 
54
                                // Out:[TargetId]
 
55
                                oOutMatch = sLocation.match( /^Out:(\w+)$/ ) ;
 
56
                                if ( oOutMatch )
 
57
                                        eToolbarTarget = parent.document.getElementById( oOutMatch[1] ) ;
 
58
                        }
 
59
 
 
60
                        if ( !eToolbarTarget )
 
61
                        {
 
62
                                alert( 'Invalid value for "ToolbarLocation"' ) ;
 
63
                                return this._Init( 'In' ) ;
 
64
                        }
 
65
 
 
66
                        // If it is a shared toolbar, it may be already available in the target element.
 
67
                        oToolbarSet = eToolbarTarget.__FCKToolbarSet ;
 
68
                        if ( oToolbarSet )
 
69
                                break ;
 
70
 
 
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' ;
 
79
 
 
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() ;
 
85
 
 
86
                        eTargetDocument.oncontextmenu = FCKTools.CancelEvent ;
 
87
 
 
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' ) ;
 
91
 
 
92
                        oToolbarSet = eToolbarTarget.__FCKToolbarSet = new FCKToolbarSet( eTargetDocument ) ;
 
93
                        oToolbarSet._IFrame = eToolbarIFrame ;
 
94
 
 
95
                        if ( FCK.IECleanup )
 
96
                                FCK.IECleanup.AddItem( eToolbarTarget, FCKToolbarSet_Target_Cleanup ) ;
 
97
        }
 
98
 
 
99
        oToolbarSet.CurrentInstance = FCK ;
 
100
 
 
101
        FCK.AttachToOnSelectionChange( oToolbarSet.RefreshItemsState ) ;
 
102
 
 
103
        return oToolbarSet ;
 
104
}
 
105
 
 
106
function FCK_OnBlur( editorInstance )
 
107
{
 
108
        var eToolbarSet = editorInstance.ToolbarSet ;
 
109
 
 
110
        if ( eToolbarSet.CurrentInstance == editorInstance )
 
111
                eToolbarSet.Disable() ;
 
112
}
 
113
 
 
114
function FCK_OnFocus( editorInstance )
 
115
{
 
116
        var oToolbarset = editorInstance.ToolbarSet ;
 
117
        var oInstance = editorInstance || FCK ;
 
118
 
 
119
        // Unregister the toolbar window from the current instance.
 
120
        oToolbarset.CurrentInstance.FocusManager.RemoveWindow( oToolbarset._IFrame.contentWindow ) ;
 
121
 
 
122
        // Set the new current instance.
 
123
        oToolbarset.CurrentInstance = oInstance ;
 
124
 
 
125
        // Register the toolbar window in the current instance.
 
126
        oInstance.FocusManager.AddWindow( oToolbarset._IFrame.contentWindow, true ) ;
 
127
 
 
128
        oToolbarset.Enable() ;
 
129
}
 
130
 
 
131
function FCKToolbarSet_Cleanup()
 
132
{
 
133
        this._TargetElement = null ;
 
134
        this._IFrame = null ;
 
135
}
 
136
 
 
137
function FCKToolbarSet_Target_Cleanup()
 
138
{
 
139
        this.__FCKToolbarSet = null ;
 
140
}
 
141
 
 
142
var FCKToolbarSet = function( targetDocument )
 
143
{
 
144
        this._Document = targetDocument ;
 
145
 
 
146
        // Get the element that will hold the elements structure.
 
147
        this._TargetElement     = targetDocument.getElementById( 'xToolbar' ) ;
 
148
 
 
149
        // Setup the expand and collapse handlers.
 
150
        var eExpandHandle       = targetDocument.getElementById( 'xExpandHandle' ) ;
 
151
        var eCollapseHandle     = targetDocument.getElementById( 'xCollapseHandle' ) ;
 
152
 
 
153
        eExpandHandle.title             = FCKLang.ToolbarExpand ;
 
154
        eExpandHandle.onclick   = FCKToolbarSet_Expand_OnClick ;
 
155
 
 
156
        eCollapseHandle.title   = FCKLang.ToolbarCollapse ;
 
157
        eCollapseHandle.onclick = FCKToolbarSet_Collapse_OnClick ;
 
158
 
 
159
        // Set the toolbar state at startup.
 
160
        if ( !FCKConfig.ToolbarCanCollapse || FCKConfig.ToolbarStartExpanded )
 
161
                this.Expand() ;
 
162
        else
 
163
                this.Collapse() ;
 
164
 
 
165
        // Enable/disable the collapse handler
 
166
        eCollapseHandle.style.display = FCKConfig.ToolbarCanCollapse ? '' : 'none' ;
 
167
 
 
168
        if ( FCKConfig.ToolbarCanCollapse )
 
169
                eCollapseHandle.style.display = '' ;
 
170
        else
 
171
                targetDocument.getElementById( 'xTBLeftBorder' ).style.display = '' ;
 
172
 
 
173
        // Set the default properties.
 
174
        this.Toolbars = new Array() ;
 
175
        this.IsLoaded = false ;
 
176
 
 
177
        if ( FCK.IECleanup )
 
178
                FCK.IECleanup.AddItem( this, FCKToolbarSet_Cleanup ) ;
 
179
}
 
180
 
 
181
function FCKToolbarSet_Expand_OnClick()
 
182
{
 
183
        FCK.ToolbarSet.Expand() ;
 
184
}
 
185
 
 
186
function FCKToolbarSet_Collapse_OnClick()
 
187
{
 
188
        FCK.ToolbarSet.Collapse() ;
 
189
}
 
190
 
 
191
FCKToolbarSet.prototype.Expand = function()
 
192
{
 
193
        this._ChangeVisibility( false ) ;
 
194
}
 
195
 
 
196
FCKToolbarSet.prototype.Collapse = function()
 
197
{
 
198
        this._ChangeVisibility( true ) ;
 
199
}
 
200
 
 
201
FCKToolbarSet.prototype._ChangeVisibility = function( collapse )
 
202
{
 
203
        this._Document.getElementById( 'xCollapsed' ).style.display = collapse ? '' : 'none' ;
 
204
        this._Document.getElementById( 'xExpanded' ).style.display = collapse ? 'none' : '' ;
 
205
 
 
206
        if ( FCKBrowserInfo.IsGecko )
 
207
        {
 
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 ) ;
 
211
        }
 
212
}
 
213
 
 
214
FCKToolbarSet.prototype.Load = function( toolbarSetName )
 
215
{
 
216
        this.Name = toolbarSetName ;
 
217
 
 
218
        this.Items = new Array() ;
 
219
 
 
220
        // Reset the array of toolbat items that are active only on WYSIWYG mode.
 
221
        this.ItemsWysiwygOnly = new Array() ;
 
222
 
 
223
        // Reset the array of toolbar items that are sensitive to the cursor position.
 
224
        this.ItemsContextSensitive = new Array() ;
 
225
 
 
226
        // Cleanup the target element.
 
227
        this._TargetElement.innerHTML = '' ;
 
228
 
 
229
        var ToolbarSet = FCKConfig.ToolbarSets[toolbarSetName] ;
 
230
 
 
231
        if ( !ToolbarSet )
 
232
        {
 
233
                alert( FCKLang.UnknownToolbarSet.replace( /%1/g, toolbarSetName ) ) ;
 
234
                return ;
 
235
        }
 
236
 
 
237
        this.Toolbars = new Array() ;
 
238
 
 
239
        for ( var x = 0 ; x < ToolbarSet.length ; x++ )
 
240
        {
 
241
                var oToolbarItems = ToolbarSet[x] ;
 
242
 
 
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 ) 
 
246
                        continue ;
 
247
 
 
248
                var oToolbar ;
 
249
 
 
250
                if ( typeof( oToolbarItems ) == 'string' )
 
251
                {
 
252
                        if ( oToolbarItems == '/' )
 
253
                                oToolbar = new FCKToolbarBreak() ;
 
254
                }
 
255
                else
 
256
                {
 
257
                        oToolbar = new FCKToolbar() ;
 
258
 
 
259
                        for ( var j = 0 ; j < oToolbarItems.length ; j++ )
 
260
                        {
 
261
                                var sItem = oToolbarItems[j] ;
 
262
 
 
263
                                if ( sItem == '-')
 
264
                                        oToolbar.AddSeparator() ;
 
265
                                else
 
266
                                {
 
267
                                        var oItem = FCKToolbarItems.GetItem( sItem ) ;
 
268
                                        if ( oItem )
 
269
                                        {
 
270
                                                oToolbar.AddItem( oItem ) ;
 
271
 
 
272
                                                this.Items.push( oItem ) ;
 
273
 
 
274
                                                if ( !oItem.SourceView )
 
275
                                                        this.ItemsWysiwygOnly.push( oItem ) ;
 
276
 
 
277
                                                if ( oItem.ContextSensitive )
 
278
                                                        this.ItemsContextSensitive.push( oItem ) ;
 
279
                                        }
 
280
                                }
 
281
                        }
 
282
 
 
283
                        // oToolbar.AddTerminator() ;
 
284
                }
 
285
 
 
286
                oToolbar.Create( this._TargetElement ) ;
 
287
 
 
288
                this.Toolbars[ this.Toolbars.length ] = oToolbar ;
 
289
        }
 
290
 
 
291
        FCKTools.DisableSelection( this._Document.getElementById( 'xCollapseHandle' ).parentNode ) ;
 
292
 
 
293
        if ( FCK.Status != FCK_STATUS_COMPLETE )
 
294
                FCK.Events.AttachEvent( 'OnStatusChange', this.RefreshModeState ) ;
 
295
        else
 
296
                this.RefreshModeState() ;
 
297
 
 
298
        this.IsLoaded = true ;
 
299
        this.IsEnabled = true ;
 
300
 
 
301
        FCKTools.RunFunction( this.OnLoad ) ;
 
302
}
 
303
 
 
304
FCKToolbarSet.prototype.Enable = function()
 
305
{
 
306
        if ( this.IsEnabled )
 
307
                return ;
 
308
 
 
309
        this.IsEnabled = true ;
 
310
 
 
311
        var aItems = this.Items ;
 
312
        for ( var i = 0 ; i < aItems.length ; i++ )
 
313
                aItems[i].RefreshState() ;
 
314
}
 
315
 
 
316
FCKToolbarSet.prototype.Disable = function()
 
317
{
 
318
        if ( !this.IsEnabled )
 
319
                return ;
 
320
 
 
321
        this.IsEnabled = false ;
 
322
 
 
323
        var aItems = this.Items ;
 
324
        for ( var i = 0 ; i < aItems.length ; i++ )
 
325
                aItems[i].Disable() ;
 
326
}
 
327
 
 
328
FCKToolbarSet.prototype.RefreshModeState = function( editorInstance )
 
329
{
 
330
        if ( FCK.Status != FCK_STATUS_COMPLETE )
 
331
                return ;
 
332
 
 
333
        var oToolbarSet = editorInstance ? editorInstance.ToolbarSet : this ;
 
334
        var aItems = oToolbarSet.ItemsWysiwygOnly ;
 
335
 
 
336
        if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
 
337
        {
 
338
                // Enable all buttons that are available on WYSIWYG mode only.
 
339
                for ( var i = 0 ; i < aItems.length ; i++ )
 
340
                        aItems[i].Enable() ;
 
341
 
 
342
                // Refresh the buttons state.
 
343
                oToolbarSet.RefreshItemsState( editorInstance ) ;
 
344
        }
 
345
        else
 
346
        {
 
347
                // Refresh the buttons state.
 
348
                oToolbarSet.RefreshItemsState( editorInstance ) ;
 
349
 
 
350
                // Disable all buttons that are available on WYSIWYG mode only.
 
351
                for ( var j = 0 ; j < aItems.length ; j++ )
 
352
                        aItems[j].Disable() ;
 
353
        }
 
354
}
 
355
 
 
356
FCKToolbarSet.prototype.RefreshItemsState = function( editorInstance )
 
357
{
 
358
 
 
359
        var aItems = ( editorInstance ? editorInstance.ToolbarSet : this ).ItemsContextSensitive ;
 
360
 
 
361
        for ( var i = 0 ; i < aItems.length ; i++ )
 
362
                aItems[i].RefreshState() ;
 
363
}