Hi
I did something like this, here's my code (mind you it's just test code, but it works):
- Code: Select all
var editing = false;
jQuery(function() {
//jQuery(".wymeditor").wymeditor();
//$(document).bind("keyup", show_editable);
$("body").bind("click", disable_editor);
$(".editpane").bind("dblclick", enable_editor);
});
function enable_editor(par1) {
if (!editing) {
hide_editable();
var orig_pane = $(this);
var width = orig_pane.css("width");
var height = orig_pane.css("height");
orig_pane.wymeditor({
html: orig_pane.html(),
postInit: function(wym) { orig_pane.html(wym.xhtml()); wym }
});
$(".wym_box iframe").width(width);
$(".wym_box iframe").height(height);
editing = true;
}
}
function disable_editor() {
if (editing) {
var editor = $.wymeditors(0);
var orig_pane = editor._element;
if (orig_pane.html() != editor.xhtml() && confirm("Save changes?")) {
//$(".editpane").html($.wymeditors(0).xhtml());
orig_pane.html(editor.xhtml());
// -> postback changes
}
orig_pane.css("display", "");
$(".wym_box").remove();
WYM_INSTANCES = new Array(); // reinitialize global instance array
editing = false;
}
}
So the idea is to use the editor as an Ajax widget, when double clicking on the text it get's converted to a WymEditor, by clicking outside of the editor it get's disabled again (setting WYM_INSTANCES directly is a hack obviously but it works only this way)
On disabling edit mode, I compare orig_pane.html() to editor.xhtml(), which yields a save confirm dialog if the user changed anything.
Needs the jQuery Dimensions (needed to adjust the height of the editor to the to-be-edited text) extensions!
br,
Ben