My complete solution for SharePoint 2013 - style ribbon-based rich-text editor. I made this some time ago, so I certainly borrowed some code from google.
ASPX / ASCX:
<div id="editor">
<div id="RTEDiv" tabindex="0"></div>
<asp:HiddenField ID="RTEDivHidden" runat="server" />
<div class="commands">
<asp:Button ID="btnSubmit" Text="Submit" runat="server" CssClass="editorbtn" />
<input type="button" value="Cancel" id="btnCancel" class="editorbtn" />
</div>
</div>
Simple div container, future rich text div id="RTEDiv"
, hidden field to post data and two simple buttons.
JS:
(function ($) {
// add SP13 rich text params to div
$.fn.SPEditable = function () {
return this.each(function () {
$(this).addClass("ms-rte-layoutszone-inner-editable ms-rtestate-write").attr("role", "textbox").attr("aria-haspopup", "true").attr("contentEditable", "true").attr("aria-autocomplete", "both").attr("aria-autocomplete", "both").attr("aria-multiline", "true");
});
};
// remove SP13 rich text params from div
$.fn.SPNonEditable = function () {
return this.each(function () {
$(this).removeClass("ms-rte-layoutszone-inner-editable ms-rtestate-write").removeAttr("role aria-haspopup contentEditable aria-autocomplete aria-multiline");
});
};
// add event actions before existing ones
$.fn.preBind = function (type, data, fn) {
this.each(function () {
var $this = $(this);
$this.bind(type, data, fn);
var currentBindings = $._data(this, "events")[type];
if ($.isArray(currentBindings)) {
currentBindings.unshift(currentBindings.pop());
}
});
return this;
};
})(jQuery);
preBind
function is used for transfer rich-text data to hidden field on before submit (usage below). Then use this:
// Rich Edit start
// mark div as Ribbon enabled rich edit area
$("#RTEDiv").SPEditable();
// transfer data from rich edit div to hidden field
$("input[id$='btnSubmit']").preBind("click", function () {
var rText = $("#RTEDiv").html();
$("input[id$='RTEDivHidden']").val(rText);
});
Codebehind:
And the main part. In codebehind you have to do this:
protected void Page_Load(object sender, EventArgs e)
{
// tweak SPRibbon to show RichEdit
SPRibbon current = SPRibbon.GetCurrent(this.Page);
if (current != null)
{
current.MakeRTEContextualTabsAvailable(SPRibbon.RTEVisibilityContext);
current.Visible = true;
current.CommandUIVisible = true;
}
if (IsPostBack)
{
var body = RTEDivHidden.Value;
if (!string.IsNullOrWhiteSpace(body))
{
// now you have pure HTML value of rich-text
}
}
}
To write something in rich-text div use this in JS:
$('#RTEDiv').html("<b>pure html text</b>");
And final result (sorry for lots of russian stuff):

Rich edit part of Ribbon correctly slides down and up, when you set of remove focus from rich-text div.
Hope this will help!