[795] | 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 | |
---|
| 24 | var FCKToolbarStyleCombo = function( tooltip, style ) |
---|
| 25 | { |
---|
| 26 | this.CommandName = 'Style' ; |
---|
| 27 | this.Label = this.GetLabel() ; |
---|
| 28 | this.Tooltip = tooltip ? tooltip : this.Label ; |
---|
| 29 | this.Style = style ? style : FCK_TOOLBARITEM_ICONTEXT ; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | // Inherit from FCKToolbarSpecialCombo. |
---|
| 33 | FCKToolbarStyleCombo.prototype = new FCKToolbarSpecialCombo ; |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | FCKToolbarStyleCombo.prototype.GetLabel = function() |
---|
| 37 | { |
---|
| 38 | return FCKLang.Style ; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | FCKToolbarStyleCombo.prototype.CreateItems = function( targetSpecialCombo ) |
---|
| 42 | { |
---|
| 43 | var oTargetDoc = targetSpecialCombo._Panel.Document ; |
---|
| 44 | |
---|
| 45 | // Add the Editor Area CSS to the panel so the style classes are previewed correctly. |
---|
| 46 | FCKTools.AppendStyleSheet( oTargetDoc, FCKConfig.ToolbarComboPreviewCSS ) ; |
---|
| 47 | oTargetDoc.body.className += ' ForceBaseFont' ; |
---|
| 48 | |
---|
| 49 | // Add ID and Class to the body |
---|
| 50 | if ( FCKConfig.BodyId && FCKConfig.BodyId.length > 0 ) |
---|
| 51 | oTargetDoc.body.id = FCKConfig.BodyId ; |
---|
| 52 | if ( FCKConfig.BodyClass && FCKConfig.BodyClass.length > 0 ) |
---|
| 53 | oTargetDoc.body.className += ' ' + FCKConfig.BodyClass ; |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | // For some reason Gecko is blocking inside the "RefreshVisibleItems" function. |
---|
| 57 | // The problem is present only in old versions |
---|
| 58 | if ( !( FCKBrowserInfo.IsGecko && FCKBrowserInfo.IsGecko10 ) ) |
---|
| 59 | targetSpecialCombo.OnBeforeClick = this.RefreshVisibleItems ; |
---|
| 60 | |
---|
| 61 | // Add the styles to the special combo. |
---|
| 62 | var aCommandStyles = FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( this.CommandName ).Styles ; |
---|
| 63 | for ( var s in aCommandStyles ) |
---|
| 64 | { |
---|
| 65 | var oStyle = aCommandStyles[s] ; |
---|
| 66 | var oItem ; |
---|
| 67 | |
---|
| 68 | if ( oStyle.IsObjectElement ) |
---|
| 69 | oItem = targetSpecialCombo.AddItem( s, s ) ; |
---|
| 70 | else |
---|
| 71 | oItem = targetSpecialCombo.AddItem( s, oStyle.GetOpenerTag() + s + oStyle.GetCloserTag() ) ; |
---|
| 72 | |
---|
| 73 | oItem.Style = oStyle ; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | FCKToolbarStyleCombo.prototype.RefreshActiveItems = function( targetSpecialCombo ) |
---|
| 78 | { |
---|
| 79 | // Clear the actual selection. |
---|
| 80 | targetSpecialCombo.DeselectAll() ; |
---|
| 81 | |
---|
| 82 | // Get the active styles. |
---|
| 83 | var aStyles = FCK.ToolbarSet.CurrentInstance.Commands.GetCommand( this.CommandName ).GetActiveStyles() ; |
---|
| 84 | |
---|
| 85 | if ( aStyles.length > 0 ) |
---|
| 86 | { |
---|
| 87 | // Select the active styles in the combo. |
---|
| 88 | for ( var i = 0 ; i < aStyles.length ; i++ ) |
---|
| 89 | targetSpecialCombo.SelectItem( aStyles[i].Name ) ; |
---|
| 90 | |
---|
| 91 | // Set the combo label to the first style in the collection. |
---|
| 92 | targetSpecialCombo.SetLabelById( aStyles[0].Name ) ; |
---|
| 93 | } |
---|
| 94 | else |
---|
| 95 | targetSpecialCombo.SetLabel('') ; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | FCKToolbarStyleCombo.prototype.RefreshVisibleItems = function( targetSpecialCombo ) |
---|
| 99 | { |
---|
| 100 | if ( FCKSelection.GetType() == 'Control' ) |
---|
| 101 | var sTagName = FCKSelection.GetSelectedElement().tagName ; |
---|
| 102 | |
---|
| 103 | for ( var i in targetSpecialCombo.Items ) |
---|
| 104 | { |
---|
| 105 | var oItem = targetSpecialCombo.Items[i] ; |
---|
| 106 | if ( ( sTagName && oItem.Style.Element == sTagName ) || ( ! sTagName && ! oItem.Style.IsObjectElement ) ) |
---|
| 107 | oItem.style.display = '' ; |
---|
| 108 | else |
---|
| 109 | oItem.style.display = 'none' ; // For some reason Gecko is blocking here. |
---|
| 110 | } |
---|
| 111 | } |
---|