mein problem:
obwohl ich nur ein wort markiert habe, wird bei mir immer gleich der gesamte absatz mit dem style-sheet ausgezeichnet.
 
 weiß jemand rat?
matze
 
 Code: Alles auswählen
  function SPAW_style_change(editor, sender)
  {
    classname = sender.options[sender.selectedIndex].value;
    window.frames[editor+'_rEdit'].focus();
    var el = SPAW_getParentTag(editor);
    if (el != null && el.tagName.toLowerCase() != 'body')
    {
      if (classname != 'default')
        el.className = classname;
      else
        el.removeAttribute('className');
    }
    else if (el.tagName.toLowerCase() == 'body')
    {
      if (classname != 'default')
        this[editor+'_rEdit'].document.body.innerHTML = '<P class="'+classname+'">'+this[editor+'_rEdit'].document.body.innerHTML+'</P>';
      else
        this[editor+'_rEdit'].document.body.innerHTML = '<P>'+this[editor+'_rEdit'].document.body.innerHTML+'</P>';
    }
    sender.selectedIndex = 0;
    SPAW_update_toolbar(editor, true);
  }
Code: Alles auswählen
  function SPAW_bold_click(editor, sender)
  {
    window.frames[editor+'_rEdit'].focus();
    this[editor+'_rEdit'].document.execCommand('bold', false, null);
    SPAW_update_toolbar(editor, true);
  }
korrekt, das ist die funktion die man ändern muss...matze hat geschrieben:theoretisch müsste man demnach in der "script.js.php" nur folgende SPAW_style_change(editor, sender) umschreiben, oder?
eben nicht, das wird nicht funktionieren...matze hat geschrieben:also das <p> kann man ja einfach durch <span> ersetzen.
ähm wie du den text bekommst siehst du in der function SPAW_isFoolTag zb mit:matze hat geschrieben:aber wie schaff ich es nur das markierte zu "taggen"? hast du da eine idee?
Code: Alles auswählen
    var trange = this[editor+'_rEdit'].document.selection.createRange();
    var ttext;
    if (trange != null) ttext = SPAW_trim(trange.htmlText);das geht nicht, da innerHTML den kompletten text in textarea umfasst !matze hat geschrieben:(".innerHTML" mit ".execCommand" ersetzen?)
ähm ja...matze hat geschrieben:oder ist das doch schwieriger als ich denke?
Code: Alles auswählen
  // trim functions
  function SPAW_ltrim(txt)
  {
    var spacers = " \t\r\n";
    while (spacers.indexOf(txt.charAt(0)) != -1)
    {
      txt = txt.substr(1);
    }
    return(txt);
  }
  function SPAW_rtrim(txt)
  {
    var spacers = " \t\r\n";
    while (spacers.indexOf(txt.charAt(txt.length-1)) != -1)
    {
      txt = txt.substr(0,txt.length-1);
    }
    return(txt);
  }
  function SPAW_trim(txt)
  {
    return(SPAW_ltrim(SPAW_rtrim(txt)));
  }Code: Alles auswählen
  // trim functions
  function SPAW_ltrim(txt)
  {
    //Match spaces at beginning of text and replace with a null string
    return txt.replace(/^\s+/,'');
  }
  function SPAW_rtrim(txt)
  {
    //Match spaces at end of text and replace with a null string
    return txt.replace(/\s+$/,'');
  }
  function SPAW_trim(txt)
  {
    //Remove spaces at beginning and end of text
    return(SPAW_ltrim(SPAW_rtrim(txt)));
  }Code: Alles auswählen
  function SPAW_style_change(editor, sender)
  {
    classname = sender.options[sender.selectedIndex].value;
    window.frames[editor+'_rEdit'].focus();
    // v2.1 modified version by horwath@opensa.org
    var ttext = "";
    var trange = this[editor+'_rEdit'].document.selection.createRange();
    if (trange != null && this[editor+'_rEdit'].document.selection.type != "Control")
      ttext = SPAW_trim(trange.htmlText);
    var el = SPAW_getParentTag(editor);
    if (ttext == "") { // if no range was selected
      if (el != null && el.tagName.toLowerCase() != 'body')
      {
        if (classname != 'default' && classname != "")
          el.className = classname;
        else
          if (el.tagName.toLowerCase() != 'span')
            el.removeAttribute('className');
          else
            el.removeNode(); // remove span tag
      }
      else if (el.tagName.toLowerCase() == 'body')
      {
        if (classname != 'default' && classname != "")
          this[editor+'_rEdit'].document.body.innerHTML = '<p class="'+classname+'">'+this[editor+'_rEdit'].document.body.innerHTML+'</p>';
        else
          this[editor+'_rEdit'].document.body.innerHTML = '<p>'+this[editor+'_rEdit'].document.body.innerHTML+'</p>';
      }
    } else { // if range was found
      var otext = ttext; // orginal html replacement string
      // remove spans from our ttext
      if (otext.match(/<span[^>]*>/i)) {
        ttext = otext.replace(/<span[^>]*>/i,'');
        ttext = ttext.replace(/<\/span>/i,'');
      }
      if (classname != 'default' && classname != "")
        ttext = '<span class="'+classname+'">'+ttext+'</span>';
      // replace orginal string with our span tag
      this[editor+'_rEdit'].document.body.innerHTML = this[editor+'_rEdit'].document.body.innerHTML.replace(otext,ttext);
    }
    sender.selectedIndex = 0;
    SPAW_update_toolbar(editor, true);
  }
funktioniert tadellos!emergence hat geschrieben: zur funktionsweise:
wenn kein text markiert ist funktioniert es wie bisher
ausnahme:
sollte ein style entfernt werden und das übergeordnete element ist span wird es entfernt.
ebenso wird das style entfernt wenn das value "" ist (bisher war dies nur bei default der fall)
funktioniert nicht ganz! (oder hab ich das falsch verstanden?)emergence hat geschrieben: die andere sache ist simpel...
wenn ein markierter bereich gefunden wird, werden aus diesem string alle span tags entfernt
anschließend wird beim string das eigene style mittels span hinzugefügt...
letzer schritt ist den orginal string mit dem neuen string zu ersetzen...
anmerkung: beim letzten schritt kann es zu problemen kommen wenn der orginalstring mehrfach vorkommt... halte ich aber für unwahrscheinlich...
Code: Alles auswählen
<SPAN class=blau>überschrift blau</SPAN> text rot
Code: Alles auswählen
<SPAN class=rot>überschrift blau text rot</SPAN>
GENIAL!!!emergence hat geschrieben: tja und somit kann man nun im spaw spannen
mit bitte um feedback...

was funktioniert nicht ganz ?matze hat geschrieben:funktioniert nicht ganz! (oder hab ich das falsch verstanden?)
nein eigentlich nicht, man wählt ein anderes style aus dem dropdown aus und das sollte umgestellt werden... (der komplette textblock mit span muss nicht markiert sein)matze hat geschrieben:auch wenn ich die span-area nur erweitern möchte, muss ich vorher immer das alte tag entfernen.
 
 Code: Alles auswählen
  function SPAW_style_change(editor, sender)
  {
    classname = sender.options[sender.selectedIndex].value;
    window.frames[editor+'_rEdit'].focus();
    // v2.2 modified version by horwath@opensa.org
    var ttext = "";
    var trange = this[editor+'_rEdit'].document.selection.createRange();
    if (trange != null && this[editor+'_rEdit'].document.selection.type != "Control")
      ttext = SPAW_trim(trange.htmlText);
    var el = SPAW_getParentTag(editor);
    if (ttext == "") { // if no range was selected
      if (el != null && el.tagName.toLowerCase() != 'body')
      {
        if (classname != 'default' && classname != "")
          el.className = classname;
        else
          if (el.tagName.toLowerCase() != 'span')
            el.removeAttribute('className');
          else
            el.removeNode(); // remove span tag
      }
      else if (el.tagName.toLowerCase() == 'body')
      {
        if (classname != 'default' && classname != "")
          this[editor+'_rEdit'].document.body.innerHTML = '<p class="'+classname+'">'+this[editor+'_rEdit'].document.body.innerHTML+'</p>';
        else
          this[editor+'_rEdit'].document.body.innerHTML = '<p>'+this[editor+'_rEdit'].document.body.innerHTML+'</p>';
      }
    } else { // if range was found
      var otext = ttext; // orginal html replacement string
      if (otext.match(/<span[^>]*>/i)) {
        // remove spans from our ttext
        ttext = ttext.replace(/<span[^>]*>/ig,'');
        ttext = ttext.replace(/<\/span>/ig,'');
      } else {
        // create a unique replacement string for our ttext
        // a single span for any multiple char is possible
        idstr = "556e697175657e537472696e67";
        trange.pasteHTML(idstr);
        otext = idstr;
      }
      if (classname != 'default' && classname != "")
        ttext = '<span class="'+classname+'">'+ttext+'</span>';
      // replace orginal string with our span tag
      this[editor+'_rEdit'].document.body.innerHTML = this[editor+'_rEdit'].document.body.innerHTML.replace(otext,ttext);
    }
    sender.selectedIndex = 0;
    SPAW_update_toolbar(editor, true);
  }Code: Alles auswählen
  function SPAW_style_change(editor, sender)
  {
    classname = sender.options[sender.selectedIndex].value;
    window.frames[editor+'_rEdit'].focus();
    // v2.3 modified version by horwath@opensa.org
    var ttext = "";
    var trange = this[editor+'_rEdit'].document.selection.createRange();
    if (trange != null && this[editor+'_rEdit'].document.selection.type != "Control")
      ttext = trange.htmlText;
    if (SPAW_trim(ttext) == "") { // if no range was selected
      var el = SPAW_getParentTag(editor);
      if (el != null && el.tagName.toLowerCase() != 'body')
      {
        if (classname != 'default' && classname != "")
          el.className = classname;
        else
          if (el.tagName.toLowerCase() != 'span')
            el.removeAttribute('className');
          else
            el.removeNode(); // remove span tag
      }
      else if (el.tagName.toLowerCase() == 'body')
      {
        if (classname != 'default' && classname != "")
          this[editor+'_rEdit'].document.body.innerHTML = '<p class="'+classname+'">'+this[editor+'_rEdit'].document.body.innerHTML+'</p>';
        else
          this[editor+'_rEdit'].document.body.innerHTML = '<p>'+this[editor+'_rEdit'].document.body.innerHTML+'</p>';
      }
    } else { // if range was found
      this[editor+'_rEdit'].document.selection.clear(); // remove selection
      var otext = "556e697175657e537472696e67";         // unique string
      trange.pasteHTML(otext);                          // insert placeholder
      ttext = ttext.replace(/<\/?span[^>]*>/gi,'');     // remove all spans from ttext
      if (classname != 'default' && classname != "")
        ttext = '<span class="'+classname+'">'+ttext+'</span>';
      // replace placeholder string with ttext
      this[editor+'_rEdit'].document.body.innerHTML = this[editor+'_rEdit'].document.body.innerHTML.replace(otext,ttext);
    }
    sender.selectedIndex = 0;
    SPAW_update_toolbar(editor, true);
  }