1 | /* |
---|
2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net |
---|
3 | * Copyright (C) 2003-2007 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 | |
---|
24 | var FCKMenuBlock = function() |
---|
25 | { |
---|
26 | this._Items = new Array() ; |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | FCKMenuBlock.prototype.Count = function() |
---|
31 | { |
---|
32 | return this._Items.length ; |
---|
33 | } |
---|
34 | |
---|
35 | FCKMenuBlock.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled ) |
---|
36 | { |
---|
37 | var oItem = new FCKMenuItem( this, name, label, iconPathOrStripInfoArrayOrIndex, isDisabled ) ; |
---|
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 | |
---|
47 | FCKMenuBlock.prototype.AddSeparator = function() |
---|
48 | { |
---|
49 | this._Items.push( new FCKMenuSeparator() ) ; |
---|
50 | } |
---|
51 | |
---|
52 | FCKMenuBlock.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 | |
---|
64 | FCKMenuBlock.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 | |
---|
95 | function FCKMenuBlock_Item_OnClick( clickedItem, menuBlock ) |
---|
96 | { |
---|
97 | FCKTools.RunFunction( menuBlock.OnClick, menuBlock, [ clickedItem ] ) ; |
---|
98 | } |
---|
99 | |
---|
100 | function FCKMenuBlock_Item_OnActivate( menuBlock ) |
---|
101 | { |
---|
102 | var oActiveItem = menuBlock._ActiveItem ; |
---|
103 | |
---|
104 | if ( oActiveItem && oActiveItem != this ) |
---|
105 | { |
---|
106 | // Set the focus to this menu block window (to fire OnBlur on opened panels). |
---|
107 | if ( !FCKBrowserInfo.IsIE && oActiveItem.HasSubMenu && !this.HasSubMenu ) |
---|
108 | menuBlock._Window.focus() ; |
---|
109 | |
---|
110 | oActiveItem.Deactivate() ; |
---|
111 | } |
---|
112 | |
---|
113 | menuBlock._ActiveItem = this ; |
---|
114 | } |
---|
115 | |
---|
116 | function FCKMenuBlock_Cleanup() |
---|
117 | { |
---|
118 | this._Window = null ; |
---|
119 | this._ItemsTable = null ; |
---|
120 | } |
---|
121 | |
---|
122 | // ################# // |
---|
123 | |
---|
124 | var FCKMenuSeparator = function() |
---|
125 | {} |
---|
126 | |
---|
127 | FCKMenuSeparator.prototype.Create = function( parentTable ) |
---|
128 | { |
---|
129 | var oDoc = FCKTools.GetElementDocument( parentTable ) ; |
---|
130 | |
---|
131 | var r = parentTable.insertRow(-1) ; |
---|
132 | |
---|
133 | var eCell = r.insertCell(-1) ; |
---|
134 | eCell.className = 'MN_Separator MN_Icon' ; |
---|
135 | |
---|
136 | eCell = r.insertCell(-1) ; |
---|
137 | eCell.className = 'MN_Separator' ; |
---|
138 | eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ; |
---|
139 | |
---|
140 | eCell = r.insertCell(-1) ; |
---|
141 | eCell.className = 'MN_Separator' ; |
---|
142 | eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ; |
---|
143 | } |
---|