source: branches/1.2/workflow/js/fckeditor/editor/_source/classes/fcktoolbarbuttonui.js @ 1349

Revision 1349, 6.3 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
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 * FCKToolbarButtonUI Class: interface representation of a toolbar button.
22 */
23
24var FCKToolbarButtonUI = function( name, label, tooltip, iconPathOrStripInfoArray, style, state )
25{
26        this.Name               = name ;
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 ;
31
32        this.Icon = new FCKIcon( iconPathOrStripInfoArray ) ;
33
34        if ( FCK.IECleanup )
35                FCK.IECleanup.AddItem( this, FCKToolbarButtonUI_Cleanup ) ;
36}
37
38
39FCKToolbarButtonUI.prototype._CreatePaddingElement = function( document )
40{
41        var oImg = document.createElement( 'IMG' ) ;
42        oImg.className = 'TB_Button_Padding' ;
43        oImg.src = FCK_SPACER_PATH ;
44        return oImg ;
45}
46
47FCKToolbarButtonUI.prototype.Create = function( parentElement )
48{
49        var oMainElement = this.MainElement ;
50
51        if ( oMainElement )
52        {
53                FCKToolbarButtonUI_Cleanup.call(this) ;
54
55                if ( oMainElement.parentNode )
56                        oMainElement.parentNode.removeChild( oMainElement ) ;
57                oMainElement = this.MainElement = null ;
58        }
59
60        var oDoc = FCKTools.GetElementDocument( parentElement ) ;
61
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 ;
66
67        // The following will prevent the button from catching the focus.
68        if ( FCKBrowserInfo.IsGecko )
69                 oMainElement.onmousedown       = FCKTools.CancelEvent ;
70
71        this.ChangeState( this.State, true ) ;
72
73        if ( this.Style == FCK_TOOLBARITEM_ONLYICON && !this.ShowArrow )
74        {
75                // <td><div class="TB_Button_On" title="Smiley">{Image}</div></td>
76
77                oMainElement.appendChild( this.Icon.CreateIconElement( oDoc ) ) ;
78        }
79        else
80        {
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>
83
84                var oTable = oMainElement.appendChild( oDoc.createElement( 'TABLE' ) ) ;
85                oTable.cellPadding = 0 ;
86                oTable.cellSpacing = 0 ;
87
88                var oRow = oTable.insertRow(-1) ;
89
90                // The Image cell (icon or padding).
91                var oCell = oRow.insertCell(-1) ;
92
93                if ( this.Style == FCK_TOOLBARITEM_ONLYICON || this.Style == FCK_TOOLBARITEM_ICONTEXT )
94                        oCell.appendChild( this.Icon.CreateIconElement( oDoc ) ) ;
95                else
96                        oCell.appendChild( this._CreatePaddingElement( oDoc ) ) ;
97
98                if ( this.Style == FCK_TOOLBARITEM_ONLYTEXT || this.Style == FCK_TOOLBARITEM_ICONTEXT )
99                {
100                        // The Text cell.
101                        oCell = oRow.insertCell(-1) ;
102                        oCell.className = 'TB_Button_Text' ;
103                        oCell.noWrap = true ;
104                        oCell.appendChild( oDoc.createTextNode( this.Label ) ) ;
105                }
106
107                if ( this.ShowArrow )
108                {
109                        if ( this.Style != FCK_TOOLBARITEM_ONLYICON )
110                        {
111                                // A padding cell.
112                                oRow.insertCell(-1).appendChild( this._CreatePaddingElement( oDoc ) ) ;
113                        }
114
115                        oCell = oRow.insertCell(-1) ;
116                        var eImg = oCell.appendChild( oDoc.createElement( 'IMG' ) ) ;
117                        eImg.src        = FCKConfig.SkinPath + 'images/toolbar.buttonarrow.gif' ;
118                        eImg.width      = 5 ;
119                        eImg.height     = 3 ;
120                }
121
122                // The last padding cell.
123                oCell = oRow.insertCell(-1) ;
124                oCell.appendChild( this._CreatePaddingElement( oDoc ) ) ;
125        }
126
127        parentElement.appendChild( oMainElement ) ;
128}
129
130FCKToolbarButtonUI.prototype.ChangeState = function( newState, force )
131{
132        if ( !force && this.State == newState )
133                return ;
134
135        var e = this.MainElement ;
136
137        switch ( parseInt( newState, 10 ) )
138        {
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 ;
144
145                        break ;
146
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 ;
152
153                        break ;
154
155                case FCK_TRISTATE_DISABLED :
156                        e.className             = 'TB_Button_Disabled' ;
157                        e.onmouseover   = null ;
158                        e.onmouseout    = null ;
159                        e.onclick               = null ;
160
161                        break ;
162        }
163
164        this.State = newState ;
165}
166
167function FCKToolbarButtonUI_Cleanup()
168{
169        if ( this.MainElement )
170        {
171                this.MainElement._FCKButton = null ;
172                this.MainElement = null ;
173        }
174}
175
176// Event Handlers.
177
178function FCKToolbarButton_OnMouseOverOn()
179{
180        this.className = 'TB_Button_On_Over' ;
181}
182
183function FCKToolbarButton_OnMouseOutOn()
184{
185        this.className = 'TB_Button_On' ;
186}
187
188function FCKToolbarButton_OnMouseOverOff()
189{
190        this.className = 'TB_Button_Off_Over' ;
191}
192
193function FCKToolbarButton_OnMouseOutOff()
194{
195        this.className = 'TB_Button_Off' ;
196}
197
198function FCKToolbarButton_OnClick( e )
199{
200        if ( this._FCKButton.OnClick )
201                this._FCKButton.OnClick( this._FCKButton ) ;
202}
203
204/*
205        Sample outputs:
206
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>
211
212        These are samples of possible {Image} values:
213
214                Strip - IE version:
215                        <div class="TB_Button_Image"><img src="strip.gif" style="top:-16px"></div>
216
217                Strip : Firefox, Safari and Opera version
218                        <img class="TB_Button_Image" style="background-position: 0px -16px;background-image: url(strip.gif);">
219
220                No-Strip : Browser independent:
221                        <img class="TB_Button_Image" src="smiley.gif">
222*/
Note: See TracBrowser for help on using the repository browser.