2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * Renders a list of menu items.
\r
24 var FCKMenuBlock = function()
\r
26 this._Items = new Array() ;
\r
30 FCKMenuBlock.prototype.Count = function()
\r
32 return this._Items.length ;
\r
35 FCKMenuBlock.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData )
\r
37 var oItem = new FCKMenuItem( this, name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData ) ;
\r
39 oItem.OnClick = FCKTools.CreateEventListener( FCKMenuBlock_Item_OnClick, this ) ;
\r
40 oItem.OnActivate = FCKTools.CreateEventListener( FCKMenuBlock_Item_OnActivate, this ) ;
\r
42 this._Items.push( oItem ) ;
\r
47 FCKMenuBlock.prototype.AddSeparator = function()
\r
49 this._Items.push( new FCKMenuSeparator() ) ;
\r
52 FCKMenuBlock.prototype.RemoveAllItems = function()
\r
54 this._Items = new Array() ;
\r
56 var eItemsTable = this._ItemsTable ;
\r
59 while ( eItemsTable.rows.length > 0 )
\r
60 eItemsTable.deleteRow( 0 ) ;
\r
64 FCKMenuBlock.prototype.Create = function( parentElement )
\r
66 if ( !this._ItemsTable )
\r
68 if ( FCK.IECleanup )
\r
69 FCK.IECleanup.AddItem( this, FCKMenuBlock_Cleanup ) ;
\r
71 this._Window = FCKTools.GetElementWindow( parentElement ) ;
\r
73 var oDoc = FCKTools.GetElementDocument( parentElement ) ;
\r
75 var eTable = parentElement.appendChild( oDoc.createElement( 'table' ) ) ;
\r
76 eTable.cellPadding = 0 ;
\r
77 eTable.cellSpacing = 0 ;
\r
79 FCKTools.DisableSelection( eTable ) ;
\r
81 var oMainElement = eTable.insertRow(-1).insertCell(-1) ;
\r
82 oMainElement.className = 'MN_Menu' ;
\r
84 var eItemsTable = this._ItemsTable = oMainElement.appendChild( oDoc.createElement( 'table' ) ) ;
\r
85 eItemsTable.cellPadding = 0 ;
\r
86 eItemsTable.cellSpacing = 0 ;
\r
89 for ( var i = 0 ; i < this._Items.length ; i++ )
\r
90 this._Items[i].Create( this._ItemsTable ) ;
\r
95 function FCKMenuBlock_Item_OnClick( clickedItem, menuBlock )
\r
97 if ( menuBlock.Hide )
\r
100 FCKTools.RunFunction( menuBlock.OnClick, menuBlock, [ clickedItem ] ) ;
\r
103 function FCKMenuBlock_Item_OnActivate( menuBlock )
\r
105 var oActiveItem = menuBlock._ActiveItem ;
\r
107 if ( oActiveItem && oActiveItem != this )
\r
109 // Set the focus to this menu block window (to fire OnBlur on opened panels).
\r
110 if ( !FCKBrowserInfo.IsIE && oActiveItem.HasSubMenu && !this.HasSubMenu )
\r
112 menuBlock._Window.focus() ;
\r
114 // Due to the event model provided by Opera, we need to set
\r
115 // HasFocus here as the above focus() call will not fire the focus
\r
116 // event in the panel immediately (#1200).
\r
117 menuBlock.Panel.HasFocus = true ;
\r
120 oActiveItem.Deactivate() ;
\r
123 menuBlock._ActiveItem = this ;
\r
126 function FCKMenuBlock_Cleanup()
\r
128 this._Window = null ;
\r
129 this._ItemsTable = null ;
\r
132 // ################# //
\r
134 var FCKMenuSeparator = function()
\r
137 FCKMenuSeparator.prototype.Create = function( parentTable )
\r
139 var oDoc = FCKTools.GetElementDocument( parentTable ) ;
\r
141 var r = parentTable.insertRow(-1) ;
\r
143 var eCell = r.insertCell(-1) ;
\r
144 eCell.className = 'MN_Separator MN_Icon' ;
\r
146 eCell = r.insertCell(-1) ;
\r
147 eCell.className = 'MN_Separator' ;
\r
148 eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ;
\r
150 eCell = r.insertCell(-1) ;
\r
151 eCell.className = 'MN_Separator' ;
\r
152 eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ;
\r