Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> BBCode
Fafu
post
Post #1





Grupa: Zarejestrowani
Postów: 243
Pomógł: 33
Dołączył: 30.01.2008
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Witam,
korzystając z gotowej funkcji insertAtCursor napisałem funkcje która dodaje mi do textarea listę numerowaną. Wszystko ładnie działa tylko chciałbym żeby to dodawało w czasie realnym (tak jak jest w IPB). Niestety nie wiem jakby się za to zabrać :/ Proszę o pomoc.
Kod
function insertAtCursor(txtarea, open, close, newTXT)    {

    if (document.selection) {
        txtSel    = (document.selection.createRange().text)    ? document.selection.createRange().text : newTXT;
        txtarea.focus();
        sel = document.selection.createRange();
        sel.text = open + txtSel + close;
    } else if (txtarea.selectionStart || txtarea.selectionStart == '0') {

        var selLength    = txtarea.textLength;
        var selStart    = txtarea.selectionStart;
        var selEnd        = txtarea.selectionEnd;

        strSelect    = txtarea.value.substr(txtarea.selectionStart, txtarea.selectionEnd - txtarea.selectionStart)
        txtSel        = (strSelect != '')    ? open + strSelect + close : open + newTXT + close;

        newTXT            = txtSel;
        var startPos    = txtarea.selectionStart;
        var endPos        = txtarea.selectionEnd;
        txtarea.value    = txtarea.value.substring(0, startPos)+ newTXT + txtarea.value.substring(endPos, txtarea.value.length);
    } else {
        txtarea.value += newTXT;
    }
}

var list = "[ol]\n";

function list_ordered() {
    var element;
    element = prompt('Wprowadź element listy:');
    if(element) {
        list += "[li]" + element + "[/li]\n";
        list_ordered();
    } else {
        insertAtCursor(document.getElementById('tresc'), list, '[/ol]', '');
        list = "[ol]\n";
    }
}


--------------------
http://rafal.brzezinski.me - skrypty, tutoriale i inne.
Jeśli udało Ci się rozwiązać problem podziękuj osobom, które ci pomogły.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 12:37