Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    problema di formattazione textarea

    Ho un problema. Ho una textarea chiamata input_txt. In questa c'è un testo in formato html che viene visualizzato correttamente. Vorrei decidere che parte del testo selezionato diventa bold o, se è già bold, torni normale. Il codice seguente funziona perfettamente.

    Codice PHP:
    function doBold():Void {
        var 
    startIndex:Number Selection.getBeginIndex();
        var 
    endIndex:Number Selection.getEndIndex();
        
        var 
    stringToBold:String input_txt.text.substring(startIndexendIndex);
        
        
    //verifico se la selezione è già bold
        
    currentFormat input_txt.getTextFormat(startIndexendIndex);    
        if (
    currentFormat.bold == true) {
            
    input_txt.replaceText(startIndexendIndex"[/b]"+stringToBold+"[b]");
        }
        else {
            
    input_txt.replaceText(startIndexendIndex"[b]"+stringToBold+"[/b]");
        }    
        
    input_txt.htmlText input_txt.text;
        
        
    input_txt_simple.text input_txt.htmlText;

    Il problema è che se il testo ha anche altre formattazioni (parti in bold, parti in corsivo, link e colori), queste vengono perse, e si vede solo il bold appena applicato!!!!
    E non posso applicare un altro bold altrimenti perdo il bold eventualmente applicato in un'altra parte di testo precedentemente...

    come si può fare?
    :master:
    Rey
    La vita è un panaro, non sai mai quello che ti esce!
    photorealistic 3D rendering and animations and WEB Design

  2. #2
    Dopo un sacco di ricerca ed un sacco di studio sono riuscito a trovare e modificare questo script...

    Codice PHP:
    System.useCodepage true;


    my_txt prova;
    my_txt_simple provatesto;

    my_txt.border true;
    my_txt.wordWrap true;
    my_txt.multiline true;
    my_txt.type "input";
    my_txt.html true;

    //CSS
    //var styles:TextField.StyleSheet = new TextField.StyleSheet();
    //styles.onLoad = function(success:Boolean):Void {
       // if (success) {
            // visualizza i nomi stile.
            //trace(this.getStyleNames());
            //my_txt.styleSheet = styles;
        //} else {
            //trace("Error loading CSS file.");
        //}
    //};
    //styles.load("html_styles.css");

    my_txt.htmlText "[url='#']Prova di formattazione[/url] speriamo[b]che funzioni tutto[/b] mamma mia...";

    var 
    my_cm:ContextMenu = new ContextMenu();
    my_cm.customItems.push(new ContextMenuItem("Grassetto"formattaHTML));
    my_cm.customItems.push(new ContextMenuItem("Corsivo"formattaHTML));
    my_cm.customItems.push(new ContextMenuItem("Sottolineato"formattaHTML));
    my_cm.customItems.push(new ContextMenuItem("Link"formattaHTML));
    //my_cm.customItems.push(new ContextMenuItem("Inserisci immagine...", formattaHTML));

    function formattaHTML(obj:ObjectmenuItem:ContextMenuItem) {
      var 
    mnuItem:String menuItem.caption;
      var 
    testoHtml:String my_txt.htmlText;
      var 
    testo:String my_txt.text;
      var 
    ltxth:Number testoHtml.length;
      var 
    ltxt:Number testo.length;
      var 
    inizioSel:Number Selection.getBeginIndex();//Inizio selezione;
      
    var fineSel:Number Selection.getEndIndex();//Fine selezione;
      
    var selezione:String testo.substring(inizioSel,fineSel);//testo selezionato NON HTML
      
    var inizioSelh:Number=testoHtml.indexOf(selezione);//Inizio selezione nel testo HTML
      
    var fineSelh:Number=inizioSelh+selezione.length;
      var 
    selezioneh:String testoHtml.substring(inizioSelh,fineSelh)//testo selezionato HTML
      
    var prima:String testoHtml.substring(0,inizioSelh);//Testo HTML prima della selezione
      
    var dopo:String testoHtml.substring(fineSelh);//Testo HTML dopo della selezione
      
    switch (mnuItem){
      case 
    "Sottolineato":
          
    currentFormat my_txt.getTextFormat(inizioSelfineSel);    
            if (
    currentFormat.underline == true) {
                
    tagA="</u>";
                
    tagB="<u>";        
            } else {
                
    tagA="<u>";
                
    tagB="</u>";
            }    
          break;
      case 
    "Corsivo":
          
    currentFormat my_txt.getTextFormat(inizioSelfineSel);    
            if (
    currentFormat.italic == true) {
                
    tagA="[/i]";
                
    tagB="[i]";        
            } else {
                
    tagA="[i]";
                
    tagB="[/i]";
            }    
          break;
      case 
    "Link":
          
    currentFormat my_txt.getTextFormat(inizioSelfineSel);    
            if (
    currentFormat.underline == true) {
                
    tagA="";
                
    tagB="";        
            } else {
                
    tagA="<a href='testo da apporre' target='_blank'>";
                
    tagB="</a>";
            }    
          break;
      case 
    "Grassetto":
          
    currentFormat my_txt.getTextFormat(inizioSelfineSel);    
        if (
    currentFormat.bold == true) {
            
    tagA="[/b]";
              
    tagB="[b]";        
        } else {
            
    tagA="[b]";
              
    tagB="[/b]";
        }    
        break;
      
      }
      
    my_txt.htmlText prima tagA selezioneh tagB dopo;
      
    my_txt_simple.text my_txt.htmlText;
    }
    my_txt.menu my_cm
    Riuscirei a fare quello che mi serve, ma ho visto che a volte va, a volta fa casino... per esempio:

    se il testo è:
    "Prova di formattazione speriamoche funzioni tutto mamma mia..."
    e cioè: "Prova di formattazione speriamo che funzioni tutto mamma mia..."
    se seleziono precisamente "che funzioni tutto " (con lo spazio alla fine) e do un comando qualsiasi (o bold di nuovo, o sottoelineato per esempio) mi scompare tutto il testo della textarea.
    E lo stesso succede se seleziono "Prova di formattazione s"
    Mentre se sto molto attento a quello che clicco, con molto ordine, per il 95% dei casi funziona... perchè e come risolvo?
    Rey
    La vita è un panaro, non sai mai quello che ti esce!
    photorealistic 3D rendering and animations and WEB Design

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.