import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / classes / fckmenublock.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * Renders a list of menu items.\r
22  */\r
23 \r
24 var FCKMenuBlock = function()\r
25 {\r
26         this._Items     = new Array() ;\r
27 }\r
28 \r
29 \r
30 FCKMenuBlock.prototype.Count = function()\r
31 {\r
32         return this._Items.length ;\r
33 }\r
34 \r
35 FCKMenuBlock.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData )\r
36 {\r
37         var oItem = new FCKMenuItem( this, name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData ) ;\r
38 \r
39         oItem.OnClick           = FCKTools.CreateEventListener( FCKMenuBlock_Item_OnClick, this ) ;\r
40         oItem.OnActivate        = FCKTools.CreateEventListener( FCKMenuBlock_Item_OnActivate, this ) ;\r
41 \r
42         this._Items.push( oItem ) ;\r
43 \r
44         return oItem ;\r
45 }\r
46 \r
47 FCKMenuBlock.prototype.AddSeparator = function()\r
48 {\r
49         this._Items.push( new FCKMenuSeparator() ) ;\r
50 }\r
51 \r
52 FCKMenuBlock.prototype.RemoveAllItems = function()\r
53 {\r
54         this._Items = new Array() ;\r
55 \r
56         var eItemsTable = this._ItemsTable ;\r
57         if ( eItemsTable )\r
58         {\r
59                 while ( eItemsTable.rows.length > 0 )\r
60                         eItemsTable.deleteRow( 0 ) ;\r
61         }\r
62 }\r
63 \r
64 FCKMenuBlock.prototype.Create = function( parentElement )\r
65 {\r
66         if ( !this._ItemsTable )\r
67         {\r
68                 if ( FCK.IECleanup )\r
69                         FCK.IECleanup.AddItem( this, FCKMenuBlock_Cleanup ) ;\r
70 \r
71                 this._Window = FCKTools.GetElementWindow( parentElement ) ;\r
72 \r
73                 var oDoc = FCKTools.GetElementDocument( parentElement ) ;\r
74 \r
75                 var eTable = parentElement.appendChild( oDoc.createElement( 'table' ) ) ;\r
76                 eTable.cellPadding = 0 ;\r
77                 eTable.cellSpacing = 0 ;\r
78 \r
79                 FCKTools.DisableSelection( eTable ) ;\r
80 \r
81                 var oMainElement = eTable.insertRow(-1).insertCell(-1) ;\r
82                 oMainElement.className = 'MN_Menu' ;\r
83 \r
84                 var eItemsTable = this._ItemsTable = oMainElement.appendChild( oDoc.createElement( 'table' ) ) ;\r
85                 eItemsTable.cellPadding = 0 ;\r
86                 eItemsTable.cellSpacing = 0 ;\r
87         }\r
88 \r
89         for ( var i = 0 ; i < this._Items.length ; i++ )\r
90                 this._Items[i].Create( this._ItemsTable ) ;\r
91 }\r
92 \r
93 /* Events */\r
94 \r
95 function FCKMenuBlock_Item_OnClick( clickedItem, menuBlock )\r
96 {\r
97         if ( menuBlock.Hide )\r
98                 menuBlock.Hide() ;\r
99 \r
100         FCKTools.RunFunction( menuBlock.OnClick, menuBlock, [ clickedItem ] ) ;\r
101 }\r
102 \r
103 function FCKMenuBlock_Item_OnActivate( menuBlock )\r
104 {\r
105         var oActiveItem = menuBlock._ActiveItem ;\r
106 \r
107         if ( oActiveItem && oActiveItem != this )\r
108         {\r
109                 // Set the focus to this menu block window (to fire OnBlur on opened panels).\r
110                 if ( !FCKBrowserInfo.IsIE && oActiveItem.HasSubMenu && !this.HasSubMenu )\r
111                 {\r
112                         menuBlock._Window.focus() ;\r
113 \r
114                         // Due to the event model provided by Opera, we need to set\r
115                         // HasFocus here as the above focus() call will not fire the focus\r
116                         // event in the panel immediately (#1200).\r
117                         menuBlock.Panel.HasFocus = true ;\r
118                 }\r
119 \r
120                 oActiveItem.Deactivate() ;\r
121         }\r
122 \r
123         menuBlock._ActiveItem = this ;\r
124 }\r
125 \r
126 function FCKMenuBlock_Cleanup()\r
127 {\r
128         this._Window = null ;\r
129         this._ItemsTable = null ;\r
130 }\r
131 \r
132 // ################# //\r
133 \r
134 var FCKMenuSeparator = function()\r
135 {}\r
136 \r
137 FCKMenuSeparator.prototype.Create = function( parentTable )\r
138 {\r
139         var oDoc = FCKTools.GetElementDocument( parentTable ) ;\r
140 \r
141         var r = parentTable.insertRow(-1) ;\r
142 \r
143         var eCell = r.insertCell(-1) ;\r
144         eCell.className = 'MN_Separator MN_Icon' ;\r
145 \r
146         eCell = r.insertCell(-1) ;\r
147         eCell.className = 'MN_Separator' ;\r
148         eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ;\r
149 \r
150         eCell = r.insertCell(-1) ;\r
151         eCell.className = 'MN_Separator' ;\r
152         eCell.appendChild( oDoc.createElement( 'DIV' ) ).className = 'MN_Separator_Line' ;\r
153 }\r