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 * FCKToolbarPanelButton Class: Handles the Fonts combo selector. 22 */ 23 24var FCKToolbarFontFormatCombo = function( tooltip, style ) 25{ 26 if ( tooltip === false ) 27 return ; 28 29 this.CommandName = 'FontFormat' ; 30 this.Label = this.GetLabel() ; 31 this.Tooltip = tooltip ? tooltip : this.Label ; 32 this.Style = style ? style : FCK_TOOLBARITEM_ICONTEXT ; 33 34 this.NormalLabel = 'Normal' ; 35 36 this.PanelWidth = 190 ; 37 38 this.DefaultLabel = FCKConfig.DefaultFontFormatLabel || '' ; 39} 40 41// Inherit from FCKToolbarSpecialCombo. 42FCKToolbarFontFormatCombo.prototype = new FCKToolbarStyleCombo( false ) ; 43 44FCKToolbarFontFormatCombo.prototype.GetLabel = function() 45{ 46 return FCKLang.FontFormat ; 47} 48 49FCKToolbarFontFormatCombo.prototype.GetStyles = function() 50{ 51 var styles = {} ; 52 53 // Get the format names from the language file. 54 var aNames = FCKLang['FontFormats'].split(';') ; 55 var oNames = { 56 p : aNames[0], 57 pre : aNames[1], 58 address : aNames[2], 59 h1 : aNames[3], 60 h2 : aNames[4], 61 h3 : aNames[5], 62 h4 : aNames[6], 63 h5 : aNames[7], 64 h6 : aNames[8], 65 div : aNames[9] || ( aNames[0] + ' (DIV)') 66 } ; 67 68 // Get the available formats from the configuration file. 69 var elements = FCKConfig.FontFormats.split(';') ; 70 71 for ( var i = 0 ; i < elements.length ; i++ ) 72 { 73 var elementName = elements[ i ] ; 74 var style = FCKStyles.GetStyle( '_FCK_' + elementName ) ; 75 if ( style ) 76 { 77 style.Label = oNames[ elementName ] ; 78 styles[ '_FCK_' + elementName ] = style ; 79 } 80 else 81 alert( "The FCKConfig.CoreStyles['" + elementName + "'] setting was not found. Please check the fckconfig.js file" ) ; 82 } 83 84 return styles ; 85} 86 87FCKToolbarFontFormatCombo.prototype.RefreshActiveItems = function( targetSpecialCombo ) 88{ 89 var startElement = FCK.ToolbarSet.CurrentInstance.Selection.GetBoundaryParentElement( true ) ; 90 91 if ( startElement ) 92 { 93 var path = new FCKElementPath( startElement ) ; 94 var blockElement = path.Block ; 95 96 if ( blockElement ) 97 { 98 for ( var i in targetSpecialCombo.Items ) 99 { 100 var item = targetSpecialCombo.Items[i] ; 101 var style = item.Style ; 102 103 if ( style.CheckElementRemovable( blockElement ) ) 104 { 105 targetSpecialCombo.SetLabel( style.Label ) ; 106 return ; 107 } 108 } 109 } 110 } 111 112 targetSpecialCombo.SetLabel( this.DefaultLabel ) ; 113} 114 115FCKToolbarFontFormatCombo.prototype.StyleCombo_OnBeforeClick = function( targetSpecialCombo ) 116{ 117 // Clear the current selection. 118 targetSpecialCombo.DeselectAll() ; 119 120 var startElement = FCK.ToolbarSet.CurrentInstance.Selection.GetBoundaryParentElement( true ) ; 121 122 if ( startElement ) 123 { 124 var path = new FCKElementPath( startElement ) ; 125 var blockElement = path.Block ; 126 127 for ( var i in targetSpecialCombo.Items ) 128 { 129 var item = targetSpecialCombo.Items[i] ; 130 var style = item.Style ; 131 132 if ( style.CheckElementRemovable( blockElement ) ) 133 { 134 targetSpecialCombo.SelectItem( item ) ; 135 return ; 136 } 137 } 138 } 139} 140