2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2007 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* FCKToolbarButtonUI Class: interface representation of a toolbar button.
24
var FCKToolbarButtonUI = function( name, label, tooltip, iconPathOrStripInfoArray, style, state )
27
this.Label = label || name ;
28
this.Tooltip = tooltip || this.Label ;
29
this.Style = style || FCK_TOOLBARITEM_ONLYICON ;
30
this.State = state || FCK_TRISTATE_OFF ;
32
this.Icon = new FCKIcon( iconPathOrStripInfoArray ) ;
35
FCK.IECleanup.AddItem( this, FCKToolbarButtonUI_Cleanup ) ;
39
FCKToolbarButtonUI.prototype._CreatePaddingElement = function( document )
41
var oImg = document.createElement( 'IMG' ) ;
42
oImg.className = 'TB_Button_Padding' ;
43
oImg.src = FCK_SPACER_PATH ;
47
FCKToolbarButtonUI.prototype.Create = function( parentElement )
49
var oMainElement = this.MainElement ;
53
FCKToolbarButtonUI_Cleanup.call(this) ;
55
if ( oMainElement.parentNode )
56
oMainElement.parentNode.removeChild( oMainElement ) ;
57
oMainElement = this.MainElement = null ;
60
var oDoc = FCKTools.GetElementDocument( parentElement ) ;
62
// Create the Main Element.
63
oMainElement = this.MainElement = oDoc.createElement( 'DIV' ) ;
64
oMainElement._FCKButton = this ; // IE Memory Leak (Circular reference).
65
oMainElement.title = this.Tooltip ;
67
// The following will prevent the button from catching the focus.
68
if ( FCKBrowserInfo.IsGecko )
69
oMainElement.onmousedown = FCKTools.CancelEvent ;
71
this.ChangeState( this.State, true ) ;
73
if ( this.Style == FCK_TOOLBARITEM_ONLYICON && !this.ShowArrow )
75
// <td><div class="TB_Button_On" title="Smiley">{Image}</div></td>
77
oMainElement.appendChild( this.Icon.CreateIconElement( oDoc ) ) ;
81
// <td><div class="TB_Button_On" title="Smiley"><table cellpadding="0" cellspacing="0"><tr><td>{Image}</td><td nowrap>Toolbar Button</td><td><img class="TB_Button_Padding"></td></tr></table></div></td>
82
// <td><div class="TB_Button_On" title="Smiley"><table cellpadding="0" cellspacing="0"><tr><td><img class="TB_Button_Padding"></td><td nowrap>Toolbar Button</td><td><img class="TB_Button_Padding"></td></tr></table></div></td>
84
var oTable = oMainElement.appendChild( oDoc.createElement( 'TABLE' ) ) ;
85
oTable.cellPadding = 0 ;
86
oTable.cellSpacing = 0 ;
88
var oRow = oTable.insertRow(-1) ;
90
// The Image cell (icon or padding).
91
var oCell = oRow.insertCell(-1) ;
93
if ( this.Style == FCK_TOOLBARITEM_ONLYICON || this.Style == FCK_TOOLBARITEM_ICONTEXT )
94
oCell.appendChild( this.Icon.CreateIconElement( oDoc ) ) ;
96
oCell.appendChild( this._CreatePaddingElement( oDoc ) ) ;
98
if ( this.Style == FCK_TOOLBARITEM_ONLYTEXT || this.Style == FCK_TOOLBARITEM_ICONTEXT )
101
oCell = oRow.insertCell(-1) ;
102
oCell.className = 'TB_Button_Text' ;
103
oCell.noWrap = true ;
104
oCell.appendChild( oDoc.createTextNode( this.Label ) ) ;
107
if ( this.ShowArrow )
109
if ( this.Style != FCK_TOOLBARITEM_ONLYICON )
112
oRow.insertCell(-1).appendChild( this._CreatePaddingElement( oDoc ) ) ;
115
oCell = oRow.insertCell(-1) ;
116
var eImg = oCell.appendChild( oDoc.createElement( 'IMG' ) ) ;
117
eImg.src = FCKConfig.SkinPath + 'images/toolbar.buttonarrow.gif' ;
122
// The last padding cell.
123
oCell = oRow.insertCell(-1) ;
124
oCell.appendChild( this._CreatePaddingElement( oDoc ) ) ;
127
parentElement.appendChild( oMainElement ) ;
130
FCKToolbarButtonUI.prototype.ChangeState = function( newState, force )
132
if ( !force && this.State == newState )
135
var e = this.MainElement ;
137
switch ( parseInt( newState, 10 ) )
139
case FCK_TRISTATE_OFF :
140
e.className = 'TB_Button_Off' ;
141
e.onmouseover = FCKToolbarButton_OnMouseOverOff ;
142
e.onmouseout = FCKToolbarButton_OnMouseOutOff ;
143
e.onclick = FCKToolbarButton_OnClick ;
147
case FCK_TRISTATE_ON :
148
e.className = 'TB_Button_On' ;
149
e.onmouseover = FCKToolbarButton_OnMouseOverOn ;
150
e.onmouseout = FCKToolbarButton_OnMouseOutOn ;
151
e.onclick = FCKToolbarButton_OnClick ;
155
case FCK_TRISTATE_DISABLED :
156
e.className = 'TB_Button_Disabled' ;
157
e.onmouseover = null ;
158
e.onmouseout = null ;
164
this.State = newState ;
167
function FCKToolbarButtonUI_Cleanup()
169
if ( this.MainElement )
171
this.MainElement._FCKButton = null ;
172
this.MainElement = null ;
178
function FCKToolbarButton_OnMouseOverOn()
180
this.className = 'TB_Button_On_Over' ;
183
function FCKToolbarButton_OnMouseOutOn()
185
this.className = 'TB_Button_On' ;
188
function FCKToolbarButton_OnMouseOverOff()
190
this.className = 'TB_Button_Off_Over' ;
193
function FCKToolbarButton_OnMouseOutOff()
195
this.className = 'TB_Button_Off' ;
198
function FCKToolbarButton_OnClick( e )
200
if ( this._FCKButton.OnClick )
201
this._FCKButton.OnClick( this._FCKButton ) ;
207
This is the base structure. The variation is the image that is marked as {Image}:
208
<td><div class="TB_Button_On" title="Smiley">{Image}</div></td>
209
<td><div class="TB_Button_On" title="Smiley"><table cellpadding="0" cellspacing="0"><tr><td>{Image}</td><td nowrap>Toolbar Button</td><td><img class="TB_Button_Padding"></td></tr></table></div></td>
210
<td><div class="TB_Button_On" title="Smiley"><table cellpadding="0" cellspacing="0"><tr><td><img class="TB_Button_Padding"></td><td nowrap>Toolbar Button</td><td><img class="TB_Button_Padding"></td></tr></table></div></td>
212
These are samples of possible {Image} values:
215
<div class="TB_Button_Image"><img src="strip.gif" style="top:-16px"></div>
217
Strip : Firefox, Safari and Opera version
218
<img class="TB_Button_Image" style="background-position: 0px -16px;background-image: url(strip.gif);">
220
No-Strip : Browser independent:
221
<img class="TB_Button_Image" src="smiley.gif">
b'\\ No newline at end of file'