import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / classes / fckmenuitem.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  * Defines and renders a menu items in a menu block.\r
22  */\r
23 \r
24 var FCKMenuItem = function( parentMenuBlock, name, label, iconPathOrStripInfoArray, isDisabled, customData )\r
25 {\r
26         this.Name               = name ;\r
27         this.Label              = label || name ;\r
28         this.IsDisabled = isDisabled ;\r
29 \r
30         this.Icon = new FCKIcon( iconPathOrStripInfoArray ) ;\r
31 \r
32         this.SubMenu                    = new FCKMenuBlockPanel() ;\r
33         this.SubMenu.Parent             = parentMenuBlock ;\r
34         this.SubMenu.OnClick    = FCKTools.CreateEventListener( FCKMenuItem_SubMenu_OnClick, this ) ;\r
35         this.CustomData = customData ;\r
36 \r
37         if ( FCK.IECleanup )\r
38                 FCK.IECleanup.AddItem( this, FCKMenuItem_Cleanup ) ;\r
39 }\r
40 \r
41 \r
42 FCKMenuItem.prototype.AddItem = function( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData )\r
43 {\r
44         this.HasSubMenu = true ;\r
45         return this.SubMenu.AddItem( name, label, iconPathOrStripInfoArrayOrIndex, isDisabled, customData ) ;\r
46 }\r
47 \r
48 FCKMenuItem.prototype.AddSeparator = function()\r
49 {\r
50         this.SubMenu.AddSeparator() ;\r
51 }\r
52 \r
53 FCKMenuItem.prototype.Create = function( parentTable )\r
54 {\r
55         var bHasSubMenu = this.HasSubMenu ;\r
56 \r
57         var oDoc = FCKTools.GetElementDocument( parentTable ) ;\r
58 \r
59         // Add a row in the table to hold the menu item.\r
60         var r = this.MainElement = parentTable.insertRow(-1) ;\r
61         r.className = this.IsDisabled ? 'MN_Item_Disabled' : 'MN_Item' ;\r
62 \r
63         // Set the row behavior.\r
64         if ( !this.IsDisabled )\r
65         {\r
66                 FCKTools.AddEventListenerEx( r, 'mouseover', FCKMenuItem_OnMouseOver, [ this ] ) ;\r
67                 FCKTools.AddEventListenerEx( r, 'click', FCKMenuItem_OnClick, [ this ] ) ;\r
68 \r
69                 if ( !bHasSubMenu )\r
70                         FCKTools.AddEventListenerEx( r, 'mouseout', FCKMenuItem_OnMouseOut, [ this ] ) ;\r
71         }\r
72 \r
73         // Create the icon cell.\r
74         var eCell = r.insertCell(-1) ;\r
75         eCell.className = 'MN_Icon' ;\r
76         eCell.appendChild( this.Icon.CreateIconElement( oDoc ) ) ;\r
77 \r
78         // Create the label cell.\r
79         eCell = r.insertCell(-1) ;\r
80         eCell.className = 'MN_Label' ;\r
81         eCell.noWrap = true ;\r
82         eCell.appendChild( oDoc.createTextNode( this.Label ) ) ;\r
83 \r
84         // Create the arrow cell and setup the sub menu panel (if needed).\r
85         eCell = r.insertCell(-1) ;\r
86         if ( bHasSubMenu )\r
87         {\r
88                 eCell.className = 'MN_Arrow' ;\r
89 \r
90                 // The arrow is a fixed size image.\r
91                 var eArrowImg = eCell.appendChild( oDoc.createElement( 'IMG' ) ) ;\r
92                 eArrowImg.src = FCK_IMAGES_PATH + 'arrow_' + FCKLang.Dir + '.gif' ;\r
93                 eArrowImg.width  = 4 ;\r
94                 eArrowImg.height = 7 ;\r
95 \r
96                 this.SubMenu.Create() ;\r
97                 this.SubMenu.Panel.OnHide = FCKTools.CreateEventListener( FCKMenuItem_SubMenu_OnHide, this ) ;\r
98         }\r
99 }\r
100 \r
101 FCKMenuItem.prototype.Activate = function()\r
102 {\r
103         this.MainElement.className = 'MN_Item_Over' ;\r
104 \r
105         if ( this.HasSubMenu )\r
106         {\r
107                 // Show the child menu block. The ( +2, -2 ) correction is done because\r
108                 // of the padding in the skin. It is not a good solution because one\r
109                 // could change the skin and so the final result would not be accurate.\r
110                 // For now it is ok because we are controlling the skin.\r
111                 this.SubMenu.Show( this.MainElement.offsetWidth + 2, -2, this.MainElement ) ;\r
112         }\r
113 \r
114         FCKTools.RunFunction( this.OnActivate, this ) ;\r
115 }\r
116 \r
117 FCKMenuItem.prototype.Deactivate = function()\r
118 {\r
119         this.MainElement.className = 'MN_Item' ;\r
120 \r
121         if ( this.HasSubMenu )\r
122                 this.SubMenu.Hide() ;\r
123 }\r
124 \r
125 /* Events */\r
126 \r
127 function FCKMenuItem_SubMenu_OnClick( clickedItem, listeningItem )\r
128 {\r
129         FCKTools.RunFunction( listeningItem.OnClick, listeningItem, [ clickedItem ] ) ;\r
130 }\r
131 \r
132 function FCKMenuItem_SubMenu_OnHide( menuItem )\r
133 {\r
134         menuItem.Deactivate() ;\r
135 }\r
136 \r
137 function FCKMenuItem_OnClick( ev, menuItem )\r
138 {\r
139         if ( menuItem.HasSubMenu )\r
140                 menuItem.Activate() ;\r
141         else\r
142         {\r
143                 menuItem.Deactivate() ;\r
144                 FCKTools.RunFunction( menuItem.OnClick, menuItem, [ menuItem ] ) ;\r
145         }\r
146 }\r
147 \r
148 function FCKMenuItem_OnMouseOver( ev, menuItem )\r
149 {\r
150         menuItem.Activate() ;\r
151 }\r
152 \r
153 function FCKMenuItem_OnMouseOut( ev, menuItem )\r
154 {\r
155         menuItem.Deactivate() ;\r
156 }\r
157 \r
158 function FCKMenuItem_Cleanup()\r
159 {\r
160         this.MainElement = null ;\r
161 }\r