PluginProbe
Wp-Insert / 1.7.2
Wp-Insert v1.7.2
trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.3.0 1.3.1 1.3.3 1.4 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 2.0 All 63 releases
wp-insert / fckeditor / editor / _source / classes / fckmenuitem.js

fckmenuitem.js in Wp-Insert 1.7.2, at fckeditor/editor/_source/classes/fckmenuitem.js

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