Hi,
I need a second combo for a second xml-file. For this I wrote a plugin. With try and errorr for 5 days I got it. But there is a problem. I get the display [object Object] in the dropdownbox after setting a style to a selection. How can I set the label that I select from the dropdown?
Thanks for any help and here is my code:
I need a second combo for a second xml-file. For this I wrote a plugin. With try and errorr for 5 days I got it. But there is a problem. I get the display [object Object] in the dropdownbox after setting a style to a selection. How can I set the label that I select from the dropdown?
Thanks for any help and here is my code:
var FCKDropdownBox = function( name ) { this.Name = name ; } FCKDropdownBox.prototype.Execute = function( itemClass, itemLabel ) { var style = new FCKStyle( itemClass ) ; style.Label = itemLabel.innerHTML ; // that's the name of the label if ( typeof style == 'string' ) style = this.GetStyles()[ style ] ; if ( style ) { if ( style.GetType() == FCK_STYLE_OBJECT ) style.ApplyToObject( FCKSelection.GetSelectedElement() ) ; else style.ApplyToSelection( FCK.EditorWindow ) ; FCKUndo.SaveUndoStep() ; FCK.Events.FireEvent( 'OnSelectionChange' ) ; this.SetLabel( style.Label ) ; // try to set the selected label, but I get [object Object] } //if ( style.IsActive ) // FCKStyles.RemoveStyle( style.Name ) ; }; FCKDropdownBox.prototype.GetState = function() { return; }; FCKCommands.RegisterCommand( 'StyleCombo' , new FCKDropdownBox() ) ; var FCKToolbarStylesCombo = function( tooltip, style ) { this.Command = FCKCommands.GetCommand( 'StyleCombo' ) ; this.CommandName = 'StyleCombo' ; this.Label = this.GetLabel() ; this.Tooltip = tooltip?tooltip:this.Label ; this.Style = style ; }; FCKToolbarStylesCombo.prototype = new FCKToolbarSpecialCombo ; FCKToolbarStylesCombo.prototype.GetLabel = function() { return 'Style' ; }; FCKToolbarStylesCombo.prototype.CreateItems = function() { var stylesXmlPath = FCKConfig.StyleComboXmlPath ; // Load the XML file into a FCKXml object. var xml = new FCKXml() ; xml.LoadUrl( stylesXmlPath ) ; var stylesXmlObj = FCKXml.TransformToObject( xml.SelectSingleNode( 'Styles' ) ) ; // Get the "Style" nodes defined in the XML file. var styleNodes = stylesXmlObj.$Style ; // Add each style to our "Styles" collection. for ( var i = 0 ; i < styleNodes.length ; i++ ) { var styleNode = styleNodes[i] ; var element = ( styleNode.element || '' ).toLowerCase() ; if ( element.length == 0 ) throw( 'The element name is required. Error loading "' + stylesXmlPath + '"' ) ; var styleDef = { Element : element, Attributes : {} } ; // Get the attributes defined for the style (if any). var attNodes = styleNode.$Attribute || [] ; // Add the attributes to the style definition object. for ( var j = 0 ; j < attNodes.length ; j++ ) { styleDef.Attributes[ attNodes[j].name ] = attNodes[j].value ; } // Set styles and labels to the dropdown this._Combo.AddItem( styleDef, styleNode.name ) ; } } FCKToolbarItems.RegisterItem( 'StyleCombo', new FCKToolbarStylesCombo( 'StyleCombo', FCK_TOOLBARITEM_ICONTEXT ) ) ;
Re: How to set label for combo plugin?
- make a plugins folder called stylecombo
- copy the code to the fckplugin.js
- duplicate the file fckstyle.xml and rename it to fckstylecombo.xml
- modify your config:
FCKConfig.Plugins.Add( 'stylecombo' ) ;
FCKConfig.StyleComboXmlPath = FCKConfig.EditorPath + 'fckstylecombo.xml' ;
add 'StyleCombo' to your FCKConfig.ToolbarSets
The plugin works, there is only the problem with display [object Object].