Menu

#3 Some errors in function addTag().

open
nobody
None
5
2002-07-15
2002-07-15
No

There was an error in the "function addTag()", so it was
not possible to change the style to news HTML-Tag like
<h1>, <h2>, <p> etc. Sometimes this function couldn't
add a new HTML-Tag, it puts the new HTML-Tag
between other tags like this: <p><h1>This is a
headline</h1></p>.
With a little modification of "function addTag()" it will be
fixed (copy and paste it to your rte.js -file):

/* addTag():
This is the handler for the style dropdown. This takes
value selected and interprates it
and makes the necessary changes to the HTML to
apply this style.*/
function addTag(obj){
if(!RichEditor.txtView) return; /* Disabled in View
Source mode */
/* Determine the type of element we are dealing with.
TYPE 0 IS NORMAL-TAG, 1 IS CLASS, 2 IS
SUBCLASS, 3 = Format Block command */
var value = obj[obj.selectedIndex].value;
if(!value){ sel(obj); return; } /* Format Block */
var type = 0; /* TAG */
if (value.indexOf(".") == 0){
/* .className */
type = 1;
}else if(value.indexOf(".") != -1){ /*
TAG.className */
type = 2;
}
doc.focus();
/* Pick up the highlighted text */
var r = document.selection.createRange();
r.select();
var s = r.htmlText;
var el = r.parentElement();
/* Is this aready a TAG? // Add by M. Keck 02/07/12 */
if((el && el.nodeName == "P" && el.nodeName!
="PRE")||(el && el.nodeName == "H1") || (el &&
el.nodeName == "H2") || (el && el.nodeName == "H3") ||
(el && el.nodeName == "H4") || (el && el.nodeName
== "H5") || (el && el.nodeName == "H6") || (el &&
el.nodeName == "PRE")){
r.moveToElementText(el);
alignment=el.align;
if(alignment){
alignstr=" align=\""+alignment+"\"";
}else{
alignstr=" align=\"left\"";
}
r.pasteHTML(""); removeEmptyTags;
r.pasteHTML
("<"+value+alignstr+">"+s+"</"+value+">");
saveHistory(); return;
}else{
/* If we have some selected text, then ignore silly
selections */
//if (s == " " || s == " ") { return; }
/* How we apply formatting is based upon the type of
formitting being done. */
switch(type){
case 1:
/* class: Wrap the selected text with a span of the
specified class name */
value = value.substring(1,value.length);
r.pasteHTML("<span class="+value+">" +
r.htmlText + "</span>");
break;
case 2:
/* subclass: split the value into tag + class */
value = value.split(".");
r.pasteHTML('<' + value[0] + ' class="' + value[1]
+'">'+ r.htmlText + '</' + value[0] + '>');
break;
default:
/* TAG: wrap up the highlighted text with the
specified tag */
r.pasteHTML
("<"+value+">"+r.htmlText+"</"+value+">");
break;
}
}
saveHistory(); /* Record undo information */
}

Discussion

  • Michael Keck

    Michael Keck - 2002-07-15

    function addTag()

     
  • Nobody/Anonymous

    Logged In: NO

    It doesn''t work at all!

     

Log in to post a comment.