سؤال

How could I implement increase/decrease FontSize buttons for RadEditor control, the new font size should then be refreshed in the <telerik:EditorTool Name="RealFontSize" /> button also included in the RadEditor Toolbar

if Click in increase button, the realfontsize dropdown should increase in 1px as well as the font size of the selected text

for example from the figure if Click in increase button, the realfontsize dropdown should increase in 1px to 17px as well as the font size of the selected text

Update: Thanks to @rdmptn answer : https://stackoverflow.com/a/23365866/432424 I got this first approach function, but I still don´t manage to get the current fontSize of selected text:

Telerik.Web.UI.Editor.CommandList["IncreaseFontSize"] = function (commandName, editor, args) 
{
    if (editor.getSelectionHtml() != "")
    {
        var selection = editor.getSelection();
        var theSelectedElement = selection.getParentElement();
        var currentFontSize = parseInt(theSelectedElement.style.fontSize);
        currentFontSize++;
        editor.fire("FontSize", { value: currentFontSize.toString() }); }); //fire the FontSize command
    }
    else
    {
        alert("Please, select some text!");
        args.set_cancel(true);
    }
};

Update 2: this function works well:

Telerik.Web.UI.Editor.CommandList["IncreaseFontSize"] = function (commandName, editor, args) 
{
    if (editor.getSelectionHtml() != "") 
    {
        var selection = editor.getSelection();
        var theSelectedElement = selection.getParentElement().firstElementChild;
        var currentFontSize = parseInt(theSelectedElement.size);
        currentFontSize++;
        var strNewFontSize = currentFontSize.toString();
        editor.fire("FontSize", { value: strNewFontSize }); //fire the FontSize command    
    }
    else
    {
        alert("Please, select some text!");
        args.set_cancel(true);
    }
};
هل كانت مفيدة؟

المحلول

Here are some resources on doing that:

http://demos.telerik.com/aspnet-ajax/editor/examples/customtools/defaultcs.aspx

http://www.telerik.com/help/aspnet-ajax/editor-adding-your-own-buttons.html

The very first tool in the demo shows how to fire a fontSize change command. Use the selection and your logic to determine the current size and the desired size: http://www.telerik.com/help/aspnet-ajax/editor-getselection.html.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top