1075 |
ddelon |
1 |
/*
|
|
|
2 |
* FCKeditor - The text editor for internet
|
|
|
3 |
* Copyright (C) 2003-2006 Frederico Caldeira Knabben
|
|
|
4 |
*
|
|
|
5 |
* Licensed under the terms of the GNU Lesser General Public License:
|
|
|
6 |
* http://www.opensource.org/licenses/lgpl-license.php
|
|
|
7 |
*
|
|
|
8 |
* For further information visit:
|
|
|
9 |
* http://www.fckeditor.net/
|
|
|
10 |
*
|
|
|
11 |
* "Support Open Source software. What about a donation today?"
|
|
|
12 |
*
|
|
|
13 |
* File Name: fckmenublock.js
|
|
|
14 |
* Renders a list of menu items.
|
|
|
15 |
*
|
|
|
16 |
* File Authors:
|
|
|
17 |
* Frederico Caldeira Knabben (fredck@fckeditor.net)
|
|
|
18 |
*/
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
var FCKMenuBlock = function()
|
|
|
22 |
{
|
|
|
23 |
this._Items = new Array() ;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
FCKMenuBlock.prototype.Count = function()
|
|
|
28 |
{
|
|
|
29 |
return this._Items.length ;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
FCKMenuBlock.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled )
|
|
|
33 |
{
|
|
|
34 |
var oItem = new FCKMenuItem( this, name, label, iconPathOrStripInfoArrayOrIndex, isDisabled ) ;
|
|
|
35 |
|
|
|
36 |
oItem.OnClick = FCKTools.CreateEventListener( FCKMenuBlock_Item_OnClick, this ) ;
|
|
|
37 |
oItem.OnActivate = FCKTools.CreateEventListener( FCKMenuBlock_Item_OnActivate, this ) ;
|
|
|
38 |
|
|
|
39 |
this._Items.push( oItem ) ;
|
|
|
40 |
|
|
|
41 |
return oItem ;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
FCKMenuBlock.prototype.AddSeparator = function()
|
|
|
45 |
{
|
|
|
46 |
this._Items.push( new FCKMenuSeparator() ) ;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
FCKMenuBlock.prototype.RemoveAllItems = function()
|
|
|
50 |
{
|
|
|
51 |
this._Items = new Array() ;
|
|
|
52 |
|
|
|
53 |
var eItemsTable = this._ItemsTable ;
|
|
|
54 |
if ( eItemsTable )
|
|
|
55 |
{
|
|
|
56 |
while ( eItemsTable.rows.length > 0 )
|
|
|
57 |
eItemsTable.deleteRow( 0 ) ;
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
FCKMenuBlock.prototype.Create = function( parentElement )
|
|
|
62 |
{
|
|
|
63 |
if ( !this._ItemsTable )
|
|
|
64 |
{
|
|
|
65 |
if ( FCK.IECleanup )
|
|
|
66 |
FCK.IECleanup.AddItem( this, FCKMenuBlock_Cleanup ) ;
|
|
|
67 |
|
|
|
68 |
this._Window = FCKTools.GetElementWindow( parentElement ) ;
|
|
|
69 |
|
|
|
70 |
var oDoc = FCKTools.GetElementDocument( parentElement ) ;
|
|
|
71 |
|
|
|
72 |
var eTable = parentElement.appendChild( oDoc.createElement( 'table' ) ) ;
|
|
|
73 |
eTable.cellPadding = 0 ;
|
|
|
74 |
eTable.cellSpacing = 0 ;
|
|
|
75 |
|
|
|
76 |
FCKTools.DisableSelection( eTable ) ;
|
|
|
77 |
|
|
|
78 |
var oMainElement = eTable.insertRow(-1).insertCell(-1) ;
|
|
|
79 |
oMainElement.className = 'MN_Menu' ;
|
|
|
80 |
|
|
|
81 |
var eItemsTable = this._ItemsTable = oMainElement.appendChild( oDoc.createElement( 'table' ) ) ;
|
|
|
82 |
eItemsTable.cellPadding = 0 ;
|
|
|
83 |
eItemsTable.cellSpacing = 0 ;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
for ( var i = 0 ; i < this._Items.length ; i++ )
|
|
|
87 |
this._Items[i].Create( this._ItemsTable ) ;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/* Events */
|
|
|
91 |
|
|
|
92 |
function FCKMenuBlock_Item_OnClick( clickedItem, menuBlock )
|
|
|
93 |
{
|
|
|
94 |
FCKTools.RunFunction( menuBlock.OnClick, menuBlock, [ clickedItem ] ) ;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
function FCKMenuBlock_Item_OnActivate( menuBlock )
|
|
|
98 |
{
|
|
|
99 |
var oActiveItem = menuBlock._ActiveItem ;
|
|
|
100 |
|
|
|
101 |
if ( oActiveItem && oActiveItem != this )
|
|
|
102 |
{
|
|
|
103 |
// Set the focus to this menu block window (to fire OnBlur on opened panels).
|
|
|
104 |
if ( !FCKBrowserInfo.IsIE && oActiveItem.HasSubMenu && !this.HasSubMenu )
|
|
|
105 |
menuBlock._Window.focus() ;
|
|
|
106 |
|
|
|
107 |
oActiveItem.Deactivate() ;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
menuBlock._ActiveItem = this ;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
function FCKMenuBlock_Cleanup()
|
|
|
114 |
{
|
|
|
115 |
this._Window = null ;
|
|
|
116 |
this._ItemsTable = null ;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
// ################# //
|
|
|
120 |
|
|
|
121 |
var FCKMenuSeparator = function()
|
|
|
122 |
{}
|
|
|
123 |
|
|
|
124 |
FCKMenuSeparator.prototype.Create = function( parentTable )
|
|
|
125 |
{
|
|
|
126 |
var oDoc = FCKTools.GetElementDocument( parentTable ) ;
|
|
|
127 |
|
|
|
128 |
var r = parentTable.insertRow(-1) ;
|
|
|
129 |
|
|
|
130 |
var eCell = r.insertCell(-1) ;
|
|
|
131 |
eCell.className = 'MN_Separator MN_Icon' ;
|
|
|
132 |
|
|
|
133 |
eCell = r.insertCell(-1) ;
|
|
|
134 |
eCell.className = 'MN_Separator' ;
|
|
|
135 |
eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ;
|
|
|
136 |
|
|
|
137 |
eCell = r.insertCell(-1) ;
|
|
|
138 |
eCell.className = 'MN_Separator' ;
|
|
|
139 |
eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ;
|
|
|
140 |
}
|