I have a few custom buttons that will place the selected text into a <span> element. Each button creates a span with a different id and style. When the span text is later clicked on, I would like for the corresponding button to toggle, or change its state to FCK_TRISTATE_ON.
I have searched for days in the code but I can't find this: where does fckeditor change the state of the bold button when you click on bold text. I figured I could use that as a starting point for making my functionality work. I have also searched the boards. I found a post that mentioned setting the toolbar item to ContextSensitive, and I have done that. However, this particular post suggested using this with an ExecuteNamedCommand function. I am using a custom command with a span tag instead of a <b> tag, so this may be a bit trickier.
Somewhere I need to grab the selected text, see if its element has my id, and then toggle the button if it does. Make sense?
If anybody can point me in the right direction I would really appreciate it.
Thanks!
I have searched for days in the code but I can't find this: where does fckeditor change the state of the bold button when you click on bold text. I figured I could use that as a starting point for making my functionality work. I have also searched the boards. I found a post that mentioned setting the toolbar item to ContextSensitive, and I have done that. However, this particular post suggested using this with an ExecuteNamedCommand function. I am using a custom command with a span tag instead of a <b> tag, so this may be a bit trickier.
Somewhere I need to grab the selected text, see if its element has my id, and then toggle the button if it does. Make sense?
If anybody can point me in the right direction I would really appreciate it.
Thanks!

Re: Make Button State Toggle when Select Text
//add code here function FCKButton_Check() { alert("hello"); } //adding to fck when selection changes FCK.AttachToOnSelectionChange( FCKButton_Check ) ; function FCKButton_SetListeners() { FCK.EditorWindow.attachEvent( 'onclick', FCKButton_Check ) ; } if ( FCKBrowserInfo.IsIE ) { FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKButton_SetListeners ) ; }Re: Make Button State Toggle when Select Text
Re: Make Button State Toggle when Select Text
Here's example code for GetState:
SourceCommand.prototype.GetState=function() { var parentNode = getParent(); var id = null; if(parentNode != null){ id = parentNode.id; } if(id != null && id == "source"){ return FCK_TRISTATE_ON; } return FCK_TRISTATE_OFF; }To get the parent worked fine in mozilla but not so much in IE because that method is looking for the type "Control", which my parent is not. So here is my getParent method:
function getParent() { //works fine in mozilla, but returns nothing in ie because not a type "Control" var parentNode = FCKSelection.GetParentElement(); //in ie if(parentNode == null) { parentNode = FCK.EditorDocument.selection.createRange().parentElement(); } return parentNode; }Re: Make Button State Toggle when Select Text
After that you can check if oSelection exists and if it has the id you're searching for.