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