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 * FCKToolbarPanelButton Class: represents a special button in the toolbar
22 * that shows a panel when pressed.
23 */
24
25var FCKToolbarPanelButton = function( commandName, label, tooltip, style, icon )
26{
27	this.CommandName = commandName ;
28
29	var oIcon ;
30
31	if ( icon == null )
32		oIcon = FCKConfig.SkinPath + 'toolbar/' + commandName.toLowerCase() + '.gif' ;
33	else if ( typeof( icon ) == 'number' )
34		oIcon = [ FCKConfig.SkinPath + 'fck_strip.gif', 16, icon ] ;
35
36	var oUIButton = this._UIButton = new FCKToolbarButtonUI( commandName, label, tooltip, oIcon, style ) ;
37	oUIButton._FCKToolbarPanelButton = this ;
38	oUIButton.ShowArrow = true ;
39	oUIButton.OnClick = FCKToolbarPanelButton_OnButtonClick ;
40}
41
42FCKToolbarPanelButton.prototype.TypeName = 'FCKToolbarPanelButton' ;
43
44FCKToolbarPanelButton.prototype.Create = function( parentElement )
45{
46	parentElement.className += 'Menu' ;
47
48	this._UIButton.Create( parentElement ) ;
49
50	var oPanel = FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( this.CommandName )._Panel ;
51	oPanel._FCKToolbarPanelButton = this ;
52
53	var eLineDiv = oPanel.Document.body.appendChild( oPanel.Document.createElement( 'div' ) ) ;
54	eLineDiv.style.position = 'absolute' ;
55	eLineDiv.style.top = '0px' ;
56
57	var eLine = this.LineImg = eLineDiv.appendChild( oPanel.Document.createElement( 'IMG' ) ) ;
58	eLine.className = 'TB_ConnectionLine' ;
59	eLine.style.position = 'absolute' ;
60//	eLine.style.backgroundColor = 'Red' ;
61	eLine.src = FCK_SPACER_PATH ;
62
63	oPanel.OnHide = FCKToolbarPanelButton_OnPanelHide ;
64}
65
66/*
67	Events
68*/
69
70function FCKToolbarPanelButton_OnButtonClick( toolbarButton )
71{
72	var oButton = this._FCKToolbarPanelButton ;
73	var e = oButton._UIButton.MainElement ;
74
75	oButton._UIButton.ChangeState( FCK_TRISTATE_ON ) ;
76
77	oButton.LineImg.style.width = ( e.offsetWidth - 2 ) + 'px' ;
78
79	FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( oButton.CommandName ).Execute( 0, e.offsetHeight - 1, e ) ; // -1 to be over the border
80}
81
82function FCKToolbarPanelButton_OnPanelHide()
83{
84	var oMenuButton = this._FCKToolbarPanelButton ;
85	oMenuButton._UIButton.ChangeState( FCK_TRISTATE_OFF ) ;
86}
87
88// The Panel Button works like a normal button so the refresh state functions
89// defined for the normal button can be reused here.
90FCKToolbarPanelButton.prototype.RefreshState	= FCKToolbarButton.prototype.RefreshState ;
91FCKToolbarPanelButton.prototype.Enable			= FCKToolbarButton.prototype.Enable ;
92FCKToolbarPanelButton.prototype.Disable			= FCKToolbarButton.prototype.Disable ;
93