2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2010 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
* FCKToolbarPanelButton Class: Handles the Fonts combo selector.
24
var FCKToolbarStyleCombo = function( tooltip, style )
26
if ( tooltip === false )
29
this.CommandName = 'Style' ;
30
this.Label = this.GetLabel() ;
31
this.Tooltip = tooltip ? tooltip : this.Label ;
32
this.Style = style ? style : FCK_TOOLBARITEM_ICONTEXT ;
34
this.DefaultLabel = FCKConfig.DefaultStyleLabel || '' ;
37
// Inherit from FCKToolbarSpecialCombo.
38
FCKToolbarStyleCombo.prototype = new FCKToolbarSpecialCombo ;
40
FCKToolbarStyleCombo.prototype.GetLabel = function()
42
return FCKLang.Style ;
45
FCKToolbarStyleCombo.prototype.GetStyles = function()
48
var allStyles = FCK.ToolbarSet.CurrentInstance.Styles.GetStyles() ;
50
for ( var styleName in allStyles )
52
var style = allStyles[ styleName ] ;
54
styles[ styleName ] = style ;
59
FCKToolbarStyleCombo.prototype.CreateItems = function( targetSpecialCombo )
61
var targetDoc = targetSpecialCombo._Panel.Document ;
63
// Add the Editor Area CSS to the panel so the style classes are previewed correctly.
64
FCKTools.AppendStyleSheet( targetDoc, FCKConfig.ToolbarComboPreviewCSS ) ;
65
FCKTools.AppendStyleString( targetDoc, FCKConfig.EditorAreaStyles ) ;
66
targetDoc.body.className += ' ForceBaseFont' ;
68
// Add ID and Class to the body.
69
FCKConfig.ApplyBodyAttributes( targetDoc.body ) ;
71
// Get the styles list.
72
var styles = this.GetStyles() ;
74
for ( var styleName in styles )
76
var style = styles[ styleName ] ;
78
// Object type styles have no preview.
79
var caption = style.GetType() == FCK_STYLE_OBJECT ?
81
FCKToolbarStyleCombo_BuildPreview( style, style.Label || styleName ) ;
83
var item = targetSpecialCombo.AddItem( styleName, caption ) ;
88
// We must prepare the list before showing it.
89
targetSpecialCombo.OnBeforeClick = this.StyleCombo_OnBeforeClick ;
92
FCKToolbarStyleCombo.prototype.RefreshActiveItems = function( targetSpecialCombo )
94
var startElement = FCK.ToolbarSet.CurrentInstance.Selection.GetBoundaryParentElement( true ) ;
98
var path = new FCKElementPath( startElement ) ;
99
var elements = path.Elements ;
101
for ( var e = 0 ; e < elements.length ; e++ )
103
for ( var i in targetSpecialCombo.Items )
105
var item = targetSpecialCombo.Items[i] ;
106
var style = item.Style ;
108
if ( style.CheckElementRemovable( elements[ e ], true ) )
110
targetSpecialCombo.SetLabel( style.Label || style.Name ) ;
117
targetSpecialCombo.SetLabel( this.DefaultLabel ) ;
120
FCKToolbarStyleCombo.prototype.StyleCombo_OnBeforeClick = function( targetSpecialCombo )
122
// Two things are done here:
123
// - In a control selection, get the element name, so we'll display styles
124
// for that element only.
125
// - Select the styles that are active for the current selection.
127
// Clear the current selection.
128
targetSpecialCombo.DeselectAll() ;
134
var selection = FCK.ToolbarSet.CurrentInstance.Selection ;
136
if ( selection.GetType() == 'Control' )
138
startElement = selection.GetSelectedElement() ;
139
tagName = startElement.nodeName.toLowerCase() ;
143
startElement = selection.GetBoundaryParentElement( true ) ;
144
path = new FCKElementPath( startElement ) ;
147
for ( var i in targetSpecialCombo.Items )
149
var item = targetSpecialCombo.Items[i] ;
150
var style = item.Style ;
152
if ( ( tagName && style.Element == tagName ) || ( !tagName && style.GetType() != FCK_STYLE_OBJECT ) )
154
item.style.display = '' ;
156
if ( ( path && style.CheckActive( path ) ) || ( !path && style.CheckElementRemovable( startElement, true ) ) )
157
targetSpecialCombo.SelectItem( style.Name ) ;
160
item.style.display = 'none' ;
164
function FCKToolbarStyleCombo_BuildPreview( style, caption )
166
var styleType = style.GetType() ;
169
if ( styleType == FCK_STYLE_BLOCK )
170
html.push( '<div class="BaseFont">' ) ;
172
var elementName = style.Element ;
174
// Avoid <bdo> in the preview.
175
if ( elementName == 'bdo' )
176
elementName = 'span' ;
178
html = [ '<', elementName ] ;
180
// Assign all defined attributes.
181
var attribs = style._StyleDesc.Attributes ;
184
for ( var att in attribs )
186
html.push( ' ', att, '="', style.GetFinalAttributeValue( att ), '"' ) ;
190
// Assign the style attribute.
191
if ( style._GetStyleText().length > 0 )
192
html.push( ' style="', style.GetFinalStyleValue(), '"' ) ;
194
html.push( '>', caption, '</', elementName, '>' ) ;
196
if ( styleType == FCK_STYLE_BLOCK )
197
html.push( '</div>' ) ;
199
return html.join( '' ) ;