import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / classes / fcktoolbarfontformatcombo.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * FCKToolbarPanelButton Class: Handles the Fonts combo selector.\r
22  */\r
23 \r
24 var FCKToolbarFontFormatCombo = function( tooltip, style )\r
25 {\r
26         if ( tooltip === false )\r
27                 return ;\r
28 \r
29         this.CommandName = 'FontFormat' ;\r
30         this.Label              = this.GetLabel() ;\r
31         this.Tooltip    = tooltip ? tooltip : this.Label ;\r
32         this.Style              = style ? style : FCK_TOOLBARITEM_ICONTEXT ;\r
33 \r
34         this.NormalLabel = 'Normal' ;\r
35 \r
36         this.PanelWidth = 190 ;\r
37 \r
38         this.DefaultLabel = FCKConfig.DefaultFontFormatLabel || '' ;\r
39 }\r
40 \r
41 // Inherit from FCKToolbarSpecialCombo.\r
42 FCKToolbarFontFormatCombo.prototype = new FCKToolbarStyleCombo( false ) ;\r
43 \r
44 FCKToolbarFontFormatCombo.prototype.GetLabel = function()\r
45 {\r
46         return FCKLang.FontFormat ;\r
47 }\r
48 \r
49 FCKToolbarFontFormatCombo.prototype.GetStyles = function()\r
50 {\r
51         var styles = {} ;\r
52 \r
53         // Get the format names from the language file.\r
54         var aNames = FCKLang['FontFormats'].split(';') ;\r
55         var oNames = {\r
56                 p               : aNames[0],\r
57                 pre             : aNames[1],\r
58                 address : aNames[2],\r
59                 h1              : aNames[3],\r
60                 h2              : aNames[4],\r
61                 h3              : aNames[5],\r
62                 h4              : aNames[6],\r
63                 h5              : aNames[7],\r
64                 h6              : aNames[8],\r
65                 div             : aNames[9] || ( aNames[0] + ' (DIV)')\r
66         } ;\r
67 \r
68         // Get the available formats from the configuration file.\r
69         var elements = FCKConfig.FontFormats.split(';') ;\r
70 \r
71         for ( var i = 0 ; i < elements.length ; i++ )\r
72         {\r
73                 var elementName = elements[ i ] ;\r
74                 var style = FCKStyles.GetStyle( '_FCK_' + elementName ) ;\r
75                 if ( style )\r
76                 {\r
77                         style.Label = oNames[ elementName ] ;\r
78                         styles[ '_FCK_' + elementName ] = style ;\r
79                 }\r
80                 else\r
81                         alert( "The FCKConfig.CoreStyles['" + elementName + "'] setting was not found. Please check the fckconfig.js file" ) ;\r
82         }\r
83 \r
84         return styles ;\r
85 }\r
86 \r
87 FCKToolbarFontFormatCombo.prototype.RefreshActiveItems = function( targetSpecialCombo )\r
88 {\r
89         var startElement = FCK.ToolbarSet.CurrentInstance.Selection.GetBoundaryParentElement( true ) ;\r
90 \r
91         if ( startElement )\r
92         {\r
93                 var path = new FCKElementPath( startElement ) ;\r
94                 var blockElement = path.Block ;\r
95 \r
96                 if ( blockElement )\r
97                 {\r
98                         for ( var i in targetSpecialCombo.Items )\r
99                         {\r
100                                 var item = targetSpecialCombo.Items[i] ;\r
101                                 var style = item.Style ;\r
102 \r
103                                 if ( style.CheckElementRemovable( blockElement ) )\r
104                                 {\r
105                                         targetSpecialCombo.SetLabel( style.Label ) ;\r
106                                         return ;\r
107                                 }\r
108                         }\r
109                 }\r
110         }\r
111 \r
112         targetSpecialCombo.SetLabel( this.DefaultLabel ) ;\r
113 }\r
114 \r
115 FCKToolbarFontFormatCombo.prototype.StyleCombo_OnBeforeClick = function( targetSpecialCombo )\r
116 {\r
117         // Clear the current selection.\r
118         targetSpecialCombo.DeselectAll() ;\r
119 \r
120         var startElement = FCK.ToolbarSet.CurrentInstance.Selection.GetBoundaryParentElement( true ) ;\r
121 \r
122         if ( startElement )\r
123         {\r
124                 var path = new FCKElementPath( startElement ) ;\r
125                 var blockElement = path.Block ;\r
126 \r
127                 for ( var i in targetSpecialCombo.Items )\r
128                 {\r
129                         var item = targetSpecialCombo.Items[i] ;\r
130                         var style = item.Style ;\r
131 \r
132                         if ( style.CheckElementRemovable( blockElement ) )\r
133                         {\r
134                                 targetSpecialCombo.SelectItem( item ) ;\r
135                                 return ;\r
136                         }\r
137                 }\r
138         }\r
139 }\r