Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Minki lub Znaczniki w formularzu
#2
Zadanie błache, ale czeka cię nauka.

1) Wstawiasz do tekstu emoty czyli kombinacje znaków np - Smile, ;-] itp robisz to za pomocą JS np korzystając z poniższej funkcji

Kod:
    function insertTags(tagOpen, tagClose, sampleText) {
        var txtarea;
        txtarea = document.getElementById("jakas_textarea");
        if (document.selection && !is_gecko) {
            var theSelection = document.selection.createRange().text;
            if (!theSelection) {theSelection=sampleText;}
            txtarea.focus();
            if (theSelection.charAt(theSelection.length - 1) == " ") {
                theSelection = theSelection.substring(0, theSelection.length - 1);
                document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
            } else {
                document.selection.createRange().text = tagOpen + theSelection + tagClose;
            }
            // Mozilla
        } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
            var replaced = false;
            var startPos = txtarea.selectionStart;
            var endPos = txtarea.selectionEnd;
            if (endPos-startPos) {replaced = true;}
            var scrollTop = txtarea.scrollTop;
            var myText = (txtarea.value).substring(startPos, endPos);
            if (!myText) {myText=sampleText;}

            var subst;
            if (myText.charAt(myText.length - 1) == " ") {
                subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
            } else {
                subst = tagOpen + myText + tagClose;
            }
            txtarea.value = txtarea.value.substring(0, startPos) + subst +
            txtarea.value.substring(endPos, txtarea.value.length);
            txtarea.focus();

            if (replaced) {
                var cPos = startPos+(tagOpen.length+myText.length+tagClose.length);
                txtarea.selectionStart = cPos;
                txtarea.selectionEnd = cPos;
            } else {
                txtarea.selectionStart = startPos+tagOpen.length;
                txtarea.selectionEnd = startPos+tagOpen.length+myText.length;
            }
            txtarea.scrollTop = scrollTop;
        }
        if (txtarea.createTextRange) {txtarea.caretPos = document.selection.createRange().duplicate();}
    }

2) przy wyswietlaniu tekstu z bacy danych, robisz replace wyszukując podane wyżej ciągi i zamieniając je na odpowiednie obrazki.

Ogólnie jest to banalna sprawa, ale jak powiedziałem - czeka cię nauka. Nauka zapisu do bazy, nauka odczytu z bazy danych i nauka wyszukania i zamiany tekstu (php lub js).
Odpowiedz


Wiadomości w tym wątku
Minki lub Znaczniki w formularzu - przez rafciorb - 05-10-2011, 01:41
RE: Minki lub Znaczniki w formularzu - przez Kartofelek - 05-10-2011, 03:21

Podobne wątki…
Wątek: Autor Odpowiedzi: Wyświetleń: Ostatni post
  [PHP] Problem z załącznikiem w formularzu kontaktowym martinprz 0 1,305 09-10-2012, 02:29
Ostatni post: martinprz

Skocz do:


Użytkownicy przeglądający ten wątek:
Sponsorzy i przyjaciele
SeoHost.pl