Alterar o valor de um Telerik RadEditor com Javascript / jQuery
-
22-07-2019 - |
Pergunta
Eu estou tentando limpar manualmente o HTML de um RadEditor Telerik com Javascript, mas eu não consigo encontrar o local correto para armazenar o valor para que ele seja salvo em volta post.
Aqui está o JS eu tenho:
$(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();
});
Existe alguma maneira para acessar o objeto Telerik RadEditor com JavaScript (usando OnClientCommandExecuted()
?) Para que eu possa acessar as funções .get_html()
e .set_html(value)
? Se não, quais os valores que eu preciso para set antes de postagem de volta?
Solução
Por que você não usar costume filtros de conteúdo .
Outras dicas
Ah, só descobriu do Telerik built-in função $find()
: http: // www.telerik.com/help/aspnet-ajax/editor_getingreferencetoradeditor.html
Edit: aqui está a solução que eu vim com a minha função 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;
}
}
};