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 * Defines and renders a menu items in a menu block.
\r
24 var FCKMenuItem = function( parentMenuBlock, name, label, iconPathOrStripInfoArray, isDisabled, customData )
\r
27 this.Label = label || name ;
\r
28 this.IsDisabled = isDisabled ;
\r
30 this.Icon = new FCKIcon( iconPathOrStripInfoArray ) ;
\r
32 this.SubMenu = new FCKMenuBlockPanel() ;
\r
33 this.SubMenu.Parent = parentMenuBlock ;
\r
34 this.SubMenu.OnClick = FCKTools.CreateEventListener( FCKMenuItem_SubMenu_OnClick, this ) ;
\r
35 this.CustomData = customData ;
\r
37 if ( FCK.IECleanup )
\r
38 FCK.IECleanup.AddItem( this, FCKMenuItem_Cleanup ) ;
\r
42 FCKMenuItem.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData )
\r
44 this.HasSubMenu = true ;
\r
45 return this.SubMenu.AddItem( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData ) ;
\r
48 FCKMenuItem.prototype.AddSeparator = function()
\r
50 this.SubMenu.AddSeparator() ;
\r
53 FCKMenuItem.prototype.Create = function( parentTable )
\r
55 var bHasSubMenu = this.HasSubMenu ;
\r
57 var oDoc = FCKTools.GetElementDocument( parentTable ) ;
\r
59 // Add a row in the table to hold the menu item.
\r
60 var r = this.MainElement = parentTable.insertRow(-1) ;
\r
61 r.className = this.IsDisabled ? 'MN_Item_Disabled' : 'MN_Item' ;
\r
63 // Set the row behavior.
\r
64 if ( !this.IsDisabled )
\r
66 FCKTools.AddEventListenerEx( r, 'mouseover', FCKMenuItem_OnMouseOver, [ this ] ) ;
\r
67 FCKTools.AddEventListenerEx( r, 'click', FCKMenuItem_OnClick, [ this ] ) ;
\r
70 FCKTools.AddEventListenerEx( r, 'mouseout', FCKMenuItem_OnMouseOut, [ this ] ) ;
\r
73 // Create the icon cell.
\r
74 var eCell = r.insertCell(-1) ;
\r
75 eCell.className = 'MN_Icon' ;
\r
76 eCell.appendChild( this.Icon.CreateIconElement( oDoc ) ) ;
\r
78 // Create the label cell.
\r
79 eCell = r.insertCell(-1) ;
\r
80 eCell.className = 'MN_Label' ;
\r
81 eCell.noWrap = true ;
\r
82 eCell.appendChild( oDoc.createTextNode( this.Label ) ) ;
\r
84 // Create the arrow cell and setup the sub menu panel (if needed).
\r
85 eCell = r.insertCell(-1) ;
\r
88 eCell.className = 'MN_Arrow' ;
\r
90 // The arrow is a fixed size image.
\r
91 var eArrowImg = eCell.appendChild( oDoc.createElement( 'IMG' ) ) ;
\r
92 eArrowImg.src = FCK_IMAGES_PATH + 'arrow_' + FCKLang.Dir + '.gif' ;
\r
93 eArrowImg.width = 4 ;
\r
94 eArrowImg.height = 7 ;
\r
96 this.SubMenu.Create() ;
\r
97 this.SubMenu.Panel.OnHide = FCKTools.CreateEventListener( FCKMenuItem_SubMenu_OnHide, this ) ;
\r
101 FCKMenuItem.prototype.Activate = function()
\r
103 this.MainElement.className = 'MN_Item_Over' ;
\r
105 if ( this.HasSubMenu )
\r
107 // Show the child menu block. The ( +2, -2 ) correction is done because
\r
108 // of the padding in the skin. It is not a good solution because one
\r
109 // could change the skin and so the final result would not be accurate.
\r
110 // For now it is ok because we are controlling the skin.
\r
111 this.SubMenu.Show( this.MainElement.offsetWidth + 2, -2, this.MainElement ) ;
\r
114 FCKTools.RunFunction( this.OnActivate, this ) ;
\r
117 FCKMenuItem.prototype.Deactivate = function()
\r
119 this.MainElement.className = 'MN_Item' ;
\r
121 if ( this.HasSubMenu )
\r
122 this.SubMenu.Hide() ;
\r
127 function FCKMenuItem_SubMenu_OnClick( clickedItem, listeningItem )
\r
129 FCKTools.RunFunction( listeningItem.OnClick, listeningItem, [ clickedItem ] ) ;
\r
132 function FCKMenuItem_SubMenu_OnHide( menuItem )
\r
134 menuItem.Deactivate() ;
\r
137 function FCKMenuItem_OnClick( ev, menuItem )
\r
139 if ( menuItem.HasSubMenu )
\r
140 menuItem.Activate() ;
\r
143 menuItem.Deactivate() ;
\r
144 FCKTools.RunFunction( menuItem.OnClick, menuItem, [ menuItem ] ) ;
\r
148 function FCKMenuItem_OnMouseOver( ev, menuItem )
\r
150 menuItem.Activate() ;
\r
153 function FCKMenuItem_OnMouseOut( ev, menuItem )
\r
155 menuItem.Deactivate() ;
\r
158 function FCKMenuItem_Cleanup()
\r
160 this.MainElement = null ;
\r