Как форматировать contenteditable div по мере ввода?

Я пытаюсь написать функцию, которая позволяет contenteditable div выполнять автоматическое форматирование, пока пользователь набирает в div. Пока мне удается заставить его работать только в IE. Кто-нибудь может мне помочь?

function formatOnKeyUp(){
    if (window.getSelection) {
        // ???????
    } else if (document.selection) {
        cursorPos=document.selection.createRange().duplicate();
        clickx = cursorPos.getBoundingClientRect().left; 
        clicky = cursorPos.getBoundingClientRect().top;
    }

    text = document.getElementById('div1').innerHTML;
    text = text.replace(/this/gm, "<i>this</i>");
    // .... some other formating here...
    document.getElementById('div1').innerHTML = text;

    if (window.getSelection) {
        // ????????
    } else if (document.selection) {
        cursorPos = document.body.createTextRange();
        cursorPos.moveToPoint(clickx, clicky);
        cursorPos.select();
    }
}
5
задан Marcel Korpel 29 October 2010 в 09:01
поделиться