Domanda

Sto cercando di ripulire manualmente l'HTML di un Telerik RadEditor con Javascript ma non riesco a trovare il posto giusto per memorizzare il valore in modo che venga salvato sul post.

Ecco il JS che ho:

$(function () {    
    jQuery.fixHash = function ($html) {      

        // modify $html

        return $html;
    };

    $("#adminEditingArea input[id$='SaveButton']").unbind("click").click(function () {
        $("iframe[id$='_contentIframe']").trigger("save");

        // call .net postback

        return false;
    });

});

var editorSaveEventInit = false;
function InitSaveEvent() {
    if (!editorSaveEventInit) {
        var $EditFrames = $("iframe[id$='_contentIframe']");
        if ($EditFrames && $EditFrames.length > 0) {
            $EditFrames.bind("save", function (e) {
                var $thisFrame = $(this);
                var thisFrameContents = $thisFrame.contents();
                if (thisFrameContents) {
                    var telerikContentIFrame = thisFrameContents.get(0);
                    var $body = $("body", telerikContentIFrame);
                    var html = $.fixHash($body).html();
                    $body.html(html);

                    // also tried storing the modified HTML in the textarea, but it doesn't seem to save:
                    //$thisFrame.prev("textarea").html(encodeURIComponent("<body>" + html + "</body>"));
                }
            });
            editorSaveEventInit = true;
        }
    }
};

$(window).load(function () {
    InitSaveEvent();
});

Esiste un modo per accedere all'oggetto Telerik RadEditor con JavaScript (utilizzando OnClientCommandExecuted () ?) in modo da poter accedere a .get_html () e .set_html (valore) ? In caso contrario, quali valori devo impostare prima di postare indietro?

È stato utile?

Soluzione

Altri suggerimenti

Ah, ho appena scoperto la funzione $ find () integrata di Telerik: http://www.telerik.com/help/aspnet-ajax/editor_getingreferencetoradeditor.html

Modifica: ecco la soluzione che ho trovato per la mia funzione InitSaveEvent () :

var editorSaveEventInit = false;
function InitSaveEvent() {
    if (!editorSaveEventInit) {
        var $EditFrames = $("iframe[id$='_contentIframe']");
        if ($EditFrames && $EditFrames.length > 0) {
            $EditFrames.bind("save", function (e) {
                var $thisFrame = $(this);
                var thisFrameContents = $thisFrame.contents();
                if (thisFrameContents) {
                    var telerikContentIFrame = thisFrameContents.get(0);
                    var $body = $("body", telerikContentIFrame);
                    var html = $.fixHash($body).html();
                    // SOLUTION!
                    var $radeditor = $thisFrame.parents("div.RadEditor.Telerik:eq(0)");
                    var editor = $find($radeditor.attr("id"));
                    editor.set_html(html);
                    // ☺
                }
            });
            editorSaveEventInit = true;
        }
    }
};
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top