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