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