Risultati da 1 a 3 di 3

Discussione: javascript problema con bbcode

  1. #1
    Advanced Member L'avatar di marcobix
    Data Registrazione
    14-06-2005
    Località
    dal nulla
    Messaggi
    568

    javascript problema con bbcode

    Praticamente ho costruito una pagina php contenente una textarea, vorrei che al click su un tag, in javascript il simbolo si mostrasse nella textarea...

    Un pò come in questo form cui stò scrivendo...

    IL mio javascript iniziale è questo...
    Codice PHP:
      echo "
    <SCRIPT LANGUAGE='JavaScript'>
        <!--
        function format_sel(Which) {
          if (document.newentry.message.createTextRange) {
              document.newentry.message.focus();
              document.selection.createRange().duplicate().text = Which;
           } else {
              document.newentry.message.value += Which;
           }
      }
        
        
        //-->
        </SCRIPT> 
    Solo che vorrei che quando sottolineo un testo e clicco su un eventuale javascript, questo mi possa comprendere la parola sottolineata con i due tag di aperto [//] e chiuso .

    Questo code che ho invece appena riportato sopra non mi consente ciò..praticamente anche sottolineo un testo nella textarea e clicco su uno javascript per esempio di grassetto il tag viene inserito sempre all' ultimo della frase...

    Spero sia qualche semplice passo da cambiare....


    Nel frettamepo in giro nel web, in qualche sito di programmazione ho trovato questo codice javascript...

    Codice PHP:
    <!--
    // VARS for detect User Agent function
    var ua navigator.userAgent.toLowerCase(); 
    var 
    browser,version,data
    // detect function
    function detect(text) { 
    stringposition ua.indexOf(text) + 1
    data text
    return 
    stringposition

    //end detect function
    //browser detect function
    if (detect('msie')) {browser 'Internet Explorer';} 
    else if (
    detect('safari')) browser 'Safari'
    else if (
    detect('avant')) browser 'Avant'
    else if (
    detect('firefox')) browser 'Firefox'
    else if (
    detect('opera')) browser 'Opera'
    else if (!
    detect('compatible')) {browser 'Netscape Navigator'version ua.charAt(8);} 
    else 
    browser 'unknown'
    if (!
    versionversion ua.charAt(stringposition data.length); 
    // end browser detect function
    // add simple tags function
    function format_sel(tag) { 
    var 
    range document.getElementById('message');
    var 
    startPos range.selectionStart
    var 
    endPos range.selectionEnd
    var 
    before range.value.substringstartPos ); 
    var 
    after range.value.substringendPos 10000 ); 
    var 
    word range.value.substringstartPosendPos ); 

    if (
    browser == 'Internet Explorer' && version >= 4) { // tested MSIE v 6.0.2800 SP2 
        
    var str document.selection.createRange().text
        
    range.focus(); 
        var 
    sel document.selection.createRange(); 
        
    sel.text '[' tag ']' str '[/' tag ']'
        } else if (
    browser == 'Netscape Navigator' && version >= 5) { // tested Mozilla - 5.0 (Firefox & Netscape Navigator) 
        
    var str '' before '[' tag ']' word '[/' tag ']' after ''
        
    range.value str
        } else if (
    browser == 'Opera' && version >= 8) { // tested Opera 8.0 
        
    var str '' before '[' tag ']' word '[/' tag ']' after ''
        
    range.value str
        } else if (
    browser == 'Firefox' && version >= ) { // tested firefox 0.10 
        
    var str '' before '[' tag ']' word '[/' tag ']' after ''
        
    range.value str
        } else { 
        
    range.value += '[' tag '] [/' tag ']'
        
    alert('Sorry, the quicktags will not work in ' browser ' ' version '.\nTested and Supported browsers are:\n\nInternet Explorer 6\nNetsacpe Navigator 7.2\nFireFox 0.10.1\nOpera 8\n\nTo manually add tags use the format:\n\n[' tag '] your text here [/' tag ']'); 
        } 

    // end add simple tags

    // add URL link function
    function insert_link(tag) { 
        
        var 
    range document.getElementById('message');
        var 
    startPos range.selectionStart
        var 
    endPos range.selectionEnd
        var 
    before range.value.substringstartPos ); 
        var 
    after range.value.substringendPos 10000 ); 
        var 
    word range.value.substringstartPosendPos ); 
        
        if (
    browser == 'Internet Explorer' && version >= 4) { // tested MSIE v 6.0.2800 SP2 
            
    var word document.selection.createRange().text
            
    range.focus(); 
            var 
    my_link prompt('Please enter '+tag+':',''word +'');
            if (
    my_link != '' && my_link != null) { 
                if (
    word == '' || word == null) {
                    var 
    word my_link;
                    }
                var 
    sel document.selection.createRange(); 
                
    sel.text '['+tag+'=' my_link ']' word '[/'+tag+']'
                }
        } else if (
    browser == 'Netscape Navigator' && version >= 5) { // tested Mozilla - 5.0 (Firefox & Netscape Navigator) 
            
    var my_link prompt('Please enter '+tag+':',''word +''); 
            if (
    my_link != '' && my_link != null)  {
                if (
    word == '' || word == null) {
                    var 
    word my_link;
                    }
                var 
    str '' before '['+tag+'=' my_link ']' word '[/'+tag+']' after ''
                
    range.value str
            }
        } else if (
    browser == 'Opera' && version >= 8) { // tested Opera 8.0 
            
    var my_link prompt('Please enter '+tag+':',''word +'');
            if (
    my_link != '' && my_link != null)  {
                if (
    word == '' || word == null) {
                    var 
    word my_link;
                    }
                var 
    str '' before '['+tag+'=' my_link ']' word '[/'+tag+']' after ''
                
    range.value str
            }
        } else if (
    browser == 'Firefox' && version >= ) { // tested firefox 0.10 
            
    var my_link prompt('Please enter '+tag+':',''word +'');
            if (
    my_link != '' && my_link != null)  {
                if (
    word == '' || word == null) {
                    var 
    word my_link;
                    }
                var 
    str '' before '['+tag+'=' my_link ']' word '[/'+tag+']' after '';
                
    range.value str
            }
        } else { 
        
    range.value += '['+tag+'][/'+tag+']'
        
    alert('Sorry, the quicktags will not work in ' browser ' ' version '.\nTested and Supported browsers are:\n\nInternet Explorer 6\nNetsacpe Navigator 7.2\nFireFox 0.10.1\nOpera 8\n\nTo manually add tags use the format:\n\n['+tag+'] YourLinkHere [/'+tag+']'); 
        } 


    // end add URL link function
    // function to perform spell check
    function checkspell() {
        try {
            var 
    tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
            
    tmpis.CheckAllLinkedDocuments(document);
        }
        catch(
    exception) {
            if(
    exception.number==-2146827859) {
                if (
    confirm("ieSpell not detected.  Click Ok to go to download page."))
                    
    window.open("http://www.iespell.com/download.php","DownLoad");
            } else {
                
    alert("Error Loading ieSpell: Exception " exception.number);
            }
        }
    }
    // end function to perform spell check

    // pop up iframes
    function mypopup(elementid) {
        var 
    iframe document.getElementById(''+elementid+'');

        if (
    iframe.style.visibility == "hidden") {
        
    iframe.style.visibility "visible";
        
    iframe.style.display "inline";
        } else {
        
    iframe.style.visibility "hidden";
        
    iframe.style.display "none";
        }    
    }
    // end pop up ifames
    --> 
    Che dovrebbe essere incluso all' esterno...





    Spero di essere stato chiaro su ciò che devo fare....
    Viva Germano Mosconi

  2. #2
    Advanced Member L'avatar di marcobix
    Data Registrazione
    14-06-2005
    Località
    dal nulla
    Messaggi
    568
    oddiu...
    forze un esempio concreto l'ho trovato qui

    come si f&#224;?

    il mio form dovrebbe rifare pi&#249; o meno la stessa cosa....

    Ecco...
    questa stringa....
    Codice PHP:
        <script src="js_quicktags.js" type="text/javascript"></script
    dove la includo?


    Perch&#232; se la includo in alto mi d&#224; degli errori...
    Viva Germano Mosconi

  3. #3
    Advanced Member L'avatar di marcobix
    Data Registrazione
    14-06-2005
    Località
    dal nulla
    Messaggi
    568
    ecco ora riprogrammando alcune stringhe mi sono accorto di una dimenticanza...stupida ma importante

    -Bastava aggiungere al tag di textarea

    Codice PHP:
    id='message' class='txtBox2' 
    Poi circa due righe dopo il famoso javascript di bbcode.js

    Codice PHP:
        <script type='text/JavaScript' 

    src='BBtags.js'></script
    E configurare i vari javascript di action con

    Codice PHP:
        <area shape='rect' coords='3,4,25,24' 

    href=\"javascript:format_sel('b')\" ONFOCUS=\"filter:blur()\"> 
    ora funziona
    Ultima modifica di marcobix; 15-01-2006 alle 16.58.30
    Viva Germano Mosconi

Segnalibri

Permessi di Scrittura

  • Tu non puoi inviare nuove discussioni
  • Tu non puoi inviare risposte
  • Tu non puoi inviare allegati
  • Tu non puoi modificare i tuoi messaggi
  •