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 * Renders a list of menu items. 22 */ 23 24var FCKMenuBlock = function() 25{ 26 this._Items = new Array() ; 27} 28 29 30FCKMenuBlock.prototype.Count = function() 31{ 32 return this._Items.length ; 33} 34 35FCKMenuBlock.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled ) 36{ 37 var oItem = new FCKMenuItem( this, name, label, iconPathOrStripInfoArrayOrIndex, isDisabled ) ; 38 39 oItem.OnClick = FCKTools.CreateEventListener( FCKMenuBlock_Item_OnClick, this ) ; 40 oItem.OnActivate = FCKTools.CreateEventListener( FCKMenuBlock_Item_OnActivate, this ) ; 41 42 this._Items.push( oItem ) ; 43 44 return oItem ; 45} 46 47FCKMenuBlock.prototype.AddSeparator = function() 48{ 49 this._Items.push( new FCKMenuSeparator() ) ; 50} 51 52FCKMenuBlock.prototype.RemoveAllItems = function() 53{ 54 this._Items = new Array() ; 55 56 var eItemsTable = this._ItemsTable ; 57 if ( eItemsTable ) 58 { 59 while ( eItemsTable.rows.length > 0 ) 60 eItemsTable.deleteRow( 0 ) ; 61 } 62} 63 64FCKMenuBlock.prototype.Create = function( parentElement ) 65{ 66 if ( !this._ItemsTable ) 67 { 68 if ( FCK.IECleanup ) 69 FCK.IECleanup.AddItem( this, FCKMenuBlock_Cleanup ) ; 70 71 this._Window = FCKTools.GetElementWindow( parentElement ) ; 72 73 var oDoc = FCKTools.GetElementDocument( parentElement ) ; 74 75 var eTable = parentElement.appendChild( oDoc.createElement( 'table' ) ) ; 76 eTable.cellPadding = 0 ; 77 eTable.cellSpacing = 0 ; 78 79 FCKTools.DisableSelection( eTable ) ; 80 81 var oMainElement = eTable.insertRow(-1).insertCell(-1) ; 82 oMainElement.className = 'MN_Menu' ; 83 84 var eItemsTable = this._ItemsTable = oMainElement.appendChild( oDoc.createElement( 'table' ) ) ; 85 eItemsTable.cellPadding = 0 ; 86 eItemsTable.cellSpacing = 0 ; 87 } 88 89 for ( var i = 0 ; i < this._Items.length ; i++ ) 90 this._Items[i].Create( this._ItemsTable ) ; 91} 92 93/* Events */ 94 95function FCKMenuBlock_Item_OnClick( clickedItem, menuBlock ) 96{ 97 FCKTools.RunFunction( menuBlock.OnClick, menuBlock, [ clickedItem ] ) ; 98} 99 100function FCKMenuBlock_Item_OnActivate( menuBlock ) 101{ 102 var oActiveItem = menuBlock._ActiveItem ; 103 104 if ( oActiveItem && oActiveItem != this ) 105 { 106 // Set the focus to this menu block window (to fire OnBlur on opened panels). 107 if ( !FCKBrowserInfo.IsIE && oActiveItem.HasSubMenu && !this.HasSubMenu ) 108 { 109 menuBlock._Window.focus() ; 110 111 // Due to the event model provided by Opera, we need to set 112 // HasFocus here as the above focus() call will not fire the focus 113 // event in the panel immediately (#1200). 114 menuBlock.Panel.HasFocus = true ; 115 } 116 117 oActiveItem.Deactivate() ; 118 } 119 120 menuBlock._ActiveItem = this ; 121} 122 123function FCKMenuBlock_Cleanup() 124{ 125 this._Window = null ; 126 this._ItemsTable = null ; 127} 128 129// ################# // 130 131var FCKMenuSeparator = function() 132{} 133 134FCKMenuSeparator.prototype.Create = function( parentTable ) 135{ 136 var oDoc = FCKTools.GetElementDocument( parentTable ) ; 137 138 var r = parentTable.insertRow(-1) ; 139 140 var eCell = r.insertCell(-1) ; 141 eCell.className = 'MN_Separator MN_Icon' ; 142 143 eCell = r.insertCell(-1) ; 144 eCell.className = 'MN_Separator' ; 145 eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ; 146 147 eCell = r.insertCell(-1) ; 148 eCell.className = 'MN_Separator' ; 149 eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ; 150}