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

getToolByName() semms to return only nulls

2 Answers 64 Views
WebParts for SharePoint
This is a migrated thread and some comments may be shown as answers.
Nils
Top achievements
Rank 1
Nils asked on 05 Dec 2012, 06:48 AM
Hi,
in some pages I need to hide Tool-Buttons from a RadEditor.
So I attached an OnClientLoad function and in there wanted to remove the Tools.
But editor.getToolByName seems to always return null.
I am using a ToolBarMode of "Floating" could it be, that getToolByName only works when the Toolbar is visible?

Best,
Nils

2 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 06 Dec 2012, 11:12 AM
Hi Nils,

Here is an example how to get reference to a tool in RadWindow based toolbar:

<telerik:RadEditor runat="server" ID="RadEditor1" ToolbarMode="ShowOnFocus" OnClientLoad="OnClientLoad"></telerik:RadEditor>
<script type="text/javascript">
    function OnClientLoad(editor) {
        var wnd = editor.get_toolAdapter().get_window();
        wnd.add_show(function () {
            setTimeout(function () {
                var tool = editor.getToolByName("RealFontSize");
                tool.set_value("13px");
            }, 100);
        });
    }
</script>

If you work in SharePoint environment, see this article: Using RadEditor's Client-Side events in SharePoint 2010.


Regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Nils
Top achievements
Rank 1
answered on 11 Dec 2012, 08:58 AM
Thanks Rumen,
I have now the following up-and-running. (TypeScript-Code)
    export class RadEditor  {
        public static ClientLoaded(editor, args) {           
            console.info("RadEditor loaded: " + editor.get_id());
            var wnd = (<Telerik.Web.UI.RadEditor>editor).get_toolAdapter().get_window();
            wnd.add_show(() => {
                if (ShouldHideButtons()) {
                    setTimeout(() => {
                        $.each(
                        [
                            "EditReusableContent",
                            "MedInsertCT",
                            "SPTemplateManager"
                        ], (i, name) => {
                            var tool = <Telerik.Web.UI.EditorButton>editor.getToolByName(name);
                            if (!tool)
                                return;
                            //tool.set_enabled(false);
                            //tool.setState(-1);
                            tool.set_visible(false);
                            console.info(name + " hidden in " + editor.get_id());
                        })
                    }, 100);
                }
            });
         }
//... rest...
}

or in JavaScript:
        var RadEditor = (function () {
            function RadEditor() { }
            RadEditor.ClientLoaded = function ClientLoaded(editor, args) {
                console.info("RadEditor loaded: " + editor.get_id());
                var wnd = (editor).get_toolAdapter().get_window();
                wnd.add_show(function () {
                    if(ShouldHideButtons()) {
                        setTimeout(function () {
                            $.each([
                                "EditReusableContent",
                                "MedInsertCT",
                                "SPTemplateManager"
                            ], function (i, name) {
                                var tool = editor.getToolByName(name);
                                if(!tool) {
                                    return;
                                }
                                //tool.set_enabled(false);
                                //tool.setState(-1);
                                tool.set_visible(false);
                                console.info(name + " hidden in " + editor.get_id());
                            });
                        }, 100);
                    }
                });
            }
           // ... rest...
}

Where RadEditor.ClientLoaded is set as the OnClientLoad-Function.
Thanks again.

Best, Nils
Tags
WebParts for SharePoint
Asked by
Nils
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Nils
Top achievements
Rank 1
Share this question
or