PageRenderTime 16ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/EQT_V1/EQTWebApp/fckeditor/editor/_source/classes/fckmenuitem.js

http://sgsoft-las.googlecode.com/
JavaScript | 161 lines | 99 code | 29 blank | 33 comment | 8 complexity | 62be53cfa6c7df4e7eafb817783412ae MD5 | raw file
Possible License(s): LGPL-2.1
  1/*
  2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3 * Copyright (C) 2003-2009 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 and renders a menu items in a menu block.
 22 */
 23
 24var FCKMenuItem = function( parentMenuBlock, name, label, iconPathOrStripInfoArray, isDisabled, customData )
 25{
 26	this.Name		= name ;
 27	this.Label		= label || name ;
 28	this.IsDisabled	= isDisabled ;
 29
 30	this.Icon = new FCKIcon( iconPathOrStripInfoArray ) ;
 31
 32	this.SubMenu			= new FCKMenuBlockPanel() ;
 33	this.SubMenu.Parent		= parentMenuBlock ;
 34	this.SubMenu.OnClick	= FCKTools.CreateEventListener( FCKMenuItem_SubMenu_OnClick, this ) ;
 35	this.CustomData = customData ;
 36
 37	if ( FCK.IECleanup )
 38		FCK.IECleanup.AddItem( this, FCKMenuItem_Cleanup ) ;
 39}
 40
 41
 42FCKMenuItem.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData )
 43{
 44	this.HasSubMenu = true ;
 45	return this.SubMenu.AddItem( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData ) ;
 46}
 47
 48FCKMenuItem.prototype.AddSeparator = function()
 49{
 50	this.SubMenu.AddSeparator() ;
 51}
 52
 53FCKMenuItem.prototype.Create = function( parentTable )
 54{
 55	var bHasSubMenu = this.HasSubMenu ;
 56
 57	var oDoc = FCKTools.GetElementDocument( parentTable ) ;
 58
 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' ;
 62
 63	// Set the row behavior.
 64	if ( !this.IsDisabled )
 65	{
 66		FCKTools.AddEventListenerEx( r, 'mouseover', FCKMenuItem_OnMouseOver, [ this ] ) ;
 67		FCKTools.AddEventListenerEx( r, 'click', FCKMenuItem_OnClick, [ this ] ) ;
 68
 69		if ( !bHasSubMenu )
 70			FCKTools.AddEventListenerEx( r, 'mouseout', FCKMenuItem_OnMouseOut, [ this ] ) ;
 71	}
 72
 73	// Create the icon cell.
 74	var eCell = r.insertCell(-1) ;
 75	eCell.className = 'MN_Icon' ;
 76	eCell.appendChild( this.Icon.CreateIconElement( oDoc ) ) ;
 77
 78	// Create the label cell.
 79	eCell = r.insertCell(-1) ;
 80	eCell.className = 'MN_Label' ;
 81	eCell.noWrap = true ;
 82	eCell.appendChild( oDoc.createTextNode( this.Label ) ) ;
 83
 84	// Create the arrow cell and setup the sub menu panel (if needed).
 85	eCell = r.insertCell(-1) ;
 86	if ( bHasSubMenu )
 87	{
 88		eCell.className = 'MN_Arrow' ;
 89
 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' ;
 93		eArrowImg.width	 = 4 ;
 94		eArrowImg.height = 7 ;
 95
 96		this.SubMenu.Create() ;
 97		this.SubMenu.Panel.OnHide = FCKTools.CreateEventListener( FCKMenuItem_SubMenu_OnHide, this ) ;
 98	}
 99}
100
101FCKMenuItem.prototype.Activate = function()
102{
103	this.MainElement.className = 'MN_Item_Over' ;
104
105	if ( this.HasSubMenu )
106	{
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 ) ;
112	}
113
114	FCKTools.RunFunction( this.OnActivate, this ) ;
115}
116
117FCKMenuItem.prototype.Deactivate = function()
118{
119	this.MainElement.className = 'MN_Item' ;
120
121	if ( this.HasSubMenu )
122		this.SubMenu.Hide() ;
123}
124
125/* Events */
126
127function FCKMenuItem_SubMenu_OnClick( clickedItem, listeningItem )
128{
129	FCKTools.RunFunction( listeningItem.OnClick, listeningItem, [ clickedItem ] ) ;
130}
131
132function FCKMenuItem_SubMenu_OnHide( menuItem )
133{
134	menuItem.Deactivate() ;
135}
136
137function FCKMenuItem_OnClick( ev, menuItem )
138{
139	if ( menuItem.HasSubMenu )
140		menuItem.Activate() ;
141	else
142	{
143		menuItem.Deactivate() ;
144		FCKTools.RunFunction( menuItem.OnClick, menuItem, [ menuItem ] ) ;
145	}
146}
147
148function FCKMenuItem_OnMouseOver( ev, menuItem )
149{
150	menuItem.Activate() ;
151}
152
153function FCKMenuItem_OnMouseOut( ev, menuItem )
154{
155	menuItem.Deactivate() ;
156}
157
158function FCKMenuItem_Cleanup()
159{
160	this.MainElement = null ;
161}