PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/pigeoncms/Plugins/fckeditor/editor/_source/classes/fckmenublock.js

http://pigeoncms.googlecode.com/
JavaScript | 153 lines | 91 code | 34 blank | 28 comment | 12 complexity | b46b9687a06643b586fd0c5fa80d056e MD5 | raw file
  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 * 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, customData )
 36{
 37	var oItem = new FCKMenuItem( this, name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData ) ;
 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	if ( menuBlock.Hide )
 98		menuBlock.Hide() ;
 99
100	FCKTools.RunFunction( menuBlock.OnClick, menuBlock, [ clickedItem ] ) ;
101}
102
103function FCKMenuBlock_Item_OnActivate( menuBlock )
104{
105	var oActiveItem = menuBlock._ActiveItem ;
106
107	if ( oActiveItem && oActiveItem != this )
108	{
109		// Set the focus to this menu block window (to fire OnBlur on opened panels).
110		if ( !FCKBrowserInfo.IsIE && oActiveItem.HasSubMenu && !this.HasSubMenu )
111		{
112			menuBlock._Window.focus() ;
113
114			// Due to the event model provided by Opera, we need to set
115			// HasFocus here as the above focus() call will not fire the focus
116			// event in the panel immediately (#1200).
117			menuBlock.Panel.HasFocus = true ;
118		}
119
120		oActiveItem.Deactivate() ;
121	}
122
123	menuBlock._ActiveItem = this ;
124}
125
126function FCKMenuBlock_Cleanup()
127{
128	this._Window = null ;
129	this._ItemsTable = null ;
130}
131
132// ################# //
133
134var FCKMenuSeparator = function()
135{}
136
137FCKMenuSeparator.prototype.Create = function( parentTable )
138{
139	var oDoc = FCKTools.GetElementDocument( parentTable ) ;
140
141	var r = parentTable.insertRow(-1) ;
142
143	var eCell = r.insertCell(-1) ;
144	eCell.className = 'MN_Separator MN_Icon' ;
145
146	eCell = r.insertCell(-1) ;
147	eCell.className = 'MN_Separator' ;
148	eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ;
149
150	eCell = r.insertCell(-1) ;
151	eCell.className = 'MN_Separator' ;
152	eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ;
153}