我工作的一个跨浏览器基于网络的注解工具集,它允许用户选择网页HTML注释(选择,高亮,删除格式)
HIGHLIGHT的任何部分,如果您选择:
约翰大< /李> 转储< /李>
结果
john is
big dump删除格式:如果您选择:
john
从
john is
big dump结果
john is
big dump撤销/重做:好的,有特色
为了能够撤销和重做动作进行
我有一个部分解决了突出
function highlight(colour) {
var range, sel;
if (document.selection && (!window.getSelection)) {
// IE case
range = document.selection.createRange();
range.execCommand("BackColor", false, colour);
} else if (window.getSelection) {
// Non-IE case
sel = window.getSelection();
if (sel.getRangeAt) {
range = sel.getRangeAt(0);
}
//without designmode=on, you can't highlight the selected html (chrome)
document.designMode = "on";
if (range) {
sel.removeAllRanges();
sel.addRange(range);
}
// HiliteColor avoids FF3.5 from painting the background of the whole block
if (!document.execCommand("HiliteColor", false, colour)) {
document.execCommand("BackColor", false, colour);
}
document.designMode = "off";
}
}
因为我的需求与richtext编辑器有很多相似之处,所以我在google关闭编辑器中查看ckeditor的代码和(广泛地)要么。我已经放弃了希望,因为他们只在可编辑的iframe中工作。我的要求之一是不允许用户更改原始文本,但只能添加自己的注释(高亮显示,内联注释等)。
我很想在这里把你所有的意见都告诉我,如果可能的话,指点一下正确的方向。
--Choesang