This is a migrated thread and some comments may be shown as answers.

[Solved] Custom Button

9 Answers 76 Views
RadEditor
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mike
Top achievements
Rank 1
Mike asked on 31 Jul 2006, 09:39 AM

Hi there,

Is it possible to use a custom button into the toolbar?  I wish to add a new button that will insert some javascript that will prompt the user to enter a title for the page??

9 Answers, 1 is accepted

Sort by
0
Lini
Telerik team
answered on 01 Aug 2006, 09:00 AM
Hello Mike,

It is fairly easy to define your own tools in SharePoint. Take a look at the following KB article: http://www.telerik.com/support/knowledge-base/kb-article.aspx?b454K=ehd&b454T=a

Basically, you need to do three things - modify the editor's tools file, add an icon for your new tool, and finally add the script to execute when you click the tool. In a SharePoint environment all these tasks need to be performed in the editor's RadControls folder. In my case this folder was in C:\Inetpub\SharePointRoot\wpresources\RadWebParts\RadControls\Editor\ (note that this location might be different - for example if you have installed the editor in the GAC).

The only tricky part is adding the javascript. Since you don't have a normal editor definition like in the KB article, you need to take a different approach. Create a new js file and put the code for the editor tool inside. Then simply copy the js file to the editor's scripts/modules folder (in my case C:\Inetpub\SharePointRoot\wpresources\RadWebParts\RadControls\Editor\Scripts\5_6_2\Modules\).

If you have any further questions, do not hesitate to ask.

Regards,
Lini
the telerik team
0
Mike
Top achievements
Rank 1
answered on 01 Aug 2006, 09:35 AM

I have added the button into the toolsfile but then what do I need to do?  You say I need to :Create a new js file and put the code for the editor tool inside - what do you mean by that?

All I need it to do is run some JS like this:

<script language="javascript">
<!--
var s = prompt("Enter the title","Default Value");
document.title += " - " +s;
-->
</script>

So that the user can click a button and add the title.

0
Lini
Telerik team
answered on 01 Aug 2006, 10:33 AM
Hello Mike,

As the KB article says, you need to write the script that will be executed when you click on that button.
For example if your custom tool is called "SetDocumentTitle", here is what you should have in your JS file:

RadEditorCommandList["SetDocumentTitle"] = function(commandName, editor, oTool)  
   {        
    var s = prompt("Enter the title","Default Value");   
    document.title += " - " +s;   
   };   

Just put the file in the Editor/Scripts/5_6_2/Modules/ folder and r.a.d.editor will automatically load it the next time you use it.


Kind regards,
Lini
the telerik team
0
Mike
Top achievements
Rank 1
answered on 01 Aug 2006, 10:57 AM

OK I have done exactly as you said and the button now works and calls the JS.  But no code ever actually gets inserted into the editor therefore no page title.  If I view the HTML source of the editor after I have set the page title there is nothing there??

0
Lini
Telerik team
answered on 01 Aug 2006, 11:59 AM
Hello Mike,

I am not sure I understand what is your custom tool supposed to do. If you are trying to display some text on top of the editor's text then perhaps this is the code you are looking for:
    var s = prompt("Enter the title","Default Value");      
    editor.Document.getElementsByTagName("BODY")[0].innerHTML = "<h1>" + s + "</h1>" + editor.Document.getElementsByTagName("BODY")[0].innerHTML;  
 
This code will insert a title at the beginning of the editor's content.

If you are trying to set the title of the whole html document inside the editor, then you only need to look for the "TITLE" element - e.g. editor.Document.getElementsByTagName("TITLE")[0].innerText.

Please be more specific (perhaps a screenshot will help?) and I will try to help you as much as I can.

All the best,
Lini
the telerik team
0
Mike
Top achievements
Rank 1
answered on 01 Aug 2006, 12:11 PM

I am basically trying to set the page title of the whole web part page because by default it does not have one.  Im not too sure how more specific I can be.  But it should work by a user clicking a button and being prompted for the page title and then the relevant code in the actual web part page gets updated?

0
Lini
Telerik team
answered on 01 Aug 2006, 02:48 PM
Hi Mike,

I assume that you are using the editor as a Web Part. In that case the editor loads in a separate modal window. If you want to set the title of the whole page you need to reference the parent of this window - e.g.
window.parent.document.title += " - " +s;

This code will set the title of the whole page, however the change is only on the client side and will not go back to the server. If that suits you then your problem is solved. Otherwise, I am afraid that we cannot help you any further, since communicating the name change to the server and updating it there requires a lot of custom code.

Kind regards,
Lini
the telerik team
0
Mike
Top achievements
Rank 1
answered on 01 Aug 2006, 03:25 PM

So it cant be done basically??  All I want to do is set the title of the webpart page and I assumed it could be done with a custom button?

0
Lini
Telerik team
answered on 02 Aug 2006, 07:06 AM
Hi Mike,

As I said, setting the title of the page by using JavaScript is easy. Unfortunately this change is not persisted on the server - when you leave the page the title will be lost. Your best bet is to look for a custom web part that does this for you and then you can use the button to interact with this webpart and make the change permanent.

Greetings,
Lini
the telerik team
Tags
RadEditor
Asked by
Mike
Top achievements
Rank 1
Answers by
Lini
Telerik team
Mike
Top achievements
Rank 1
Share this question
or