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

Revision 1349, 10.5 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 * FCKSpecialCombo Class: represents a special combo.
22 */
23
24var FCKSpecialCombo = function( caption, fieldWidth, panelWidth, panelMaxHeight, parentWindow )
25{
26        // Default properties values.
27        this.FieldWidth         = fieldWidth || 100 ;
28        this.PanelWidth         = panelWidth || 150 ;
29        this.PanelMaxHeight     = panelMaxHeight || 150 ;
30        this.Label                      = ' ' ;
31        this.Caption            = caption ;
32        this.Tooltip            = caption ;
33        this.Style                      = FCK_TOOLBARITEM_ICONTEXT ;
34
35        this.Enabled = true ;
36
37        this.Items = new Object() ;
38
39        this._Panel = new FCKPanel( parentWindow || window, true ) ;
40        this._Panel.AppendStyleSheet( FCKConfig.SkinPath + 'fck_editor.css' ) ;
41        this._PanelBox = this._Panel.MainNode.appendChild( this._Panel.Document.createElement( 'DIV' ) ) ;
42        this._PanelBox.className = 'SC_Panel' ;
43        this._PanelBox.style.width = this.PanelWidth + 'px' ;
44
45        this._PanelBox.innerHTML = '<table cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT: fixed"><tr><td nowrap></td></tr></table>' ;
46
47        this._ItemsHolderEl = this._PanelBox.getElementsByTagName('TD')[0] ;
48
49        if ( FCK.IECleanup )
50                FCK.IECleanup.AddItem( this, FCKSpecialCombo_Cleanup ) ;
51
52//      this._Panel.StyleSheet = FCKConfig.SkinPath + 'fck_contextmenu.css' ;
53//      this._Panel.Create() ;
54//      this._Panel.PanelDiv.className += ' SC_Panel' ;
55//      this._Panel.PanelDiv.innerHTML = '<table cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT: fixed"><tr><td nowrap></td></tr></table>' ;
56//      this._ItemsHolderEl = this._Panel.PanelDiv.getElementsByTagName('TD')[0] ;
57}
58
59function FCKSpecialCombo_ItemOnMouseOver()
60{
61        this.className += ' SC_ItemOver' ;
62}
63
64function FCKSpecialCombo_ItemOnMouseOut()
65{
66        this.className = this.originalClass ;
67}
68
69function FCKSpecialCombo_ItemOnClick()
70{
71        this.className = this.originalClass ;
72
73        this.FCKSpecialCombo._Panel.Hide() ;
74
75        this.FCKSpecialCombo.SetLabel( this.FCKItemLabel ) ;
76
77        if ( typeof( this.FCKSpecialCombo.OnSelect ) == 'function' )
78                this.FCKSpecialCombo.OnSelect( this.FCKItemID, this ) ;
79}
80
81FCKSpecialCombo.prototype.AddItem = function( id, html, label, bgColor )
82{
83        // <div class="SC_Item" onmouseover="this.className='SC_Item SC_ItemOver';" onmouseout="this.className='SC_Item';"><b>Bold 1</b></div>
84        var oDiv = this._ItemsHolderEl.appendChild( this._Panel.Document.createElement( 'DIV' ) ) ;
85        oDiv.className = oDiv.originalClass = 'SC_Item' ;
86        oDiv.innerHTML = html ;
87        oDiv.FCKItemID = id ;
88        oDiv.FCKItemLabel = label || id ;
89        oDiv.FCKSpecialCombo = this ;
90        oDiv.Selected = false ;
91
92        // In IE, the width must be set so the borders are shown correctly when the content overflows.
93        if ( FCKBrowserInfo.IsIE )
94                oDiv.style.width = '100%' ;
95
96        if ( bgColor )
97                oDiv.style.backgroundColor = bgColor ;
98
99        oDiv.onmouseover        = FCKSpecialCombo_ItemOnMouseOver ;
100        oDiv.onmouseout         = FCKSpecialCombo_ItemOnMouseOut ;
101        oDiv.onclick            = FCKSpecialCombo_ItemOnClick ;
102
103        this.Items[ id.toString().toLowerCase() ] = oDiv ;
104
105        return oDiv ;
106}
107
108FCKSpecialCombo.prototype.SelectItem = function( itemId )
109{
110        itemId = itemId ? itemId.toString().toLowerCase() : '' ;
111
112        var oDiv = this.Items[ itemId ] ;
113        if ( oDiv )
114        {
115                oDiv.className = oDiv.originalClass = 'SC_ItemSelected' ;
116                oDiv.Selected = true ;
117        }
118}
119
120FCKSpecialCombo.prototype.SelectItemByLabel = function( itemLabel, setLabel )
121{
122        for ( var id in this.Items )
123        {
124                var oDiv = this.Items[id] ;
125
126                if ( oDiv.FCKItemLabel == itemLabel )
127                {
128                        oDiv.className = oDiv.originalClass = 'SC_ItemSelected' ;
129                        oDiv.Selected = true ;
130
131                        if ( setLabel )
132                                this.SetLabel( itemLabel ) ;
133                }
134        }
135}
136
137FCKSpecialCombo.prototype.DeselectAll = function( clearLabel )
138{
139        for ( var i in this.Items )
140        {
141                this.Items[i].className = this.Items[i].originalClass = 'SC_Item' ;
142                this.Items[i].Selected = false ;
143        }
144
145        if ( clearLabel )
146                this.SetLabel( '' ) ;
147}
148
149FCKSpecialCombo.prototype.SetLabelById = function( id )
150{
151        id = id ? id.toString().toLowerCase() : '' ;
152
153        var oDiv = this.Items[ id ] ;
154        this.SetLabel( oDiv ? oDiv.FCKItemLabel : '' ) ;
155}
156
157FCKSpecialCombo.prototype.SetLabel = function( text )
158{
159        this.Label = text.length == 0 ? '&nbsp;' : text ;
160
161        if ( this._LabelEl )
162        {
163                this._LabelEl.innerHTML = this.Label ;
164
165                // It may happen that the label is some HTML, including tags. This
166                // would be a problem because when the user click on those tags, the
167                // combo will get the selection from the editing area. So we must
168                // disable any kind of selection here.
169                FCKTools.DisableSelection( this._LabelEl ) ;
170        }
171}
172
173FCKSpecialCombo.prototype.SetEnabled = function( isEnabled )
174{
175        this.Enabled = isEnabled ;
176
177        this._OuterTable.className = isEnabled ? '' : 'SC_FieldDisabled' ;
178}
179
180FCKSpecialCombo.prototype.Create = function( targetElement )
181{
182        var oDoc = FCKTools.GetElementDocument( targetElement ) ;
183        var eOuterTable = this._OuterTable = targetElement.appendChild( oDoc.createElement( 'TABLE' ) ) ;
184        eOuterTable.cellPadding = 0 ;
185        eOuterTable.cellSpacing = 0 ;
186
187        eOuterTable.insertRow(-1) ;
188
189        var sClass ;
190        var bShowLabel ;
191
192        switch ( this.Style )
193        {
194                case FCK_TOOLBARITEM_ONLYICON :
195                        sClass = 'TB_ButtonType_Icon' ;
196                        bShowLabel = false;
197                        break ;
198                case FCK_TOOLBARITEM_ONLYTEXT :
199                        sClass = 'TB_ButtonType_Text' ;
200                        bShowLabel = false;
201                        break ;
202                case FCK_TOOLBARITEM_ICONTEXT :
203                        bShowLabel = true;
204                        break ;
205        }
206
207        if ( this.Caption && this.Caption.length > 0 && bShowLabel )
208        {
209                var oCaptionCell = eOuterTable.rows[0].insertCell(-1) ;
210                oCaptionCell.innerHTML = this.Caption ;
211                oCaptionCell.className = 'SC_FieldCaption' ;
212        }
213
214        // Create the main DIV element.
215        var oField = FCKTools.AppendElement( eOuterTable.rows[0].insertCell(-1), 'div' ) ;
216        if ( bShowLabel )
217        {
218                oField.className = 'SC_Field' ;
219                oField.style.width = this.FieldWidth + 'px' ;
220                oField.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" style="TABLE-LAYOUT: fixed;"><tbody><tr><td class="SC_FieldLabel"><label>&nbsp;</label></td><td class="SC_FieldButton">&nbsp;</td></tr></tbody></table>' ;
221
222                this._LabelEl = oField.getElementsByTagName('label')[0] ;               // Memory Leak
223                this._LabelEl.innerHTML = this.Label ;
224        }
225        else
226        {
227                oField.className = 'TB_Button_Off' ;
228                //oField.innerHTML = '<span className="SC_FieldCaption">' + this.Caption + '<table cellpadding="0" cellspacing="0" style="TABLE-LAYOUT: fixed;"><tbody><tr><td class="SC_FieldButton" style="border-left: none;">&nbsp;</td></tr></tbody></table>' ;
229                //oField.innerHTML = '<table cellpadding="0" cellspacing="0" style="TABLE-LAYOUT: fixed;"><tbody><tr><td class="SC_FieldButton" style="border-left: none;">&nbsp;</td></tr></tbody></table>' ;
230
231                // Gets the correct CSS class to use for the specified style (param).
232                oField.innerHTML = '<table title="' + this.Tooltip + '" class="' + sClass + '" cellspacing="0" cellpadding="0" border="0">' +
233                                '<tr>' +
234                                        //'<td class="TB_Icon"><img src="' + FCKConfig.SkinPath + 'toolbar/' + this.Command.Name.toLowerCase() + '.gif" width="21" height="21"></td>' +
235                                        '<td><img class="TB_Button_Padding" src="' + FCK_SPACER_PATH + '" /></td>' +
236                                        '<td class="TB_Text">' + this.Caption + '</td>' +
237                                        '<td><img class="TB_Button_Padding" src="' + FCK_SPACER_PATH + '" /></td>' +
238                                        '<td class="TB_ButtonArrow"><img src="' + FCKConfig.SkinPath + 'images/toolbar.buttonarrow.gif" width="5" height="3"></td>' +
239                                        '<td><img class="TB_Button_Padding" src="' + FCK_SPACER_PATH + '" /></td>' +
240                                '</tr>' +
241                        '</table>' ;
242        }
243
244
245        // Events Handlers
246
247        oField.SpecialCombo = this ;
248
249        oField.onmouseover      = FCKSpecialCombo_OnMouseOver ;
250        oField.onmouseout       = FCKSpecialCombo_OnMouseOut ;
251        oField.onclick          = FCKSpecialCombo_OnClick ;
252
253        FCKTools.DisableSelection( this._Panel.Document.body ) ;
254}
255
256function FCKSpecialCombo_Cleanup()
257{
258        this._LabelEl = null ;
259        this._OuterTable = null ;
260        this._ItemsHolderEl = null ;
261        this._PanelBox = null ;
262
263        if ( this.Items )
264        {
265                for ( var key in this.Items )
266                        this.Items[key] = null ;
267        }
268}
269
270function FCKSpecialCombo_OnMouseOver()
271{
272        if ( this.SpecialCombo.Enabled )
273        {
274                switch ( this.SpecialCombo.Style )
275                {
276                case FCK_TOOLBARITEM_ONLYICON :
277                        this.className = 'TB_Button_On_Over';
278                        break ;
279                case FCK_TOOLBARITEM_ONLYTEXT :
280                        this.className = 'TB_Button_On_Over';
281                        break ;
282                case FCK_TOOLBARITEM_ICONTEXT :
283                        this.className = 'SC_Field SC_FieldOver' ;
284                        break ;
285                }
286        }
287}
288
289function FCKSpecialCombo_OnMouseOut()
290{
291        switch ( this.SpecialCombo.Style )
292        {
293                case FCK_TOOLBARITEM_ONLYICON :
294                        this.className = 'TB_Button_Off';
295                        break ;
296                case FCK_TOOLBARITEM_ONLYTEXT :
297                        this.className = 'TB_Button_Off';
298                        break ;
299                case FCK_TOOLBARITEM_ICONTEXT :
300                        this.className='SC_Field' ;
301                        break ;
302        }
303}
304
305function FCKSpecialCombo_OnClick( e )
306{
307        // For Mozilla we must stop the event propagation to avoid it hiding
308        // the panel because of a click outside of it.
309//      if ( e )
310//      {
311//              e.stopPropagation() ;
312//              FCKPanelEventHandlers.OnDocumentClick( e ) ;
313//      }
314
315        var oSpecialCombo = this.SpecialCombo ;
316
317        if ( oSpecialCombo.Enabled )
318        {
319                var oPanel                      = oSpecialCombo._Panel ;
320                var oPanelBox           = oSpecialCombo._PanelBox ;
321                var oItemsHolder        = oSpecialCombo._ItemsHolderEl ;
322                var iMaxHeight          = oSpecialCombo.PanelMaxHeight ;
323
324                if ( oSpecialCombo.OnBeforeClick )
325                        oSpecialCombo.OnBeforeClick( oSpecialCombo ) ;
326
327                // This is a tricky thing. We must call the "Load" function, otherwise
328                // it will not be possible to retrieve "oItemsHolder.offsetHeight" (IE only).
329                if ( FCKBrowserInfo.IsIE )
330                        oPanel.Preload( 0, this.offsetHeight, this ) ;
331
332                if ( oItemsHolder.offsetHeight > iMaxHeight )
333//              {
334                        oPanelBox.style.height = iMaxHeight + 'px' ;
335
336//                      if ( FCKBrowserInfo.IsGecko )
337//                              oPanelBox.style.overflow = '-moz-scrollbars-vertical' ;
338//              }
339                else
340                        oPanelBox.style.height = '' ;
341
342//              oPanel.PanelDiv.style.width = oSpecialCombo.PanelWidth + 'px' ;
343
344                oPanel.Show( 0, this.offsetHeight, this ) ;
345        }
346
347//      return false ;
348}
349
350/*
351Sample Combo Field HTML output:
352
353<div class="SC_Field" style="width: 80px;">
354        <table width="100%" cellpadding="0" cellspacing="0" style="table-layout: fixed;">
355                <tbody>
356                        <tr>
357                                <td class="SC_FieldLabel"><label>&nbsp;</label></td>
358                                <td class="SC_FieldButton">&nbsp;</td>
359                        </tr>
360                </tbody>
361        </table>
362</div>
363*/
Note: See TracBrowser for help on using the repository browser.